Skip to content

Commit 713ee1a

Browse files
Randgalttzolov
andcommitted
fix: ServerCapabilities should not enable logging by default (#463)
- Change LoggingCapabilities from default-initialized to nullable in ServerCapabilities - Add check if server logging is enabled in McpAsyncClient before setting logging level - Ensure McpAsyncServer always enables logging capabilities when built - Ensure McpStatelessAsyncServer has disabled logging capability by default - Update tests to verify logging capabilities can be null Signed-off-by: Christian Tzolov <[email protected]> Co-authored-by: Christian Tzolov <[email protected]>
1 parent 6c38f37 commit 713ee1a

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

mcp-test/src/main/java/io/modelcontextprotocol/AbstractMcpClientServerIntegrationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ void testLoggingNotification(String clientType) throws InterruptedException {
950950
List<McpSchema.LoggingMessageNotification> receivedNotifications = new CopyOnWriteArrayList<>();
951951

952952
var clientBuilder = clientBuilders.get(clientType);
953-
;
953+
954954
// Create server with a tool that sends logging notifications
955955
McpServerFeatures.AsyncToolSpecification tool = McpServerFeatures.AsyncToolSpecification.builder()
956956
.tool(Tool.builder()
@@ -999,7 +999,7 @@ void testLoggingNotification(String clientType) throws InterruptedException {
999999
.build();
10001000

10011001
var mcpServer = prepareAsyncServerBuilder().serverInfo("test-server", "1.0.0")
1002-
.capabilities(ServerCapabilities.builder().logging().tools(true).build())
1002+
.capabilities(ServerCapabilities.builder().tools(true).build())
10031003
.tools(tool)
10041004
.build();
10051005

mcp/src/main/java/io/modelcontextprotocol/client/McpAsyncClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,9 @@ public Mono<Void> setLoggingLevel(LoggingLevel loggingLevel) {
869869
}
870870

871871
return this.initializer.withIntitialization("setting logging level", init -> {
872+
if (init.initializeResult().capabilities().logging() == null) {
873+
return Mono.error(new IllegalStateException("Server's Logging capabilities are not enabled!"));
874+
}
872875
var params = new McpSchema.SetLevelRequest(loggingLevel);
873876
return init.mcpSession().sendRequest(McpSchema.METHOD_LOGGING_SET_LEVEL, params, OBJECT_TYPE_REF).then();
874877
});

mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public class McpAsyncServer {
132132
this.mcpTransportProvider = mcpTransportProvider;
133133
this.objectMapper = objectMapper;
134134
this.serverInfo = features.serverInfo();
135-
this.serverCapabilities = features.serverCapabilities();
135+
this.serverCapabilities = features.serverCapabilities().mutate().logging().build();
136136
this.instructions = features.instructions();
137137
this.tools.addAll(withStructuredOutputHandling(jsonSchemaValidator, features.tools()));
138138
this.resources.putAll(features.resources());
@@ -157,7 +157,7 @@ public class McpAsyncServer {
157157
this.mcpTransportProvider = mcpTransportProvider;
158158
this.objectMapper = objectMapper;
159159
this.serverInfo = features.serverInfo();
160-
this.serverCapabilities = features.serverCapabilities();
160+
this.serverCapabilities = features.serverCapabilities().mutate().logging().build();
161161
this.instructions = features.instructions();
162162
this.tools.addAll(withStructuredOutputHandling(jsonSchemaValidator, features.tools()));
163163
this.resources.putAll(features.resources());

mcp/src/main/java/io/modelcontextprotocol/spec/McpSchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ public static class Builder {
548548

549549
private Map<String, Object> experimental;
550550

551-
private LoggingCapabilities logging = new LoggingCapabilities();
551+
private LoggingCapabilities logging;
552552

553553
private PromptCapabilities prompts;
554554

mcp/src/test/java/io/modelcontextprotocol/client/McpAsyncClientResponseHandlerTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ void testSuccessfulInitialization() {
8080
assertThat(result).isNotNull();
8181
assertThat(result.protocolVersion()).isEqualTo(transport.protocolVersions().get(0));
8282
assertThat(result.capabilities()).isEqualTo(serverCapabilities);
83+
assertThat(result.capabilities().logging()).isNull();
8384
assertThat(result.serverInfo()).isEqualTo(serverInfo);
8485
assertThat(result.instructions()).isEqualTo("Test instructions");
8586

0 commit comments

Comments
 (0)