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

Commit a744926

Browse files
Merge pull request #3 from modelcontextprotocol/justin/prompts-and-readme
Add an example prompt summarizing notes, add generated README
2 parents 837a5c8 + 7cfba3e commit a744926

File tree

2 files changed

+133
-2
lines changed

2 files changed

+133
-2
lines changed

template/README.md.ejs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# <%= name %> MCP Server
2+
3+
<%= description %>
4+
5+
This is a TypeScript-based MCP server that implements a simple notes system. It demonstrates core MCP concepts by providing:
6+
7+
- Resources representing text notes with URIs and metadata
8+
- Tools for creating new notes
9+
- Prompts for generating summaries of notes
10+
11+
## Features
12+
13+
### Resources
14+
- List and access notes via `note://` URIs
15+
- Each note has a title, content and metadata
16+
- Plain text mime type for simple content access
17+
18+
### Tools
19+
- `create_note` - Create new text notes
20+
- Takes title and content as required parameters
21+
- Stores note in server state
22+
23+
### Prompts
24+
- `summarize_notes` - Generate a summary of all stored notes
25+
- Includes all note contents as embedded resources
26+
- Returns structured prompt for LLM summarization
27+
28+
## Development
29+
30+
Install dependencies:
31+
```bash
32+
npm install
33+
```
34+
35+
Build the server:
36+
```bash
37+
npm run build
38+
```
39+
40+
For development with auto-rebuild:
41+
```bash
42+
npm run watch
43+
```
44+
45+
## Installation
46+
47+
To use with Claude Desktop, add the server config:
48+
49+
On MacOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
50+
On Windows: `%APPDATA%/Claude/claude_desktop_config.json`
51+
52+
```json
53+
{
54+
"mcpServers": {
55+
"<%= name %>": {
56+
"command": "/path/to/<%= name %>/build/index.js"
57+
}
58+
}
59+
}
60+
```
61+
62+
### Debugging
63+
64+
Since MCP servers communicate over stdio, debugging can be challenging. We recommend using the [MCP Inspector](https://github.com/modelcontextprotocol/inspector):
65+
66+
```bash
67+
npx @modelcontextprotocol/inspector /path/to/<%= name %>/build/index.js
68+
```
69+
70+
The Inspector will provide a URL to access debugging tools in your browser.

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)