Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@

class McpServerLogConsumer implements Consumer<LoggingMessageNotification> {

private static final Logger LOG = LoggerFactory.getLogger(McpServerLogConsumer.class);

@Override
public void accept(LoggingMessageNotification notif) {
Logger log = LoggerFactory.getLogger(notif.logger());
log.atLevel(convert(notif.level())).log("{}", notif.data());
LOG.atLevel(convert(notif.level())).log("{}", notif.data());
}

private Level convert(McpSchema.LoggingLevel level) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
import io.modelcontextprotocol.client.McpClient;
import io.modelcontextprotocol.client.McpSyncClient;
import io.modelcontextprotocol.spec.McpClientTransport;
import io.modelcontextprotocol.spec.McpSchema;
import io.modelcontextprotocol.spec.McpSchema.ClientCapabilities;
import io.modelcontextprotocol.spec.McpSchema.InitializeResult;
import java.time.Duration;
import java.util.Optional;
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;

/**
* Manages MCP client sessions.
Expand Down Expand Up @@ -71,8 +74,8 @@ public static McpSyncClient initializeSession(
.initializationTimeout(
Optional.ofNullable(initializationTimeout).orElse(Duration.ofSeconds(10)))
.requestTimeout(Optional.ofNullable(requestTimeout).orElse(Duration.ofSeconds(10)))
.loggingConsumer(new McpServerLogConsumer())
.capabilities(ClientCapabilities.builder().build())
.loggingConsumer(new McpServerLogConsumer())
.build();
InitializeResult initResult = client.initialize();
logger.debug("Initialize Client Result: {}", initResult);
Expand Down Expand Up @@ -101,6 +104,16 @@ public static McpAsyncClient initializeAsyncSession(
initializationTimeout == null ? Duration.ofSeconds(10) : initializationTimeout)
.requestTimeout(requestTimeout == null ? Duration.ofSeconds(10) : requestTimeout)
.capabilities(ClientCapabilities.builder().build())
.loggingConsumer(asyncMcpServerLogConsumer())
.build();
}

private static Function<McpSchema.LoggingMessageNotification, Mono<Void>>
asyncMcpServerLogConsumer() {
var syncConsumer = new McpServerLogConsumer();
return message -> {
syncConsumer.accept(message);
return Mono.empty();
};
}
}