Merge pull request #3 from modelcontextprotocol/justin/prompts-and-readme
Add an example prompt summarizing notes, add generated README
This commit is contained in:
commit
a744926578
2 changed files with 133 additions and 2 deletions
70
template/README.md.ejs
Normal file
70
template/README.md.ejs
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
# <%= name %> MCP Server
|
||||
|
||||
<%= description %>
|
||||
|
||||
This is a TypeScript-based MCP server that implements a simple notes system. It demonstrates core MCP concepts by providing:
|
||||
|
||||
- Resources representing text notes with URIs and metadata
|
||||
- Tools for creating new notes
|
||||
- Prompts for generating summaries of notes
|
||||
|
||||
## Features
|
||||
|
||||
### Resources
|
||||
- List and access notes via `note://` URIs
|
||||
- Each note has a title, content and metadata
|
||||
- Plain text mime type for simple content access
|
||||
|
||||
### Tools
|
||||
- `create_note` - Create new text notes
|
||||
- Takes title and content as required parameters
|
||||
- Stores note in server state
|
||||
|
||||
### Prompts
|
||||
- `summarize_notes` - Generate a summary of all stored notes
|
||||
- Includes all note contents as embedded resources
|
||||
- Returns structured prompt for LLM summarization
|
||||
|
||||
## Development
|
||||
|
||||
Install dependencies:
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
Build the server:
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
For development with auto-rebuild:
|
||||
```bash
|
||||
npm run watch
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
To use with Claude Desktop, add the server config:
|
||||
|
||||
On MacOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
||||
On Windows: `%APPDATA%/Claude/claude_desktop_config.json`
|
||||
|
||||
```json
|
||||
{
|
||||
"mcpServers": {
|
||||
"<%= name %>": {
|
||||
"command": "/path/to/<%= name %>/build/index.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Debugging
|
||||
|
||||
Since MCP servers communicate over stdio, debugging can be challenging. We recommend using the [MCP Inspector](https://github.com/modelcontextprotocol/inspector):
|
||||
|
||||
```bash
|
||||
npx @modelcontextprotocol/inspector /path/to/<%= name %>/build/index.js
|
||||
```
|
||||
|
||||
The Inspector will provide a URL to access debugging tools in your browser.
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
* - Listing notes as resources
|
||||
* - Reading individual notes
|
||||
* - Creating new notes via a tool
|
||||
* - Summarizing all notes via a prompt
|
||||
*/
|
||||
|
||||
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
||||
|
|
@ -13,6 +14,8 @@ import {
|
|||
ListResourcesRequestSchema,
|
||||
ListToolsRequestSchema,
|
||||
ReadResourceRequestSchema,
|
||||
ListPromptsRequestSchema,
|
||||
GetPromptRequestSchema,
|
||||
} from "@modelcontextprotocol/sdk/types.js";
|
||||
|
||||
/**
|
||||
|
|
@ -30,8 +33,8 @@ const notes: { [id: string]: Note } = {
|
|||
};
|
||||
|
||||
/**
|
||||
* Create an MCP server with capabilities for resources (to list/read notes)
|
||||
* and tools (to create new notes).
|
||||
* Create an MCP server with capabilities for resources (to list/read notes),
|
||||
* tools (to create new notes), and prompts (to summarize notes).
|
||||
*/
|
||||
const server = new Server(
|
||||
{
|
||||
|
|
@ -42,6 +45,7 @@ const server = new Server(
|
|||
capabilities: {
|
||||
resources: {},
|
||||
tools: {},
|
||||
prompts: {},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
|
@ -144,6 +148,63 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Handler that lists available prompts.
|
||||
* Exposes a single "summarize_notes" prompt that summarizes all notes.
|
||||
*/
|
||||
server.setRequestHandler(ListPromptsRequestSchema, async () => {
|
||||
return {
|
||||
prompts: [
|
||||
{
|
||||
name: "summarize_notes",
|
||||
description: "Summarize all notes",
|
||||
}
|
||||
]
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* Handler for the summarize_notes prompt.
|
||||
* Returns a prompt that requests summarization of all notes, with the notes' contents embedded as resources.
|
||||
*/
|
||||
server.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
||||
if (request.params.name !== "summarize_notes") {
|
||||
throw new Error("Unknown prompt");
|
||||
}
|
||||
|
||||
const embeddedNotes = Object.entries(notes).map(([id, note]) => ({
|
||||
type: "resource" as const,
|
||||
resource: {
|
||||
uri: `note:///${id}`,
|
||||
mimeType: "text/plain",
|
||||
text: note.content
|
||||
}
|
||||
}));
|
||||
|
||||
return {
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: {
|
||||
type: "text",
|
||||
text: "Please summarize the following notes:"
|
||||
}
|
||||
},
|
||||
...embeddedNotes.map(note => ({
|
||||
role: "user" as const,
|
||||
content: note
|
||||
})),
|
||||
{
|
||||
role: "user",
|
||||
content: {
|
||||
type: "text",
|
||||
text: "Provide a concise summary of all the notes above."
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* Start the server using stdio transport.
|
||||
* This allows the server to communicate via standard input/output streams.
|
||||
|
|
|
|||
Loading…
Reference in a new issue