Skip to content

MCP client: let a call pass per-call state to the request customizer #1770

Done

Description

@jlouvel

Problem

A client that sends credentials computed per call (for example a token rendered from the call's own parameters, or a token exchanged for the caller's identity) cannot do it with McpClientAdapter.setRequestCustomizer. The customizer is one Consumer<Request> for the whole adapter, and the 2026-07-28 HTTP transport runs it on a worker thread of its own (McpModernHttpTransport.exchange), so neither a ThreadLocal set by the caller nor anything else of the calling thread is visible there. A client with per-call state has to create one adapter per call, which loses the connection and limits.

Found while migrating the consumed MCP client of Ikanos to org.restlet.ext.mcp (naftiko/ikanos#1256).

Proposed fix

Add McpClientAdapter.setCallCustomizer(BiConsumer<Request, ContextView>): for a 2026-07-28 call over HTTP, it runs after the request customizer and gets the Reactor context the call was subscribed with, so the caller passes its state with contextWrite on the call (client.tool("x").call().contextWrite(Context.of(key, value))). The context is read with FluxSink.contextView(), which the SDK client already propagates into the transport's exchange, as the test of the fix shows.

Out of scope: the 2025-11-25 transport, which has no per-call hook either; it can follow once this is agreed.

Activity

  1. jlouvel commented on Nov 30, 2026

    @jlouvel
    CollaboratorAuthor

    Delivered by #1771 (merged to 3.0): McpClientAdapter.setCallCustomizer. Closing by hand because 3.0 merges don't auto-close.

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