|
21 | 21 | import io.modelcontextprotocol.spec.McpSchema.CallToolResult; |
22 | 22 | import io.modelcontextprotocol.spec.McpSchema.LoggingLevel; |
23 | 23 | import io.modelcontextprotocol.spec.McpSchema.LoggingMessageNotification; |
| 24 | +import io.modelcontextprotocol.spec.McpSchema.SetLevelRequest; |
24 | 25 | import io.modelcontextprotocol.spec.McpSchema.Tool; |
25 | 26 | import io.modelcontextprotocol.spec.McpServerSession; |
26 | 27 | import io.modelcontextprotocol.spec.McpServerTransportProvider; |
@@ -216,11 +217,17 @@ public Mono<Void> notifyPromptsListChanged() { |
216 | 217 | // --------------------------------------- |
217 | 218 |
|
218 | 219 | /** |
219 | | - * Send a logging message notification to all connected clients. Messages below the |
220 | | - * current minimum logging level will be filtered out. |
| 220 | + * This implementation would, incorrectly, broadcast the logging message to all |
| 221 | + * connected clients, using a single minLoggingLevel for all of them. Similar to the |
| 222 | + * sampling and roots, the logging level should be set per client session and use the |
| 223 | + * ServerExchange to send the logging message to the right client. |
221 | 224 | * @param loggingMessageNotification The logging message to send |
222 | 225 | * @return A Mono that completes when the notification has been sent |
| 226 | + * @deprecated Use |
| 227 | + * {@link McpAsyncServerExchange#loggingNotification(LoggingMessageNotification)} |
| 228 | + * instead. |
223 | 229 | */ |
| 230 | + @Deprecated |
224 | 231 | public Mono<Void> loggingNotification(LoggingMessageNotification loggingMessageNotification) { |
225 | 232 | return this.delegate.loggingNotification(loggingMessageNotification); |
226 | 233 | } |
@@ -257,6 +264,8 @@ private static class AsyncServerImpl extends McpAsyncServer { |
257 | 264 |
|
258 | 265 | private final ConcurrentHashMap<String, McpServerFeatures.AsyncPromptSpecification> prompts = new ConcurrentHashMap<>(); |
259 | 266 |
|
| 267 | + // FIXME: this field is deprecated and should be remvoed together with the |
| 268 | + // broadcasting loggingNotification. |
260 | 269 | private LoggingLevel minLoggingLevel = LoggingLevel.DEBUG; |
261 | 270 |
|
262 | 271 | private List<String> protocolVersions = List.of(McpSchema.LATEST_PROTOCOL_VERSION); |
@@ -677,12 +686,22 @@ public Mono<Void> loggingNotification(LoggingMessageNotification loggingMessageN |
677 | 686 | loggingMessageNotification); |
678 | 687 | } |
679 | 688 |
|
680 | | - private McpServerSession.RequestHandler<Void> setLoggerRequestHandler() { |
| 689 | + private McpServerSession.RequestHandler<Object> setLoggerRequestHandler() { |
681 | 690 | return (exchange, params) -> { |
682 | | - this.minLoggingLevel = objectMapper.convertValue(params, new TypeReference<LoggingLevel>() { |
683 | | - }); |
| 691 | + return Mono.defer(() -> { |
684 | 692 |
|
685 | | - return Mono.empty(); |
| 693 | + SetLevelRequest newMinLoggingLevel = objectMapper.convertValue(params, |
| 694 | + new TypeReference<SetLevelRequest>() { |
| 695 | + }); |
| 696 | + |
| 697 | + exchange.setMinLoggingLevel(newMinLoggingLevel.level()); |
| 698 | + |
| 699 | + // FIXME: this field is deprecated and should be removed together |
| 700 | + // with the broadcasting loggingNotification. |
| 701 | + this.minLoggingLevel = newMinLoggingLevel.level(); |
| 702 | + |
| 703 | + return Mono.just(Map.of()); |
| 704 | + }); |
686 | 705 | }; |
687 | 706 | } |
688 | 707 |
|
|
0 commit comments