11"""Todo server implementation for testing."""
22
3+ from mcp .server import Server
34
4- from mcp .server import FastMCP , Server
5+ try :
6+ from mcp .server import FastMCP
7+ HAS_FASTMCP = True
8+ except ImportError :
9+ FastMCP = None
10+ HAS_FASTMCP = False
511
612
713class Todo :
@@ -13,8 +19,10 @@ def __init__(self, id: str, text: str, completed: bool = False):
1319 self .completed = completed
1420
1521
16- def create_todo_server () -> FastMCP :
22+ def create_todo_server ():
1723 """Create a todo server for testing."""
24+ if FastMCP is None :
25+ raise ImportError ("FastMCP is not available in this MCP version. Use create_low_level_todo_server() instead." )
1826 # Fix deprecation warning by not passing version as kwarg
1927 server = FastMCP ("todo-server" )
2028
@@ -61,99 +69,3 @@ def complete_todo(id: str) -> str:
6169 }
6270
6371 return server
64-
65-
66- def create_low_level_todo_server () -> Server :
67- """Create a low-level MCP server for testing."""
68- from mcp .types import Tool , TextContent
69-
70- server = Server ("todo-server-lowlevel" )
71-
72- todos : list [Todo ] = []
73- next_id = 1
74-
75- # Define tools
76- add_todo_tool = Tool (
77- name = "add_todo" ,
78- description = "Add a new todo item" ,
79- inputSchema = {
80- "type" : "object" ,
81- "properties" : {
82- "text" : {
83- "type" : "string" ,
84- "description" : "The todo item text"
85- }
86- },
87- "required" : ["text" ]
88- }
89- )
90-
91- list_todos_tool = Tool (
92- name = "list_todos" ,
93- description = "List all todo items" ,
94- inputSchema = {
95- "type" : "object" ,
96- "properties" : {}
97- }
98- )
99-
100- complete_todo_tool = Tool (
101- name = "complete_todo" ,
102- description = "Mark a todo item as completed" ,
103- inputSchema = {
104- "type" : "object" ,
105- "properties" : {
106- "id" : {
107- "type" : "string" ,
108- "description" : "The todo item ID"
109- }
110- },
111- "required" : ["id" ]
112- }
113- )
114-
115- @server .list_tools ()
116- async def list_tools ():
117- return [add_todo_tool , list_todos_tool , complete_todo_tool ]
118-
119- @server .call_tool ()
120- async def call_tool (name : str , arguments : dict ):
121- nonlocal next_id
122-
123- if name == "add_todo" :
124- text = arguments ["text" ]
125- todo = Todo (str (next_id ), text )
126- todos .append (todo )
127- next_id += 1
128- return [TextContent (
129- type = "text" ,
130- text = f'Added todo: "{ text } " with ID { todo .id } '
131- )]
132-
133- elif name == "list_todos" :
134- if not todos :
135- return [TextContent (type = "text" , text = "No todos found" )]
136-
137- todo_list = []
138- for todo in todos :
139- status = "✓" if todo .completed else "○"
140- todo_list .append (f"{ todo .id } : { todo .text } { status } " )
141-
142- return [TextContent (type = "text" , text = "\n " .join (todo_list ))]
143-
144- elif name == "complete_todo" :
145- todo_id = arguments ["id" ]
146- for todo in todos :
147- if todo .id == todo_id :
148- todo .completed = True
149- return [TextContent (
150- type = "text" ,
151- text = f'Completed todo: "{ todo .text } "'
152- )]
153-
154- raise ValueError (f"Todo with ID { todo_id } not found" )
155-
156- else :
157- raise ValueError (f"Unknown tool: { name } " )
158-
159- return server
0 commit comments