Repository navigation
Not planned
Not planned
Copy link
Labels
bugSomething isn't working
Description
Summary
Python registers a per-call CancelToken, attaches it to the execution Context, and exposes ExecutionRouter.cancel(call_id). But nothing in the transport calls cancel() when an inbound MCP notifications/cancelled arrives, and extra carries no abort signal. A running module therefore cannot observe context.cancel_token.is_cancelled.
This corrects the original report: the premise that "only Rust implements it" is wrong. The verified cross-language state is:
| SDK | Per-call token attached | Notification flips it | Evidence |
|---|---|---|---|
| Python | Yes (router.py:287-343, 506) |
No | router.py:111-112, 618-654 describe forwarding; no transport caller; extra has no signal |
| TypeScript | Yes (router.ts:412-437, 514-526) |
Yes | SDK extra.signal → cancelToken.cancel() (router.ts:425-427, factory.ts:658-674) |
| Rust | Yes (router.rs:926-950, 1417-1477) |
No | cancel_call only in tests; notifications wired to the async bridge only |
The shared feature doc also contradicts itself: apcore-mcp/docs/features/execution-router.md:158 says Rust handles this, while :153 says synchronous calls are NOT cancelled. The code matches :153.
Evidence
src/apcore_mcp/server/router.py:287-343— token registered before dispatch, removed infinallysrc/apcore_mcp/server/router.py:506— token passed intoContext.createsrc/apcore_mcp/server/router.py:618-654—cancel(call_id)exists and cancels/tombstones- No caller of
router.cancelinserver/transport.pyorserver/factory.py;extrakeys arecall_id,progress_token,send_notification,session(no signal) src/apcore_mcp/server/transport.py:40—transport_session_varis for async-task session keys, not per-call cancellation
Impact
- A cancelled Python tool call keeps running (subprocess, render, file lock) after the client disconnects.
- Behavior differs from TypeScript, breaking the parity promise.
- The router docstring claims transport wiring that does not exist, so integrators over-trust it.
Proposed fix
- Forward the inbound cancellation to the per-call token: hook
notifications/cancelled(or the SDK's abort signal) torouter.cancel(call_id), populatingcall_idfrom the JSON-RPC request id; or pass an abort signal throughextraand cancel the token on it. - Correct the router docstring and the shared feature doc (
execution-router.md:153,158) to one statement. - Add a cross-language conformance fixture for cancellation.
Acceptance criteria
- A Python sync tool observes
context.cancel_token.is_cancelledafternotifications/cancelled. - The tool can terminate its subprocess and return/raise cleanly.
- stdio and streamable-http are both covered.
- A shared fixture pins the behavior for Python, TypeScript, and Rust.
Related
- Central cross-language issue:
aiperceivable/apcore-mcp#21 - TypeScript reference implementation:
router.ts:412-437,factory.ts:658-674
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
[-]Cooperative cancel token is not wired for synchronous tool calls[/-][+]Per-call CancelToken is registered but never cancelled by inbound notifications/cancelled[/+]tercel commentedon Nov 23, 2026
Cross-language follow-up (corrects the original premise): TypeScript is already wired via the SDK abort signal; Rust is also missing the notification->token wiring. Central issue: #122.
tercel commentedon Nov 29, 2026
Duplicate of #122. The direct-call cancellation behavior landed in #124. Use #122 to track the remaining shared acceptance and documentation.