-
Notifications
You must be signed in to change notification settings - Fork 783
Open
Description
Bug description
Using the java mcp client can not connect to postman mcp server:
try (McpSyncClient client = McpClient.sync(HttpClientStreamableHttpTransport
.builder("https://mcp.postman.com")
.jsonMapper(new JacksonMcpJsonMapper(new ObjectMapper()))
.endpoint("/mcp")
.requestBuilder(HttpRequest.newBuilder()
.header("Authorization", System.getenv("POSTMAN_API_KEY")))
.build())
.jsonSchemaValidator(new JacksonJsonSchemaValidatorSupplier().get())
.clientInfo(new McpSchema.Implementation("Test", "1.0.0"))
.requestTimeout(Duration.ofMillis(10000))
.build()) {
McpSchema.InitializeResult initialize = client.initialize();
System.out.println(initialize);
if (client.isInitialized()) {
client.listTools().tools().forEach(tool -> {
System.out.println("Tool: " + tool.name() + " - " + tool.description());
});
}
}Throws:
java.lang.RuntimeException: Unknown media type returned: text/plain; charset=utf-8It's arguable if this is actually a bug in the Postman mcp server as they are returning text/plan while client indicates that it accepts only application/json and text/event-stream.
But using mcp inspector or Postman MCP client connection there is no error and initialization and tools listing works as expected.
Possible fix to maybe ignore the content type header for notification responses:
Subject: [PATCH] mcp client
---
Index: mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java
--- a/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java (revision f7a460fb505aeba239165f9bc4ef508a77ba102a)
+++ b/mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java (date 1768333732198)
@@ -491,6 +491,17 @@
.firstValue(HttpHeaders.CONTENT_LENGTH)
.orElse(null);
+ if (sentMessage instanceof McpSchema.JSONRPCNotification) {
+ deliveredSink.success();
+ if (contentType.contains(APPLICATION_JSON)
+ && Integer.parseInt(Optional.ofNullable(contentLength).orElse("0")) > 0) {
+ String data = ((ResponseSubscribers.AggregateResponseEvent) responseEvent).data();
+ logger.warn("Notification: {} received non-compliant response: {}", sentMessage,
+ Utils.hasText(data) ? data : "[empty]");
+ }
+ return Mono.empty();
+ }
+
if (contentType.isBlank() || "0".equals(contentLength)) {
logger.debug("No body returned for POST in session {}", sessionRepresentation);
// No content type means no response body, so we can just
@@ -530,11 +541,6 @@
else if (contentType.contains(APPLICATION_JSON)) {
deliveredSink.success();
String data = ((ResponseSubscribers.AggregateResponseEvent) responseEvent).data();
- if (sentMessage instanceof McpSchema.JSONRPCNotification) {
- logger.warn("Notification: {} received non-compliant response: {}", sentMessage,
- Utils.hasText(data) ? data : "[empty]");
- return Mono.empty();
- }
try {
return Mono.just(McpSchema.deserializeJsonRpcMessage(jsonMapper, data));Metadata
Metadata
Assignees
Labels
No labels