Skip to content

Commit 78ff6c9

Browse files
committed
clean up after review comments
1 parent 982b115 commit 78ff6c9

File tree

13 files changed

+70
-105
lines changed

13 files changed

+70
-105
lines changed

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ mcp = FastMCP("Demo")
121121

122122
# Add an addition tool
123123
@mcp.tool()
124-
def add(a: int, b: int) -> int:
124+
def sum(a: int, b: int) -> int:
125125
"""Add two numbers"""
126126
return a + b
127127

@@ -246,13 +246,13 @@ from mcp.server.fastmcp import FastMCP
246246
mcp = FastMCP(name="Tool Example")
247247

248248

249-
@mcp.tool(description="Add two numbers")
250-
def add(a: int, b: int) -> int:
249+
@mcp.tool()
250+
def sum(a: int, b: int) -> int:
251251
"""Add two numbers together."""
252252
return a + b
253253

254254

255-
@mcp.tool(description="Get weather for a city")
255+
@mcp.tool()
256256
def get_weather(city: str, unit: str = "celsius") -> str:
257257
"""Get weather for a city."""
258258
# This would normally call a weather API
@@ -440,7 +440,7 @@ from mcp.server.fastmcp import Context, FastMCP
440440
mcp = FastMCP(name="Progress Example")
441441

442442

443-
@mcp.tool(description="Demonstrates progress reporting")
443+
@mcp.tool()
444444
async def long_running_task(task_name: str, ctx: Context, steps: int = 5) -> str:
445445
"""Execute a task with progress updates."""
446446
await ctx.info(f"Starting: {task_name}")
@@ -567,7 +567,7 @@ class BookingPreferences(BaseModel):
567567
)
568568

569569

