Skip to content

MCP: replace McpModernClient with the SDK 2.2.0 modern client - #1728

Merged
jlouvel merged 3 commits into
3.0from
feature/mcp-sdk-modern-client
Nov 28, 2026
Merged

jlouvel merged 3 commits into
3.0from
feature/mcp-sdk-modern-client

Conversation

@jlouvel

@jlouvel jlouvel commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Replaces our own MCP 2026-07-28 client, McpModernClient, with the MCP Java SDK 2.2.0 one (McpAsyncClient), keeping Restlet as the transport.

What changes

  • The SDK client over Restlet. McpModernHttpTransport now implements the SDK's McpClientTransport. The request customizer, size limit, call limit, timeout and followRedirects check all stay. The MCP-Protocol-Version header now follows the version the SDK negotiated, and the SDK's round timeout applies to every request except listen streams.
  • Messages are delivered on a virtual thread per task, not on boundedElastic. The SDK takes a response with next(), which cancels the stream and hands the pooled thread back while the subscriber is still running on it. With one call slot, an elicitation handler that made a blocking call queued that call's delivery behind itself and deadlocked. anElicitationHandlerMayCallWithOneSlot caught this.
  • What the adapter returns. McpClientAdapter.getModernClient() returns the SDK's McpAsyncClient. listTools, callTool, readResource and getPrompt go through it. McpModernClient is deleted.
  • Tasks go through a separate client. The SDK client can't declare the Tasks extension: the client works out each request's capabilities from its elicitation handlers alone, and refuses _meta keys under io.modelcontextprotocol/. It also rejects a resultType: "task" result. So the task code moves to a new McpTasksClient, from McpClientAdapter.getTasksClient().
    • It does task-augmented callTool, plus getTask, updateTask, cancelTask and awaitTask.
    • It shares the adapter's transport and declares the extension on each request.
    • callTool takes the tool's definition and mirrors the arguments it annotates, as the SDK's tool(Tool) does.
  • Input handling uses the SDK's handler types. McpInputHandler, setInputHandler and setModernCapabilities give way to setFormElicitation and setUrlElicitation, with SDK McpAsyncElicitationHandlers. Both clients answer input_required with these handlers. The declared elicitation capabilities follow from which handlers are set.

Breaking changes (in changes.md)

  • getModernClient() now returns McpAsyncClient, and McpModernClient is gone.
  • An input_required the handlers can't answer now fails the call; before, the result was returned. callOnce, readOnce and getOnce return it after one round. Without a handler, the client declares no elicitation capability, so an SDK server won't ask for input and fails the call with -32603.
  • The SDK client lists the tools it doesn't know before calling one with x-mcp-header arguments. The old client sent such a call without the headers, and the server refused it.
  • The SDK client mirrors only string, integer and boolean header arguments. A tool whose header argument is a number is left out of its listings, and calling it fails with IllegalArgumentException. The old client mirrored numbers in plain notation, so mirrorsNumbersInPlainNotation becomes aToolWithANumberHeaderIsNotCalled.
  • setMaxInputRounds now requires at least one round, as the SDK does.
  • The SDK's listen() emits typed SubscriptionEvents, so notifications it doesn't model, such as an application's own (MCP: publish application notifications on subscriptions/listen streams #1700), don't reach this client.

Tests

  • McpModernClientTestCase is rewritten against the SDK client and covers the same ground: discovery, listings, calls, progress, input_required, listen, cancellation, header mirroring, and a nested call from a handler with one slot. It also tests the adapter's convenience methods.
  • McpTasksTestCase now uses McpTasksClient. Two new tests cover its own input_required rounds, header mirroring from the definition given, and a result handed back when the handler gives no answer or the round limit is reached.
  • ./mvnw -B verify -P default,test -pl org.restlet.ext.mcp: see the checks.

🤖 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.

Round 1. The SDK client sits well on the Restlet transport, and the per-task virtual-thread delivery scheduler is justified: with publishOn(Schedulers.boundedElastic()) put back, anElicitationHandlerMayCallWithOneSlot times out, so that test guards the change. Close/stop and the probe/start paths look right, apart from one cleanup point. The comments below cover two places where the transport doesn't keep the McpClientTransport contract the SDK client relies on, and one place where the tasks client handles input_required differently from the SDK client. Three Lows follow. Review assisted by Claude Code.

Comment thread changes.md Resolved

@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.

Round 2. The six round-1 fixes are in place and their tests fail without them. The SDK round timeout is now the only limit on SDK requests. The state-only backoff and round counting match MultiRoundTripRequest. The probe ignores close failures. The changes.md entry is complete. One remaining point is about which failures exchange reports as lost. Review assisted by Claude Code.

jlouvel and others added 3 commits November 28, 2026 11:19
McpClientAdapter.getModernClient() returns the SDK's McpAsyncClient, over
McpModernHttpTransport, which now implements the SDK's McpClientTransport
within the adapter's limits. Task-augmented calls and tasks/get, update,
cancel and await move to McpTasksClient, since the SDK client can't
declare the Tasks extension. McpInputHandler and setModernCapabilities
give way to SDK form and URL elicitation handlers.

Messages are delivered on a virtual thread per task: the SDK cancels the
stream on the response, which handed the boundedElastic thread back while
an elicitation handler still blocked on it, deadlocking a nested call
with one call slot.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tate-only rounds

- The SDK client's round timeout is now the only limit on its requests:
  McpWorkers takes a per-call limit, and the transport's fixed call timeout
  applies only to McpTasksClient's requests.
- An SDK exchange broken before its response fails with
  McpResponseLostException, as McpClientTransport specifies; HTTP failures
  keep McpHttpStatusException.
- McpTasksClient retries a state-only input_required with the SDK's backoff,
  and refuses a tool with invalid x-mcp-header annotations.
- A probe candidate failing to close no longer replaces the probe outcome.
- changes.md: rewrapped, and lists the tasks client's breaking changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ector

A request refused before it is sent (closed transport, call or listen
limit, size limit) now fails as it is, so a client retrying lost exchanges
isn't refused in a loop. A connection lost before the response's head
(status 1001 or 1002) is now lost too, rather than an HTTP status failure.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jlouvel
jlouvel force-pushed the feature/mcp-sdk-modern-client branch from 3f60872 to 1dd2b69 Compare November 28, 2026 16:19
@sonarqubecloud

Copy link
Copy Markdown

@jlouvel
jlouvel merged commit a95ea10 into 3.0 Nov 28, 2026
3 checks passed
@jlouvel
jlouvel deleted the feature/mcp-sdk-modern-client branch November 28, 2026 16:30
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