Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit 0f9d240

Browse files
committed
Add an example prompt for summarizing notes
1 parent 837a5c8 commit 0f9d240

1 file changed

Lines changed: 63 additions & 2 deletions

File tree

template/src/index.ts.ejs

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* - Listing notes as resources
55
* - Reading individual notes
66
* - Creating new notes via a tool
7+
* - Summarizing all notes via a prompt
78
*/
89

910
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
@@ -13,6 +14,8 @@ import {
1314
ListResourcesRequestSchema,
1415
ListToolsRequestSchema,
1516
ReadResourceRequestSchema,
17+
ListPromptsRequestSchema,
18+
GetPromptRequestSchema,
1619
} from "@modelcontextprotocol/sdk/types.js";
1720

1821
/**
@@ -30,8 +33,8 @@ const notes: { [id: string]: Note } = {
3033
};
3134

3235
/**
33-
* Create an MCP server with capabilities for resources (to list/read notes)
34-
* and tools (to create new notes).
36+
* Create an MCP server with capabilities for resources (to list/read notes),
37+
* tools (to create new notes), and prompts (to summarize notes).
3538
*/
3639
const server = new Server(
3740
{
@@ -42,6 +45,7 @@ const server = new Server(
4245
capabilities: {
4346
resources: {},
4447
tools: {},
48+
prompts: {},
4549
},
4650
}
4751
);
@@ -144,6 +148,63 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
144148
}
145149
});
146150

151+
/**
152+
* Handler that lists available prompts.
153+
* Exposes a single "summarize_notes" prompt that summarizes all notes.
154+
*/
155+
server.setRequestHandler(ListPromptsRequestSchema, async () => {
156+
return {
157+
prompts: [
158+
{
159+
name: "summarize_notes",
160+
description: "Summarize all notes",
161+
}
162+
]
163+
};
164+
});
165+
166+
/**
167+
* Handler for the summarize_notes prompt.
168+
* Returns a prompt that requests summarization of all notes, with the notes' contents embedded as resources.
169+
*/
170+
server.setRequestHandler(GetPromptRequestSchema, async (request) => {
171+
if (request.params.name !== "summarize_notes") {
172+
throw new Error("Unknown prompt");
173+
}
174+
175+
const embeddedNotes = Object.entries(notes).map(([id, note]) => ({
176+
type: "resource" as const,
177+
resource: {
178+
uri: `note:///${id}`,
179+
mimeType: "text/plain",
180+
text: note.content
181+
}
182+
}));
183+
184+
return {
185+
messages: [
186+
{
187+
role: "user",
188+
content: {
189+
type: "text",
190+
text: "Please summarize the following notes:"
191+
}
192+
},
193+
...embeddedNotes.map(note => ({
194+
role: "user" as const,
195+
content: note
196+
})),
197+
{
198+
role: "user",
199+
content: {
200+
type: "text",
201+
text: "Provide a concise summary of all the notes above."
202+
}
203+
}
204+
]
205+
};
206+
});
207+
147208
/**
148209
* Start the server using stdio transport.
149210
* This allows the server to communicate via standard input/output streams.

0 commit comments

Comments
 (0)