570-
@mcp.tool(description="Book a restaurant table")
570+
@mcp.tool()
571571
async def book_table(
572572
date: str,
573573
time: str,
@@ -612,7 +612,7 @@ from mcp.types import SamplingMessage, TextContent
612612
mcp = FastMCP(name="Sampling Example")
613613

614614

615-
@mcp.tool(description="Uses sampling to generate content")
615+
@mcp.tool()
616616
async def generate_poem(topic: str, ctx: Context) -> str:
617617
"""Generate a poem using LLM sampling."""
618618
prompt = f"Write a short poem about {topic}"
@@ -645,9 +645,9 @@ from mcp.server.fastmcp import Context, FastMCP
645645
mcp = FastMCP(name="Notifications Example")
646646

647647

648-
@mcp.tool(description="Demonstrates logging at different levels")
648+
@mcp.tool()
649649
async def process_data(data: str, ctx: Context) -> str:
650-
"""Process data with comprehensive logging."""
650+
"""Process data with logging."""
651651
# Different log levels
652652
await ctx.debug(f"Debug: Processing '{data}'")
653653
await ctx.info("Info: Starting processing")
@@ -785,8 +785,9 @@ from mcp.server.fastmcp import FastMCP
785785
mcp = FastMCP(name="EchoServer", stateless_http=True)
786786

787787

788-
@mcp.tool(description="A simple echo tool")
788+
@mcp.tool()
789789
def echo(message: str) -> str:
790+
"""A simple echo tool"""
790791
return f"Echo: {message}"
791792
```
792793

@@ -797,8 +798,9 @@ from mcp.server.fastmcp import FastMCP
797798
mcp = FastMCP(name="MathServer", stateless_http=True)
798799

799800

800-
@mcp.tool(description="A simple add tool")
801+
@mcp.tool()
801802
def add_two(n: int) -> int:
803+
"""Tool to add two to the input"""
802804
return n + 2
803805
```
804806

examples/fastmcp/desktop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ def desktop() -> list[str]:
2020

2121

2222
@mcp.tool()
23-
def add(a: int, b: int) -> int:
23+
def sum(a: int, b: int) -> int:
2424
"""Add two numbers"""
2525
return a + b

examples/fastmcp/readme-quickstart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Add an addition tool
88
@mcp.tool()
9-
def add(a: int, b: int) -> int:
9+
def sum(a: int, b: int) -> int:
1010
"""Add two numbers"""
1111
return a + b
1212

examples/snippets/pyproject.toml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,4 @@ build-backend = "setuptools.build_meta"
1515
packages = ["servers"]
1616

1717
[project.scripts]
18-
basic-tool = "servers:run_basic_tool"
19-
basic-resource = "servers:run_basic_resource"
20-
basic-prompt = "servers:run_basic_prompt"
21-
tool-progress = "servers:run_tool_progress"
22-
sampling = "servers:run_sampling"
23-
elicitation = "servers:run_elicitation"
24-
completion = "servers:run_completion"
25-
notifications = "servers:run_notifications"
18+
server = "servers:run_server"

examples/snippets/servers/__init__.py

Lines changed: 24 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,35 @@
22
33
This package contains simple examples of MCP server features.
44
Each server demonstrates a single feature and can be run as a standalone server.
5+
6+
To run a server, use the command:
7+
uv run server basic_tool sse
58
"""
69

710
import importlib
811
import sys
9-
from typing import Literal
10-
11-
# Available snippet modules
12-
SNIPPET_MODULES = [
13-
"basic_tool",
14-
"basic_resource",
15-
"basic_prompt",
16-
"tool_progress",
17-
"sampling",
18-
"elicitation",
19-
"completion",
20-
"notifications",
21-
]
12+
from typing import Literal, cast
2213

2314

24-
def run_server(module_name: str, transport: Literal["stdio", "sse", "streamable-http"] | None = None) -> None:
25-
"""Run a snippet server with the specified transport.
15+
def run_server():
16+
"""Run a server by name with optional transport.
2617
27-
Args:
28-
module_name: Name of the snippet module to run
29-
transport: Transport to use (stdio, sse, streamable-http).
30-
If None, uses first command line arg or defaults to stdio.
18+
Usage: server <server-name> [transport]
19+
Example: server basic_tool sse
3120
"""
32-
# Validate module name
33-
if module_name not in SNIPPET_MODULES:
34-
raise ValueError(f"Unknown module: {module_name}. Available modules: {', '.join(SNIPPET_MODULES)}")
35-
36-
# Import the module dynamically
37-
module = importlib.import_module(f".{module_name}", package=__name__)
38-
mcp = module.mcp
39-
40-
# Determine transport
41-
if transport is None:
42-
transport_arg = sys.argv[1] if len(sys.argv) > 1 else "stdio"
43-
# Validate and cast transport
44-
if transport_arg not in ["stdio", "sse", "streamable-http"]:
45-
raise ValueError(f"Invalid transport: {transport_arg}. Must be one of: stdio, sse, streamable-http")
46-
transport = transport_arg # type: ignore
47-
48-
# Run the server
49-
print(f"Starting {module_name} server with {transport} transport...")
50-
mcp.run(transport=transport) # type: ignore
51-
52-
53-
# Create entry point functions dynamically
54-
def _create_run_function(module_name: str):
55-
"""Create a run function for a specific module."""
56-
57-
def run_function():
58-
f"""Run the {module_name.replace('_', ' ')} example server."""
59-
run_server(module_name)
60-
61-
return run_function
62-
63-
64-
# Generate entry points for each snippet
65-
for module in SNIPPET_MODULES:
66-
func_name = f"run_{module}"
67-
globals()[func_name] = _create_run_function(module)
21+
if len(sys.argv) < 2:
22+
print("Usage: server <server-name> [transport]")
23+
print("Available servers: basic_tool, basic_resource, basic_prompt, tool_progress,")
24+
print(" sampling, elicitation, completion, notifications")
25+
print("Available transports: stdio (default), sse, streamable-http")
26+
sys.exit(1)
27+
28+
server_name = sys.argv[1]
29+
transport = sys.argv[2] if len(sys.argv) > 2 else "stdio"
30+
31+
try:
32+
module = importlib.import_module(f".{server_name}", package=__name__)
33+
module.mcp.run(cast(Literal["stdio", "sse", "streamable-http"], transport))
34+
except ImportError:
35+
print(f"Error: Server '{server_name}' not found")
36+
sys.exit(1)

examples/snippets/servers/basic_tool.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
mcp = FastMCP(name="Tool Example")
44

55

6-
@mcp.tool(description="Add two numbers")
7-
def add(a: int, b: int) -> int:
6+
@mcp.tool()
7+
def sum(a: int, b: int) -> int:
88
"""Add two numbers together."""
99
return a + b
1010

1111

12-
@mcp.tool(description="Get weather for a city")
12+
@mcp.tool()
1313
def get_weather(city: str, unit: str = "celsius") -> str:
1414
"""Get weather for a city."""
1515
# This would normally call a weather API

examples/snippets/servers/elicitation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class BookingPreferences(BaseModel):
1515
)
1616

1717

18-
@mcp.tool(description="Book a restaurant table")
18+
@mcp.tool()
1919
async def book_table(
2020
date: str,
2121
time: str,

examples/snippets/servers/notifications.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
mcp = FastMCP(name="Notifications Example")
44

55

6-
@mcp.tool(description="Demonstrates logging at different levels")
6+
@mcp.tool()
77
async def process_data(data: str, ctx: Context) -> str:
8-
"""Process data with comprehensive logging."""
8+
"""Process data with logging."""
99
# Different log levels
1010
await ctx.debug(f"Debug: Processing '{data}'")
1111
await ctx.info("Info: Starting processing")

examples/snippets/servers/sampling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
mcp = FastMCP(name="Sampling Example")
55

66

7-
@mcp.tool(description="Uses sampling to generate content")
7+
@mcp.tool()
88
async def generate_poem(topic: str, ctx: Context) -> str:
99
"""Generate a poem using LLM sampling."""
1010
prompt = f"Write a short poem about {topic}"

examples/snippets/servers/tool_progress.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
mcp = FastMCP(name="Progress Example")
44

55

6-
@mcp.tool(description="Demonstrates progress reporting")
6+
@mcp.tool()
77
async def long_running_task(task_name: str, ctx: Context, steps: int = 5) -> str:
88
"""Execute a task with progress updates."""
99
await ctx.info(f"Starting: {task_name}")

0 commit comments

Comments
 (0)