Skip to content

fix: keep long MCP tool calls alive before host timeout #352

Description

@sperwe

Problem

Long-running MCP tool calls can remain silent until the final tool result is ready. In the real Mac mini production path through Cloudflare Tunnel, several successful /mcp requests completed near the apparent client timeout boundary:

  • 12,023 ms
  • 11,663 ms
  • 9,096 ms
  • 12,027 ms

The host UI can remain at “Waiting for a tool result” and then report that sending the message timed out, even though DevSpace and the tunnel remain healthy.

Current diagnosis

The modern MCP handler uses its default response mode, so an ordinary tool call may not establish SSE before the result completes. exec_command waits 10 seconds by default and permits a 12-second yield window. This creates a long time-to-first-byte window that is close to the observed client timeout.

Current request logging is completion-only, which makes a stuck or client-aborted request invisible. Aggregate narrow-tool calls also log their internal child calls without a parent identifier, and a batch with running children can currently be logged as successful.

Proposed scope

  1. Establish the OpenAI-facing modern MCP response as SSE and emit periodic keepalive traffic.
  2. Reduce the default process yield window to 3 seconds while retaining the existing explicit maximum.
  3. Add request lifecycle observability for request start, first byte or stream establishment, completion, and client abort.
  4. Make aggregate/child tool-call relationships and running outcomes unambiguous in logs.
  5. Add regression coverage for time-to-first-byte, long-running command session return, request abort, and aggregate logging semantics.

Acceptance

  • A silent command longer than the default yield returns a running process session within the client-safe window.
  • The public MCP transport establishes a streaming response promptly and keeps it active during long work.
  • Client disconnects are visible in logs and do not appear as successful completion.
  • Running aggregate operations are not reported as terminal success.
  • Existing MCP compatibility, process-session, typecheck, tests, and build remain green.

Non-goals

  • Changing Cloudflare Tunnel ownership or configuration.
  • Auto-cancelling every detached process without an explicit lifecycle policy.
  • Broad redesign of all long-running tools in this patch.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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