From c0e70bfbf526ea95c55fb52c0fb38ddce8c6fec7 Mon Sep 17 00:00:00 2001 From: Jerome Louvel <374450+jlouvel@users.noreply.github.com> Date: Mon, 30 Nov 2026 17:31:29 -0500 Subject: [PATCH 1/2] Send MCP client requests as an entity that can be read again (#1777) A transient body could not be hashed by the AWS SigV4 signer of a request customizer. Signed-off-by: Jerome Louvel <374450+jlouvel@users.noreply.github.com> --- changes.md | 4 +++ .../mcp/internal/McpModernHttpTransport.java | 16 ++++++++--- .../legacy/RestletMcpClientTransport.java | 7 ++--- .../ext/mcp/McpModernClientTestCase.java | 27 +++++++++++++++++++ 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/changes.md b/changes.md index 665f5e2272..1c88e742f1 100644 --- a/changes.md +++ b/changes.md @@ -173,6 +173,10 @@ Changes log result of another call, such as an elicitation handler, when `maxConcurrentCalls` leaves no other slot: a call now frees its slot before it hands over its answer, where it freed it a moment after, and the handler's call could find the slot still held (#1772). + - The MCP client sends its requests as an entity that can be read again, where it sent a + transient one: a request customizer can hash the body, as the signer of AWS Signature + Version 4 (`ChallengeScheme.HTTP_AWS_SIGV4`) does, which refused a service other than S3 + and left an S3 body unsigned (`UNSIGNED-PAYLOAD`) (#1777). - The MCP STDIO connector no longer treats a clean end of its input as a failure: the requests already sent are answered before it closes (within the request timeout of the adapter, plus 5 s), where they were aborted, so a client that half-closes stdin after its last request, or a diff --git a/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/internal/McpModernHttpTransport.java b/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/internal/McpModernHttpTransport.java index 006c286460..3fcf3de66a 100644 --- a/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/internal/McpModernHttpTransport.java +++ b/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/internal/McpModernHttpTransport.java @@ -42,9 +42,9 @@ import org.restlet.data.ServerSentEvent; import org.restlet.data.Status; import org.restlet.ext.mcp.McpProtocol; -import org.restlet.representation.ByteArrayRepresentation; import org.restlet.representation.EventStreamReader; import org.restlet.representation.Representation; +import org.restlet.representation.StringRepresentation; import reactor.core.Disposable; import reactor.core.publisher.Flux; import reactor.core.publisher.Operators; @@ -297,6 +297,16 @@ private void exchange( } } + /** + * The message as an entity that can be read again, which a request customizer may need: the + * signer of AWS Signature Version 4 hashes the body before it is sent, and refuses, or leaves + * unsigned, a transient entity such as a {@code ByteArrayRepresentation}. + */ + public static Representation repeatable(byte[] message) { + return new StringRepresentation( + new String(message, StandardCharsets.UTF_8), MediaType.APPLICATION_JSON); + } + private Request request( JsonRpc.JSONRPCRequest rpc, String version, @@ -308,9 +318,7 @@ private Request request( new Request( Method.POST, target, - new ByteArrayRepresentation( - McpMessages.encode(mapper, rpc, maxMessageBytes), - MediaType.APPLICATION_JSON)); + repeatable(McpMessages.encode(mapper, rpc, maxMessageBytes))); customizer.accept(request); callCustomizer.accept(request, context); request.getHeaders().set(McpProtocol.VERSION_HEADER, version); diff --git a/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/internal/legacy/RestletMcpClientTransport.java b/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/internal/legacy/RestletMcpClientTransport.java index 6f4bc5c062..4f29d7bb66 100644 --- a/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/internal/legacy/RestletMcpClientTransport.java +++ b/org.restlet.ext.mcp/src/main/java/org/restlet/ext/mcp/internal/legacy/RestletMcpClientTransport.java @@ -41,8 +41,8 @@ import org.restlet.ext.mcp.McpProtocol; import org.restlet.ext.mcp.internal.McpHttpStatusException; import org.restlet.ext.mcp.internal.McpMessages; +import org.restlet.ext.mcp.internal.McpModernHttpTransport; import org.restlet.ext.mcp.internal.McpWorkers; -import org.restlet.representation.ByteArrayRepresentation; import org.restlet.representation.EventStreamReader; import reactor.core.publisher.Mono; @@ -214,10 +214,7 @@ private void exchange(McpSchema.JSONRPCMessage message, AtomicReference String sent = getSessionId(); byte[] bytes = McpMessages.encode(mapper, message, maxMessageBytes); Request request = - new Request( - Method.POST, - target, - new ByteArrayRepresentation(bytes, MediaType.APPLICATION_JSON)); + new Request(Method.POST, target, McpModernHttpTransport.repeatable(bytes)); customizer.accept(request); String version = negotiated; request.getHeaders() diff --git a/org.restlet.ext.mcp/src/test/java/org/restlet/ext/mcp/McpModernClientTestCase.java b/org.restlet.ext.mcp/src/test/java/org/restlet/ext/mcp/McpModernClientTestCase.java index 1ea170a49c..fa73e988ca 100644 --- a/org.restlet.ext.mcp/src/test/java/org/restlet/ext/mcp/McpModernClientTestCase.java +++ b/org.restlet.ext.mcp/src/test/java/org/restlet/ext/mcp/McpModernClientTestCase.java @@ -419,6 +419,33 @@ void aCallCustomizerGetsTheReactorContextOfItsCall() throws Exception { assertEquals(List.of("alice", "none", "bob"), runs); } + /** + * The body of a request can be read again, so a request customizer can hash it, as the signer + * of AWS Signature Version 4 does (#1777). + */ + @Test + void theBodyOfARequestCanBeReadAgainByItsCustomizer() throws Exception { + List hashed = new CopyOnWriteArrayList<>(); + start( + "HTTP2", + null, + configured -> + configured.setRequestCustomizer( + request -> { + try { + assertFalse(request.getEntity().isTransient()); + String first = request.getEntity().getText(); + assertEquals(first, request.getEntity().getText()); + hashed.add(first); + } catch (Exception e) { + throw new IllegalStateException(e); + } + })); + + assertFalse(hashed.isEmpty(), "the start sends a discovery"); + assertTrue(hashed.getFirst().contains("server/discover"), hashed.toString()); + } + /** Starts the server, if needed, and a modern client with an optional form handler. */ private McpAsyncClient start( String mode, McpAsyncElicitationHandler form) From 5c790393a11f34d1804f71afdb9390e86cdd4067 Mon Sep 17 00:00:00 2001 From: Jerome Louvel <374450+jlouvel@users.noreply.github.com> Date: Mon, 30 Nov 2026 17:31:55 -0500 Subject: [PATCH 2/2] Log the #1777 fix under milestone 4 in changes.md Signed-off-by: Jerome Louvel <374450+jlouvel@users.noreply.github.com> --- changes.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/changes.md b/changes.md index 1c88e742f1..f3905510d2 100644 --- a/changes.md +++ b/changes.md @@ -2,6 +2,11 @@ Changes log =========== - 3.0 Milestone 4 (month-day-2026) + - Bugs fixed + - The MCP client sends its requests as an entity that can be read again, where it sent a + transient one: a request customizer can hash the body, as the signer of AWS Signature + Version 4 (`ChallengeScheme.HTTP_AWS_SIGV4`) does, which refused a service other than S3 + and left an S3 body unsigned (`UNSIGNED-PAYLOAD`) (#1777). - 3.0 Milestone 3 (12-01-2026) - Breaking changes @@ -173,10 +178,6 @@ Changes log result of another call, such as an elicitation handler, when `maxConcurrentCalls` leaves no other slot: a call now frees its slot before it hands over its answer, where it freed it a moment after, and the handler's call could find the slot still held (#1772). - - The MCP client sends its requests as an entity that can be read again, where it sent a - transient one: a request customizer can hash the body, as the signer of AWS Signature - Version 4 (`ChallengeScheme.HTTP_AWS_SIGV4`) does, which refused a service other than S3 - and left an S3 body unsigned (`UNSIGNED-PAYLOAD`) (#1777). - The MCP STDIO connector no longer treats a clean end of its input as a failure: the requests already sent are answered before it closes (within the request timeout of the adapter, plus 5 s), where they were aborted, so a client that half-closes stdin after its last request, or a