forked from modelcontextprotocol/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
61 lines (44 loc) · 1.77 KB
/
server.py
File metadata and controls
61 lines (44 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
Example FastMCP server demonstrating recommended layout for larger servers.
This server shows how to:
- Organize tools into separate modules
- Implement versioned tools using name-based versioning
- Structure a maintainable FastMCP server
Run from the repository root:
uv run examples/snippets/servers/server_layout/server.py
"""
from mcp.server.fastmcp import FastMCP
# Import tool implementations from the tools package
from servers.server_layout.tools import get_info
# Create the FastMCP server instance
mcp = FastMCP("ServerLayoutDemo", json_response=True)
# Register version 1 of the get_info tool
# The function name determines the tool name exposed to clients
@mcp.tool()
def get_info_v1(topic: str) -> str:
"""Get basic information about a topic (v1).
Version 1 provides simple string output with basic information.
Args:
topic: The topic to get information about
Returns:
A simple string with basic information
"""
return get_info.get_info_v1(topic)
# Register version 2 of the get_info tool
# Breaking changes from v1: different return type and new parameter
@mcp.tool()
def get_info_v2(topic: str, include_metadata: bool = False) -> dict[str, str | dict[str, str]]:
"""Get information about a topic with optional metadata (v2).
Version 2 introduces breaking changes:
- Returns structured dict instead of string (breaking change)
- Adds include_metadata parameter for richer output
Args:
topic: The topic to get information about
include_metadata: Whether to include additional metadata
Returns:
A dictionary with structured information
"""
return get_info.get_info_v2(topic, include_metadata)
# Run the server
if __name__ == "__main__":
mcp.run(transport="streamable-http")