From d420cafb3f6591abe9d398b4910fd635b4c6fffa Mon Sep 17 00:00:00 2001 From: Daniel Garnier-Moiroux Date: Thu, 7 Aug 2025 09:32:40 +0200 Subject: [PATCH] Fix httpRequestCustomizer usage in HttpClientStreamableHttpTransport - Closes #458 Signed-off-by: Daniel Garnier-Moiroux --- .../client/transport/HttpClientStreamableHttpTransport.java | 2 +- ...ttpClientStreamableHttpTransportEmptyJsonResponseTest.java | 2 +- .../transport/HttpClientStreamableHttpTransportTest.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mcp/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java b/mcp/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java index 3cfa7359b..a9e5897b9 100644 --- a/mcp/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java +++ b/mcp/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java @@ -400,7 +400,7 @@ public Mono sendMessage(McpSchema.JSONRPCMessage sentMessage) { .header("Cache-Control", "no-cache") .header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION) .POST(HttpRequest.BodyPublishers.ofString(jsonBody)); - return Mono.from(this.httpRequestCustomizer.customize(builder, "GET", uri, jsonBody)); + return Mono.from(this.httpRequestCustomizer.customize(builder, "POST", uri, jsonBody)); }).flatMapMany(requestBuilder -> Flux.create(responseEventSink -> { // Create the async request with proper body subscriber selection diff --git a/mcp/src/test/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransportEmptyJsonResponseTest.java b/mcp/src/test/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransportEmptyJsonResponseTest.java index f047015d7..8b3668671 100644 --- a/mcp/src/test/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransportEmptyJsonResponseTest.java +++ b/mcp/src/test/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransportEmptyJsonResponseTest.java @@ -84,7 +84,7 @@ void testNotificationInitialized() throws URISyntaxException { StepVerifier.create(transport.sendMessage(testMessage)).verifyComplete(); // Verify the customizer was called - verify(mockRequestCustomizer, atLeastOnce()).customize(any(), eq("GET"), eq(uri), eq( + verify(mockRequestCustomizer, atLeastOnce()).customize(any(), eq("POST"), eq(uri), eq( "{\"jsonrpc\":\"2.0\",\"method\":\"initialize\",\"id\":\"test-id\",\"params\":{\"protocolVersion\":\"2025-03-26\",\"capabilities\":{\"roots\":{\"listChanged\":true}},\"clientInfo\":{\"name\":\"Spring AI MCP Client\",\"version\":\"0.3.1\"}}}")); } diff --git a/mcp/src/test/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransportTest.java b/mcp/src/test/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransportTest.java index 479468f63..d645bb0b3 100644 --- a/mcp/src/test/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransportTest.java +++ b/mcp/src/test/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransportTest.java @@ -80,7 +80,7 @@ void testRequestCustomizer() throws URISyntaxException { StepVerifier.create(t.sendMessage(testMessage)).verifyComplete(); // Verify the customizer was called - verify(mockRequestCustomizer, atLeastOnce()).customize(any(), eq("GET"), eq(uri), eq( + verify(mockRequestCustomizer, atLeastOnce()).customize(any(), eq("POST"), eq(uri), eq( "{\"jsonrpc\":\"2.0\",\"method\":\"initialize\",\"id\":\"test-id\",\"params\":{\"protocolVersion\":\"2025-03-26\",\"capabilities\":{\"roots\":{\"listChanged\":true}},\"clientInfo\":{\"name\":\"Spring AI MCP Client\",\"version\":\"0.3.1\"}}}")); }); } @@ -107,7 +107,7 @@ void testAsyncRequestCustomizer() throws URISyntaxException { StepVerifier.create(t.sendMessage(testMessage)).verifyComplete(); // Verify the customizer was called - verify(mockRequestCustomizer, atLeastOnce()).customize(any(), eq("GET"), eq(uri), eq( + verify(mockRequestCustomizer, atLeastOnce()).customize(any(), eq("POST"), eq(uri), eq( "{\"jsonrpc\":\"2.0\",\"method\":\"initialize\",\"id\":\"test-id\",\"params\":{\"protocolVersion\":\"2025-03-26\",\"capabilities\":{\"roots\":{\"listChanged\":true}},\"clientInfo\":{\"name\":\"Spring AI MCP Client\",\"version\":\"0.3.1\"}}}")); }); }