Skip to content

MCP tool calls ignore abort_controller — ESC hangs until server replies #171

@ericleepi314

Description

@ericleepi314

Files

`src/services/mcp/client.py`, `src/services/mcp/transport.py`, `src/tool_system/tools/mcp_tool_wrapper.py` (or equivalent)

Background

PR #135 explicitly defers MCP cancellation:

MCP tools: out-of-process JSON-RPC; transport-level cancellation is a cross-cutting change across the entire MCP client.

Verification

`grep -rn abort_controller src/services/mcp/` returns nothing on HEAD `e1832a0`. JSON-RPC requests block until the upstream server replies (or hits its own timeout).

Impact

A user running a slow MCP tool (e.g. a database query, a remote API call exposed by a plugin) cannot cancel mid-call. If the server hangs or is slow to respond, the REPL hangs with it until the (often generous) MCP request timeout. ESC has no effect on the in-flight call.

Fix sketch

JSON-RPC 2.0 supports `$/cancelRequest` (per LSP/MCP convention). Plumb the abort signal through `McpClient.call_tool`:

  1. Track the in-flight request id per call.
  2. On abort, send `$/cancelRequest` with that id.
  3. Return an `AbortError` from the call without waiting for the server's response.

Servers that ignore the cancel notification still leak a request server-side, but the client unblocks immediately. Cover with a fake-MCP-server regression test that pins the cancellation latency.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions