MCPcopy Index your code
hub / github.com/modelcontextprotocol/python-sdk / handle_call_tool

Function handle_call_tool

tests/server/test_cancel_handling.py:49–58  ·  view source on GitHub ↗
(ctx: ServerRequestContext, params: CallToolRequestParams)

Source from the content-addressed store, hash-verified

47 )
48
49 async def handle_call_tool(ctx: ServerRequestContext, params: CallToolRequestParams) -> CallToolResult:
50 nonlocal call_count, first_request_id
51 if params.name == "test_tool":
52 call_count += 1
53 if call_count == 1:
54 first_request_id = ctx.request_id
55 ev_first_call.set()
56 await anyio.sleep(5) # First call is slow
57 return CallToolResult(content=[TextContent(type="text", text=f"Call number: {call_count}")])
58 raise ValueError(f"Unknown tool: {params.name}") # pragma: no cover
59
60 server = Server("test-server", on_list_tools=handle_list_tools, on_call_tool=handle_call_tool)
61

Callers

nothing calls this directly

Calls 3

CallToolResultClass · 0.90
TextContentClass · 0.90
list_rootsMethod · 0.45

Tested by

no test coverage detected