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

Commit 6d9576f

Browse files
refactor: simplify template with empty stubs
Co-Authored-By: [email protected] <[email protected]>
1 parent b07744d commit 6d9576f

File tree

2 files changed

+17
-113
lines changed

2 files changed

+17
-113
lines changed

src/create_mcp_server/template/README.md.jinja2

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,15 @@
66

77
### Resources
88

9-
The server implements a simple note storage system with:
10-
- Custom note:// URI scheme for accessing individual notes
11-
- Each note resource has a name, description and text/plain mimetype
9+
Implement the `handle_list_resources()` and `handle_read_resource()` methods to expose and read resources.
1210

1311
### Prompts
1412

15-
The server provides a single prompt:
16-
- summarize-notes: Creates summaries of all stored notes
17-
- Optional "style" argument to control detail level (brief/detailed)
18-
- Generates prompt combining all current notes with style preference
13+
Implement the `handle_list_prompts()` and `handle_get_prompt()` methods to expose and generate prompts.
1914

2015
### Tools
2116

22-
The server implements one tool:
23-
- add-note: Adds a new note to the server
24-
- Takes "name" and "content" as required string arguments
25-
- Updates server state and notifies clients of resource changes
17+
Implement the `handle_list_tools()` and `handle_call_tool()` methods to expose and execute tools.
2618

2719
## Configuration
2820

src/create_mcp_server/template/server.py.jinja2

Lines changed: 14 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -6,149 +6,61 @@ from mcp.server import NotificationOptions, Server
66
from pydantic import AnyUrl
77
import mcp.server.stdio
88

9-
# Store notes as a simple key-value dict to demonstrate state management
10-
notes: dict[str, str] = {}
11-
129
server = Server("{{server_name}}")
1310

1411
@server.list_resources()
1512
async def handle_list_resources() -> list[types.Resource]:
1613
"""
17-
List available note resources.
18-
Each note is exposed as a resource with a custom note:// URI scheme.
14+
List available resources.
15+
Implement this method to expose your server's resources.
1916
"""
20-
return [
21-
types.Resource(
22-
uri=AnyUrl(f"note://internal/{name}"),
23-
name=f"Note: {name}",
24-
description=f"A simple note named {name}",
25-
mimeType="text/plain",
26-
)
27-
for name in notes
28-
]
17+
return []
2918

3019
@server.read_resource()
3120
async def handle_read_resource(uri: AnyUrl) -> str:
3221
"""
33-
Read a specific note's content by its URI.
34-
The note name is extracted from the URI host component.
22+
Read a specific resource's content by its URI.
23+
Implement this method to return the content of a resource.
3524
"""
36-
if uri.scheme != "note":
37-
raise ValueError(f"Unsupported URI scheme: {uri.scheme}")
38-
39-
name = uri.path
40-
if name is not None:
41-
name = name.lstrip("/")
42-
return notes[name]
43-
raise ValueError(f"Note not found: {name}")
25+
raise NotImplementedError("Resource reading not implemented")
4426

4527
@server.list_prompts()
4628
async def handle_list_prompts() -> list[types.Prompt]:
4729
"""
4830
List available prompts.
49-
Each prompt can have optional arguments to customize its behavior.
31+
Implement this method to expose your server's prompts.
5032
"""
51-
return [
52-
types.Prompt(
53-
name="summarize-notes",
54-
description="Creates a summary of all notes",
55-
arguments=[
56-
types.PromptArgument(
57-
name="style",
58-
description="Style of the summary (brief/detailed)",
59-
required=False,
60-
)
61-
],
62-
)
63-
]
33+
return []
6434

6535
@server.get_prompt()
6636
async def handle_get_prompt(
6737
name: str, arguments: dict[str, str] | None
6838
) -> types.GetPromptResult:
6939
"""
7040
Generate a prompt by combining arguments with server state.
71-
The prompt includes all current notes and can be customized via arguments.
41+
Implement this method to generate prompts based on the given name and arguments.
7242
"""
73-
if name != "summarize-notes":
74-
raise ValueError(f"Unknown prompt: {name}")
75-
76-
style = (arguments or {}).get("style", "brief")
77-
detail_prompt = " Give extensive details." if style == "detailed" else ""
78-
79-
return types.GetPromptResult(
80-
description="Summarize the current notes",
81-
messages=[
82-
types.PromptMessage(
83-
role="user",
84-
content=types.TextContent(
85-
type="text",
86-
text=f"Here are the current notes to summarize:{detail_prompt}\n\n"
87-
+ "\n".join(
88-
f"- {name}: {content}"
89-
for name, content in notes.items()
90-
),
91-
),
92-
)
93-
],
94-
)
43+
raise NotImplementedError("Prompt generation not implemented")
9544

9645
@server.list_tools()
9746
async def handle_list_tools() -> list[types.Tool]:
9847
"""
9948
List available tools.
100-
Each tool specifies its arguments using JSON Schema validation.
49+
Implement this method to expose your server's tools.
10150
"""
102-
return [
103-
types.Tool(
104-
name="add-note",
105-
description="Add a new note",
106-
inputSchema={
107-
"type": "object",
108-
"properties": {
109-
"name": {"type": "string"},
110-
"content": {"type": "string"},
111-
},
112-
"required": ["name", "content"],
113-
},
114-
)
115-
]
51+
return []
11652

11753
@server.call_tool()
11854
async def handle_call_tool(
11955
name: str, arguments: dict | None
12056
) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
12157
"""
12258
Handle tool execution requests.
123-
Tools can modify server state and notify clients of changes.
59+
Implement this method to handle tool calls with the given name and arguments.
12460
"""
125-
if name != "add-note":
126-
raise ValueError(f"Unknown tool: {name}")
127-
128-
if not arguments:
129-
raise ValueError("Missing arguments")
130-
131-
note_name = arguments.get("name")
132-
content = arguments.get("content")
133-
134-
if not note_name or not content:
135-
raise ValueError("Missing name or content")
136-
137-
# Update server state
138-
notes[note_name] = content
139-
140-
# Notify clients that resources have changed
141-
await server.request_context.session.send_resource_list_changed()
142-
143-
return [
144-
types.TextContent(
145-
type="text",
146-
text=f"Added note '{note_name}' with content: {content}",
147-
)
148-
]
61+
raise NotImplementedError("Tool execution not implemented")
14962

15063
async def main():
151-
# Run the server using stdin/stdout streams
15264
async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
15365
await server.run(
15466
read_stream,

0 commit comments

Comments
 (0)