Repository navigation
MCP: replace McpModernClient with the SDK 2.2.0 modern client - #1728
Conversation
jlouvel
left a comment
There was a problem hiding this comment.
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.
jlouvel
left a comment
There was a problem hiding this comment.
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.
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]>
3f60872 to
1dd2b69
Compare
|



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
McpModernHttpTransportnow implements the SDK'sMcpClientTransport. The request customizer, size limit, call limit, timeout andfollowRedirectscheck all stay. TheMCP-Protocol-Versionheader now follows the version the SDK negotiated, and the SDK's round timeout applies to every request except listen streams.boundedElastic. The SDK takes a response withnext(), 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.anElicitationHandlerMayCallWithOneSlotcaught this.McpClientAdapter.getModernClient()returns the SDK'sMcpAsyncClient.listTools,callTool,readResourceandgetPromptgo through it.McpModernClientis deleted._metakeys underio.modelcontextprotocol/. It also rejects aresultType: "task"result. So the task code moves to a newMcpTasksClient, fromMcpClientAdapter.getTasksClient().callTool, plusgetTask,updateTask,cancelTaskandawaitTask.callTooltakes the tool's definition and mirrors the arguments it annotates, as the SDK'stool(Tool)does.McpInputHandler,setInputHandlerandsetModernCapabilitiesgive way tosetFormElicitationandsetUrlElicitation, with SDKMcpAsyncElicitationHandlers. Both clients answerinput_requiredwith these handlers. The declared elicitation capabilities follow from which handlers are set.Breaking changes (in
changes.md)getModernClient()now returnsMcpAsyncClient, andMcpModernClientis gone.input_requiredthe handlers can't answer now fails the call; before, the result was returned.callOnce,readOnceandgetOncereturn 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.x-mcp-headerarguments. The old client sent such a call without the headers, and the server refused it.numberis left out of its listings, and calling it fails withIllegalArgumentException. The old client mirrored numbers in plain notation, somirrorsNumbersInPlainNotationbecomesaToolWithANumberHeaderIsNotCalled.setMaxInputRoundsnow requires at least one round, as the SDK does.listen()emits typedSubscriptionEvents, 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
McpModernClientTestCaseis 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.McpTasksTestCasenow usesMcpTasksClient. Two new tests cover its owninput_requiredrounds, 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