diff --git a/changes.md b/changes.md
index 8c689424a2..0a4b3d5451 100644
--- a/changes.md
+++ b/changes.md
@@ -23,6 +23,20 @@ Changes log
- The MCP extension depends on Jackson 3, as `org.restlet.ext.jackson` does, through the
SDK's `mcp-json-jackson3` module, instead of Jackson 2 (#1705). An application that got
Jackson 2 through it must now declare it.
+ - The MCP 2026-07-28 client is the SDK's: `McpClientAdapter.getModernClient()` returns
+ its `McpAsyncClient`, which sends its requests over the adapter's Restlet HTTP
+ connector, within the adapter's limits, and `McpModernClient` is removed. The SDK's
+ client lists the tools it doesn't know before calling one with `x-mcp-header`
+ arguments, leaves out of its listings, and refuses to call, a tool whose header
+ argument is a number, and fails an `input_required` request it can't answer instead of
+ returning the result; its `callOnce`, `readOnce` and `getOnce` return it.
+ `McpInputHandler`, `setInputHandler` and `setModernCapabilities` give way to
+ `setFormElicitation` and `setUrlElicitation`, whose handlers also set the declared
+ elicitation capabilities, and `setMaxInputRounds` requires at least one round.
+ Task-augmented calls, which the SDK's client can't declare, go through
+ `McpClientAdapter.getTasksClient()`, an `McpTasksClient`: its `callTool` takes the
+ tool's definition, from which it mirrors the annotated arguments, no longer takes a
+ progress listener, and still returns an `input_required` result it can't answer.
- `DefaultSslContextFactory` now uses the JVM default algorithms for the trust manager
(`TrustManagerFactory.getDefaultAlgorithm()`, `PKIX`) and the key manager
(`KeyManagerFactory.getDefaultAlgorithm()`) instead of the obsolete `SunX509`, unless the
@@ -95,9 +109,9 @@ Changes log
`tasks/cancel` on the application's tasks, scoped to the principal that created them
(`McpRequestContext.principal()`), and advertises the extension. A tool returns an
`McpTaskResult` to run a call as a task, only to clients declaring the extension
- (`McpTaskResult.isDeclared`). `McpModernClient.callTool` returns that task, and
- `awaitTask` polls it to its result, answering its questions through the input handler;
- `getTask`, `updateTask` and `cancelTask` drive it directly.
+ (`McpTaskResult.isDeclared`). `McpTasksClient.callTool` returns that task, and
+ `awaitTask` polls it to its result, answering its questions through the elicitation
+ handlers; `getTask`, `updateTask` and `cancelTask` drive it directly.
- The sealed `requestState` of MCP `input_required` results can be sealed by the
application's codec, `McpServerAdapter.setRequestStateCodec(RequestStateCodec)` (#1701).
`McpAeadRequestStateCodec` seals it with AES-256-GCM, so the client can't read it, with a
diff --git a/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/McpClientAdapter.java b/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/McpClientAdapter.java
index e1e046146b..2fc93aa33b 100644
--- a/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/McpClientAdapter.java
+++ b/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/McpClientAdapter.java
@@ -11,6 +11,9 @@
import io.modelcontextprotocol.json.McpJsonDefaults;
import io.modelcontextprotocol.json.McpJsonMapper;
import io.modelcontextprotocol.modern.McpSchema;
+import io.modelcontextprotocol.modern.client.McpAsyncClient;
+import io.modelcontextprotocol.modern.client.McpAsyncElicitationHandler;
+import io.modelcontextprotocol.modern.client.McpClient;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.time.Duration;
@@ -35,7 +38,8 @@
*
By default it speaks MCP {@link McpProtocol#VERSION} through the SDK's client, behind a legacy
* edge. With {@link #setProtocolVersion(String)} set to {@link McpProtocol#MODERN_VERSION}, it
* speaks {@code 2026-07-28} over HTTP instead, experimentally: {@link #start()} discovers the
- * server, and {@link #getModernClient()} makes the requests.
+ * server, and {@link #getModernClient()}, the SDK's client over this adapter's HTTP connector,
+ * makes the requests, the task-augmented ones excepted, which {@link #getTasksClient()} makes.
*
*
With {@link McpProtocol#AUTO}, also experimental, it speaks whichever era the server does, as
* the 2026-07-28 revision specifies for a dual-era client. Over HTTP, {@link #start()} sends {@code
@@ -77,13 +81,13 @@ public final class McpClientAdapter implements AutoCloseable {
private int maxConcurrentCalls = McpProtocol.DEFAULT_MAX_CONCURRENT_CALLS;
private Consumer requestCustomizer = request -> {};
private String protocolVersion = McpProtocol.VERSION;
- private McpSchema.ClientCapabilities modernCapabilities = McpSchema.ClientCapabilities.NONE;
- private McpInputHandler inputHandler;
+ private McpAsyncElicitationHandler formElicitation;
+ private McpAsyncElicitationHandler urlElicitation;
private int maxInputRounds = DEFAULT_MAX_INPUT_ROUNDS;
private McpJsonMapper jsonMapper = McpJsonDefaults.getMapper();
private boolean legacySessions;
private String legacySessionId;
- private McpModernClient modern;
+ private Modern modern;
private McpLegacyEdge.Client legacy;
private String negotiatedVersion;
private boolean started;
@@ -190,61 +194,66 @@ public synchronized String getProtocolVersion() {
}
/**
- * Sets the client capabilities sent with each {@link McpProtocol#MODERN_VERSION} request, none
- * by default. A server asks only for the input they declare, such as elicitation.
+ * Sets the JSON mapper of the {@link McpProtocol#MODERN_VERSION} client's messages, so that
+ * they share the application's settings. The SDK's default, Jackson 3 based, otherwise.
*
- * @param value The capabilities.
+ * @param value The mapper.
*/
- public synchronized void setModernCapabilities(McpSchema.ClientCapabilities value) {
+ public synchronized void setJsonMapper(McpJsonMapper value) {
requireConfigurable();
- modernCapabilities = Objects.requireNonNull(value, "value");
+ jsonMapper = Objects.requireNonNull(value, "jsonMapper");
}
- public synchronized McpSchema.ClientCapabilities getModernCapabilities() {
- return modernCapabilities;
+ public synchronized McpJsonMapper getJsonMapper() {
+ return jsonMapper;
}
/**
- * Sets the JSON mapper of the {@link McpProtocol#MODERN_VERSION} client's messages, so that
- * they share the application's settings. The SDK's default, Jackson 3 based, otherwise.
+ * Sets what answers the form elicitations of {@link McpProtocol#MODERN_VERSION} requests,
+ * through {@code input_required} results, after which the request is retried. With a handler,
+ * each request declares the form elicitation capability. Legacy servers ask for no input: the
+ * legacy edge declares no elicitation capability.
*
- * @param value The mapper.
+ * @param value The handler, or null for none.
*/
- public synchronized void setJsonMapper(McpJsonMapper value) {
+ public synchronized void setFormElicitation(
+ McpAsyncElicitationHandler value) {
requireConfigurable();
- jsonMapper = Objects.requireNonNull(value, "jsonMapper");
+ formElicitation = value;
}
- public synchronized McpJsonMapper getJsonMapper() {
- return jsonMapper;
+ public synchronized McpAsyncElicitationHandler
+ getFormElicitation() {
+ return formElicitation;
}
/**
- * Sets what answers the {@code input_required} results of {@link McpProtocol#MODERN_VERSION}
- * requests, after which the request is retried; without one, the result is returned. Legacy
- * servers ask for no input: the legacy edge declares no elicitation capability.
+ * Sets what answers the URL elicitations of {@link McpProtocol#MODERN_VERSION} requests, as
+ * {@link #setFormElicitation} does for forms.
*
* @param value The handler, or null for none.
*/
- public synchronized void setInputHandler(McpInputHandler value) {
+ public synchronized void setUrlElicitation(
+ McpAsyncElicitationHandler value) {
requireConfigurable();
- inputHandler = value;
+ urlElicitation = value;
}
- public synchronized McpInputHandler getInputHandler() {
- return inputHandler;
+ public synchronized McpAsyncElicitationHandler getUrlElicitation() {
+ return urlElicitation;
}
/**
- * Sets how many {@code input_required} results the input handler answers for one request,
- * {@value #DEFAULT_MAX_INPUT_ROUNDS} by default; the next one is returned.
+ * Sets how many {@code input_required} rounds the elicitation handlers answer for one request,
+ * {@value #DEFAULT_MAX_INPUT_ROUNDS} by default. Past it, the SDK's client fails the request,
+ * and {@link McpTasksClient} returns the result or task as it is.
*
- * @param value The number of rounds, zero or more.
+ * @param value The number of rounds, one or more.
*/
public synchronized void setMaxInputRounds(int value) {
requireConfigurable();
- if (value < 0) {
- throw new IllegalArgumentException("Input rounds must not be negative");
+ if (value <= 0) {
+ throw new IllegalArgumentException("Input rounds must be positive");
}
maxInputRounds = value;
}
@@ -360,7 +369,7 @@ private void startAuto() {
McpEras.remove(target);
}
}
- McpModernClient candidate = createModern();
+ Modern candidate = createModern();
if (probe(candidate)) {
modern = candidate;
negotiatedVersion = McpProtocol.MODERN_VERSION;
@@ -408,10 +417,11 @@ private NotModern() {
* @return True for a modern server, which the candidate then serves; false for a legacy one,
* for which the candidate is closed.
*/
- private boolean probe(McpModernClient candidate) {
+ private boolean probe(Modern candidate) {
boolean kept = false;
try {
- McpSchema.DiscoverResult discovered = candidate.discover().block(requestTimeout);
+ McpSchema.DiscoverResult discovered =
+ candidate.client().discover().block(requestTimeout);
List supported =
discovered == null || discovered.supportedVersions() == null
? List.of()
@@ -431,8 +441,9 @@ private boolean probe(McpModernClient candidate) {
if (!kept) {
try {
candidate.close();
- } catch (IOException cleanup) {
- // The probe exchange is over: nothing is left to release.
+ } catch (RuntimeException cleanup) {
+ // The probe exchange is over: its failure to close neither replaces the
+ // fallback nor the probe's own failure.
}
}
}
@@ -481,7 +492,23 @@ private static boolean offersLegacy(List supported) {
return supported.stream().anyMatch(McpProtocol.LEGACY_VERSIONS::contains);
}
- private McpModernClient createModern() {
+ /**
+ * The {@code 2026-07-28} clients over one HTTP transport: the SDK's and the Tasks extension's.
+ */
+ private record Modern(
+ McpAsyncClient client, McpTasksClient tasks, McpModernHttpTransport transport) {
+
+ /** Ends the exchanges in flight and listen streams. */
+ void close() {
+ try {
+ transport.close();
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+ }
+
+ private Modern createModern() {
if (stream != null || target.startsWith("stdio:")) {
throw new UnsupportedOperationException(
"The MCP 2026-07-28 client supports HTTP only for now");
@@ -496,26 +523,38 @@ private McpModernClient createModern() {
throw new IllegalStateException(
"Borrowed MCP client must be started with followRedirects=false");
}
- McpJsonMapper mapper = jsonMapper;
- return new McpModernClient(
+ McpModernHttpTransport transport =
new McpModernHttpTransport(
client,
target,
- mapper,
+ jsonMapper,
maxMessageBytes,
maxConcurrentCalls,
requestTimeout,
- requestCustomizer),
- mapper,
- modernCapabilities,
- inputHandler,
- maxInputRounds);
+ requestCustomizer);
+ McpClient.AsyncBuilder builder =
+ McpClient.async(transport)
+ .jsonMapper(jsonMapper)
+ .roundTimeout(requestTimeout)
+ .maxInputRounds(maxInputRounds);
+ if (formElicitation != null) {
+ builder.formElicitation(formElicitation);
+ }
+ if (urlElicitation != null) {
+ builder.urlElicitation(urlElicitation);
+ }
+ return new Modern(
+ builder.build(),
+ new McpTasksClient(
+ transport, jsonMapper, formElicitation, urlElicitation, maxInputRounds),
+ transport);
}
/** Starts a {@code 2026-07-28} client, and discovers the server's support of it. */
- private void startModern(McpModernClient candidate) {
+ private void startModern(Modern candidate) {
try {
- McpSchema.DiscoverResult discovered = candidate.discover().block(requestTimeout);
+ McpSchema.DiscoverResult discovered =
+ candidate.client().discover().block(requestTimeout);
if (discovered == null
|| discovered.supportedVersions() == null
|| !discovered.supportedVersions().contains(McpProtocol.MODERN_VERSION)) {
@@ -524,7 +563,7 @@ private void startModern(McpModernClient candidate) {
} catch (RuntimeException e) {
try {
candidate.close();
- } catch (IOException cleanup) {
+ } catch (RuntimeException cleanup) {
e.addSuppressed(cleanup);
}
throw e;
@@ -535,11 +574,28 @@ private void startModern(McpModernClient candidate) {
}
/**
- * The {@link McpProtocol#MODERN_VERSION} client, when that is the revision set.
+ * The SDK's {@link McpProtocol#MODERN_VERSION} client, once that is the revision spoken. It
+ * sends its requests over this adapter's HTTP connector, within its limits, and answers their
+ * {@code input_required} results with its elicitation handlers. It declares the capabilities of
+ * those handlers only: task-augmented calls go through {@link #getTasksClient()}.
+ *
+ * @return The client.
+ */
+ public synchronized McpAsyncClient getModernClient() {
+ return modern().client();
+ }
+
+ /**
+ * The client of the Tasks extension, once {@link McpProtocol#MODERN_VERSION} is the revision
+ * spoken.
*
* @return The client.
*/
- public synchronized McpModernClient getModernClient() {
+ public synchronized McpTasksClient getTasksClient() {
+ return modern().tasks();
+ }
+
+ private Modern modern() {
if (!started || modern == null) {
throw new IllegalStateException("MCP 2026-07-28 client is not started");
}
@@ -580,11 +636,11 @@ public synchronized boolean isStarted() {
return started;
}
- private synchronized McpModernClient modernOrNull() {
+ private synchronized McpAsyncClient modernOrNull() {
if (!started) {
throw new IllegalStateException("MCP client is not started");
}
- return modern;
+ return modern == null ? null : modern.client();
}
/**
@@ -594,15 +650,15 @@ private synchronized McpModernClient modernOrNull() {
* @return The page of tools.
*/
public McpSchema.ListToolsResult listTools(String cursor) {
- McpModernClient current = modernOrNull();
+ McpAsyncClient current = modernOrNull();
if (current != null) {
- return current.listTools(cursor).block(requestTimeout);
+ return current.tools().cursor(cursor).list().block(requestTimeout);
}
return legacy().listTools(cursor).block(requestTimeout);
}
/**
- * Calls a tool, in either era. An {@code input_required} result the input handler doesn't
+ * Calls a tool, in either era. An {@code input_required} result the elicitation handlers don't
* answer fails the call.
*
* @param name The tool.
@@ -610,47 +666,34 @@ public McpSchema.ListToolsResult listTools(String cursor) {
* @return The tool's result.
*/
public McpSchema.CallToolResult callTool(String name, Map arguments) {
- McpModernClient current = modernOrNull();
+ McpAsyncClient current = modernOrNull();
if (current == null) {
return legacy().callTool(
new McpSchema.CallToolRequest(name, arguments, null, null, null))
.block(requestTimeout);
}
- var outcome =
- current.callTool(new McpSchema.CallToolRequest(name, arguments, null, null, null))
- .block(requestTimeout);
- if (!(outcome instanceof McpSchema.CallToolResult result)) {
- throw new IllegalStateException(
- "MCP tool " + name + " requires input that was not provided");
- }
- return result;
+ var tool = current.tool(name);
+ return (arguments == null ? tool : tool.arguments(arguments)).call().block(requestTimeout);
}
/**
- * Reads a resource, in either era. An {@code input_required} result the input handler doesn't
- * answer fails the read.
+ * Reads a resource, in either era. An {@code input_required} result the elicitation handlers
+ * don't answer fails the read.
*
* @param uri The resource URI.
* @return The resource's contents.
*/
public McpSchema.ReadResourceResult readResource(String uri) {
- McpModernClient current = modernOrNull();
+ McpAsyncClient current = modernOrNull();
if (current == null) {
return legacy().readResource(new McpSchema.ReadResourceRequest(uri, null, null, null))
.block(requestTimeout);
}
- var outcome =
- current.readResource(new McpSchema.ReadResourceRequest(uri, null, null, null), null)
- .block(requestTimeout);
- if (!(outcome instanceof McpSchema.ReadResourceResult result)) {
- throw new IllegalStateException(
- "MCP resource " + uri + " requires input that was not provided");
- }
- return result;
+ return current.resource(uri).read().block(requestTimeout);
}
/**
- * Gets a prompt, in either era. An {@code input_required} result the input handler doesn't
+ * Gets a prompt, in either era. An {@code input_required} result the elicitation handlers don't
* answer fails the request.
*
* @param name The prompt.
@@ -658,17 +701,16 @@ public McpSchema.ReadResourceResult readResource(String uri) {
* @return The prompt.
*/
public McpSchema.GetPromptResult getPrompt(String name, Map arguments) {
- McpModernClient current = modernOrNull();
- var request = new McpSchema.GetPromptRequest(name, arguments, null, null, null);
+ McpAsyncClient current = modernOrNull();
if (current == null) {
- return legacy().getPrompt(request).block(requestTimeout);
- }
- var outcome = current.getPrompt(request, null).block(requestTimeout);
- if (!(outcome instanceof McpSchema.GetPromptResult result)) {
- throw new IllegalStateException(
- "MCP prompt " + name + " requires input that was not provided");
+ return legacy().getPrompt(
+ new McpSchema.GetPromptRequest(name, arguments, null, null, null))
+ .block(requestTimeout);
}
- return result;
+ var prompt = current.prompt(name);
+ return (arguments == null ? prompt : prompt.arguments(arguments))
+ .get()
+ .block(requestTimeout);
}
private synchronized McpLegacyEdge.Client legacy() {
@@ -683,8 +725,6 @@ public synchronized void stop() {
started = false;
try {
modern.close();
- } catch (IOException e) {
- throw new UncheckedIOException(e);
} finally {
modern = null;
}
diff --git a/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/McpInputHandler.java b/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/McpInputHandler.java
deleted file mode 100644
index 09d36d067f..0000000000
--- a/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/McpInputHandler.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * Copyright 2005-2026 Qlik
- *
- * The content of this file is subject to the terms of the Apache 2.0 open
- * source license available at https://www.opensource.org/licenses/apache-2.0
- *
- * Restlet is a registered trademark of QlikTech International AB.
- */
-package org.restlet.ext.mcp;
-
-import io.modelcontextprotocol.modern.McpSchema;
-import java.util.Map;
-import reactor.core.publisher.Mono;
-
-/**
- * Answers the input an MCP {@link McpProtocol#MODERN_VERSION} server asks for, through an {@code
- * input_required} result, such as an elicitation: {@link McpModernClient} then retries the request
- * with the responses and the result's request state. Experimental: the SDK's modern API is a
- * preview.
- */
-@FunctionalInterface
-public interface McpInputHandler {
-
- /**
- * Answers the input requests of a result.
- *
- * @param required The result, with its input requests by key.
- * @return The responses, by the keys of the input requests, such as {@code {"action": "accept",
- * "content": {...}}} for an elicitation; or an empty {@code Mono} to return the result to
- * the caller instead of retrying.
- */
- Mono