Skip to content

Hosted MCP server: overlapping requests with the same JSON-RPC id hang one of them #122

Open

Description

@Vithanco

Migrated from Vithanco/VGraph-archive#265 (private).

Waiting for: a modelcontextprotocol/swift-sdk release containing modelcontextprotocol/swift-sdk#298 (unmerged as of 2026-11-20; latest release 0.12.1).
Then: bump the SDK, drop the withKnownIssue wrappers in RequestIDTests, update docs/mcp-hardening.md.


Found while measuring the hosted server for Vithanco/VGraph-archive#252.

StatelessHTTPServerTransport in the MCP Swift SDK (pinned here; upstream main and release 0.12.1 have the same code) keeps responseWaiters keyed by the JSON-RPC request id and assigns responseWaiters[requestID] = continuation without checking for an existing entry. Two overlapping requests with the same id overwrite each other, and the first is never resumed.

Two clients that both start counting at 1 will do this. Reproduced against vgraph-mcp-http: four concurrent tools/call with id: 1 returned one answer and three hung connections; with distinct ids all four answered.

Since Vithanco/VGraph-archive#263 the request deadline turns the hang into a 504 after 120 s, so it no longer holds a request forever, but each one still ties up a connection and the client waits two minutes.

Options:

  • Report upstream to modelcontextprotocol/swift-sdk with the repro above.
  • Work around in MCPHTTPApp: rewrite the id per request before it reaches the transport and map it back in the response. Small, but it covers someone else's bug.

Not a problem for the local stdio server or the Node host: a single client owns the ids.

Activity

  1. added
    bug
    track:6-mcp-server
    on Nov 21, 2026
  2. Vithanco commented on Nov 21, 2026

    @Vithanco
    OwnerAuthor

    Comment of 2026-10-29 on the original issue:

    Assumptions (confirmed)

    Upstream already has this. MCP Swift SDK issues modelcontextprotocol/swift-sdk#254 (hang) and modelcontextprotocol/swift-sdk#265 (wrong response / HTTP context shared across clients with colliding ids). Both are fixed by modelcontextprotocol/swift-sdk#298, which gives each exchange a private id. That PR was approved 2026-10-25 and isn't merged yet. The latest release is 0.12.1. Rejecting duplicate ids (modelcontextprotocol/swift-sdk#267) was turned down there: two clients may legitimately share an id.

    Decision: wait for the upstream fix, no workaround in MCPHTTPApp. Until the bump, the Vithanco/VGraph-archive#263 deadline caps each hang at a 504 after 120 s.

    Scope

    • Now:
      • A regression test, marked as a known issue.
      • Update docs/mcp-hardening.md ("Identical JSON-RPC ids hang") to point at the upstream issues and PR.
    • Once a release contains swift-sdk#298:
      • Bump the SDK (from: "0.10.0" already allows it).
      • Remove the known-issue marking, update the docs.
    • No upstream report. One exists.
    • Out of scope:
      • Transport entries left behind after a 504 (revisit after the bump).
      • Batches.
      • The stdio server and the Node host.

    Constraints

    • The test must fail within seconds, not hang. A hung exchange would block the suite, so it waits for each response with a short timeout, as HTTPLimitsTests.nextResponse does.

    Approach (test first)

    • In VGraphMCPHTTPTests: a real Server on StatelessHTTPServerTransport behind MCPHTTPApp.makeHandler().
      • Send 4 overlapping tools/call requests with id: 1.
      • Expect 4 responses, each with id: 1 and its own request's result. That catches the wrong-response half too.
    • A test tool holds each request until all 4 have arrived, so the overlap is deterministic.
    • Wrapped in withKnownIssue, so it flags itself once the bump fixes it.

    Unknowns

    • When swift-sdk#298 merges and is released. Releases have come every two to four months.
    • Behaviour changes in swift-sdk#298 to check at the bump: ids that are true/false, fractional or null now get a 400, and a cancelled request's POST ends with an empty SSE response or a -32800 error.
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

    bugtrack:6-mcp-server

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions