Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -214,10 +214,7 @@ private void exchange(McpSchema.JSONRPCMessage message, AtomicReference<Request>
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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<McpSchema.ElicitFormRequest> form)
Expand Down