|
7 | 7 | from mcp.server.subscriptions import InMemorySubscriptionBus, ListenHandler, ResourceUpdated |
8 | 8 |
|
9 | 9 | bus = InMemorySubscriptionBus() |
| 10 | +listen_handler = ListenHandler(bus) |
10 | 11 |
|
11 | | -NOTES = {"todo": "buy milk"} |
| 12 | +BOARD = {"design": False, "build": False} |
12 | 13 |
|
13 | | -EDIT_NOTE_SCHEMA: dict[str, Any] = { |
| 14 | +COMPLETE_TASK_SCHEMA: dict[str, Any] = { |
14 | 15 | "type": "object", |
15 | | - "properties": {"name": {"type": "string"}, "text": {"type": "string"}}, |
16 | | - "required": ["name", "text"], |
| 16 | + "properties": {"task": {"type": "string"}}, |
| 17 | + "required": ["task"], |
17 | 18 | } |
18 | 19 |
|
19 | 20 |
|
| 21 | +async def read_resource( |
| 22 | + ctx: ServerRequestContext[Any], params: types.ReadResourceRequestParams |
| 23 | +) -> types.ReadResourceResult: |
| 24 | + board = "\n".join(f"[{'x' if done else ' '}] {task}" for task, done in BOARD.items()) |
| 25 | + return types.ReadResourceResult(contents=[types.TextResourceContents(uri=params.uri, text=board)]) |
| 26 | + |
| 27 | + |
20 | 28 | async def list_tools( |
21 | 29 | ctx: ServerRequestContext[Any], params: types.PaginatedRequestParams | None |
22 | 30 | ) -> types.ListToolsResult: |
23 | 31 | return types.ListToolsResult( |
24 | | - tools=[types.Tool(name="edit_note", description="Replace a note's text.", input_schema=EDIT_NOTE_SCHEMA)] |
| 32 | + tools=[types.Tool(name="complete_task", description="Mark a task done.", input_schema=COMPLETE_TASK_SCHEMA)] |
25 | 33 | ) |
26 | 34 |
|
27 | 35 |
|
28 | 36 | async def call_tool(ctx: ServerRequestContext[Any], params: types.CallToolRequestParams) -> types.CallToolResult: |
29 | 37 | args = params.arguments or {} |
30 | | - NOTES[args["name"]] = args["text"] |
31 | | - await bus.publish(ResourceUpdated(uri=f"note://{args['name']}")) |
32 | | - return types.CallToolResult(content=[types.TextContent(type="text", text="saved")]) |
| 38 | + BOARD[args["task"]] = True |
| 39 | + await bus.publish(ResourceUpdated(uri="board://sprint")) |
| 40 | + return types.CallToolResult(content=[types.TextContent(type="text", text="done")]) |
33 | 41 |
|
34 | 42 |
|
35 | 43 | server = Server( |
36 | | - "notebook", |
| 44 | + "sprint-board", |
| 45 | + on_read_resource=read_resource, |
37 | 46 | on_list_tools=list_tools, |
38 | 47 | on_call_tool=call_tool, |
39 | | - on_subscriptions_listen=ListenHandler(bus), |
| 48 | + on_subscriptions_listen=listen_handler, |
40 | 49 | ) |
0 commit comments