From 5bd950d668a939e4c6c3f01f0233b6f01b6a8c1e Mon Sep 17 00:00:00 2001 From: ryan xu Date: Sat, 15 Mar 2025 23:27:00 +0800 Subject: [PATCH] Update PING request handler, return empty map instead of empty string Co-authored-by: NAME Signed-off-by: Christian Tzolov --- .../java/io/modelcontextprotocol/server/McpAsyncServer.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java b/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java index 07a9f15..ef69539 100644 --- a/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java +++ b/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java @@ -6,6 +6,7 @@ package io.modelcontextprotocol.server; import java.time.Duration; import java.util.HashMap; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; @@ -403,7 +404,7 @@ public class McpAsyncServer { // Initialize request handlers for standard MCP methods // Ping MUST respond with an empty data, but not NULL response. - requestHandlers.put(McpSchema.METHOD_PING, (exchange, params) -> Mono.just("")); + requestHandlers.put(McpSchema.METHOD_PING, (exchange, params) -> Mono.just(Map.of())); // Add tools API handlers if the tool capability is enabled if (this.serverCapabilities.tools() != null) { @@ -926,7 +927,7 @@ public class McpAsyncServer { requestHandlers.put(McpSchema.METHOD_INITIALIZE, asyncInitializeRequestHandler()); // Ping MUST respond with an empty data, but not NULL response. - requestHandlers.put(McpSchema.METHOD_PING, (params) -> Mono.just("")); + requestHandlers.put(McpSchema.METHOD_PING, (params) -> Mono.just(Map.of())); // Add tools API handlers if the tool capability is enabled if (this.serverCapabilities.tools() != null) {