File tree Expand file tree Collapse file tree 2 files changed +21
-21
lines changed
Expand file tree Collapse file tree 2 files changed +21
-21
lines changed Original file line number Diff line number Diff line change @@ -1138,27 +1138,6 @@ The request context accessible via `ctx.request_context` contains request-specif
11381138- ` ctx.request_context.request ` - The original MCP request object for advanced processing
11391139- ` ctx.request_context.request_id ` - Unique identifier for this request
11401140
1141- Inside a FastMCP tool, the current request ID is available as ` ctx.request_id `
1142- or ` ctx.request_context.request_id ` . This is the same JSON-RPC request ID that
1143- would be used in a ` notifications/cancelled ` message.
1144-
1145- Use ` notifications/cancelled ` for cancelling normal in-flight requests such as
1146- ` tools/call ` . For task-based work, use ` tasks/cancel ` instead.
1147-
1148- ``` python
1149- @mcp.tool ()
1150- async def slow_tool (ctx : Context) -> str :
1151- current_request_id = ctx.request_id
1152- return f " handling request { current_request_id} "
1153- ```
1154-
1155- If you are using the SDK's high-level client helpers such as
1156- ` client.call_tool() ` or ` client.session.call_tool() ` , the SDK manages request
1157- IDs for you and does not currently expose them directly. If you need explicit
1158- client-driven cancellation, prefer a task-based workflow (` tasks/cancel ` ) or a
1159- lower-level integration where you control request/notification correlation
1160- yourself.
1161-
11621141``` python
11631142# Example with typed lifespan context
11641143@dataclass
Original file line number Diff line number Diff line change @@ -1134,6 +1134,27 @@ The request context accessible via `ctx.request_context` contains request-specif
11341134- ` ctx.request_context.request ` - The original MCP request object for advanced processing
11351135- ` ctx.request_context.request_id ` - Unique identifier for this request
11361136
1137+ Inside a FastMCP tool, the current request ID is available as ` ctx.request_id `
1138+ or ` ctx.request_context.request_id ` . This is the same JSON-RPC request ID that
1139+ would be used in a ` notifications/cancelled ` message.
1140+
1141+ Use ` notifications/cancelled ` for cancelling normal in-flight requests such as
1142+ ` tools/call ` . For task-based work, use ` tasks/cancel ` instead.
1143+
1144+ ``` python
1145+ @mcp.tool ()
1146+ async def slow_tool (ctx : Context) -> str :
1147+ current_request_id = ctx.request_id
1148+ return f " handling request { current_request_id} "
1149+ ```
1150+
1151+ If you are using the SDK's high-level client helpers such as
1152+ ` client.call_tool() ` or ` client.session.call_tool() ` , the SDK manages request
1153+ IDs for you and does not currently expose them directly. If you need explicit
1154+ client-driven cancellation, prefer a task-based workflow (` tasks/cancel ` ) or a
1155+ lower-level integration where you control request/notification correlation
1156+ yourself.
1157+
11371158``` python
11381159# Example with typed lifespan context
11391160@dataclass
You can’t perform that action at this time.
0 commit comments