Skip to content

Commit 177ddbe

Browse files
committed
docs: update ServerSession docstring to use on_* handler pattern
1 parent 10766c8 commit 177ddbe

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/mcp/server/session.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,22 @@
66
77
Common usage pattern:
88
```
9-
server = Server(name)
10-
11-
@server.call_tool()
12-
async def handle_tool_call(ctx: RequestContext, arguments: dict[str, Any]) -> Any:
9+
async def handle_call_tool(ctx: RequestContext, params: CallToolRequestParams) -> CallToolResult:
1310
# Check client capabilities before proceeding
1411
if ctx.session.check_client_capability(
1512
types.ClientCapabilities(experimental={"advanced_tools": dict()})
1613
):
17-
# Perform advanced tool operations
18-
result = await perform_advanced_tool_operation(arguments)
14+
result = await perform_advanced_tool_operation(params.arguments)
1915
else:
20-
# Fall back to basic tool operations
21-
result = await perform_basic_tool_operation(arguments)
22-
16+
result = await perform_basic_tool_operation(params.arguments)
2317
return result
2418
25-
@server.list_prompts()
26-
async def handle_list_prompts(ctx: RequestContext) -> list[types.Prompt]:
27-
# Access session for any necessary checks or operations
19+
async def handle_list_prompts(ctx: RequestContext, params) -> ListPromptsResult:
2820
if ctx.session.client_params:
29-
# Customize prompts based on client initialization parameters
30-
return generate_custom_prompts(ctx.session.client_params)
31-
else:
32-
return default_prompts
21+
return ListPromptsResult(prompts=generate_custom_prompts(ctx.session.client_params))
22+
return ListPromptsResult(prompts=default_prompts)
23+
24+
server = Server(name, on_call_tool=handle_call_tool, on_list_prompts=handle_list_prompts)
3325
```
3426
3527
The ServerSession class is typically used internally by the Server class and should not

0 commit comments

Comments
 (0)