Skip to content

MCP client: a call made from a handler can be refused for the permit its parent still holds #1772

Done

Description

@jlouvel

Problem

An MCP client call made from inside a handler that answers the result of another call (an elicitation handler, for example) can fail with java.io.IOException: MCP transport closed or call limit exceeded when maxConcurrentCalls is 1. It happens at random: McpModernClientTestCase.anElicitationHandlerMayCallWithOneSlot failed on CI in 2 of 4 runs and never locally.

McpModernHttpTransport hands the final response to its subscriber from inside the worker's operation, and the worker frees its admission permit only after the operation returns (McpWorkers.work). The SDK runs the handler on another thread as soon as it has the response, so the handler's nested call can try to take the single permit while the outer worker is still cleaning up, and McpWorkers.admit refuses it at once.

Proposed fix

Let a call free its permit before it hands over its final response: McpWorkers.submit takes an operation that receives a release callback (idempotent; the permit is still freed when the call ends), and McpModernHttpTransport calls it just before emitting a JSON reply or the matching event of a stream.

Activity

  1. jlouvel commented on Nov 30, 2026

    @jlouvel
    CollaboratorAuthor

    Delivered by #1771 (merged to 3.0), third commit 'Free the permit of an MCP call before handing over its answer (#1772)'. The PR text only named #1770, so GitHub didn't link it. Closing by hand.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions