Summary
None of the MCP tool handlers accept or propagate a CancellationToken. JSON-RPC $/cancelRequest notifications from the client are effectively ignored — long-running impact_analysis, index, or large search calls run to completion even after the client cancels (or disconnects).
Evidence
src/CodeIndex/Mcp/McpServer.cs dispatches each tool call synchronously and does not maintain a per-request CancellationTokenSource.
src/CodeIndex/Mcp/McpToolHandlers.cs — every Execute* method is synchronous (JsonNode Execute*(...)) with no CancellationToken parameter.
- Verified codebase-wide: a search for
catch (OperationCanceledException) returns zero hits, confirming there is no cooperative cancellation anywhere downstream of MCP handlers.
Impact
- A user pressing Ctrl-C in their IDE-side MCP client cannot interrupt a multi-minute indexing or analysis call.
- Disconnected clients leave the server doing wasted work.
- This is a prerequisite for the cancellation issues in
IndexCommandRunner.RunFullScan and DbWriter backfills (related issues filed separately).
Proposed direction
- Maintain a
ConcurrentDictionary<requestId, CancellationTokenSource> in McpServer.
- On
$/cancelRequest, look up the request id and cancel the token.
- Plumb
CancellationToken through all Execute* methods and into DB / file walks.
- Wrap each handler invocation in a
try { ... } catch (OperationCanceledException) { return CreateCancelledResponse(id); }.
Repro env
- Branch:
main @ 2ee912d (release v1.21.0)
Summary
None of the MCP tool handlers accept or propagate a
CancellationToken. JSON-RPC$/cancelRequestnotifications from the client are effectively ignored — long-runningimpact_analysis,index, or largesearchcalls run to completion even after the client cancels (or disconnects).Evidence
src/CodeIndex/Mcp/McpServer.csdispatches each tool call synchronously and does not maintain a per-requestCancellationTokenSource.src/CodeIndex/Mcp/McpToolHandlers.cs— everyExecute*method is synchronous (JsonNode Execute*(...)) with noCancellationTokenparameter.catch (OperationCanceledException)returns zero hits, confirming there is no cooperative cancellation anywhere downstream of MCP handlers.Impact
IndexCommandRunner.RunFullScanandDbWriterbackfills (related issues filed separately).Proposed direction
ConcurrentDictionary<requestId, CancellationTokenSource>inMcpServer.$/cancelRequest, look up the request id and cancel the token.CancellationTokenthrough allExecute*methods and into DB / file walks.try { ... } catch (OperationCanceledException) { return CreateCancelledResponse(id); }.Repro env
main@ 2ee912d (release v1.21.0)