diff --git a/mcp-test/src/main/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientTests.java b/mcp-test/src/main/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientTests.java index 71356351..2af4a83c 100644 --- a/mcp-test/src/main/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientTests.java +++ b/mcp-test/src/main/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientTests.java @@ -453,8 +453,8 @@ void testLoggingLevelsWithoutInitialization() { @Test void testLoggingLevels() { withClient(createMcpTransport(), mcpAsyncClient -> { - Mono testAllLevels = mcpAsyncClient.initialize().then(Mono.defer(() -> { - Mono chain = Mono.empty(); + Mono testAllLevels = mcpAsyncClient.initialize().then(Mono.defer(() -> { + Mono chain = Mono.just(Map.of()); for (McpSchema.LoggingLevel level : McpSchema.LoggingLevel.values()) { chain = chain.then(mcpAsyncClient.setLoggingLevel(level)); } diff --git a/mcp/src/main/java/io/modelcontextprotocol/client/McpAsyncClient.java b/mcp/src/main/java/io/modelcontextprotocol/client/McpAsyncClient.java index ce49b0a5..b400bd66 100644 --- a/mcp/src/main/java/io/modelcontextprotocol/client/McpAsyncClient.java +++ b/mcp/src/main/java/io/modelcontextprotocol/client/McpAsyncClient.java @@ -780,7 +780,7 @@ private NotificationHandler asyncLoggingNotificationHandler( * @return A Mono that completes when the logging level is set. * @see McpSchema.LoggingLevel */ - public Mono setLoggingLevel(LoggingLevel loggingLevel) { + public Mono setLoggingLevel(LoggingLevel loggingLevel) { if (loggingLevel == null) { return Mono.error(new McpError("Logging level must not be null")); } @@ -789,7 +789,8 @@ public Mono setLoggingLevel(LoggingLevel loggingLevel) { String levelName = this.transport.unmarshalFrom(loggingLevel, new TypeReference() { }); Map params = Map.of("level", levelName); - return this.mcpSession.sendNotification(McpSchema.METHOD_LOGGING_SET_LEVEL, params); + return this.mcpSession.sendRequest(McpSchema.METHOD_LOGGING_SET_LEVEL, params, new TypeReference<>() { + }); }); } diff --git a/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java b/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java index df938668..b1c5c662 100644 --- a/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java +++ b/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java @@ -680,12 +680,13 @@ public Mono loggingNotification(LoggingMessageNotification loggingMessageN return this.mcpTransportProvider.notifyClients(McpSchema.METHOD_NOTIFICATION_MESSAGE, params); } - private McpServerSession.RequestHandler setLoggerRequestHandler() { + private McpServerSession.RequestHandler setLoggerRequestHandler() { return (exchange, params) -> { - this.minLoggingLevel = objectMapper.convertValue(params, new TypeReference() { - }); - - return Mono.empty(); + this.minLoggingLevel = objectMapper + .convertValue(params, new TypeReference() { + }) + .level(); + return Mono.just(Map.of()); }; } diff --git a/mcp/src/main/java/io/modelcontextprotocol/spec/McpSchema.java b/mcp/src/main/java/io/modelcontextprotocol/spec/McpSchema.java index e38403c3..f5d785e9 100644 --- a/mcp/src/main/java/io/modelcontextprotocol/spec/McpSchema.java +++ b/mcp/src/main/java/io/modelcontextprotocol/spec/McpSchema.java @@ -1143,6 +1143,10 @@ public LoggingMessageNotification build() { } }// @formatter:on + @JsonIgnoreProperties(ignoreUnknown = true) + public record SetLoggingLevelRequest(@JsonProperty("level") LoggingLevel level) { + } + public enum LoggingLevel {// @formatter:off @JsonProperty("debug") DEBUG(0), @JsonProperty("info") INFO(1), diff --git a/mcp/src/test/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientTests.java b/mcp/src/test/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientTests.java index ac7b9e5e..6150b450 100644 --- a/mcp/src/test/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientTests.java +++ b/mcp/src/test/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientTests.java @@ -454,8 +454,8 @@ void testLoggingLevelsWithoutInitialization() { @Test void testLoggingLevels() { withClient(createMcpTransport(), mcpAsyncClient -> { - Mono testAllLevels = mcpAsyncClient.initialize().then(Mono.defer(() -> { - Mono chain = Mono.empty(); + Mono testAllLevels = mcpAsyncClient.initialize().then(Mono.defer(() -> { + Mono chain = Mono.just(Map.of()); for (McpSchema.LoggingLevel level : McpSchema.LoggingLevel.values()) { chain = chain.then(mcpAsyncClient.setLoggingLevel(level)); }