Skip to content

Commit 2805809

Browse files
committed
Address review comments
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
1 parent d806d7a commit 2805809

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

mcp-spring/mcp-spring-webflux/src/test/java/io/modelcontextprotocol/WebFluxSseIntegrationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ void testRootsWithMultipleHandlers(String clientType) {
344344
mcpServer.close();
345345
}
346346

347-
// @ParameterizedTest(name = "{0} : {displayName} ")
348-
// @ValueSource(strings = { "httpclient", "webflux" })
347+
@ParameterizedTest(name = "{0} : {displayName} ")
348+
@ValueSource(strings = { "httpclient", "webflux" })
349349
void testRootsServerCloseWithActiveSubscription(String clientType) {
350350

351351
var clientBuilder = clientBuilders.get(clientType);
@@ -380,7 +380,7 @@ void testRootsServerCloseWithActiveSubscription(String clientType) {
380380

381381
String emptyJsonSchema = """
382382
{
383-
"": "http://json-schema.org/draft-07/schema#",
383+
"$schema": "http://json-schema.org/draft-07/schema#",
384384
"type": "object",
385385
"properties": {}
386386
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import java.time.Duration;
88

9-
import io.modelcontextprotocol.spec.McpClientTransport;
109
import io.modelcontextprotocol.spec.McpSchema;
1110
import io.modelcontextprotocol.spec.McpSchema.ClientCapabilities;
1211
import io.modelcontextprotocol.spec.McpSchema.GetPromptRequest;
@@ -321,6 +320,7 @@ public GetPromptResult getPrompt(GetPromptRequest getPromptRequest) {
321320
/**
322321
* Client can set the minimum logging level it wants to receive from the server.
323322
* @param loggingLevel the min logging level
323+
* @return empty response
324324
*/
325325
public Object setLoggingLevel(McpSchema.LoggingLevel loggingLevel) {
326326
return this.delegate.setLoggingLevel(loggingLevel).block();

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,19 @@ public Mono<Void> loggingNotification(LoggingMessageNotification loggingMessageN
122122
}
123123

124124
return Mono.defer(() -> {
125-
if (loggingMessageNotification.level().level() < this.session.getMinLoggingLevel().level()) {
125+
if (!this.session.isLoingLevelEnabled(loggingMessageNotification.level())) {
126126
return Mono.empty();
127127
}
128128

129129
return this.session.sendNotification(McpSchema.METHOD_NOTIFICATION_MESSAGE, loggingMessageNotification);
130130
});
131131
}
132132

133+
/**
134+
* Set the minimum logging level for the client. Messages below this level will be
135+
* filtered out.
136+
* @param minLoggingLevel The minimum logging level
137+
*/
133138
public void setMinLoggingLevel(LoggingLevel minLoggingLevel) {
134139
Assert.notNull(minLoggingLevel, "minLoggingLevel must not be null");
135140
this.session.setMinLoggingLevel(minLoggingLevel);

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.fasterxml.jackson.core.type.TypeReference;
1111
import io.modelcontextprotocol.server.McpAsyncServerExchange;
1212
import io.modelcontextprotocol.spec.McpSchema.LoggingLevel;
13+
import io.modelcontextprotocol.util.Assert;
1314
import org.slf4j.Logger;
1415
import org.slf4j.LoggerFactory;
1516
import reactor.core.publisher.Mono;
@@ -54,7 +55,7 @@ public class McpServerSession implements McpSession {
5455

5556
private final AtomicInteger state = new AtomicInteger(STATE_UNINITIALIZED);
5657

57-
private final AtomicReference<LoggingLevel> minLoggingLevel = new AtomicReference<>(LoggingLevel.INFO);
58+
private volatile LoggingLevel minLoggingLevel = LoggingLevel.INFO;
5859

5960
/**
6061
* Creates a new server session with the given parameters and the transport to use.
@@ -87,12 +88,21 @@ public String getId() {
8788
return this.id;
8889
}
8990

90-
public LoggingLevel getMinLoggingLevel() {
91-
return this.minLoggingLevel.get();
91+
/**
92+
* Checks if the logging level bigger or equal to the minimum set logging level.
93+
* @return true if the logging level is enabled, false otherwise
94+
*/
95+
public boolean isLoingLevelEnabled(LoggingLevel loggingLevel) {
96+
return loggingLevel.level() >= this.minLoggingLevel.level();
9297
}
9398

99+
/**
100+
* Set the minimum logging level for this session.
101+
* @param minLoggingLevel the minimum logging level
102+
*/
94103
public void setMinLoggingLevel(LoggingLevel minLoggingLevel) {
95-
this.minLoggingLevel.set(minLoggingLevel);
104+
Assert.notNull(minLoggingLevel, "minLoggingLevel can't be null");
105+
this.minLoggingLevel = minLoggingLevel;
96106
}
97107

98108
/**
@@ -149,6 +159,10 @@ public Mono<Void> sendNotification(String method, Map<String, Object> params) {
149159
return this.transport.sendMessage(jsonrpcNotification);
150160
}
151161

162+
// NOTE: This is a workaround for the fact that the {@link #sendNotification(String,
163+
// Map)} method doesn't accept types like LoggingMessageNotification
164+
// TODO investigate if this method can replace the {@link #sendNotification(String,
165+
// Map)} - Breaking change.
152166
public Mono<Void> sendNotification(String method, Object params) {
153167
McpSchema.JSONRPCNotification jsonrpcNotification = new McpSchema.JSONRPCNotification(McpSchema.JSONRPC_VERSION,
154168
method, this.transport.unmarshalFrom(params, new TypeReference<Map<String, Object>>() {

0 commit comments

Comments
 (0)