Skip to content

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

Merged
jlouvel merged 3 commits into
3.0from
feature/mcp-client-call-context
Nov 30, 2026
Merged

jlouvel merged 3 commits into
3.0from
feature/mcp-client-call-context

Conversation

@jlouvel

@jlouvel jlouvel commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1770.

Adds 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 (FluxSink.contextView()), so a caller passes per-call state with contextWrite on the call. The request customizer runs on a worker thread of the transport, where the calling thread's state is not visible.

Test: McpModernClientTestCase.aCallCustomizerGetsTheReactorContextOfItsCall (a call with a context, one without, another with a different one). ./mvnw verify -P default,test -pl org.restlet.ext.mcp: 253 tests, JaCoCo, SpotBugs, Spotless. The 2025-11-25 transport has no per-call hook yet.

🤖 Generated with Claude Code

@jlouvel jlouvel left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is correct: sink.contextView() is the subscriber's context at the time the Flux.create callback runs, it is an immutable snapshot handed to the worker, the customizer order keeps the protocol headers last so a call customizer cannot override them, and the setter follows the configure-once and null rules of the other setters. One small point inline.

Review assisted by Claude Code.

@jlouvel

jlouvel commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator Author

CI failed on McpModernClientTestCase.anElicitationHandlerMayCallWithOneSlot (also seen once on #1769), a race unrelated to this change: filed as #1772 and fixed in the last commit of this PR (the permit of a call is freed before its answer is handed over).

@jlouvel
jlouvel force-pushed the feature/mcp-client-call-context branch from c987458 to b0119d1 Compare November 30, 2026 03:53
@sonarqubecloud

Copy link
Copy Markdown

@jlouvel
jlouvel merged commit 7ea1365 into 3.0 Nov 30, 2026
3 checks passed
@jlouvel
jlouvel deleted the feature/mcp-client-call-context branch November 30, 2026 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant