1313import java .util .concurrent .atomic .AtomicBoolean ;
1414import java .util .function .Function ;
1515
16+ import io .modelcontextprotocol .logger .McpLogger ;
1617import io .modelcontextprotocol .schema .McpType ;
1718import io .modelcontextprotocol .session .McpClientSession ;
1819import io .modelcontextprotocol .session .McpClientSession .NotificationHandler ;
3334import io .modelcontextprotocol .spec .McpTransport ;
3435import io .modelcontextprotocol .util .Assert ;
3536import io .modelcontextprotocol .util .Utils ;
36- import org .slf4j .Logger ;
37- import org .slf4j .LoggerFactory ;
3837import reactor .core .publisher .Flux ;
3938import reactor .core .publisher .Mono ;
4039import reactor .core .publisher .Sinks ;
7877 */
7978public class McpAsyncClient implements McpClient {
8079
81- private static final Logger logger = LoggerFactory .getLogger (McpAsyncClient .class );
82-
8380 private static final McpType <Void > VOID_TYPE_REFERENCE = McpType .of (Void .class );
8481
8582 protected final Sinks .One <McpSchema .InitializeResult > initializedSink = Sinks .one ();
@@ -145,6 +142,8 @@ public class McpAsyncClient implements McpClient {
145142 */
146143 private final McpTransport transport ;
147144
145+ private final McpLogger logger ;
146+
148147 /**
149148 * Supported protocol versions.
150149 */
@@ -159,7 +158,7 @@ public class McpAsyncClient implements McpClient {
159158 * @param features the MCP Client supported features.
160159 */
161160 McpAsyncClient (McpClientTransport transport , Duration requestTimeout , Duration initializationTimeout ,
162- McpClientFeatures .Async features ) {
161+ McpClientFeatures .Async features , McpLogger logger ) {
163162
164163 Assert .notNull (transport , "Transport must not be null" );
165164 Assert .notNull (requestTimeout , "Request timeout must not be null" );
@@ -170,6 +169,7 @@ public class McpAsyncClient implements McpClient {
170169 this .transport = transport ;
171170 this .roots = new ConcurrentHashMap <>(features .roots ());
172171 this .initializationTimeout = initializationTimeout ;
172+ this .logger = logger ;
173173
174174 // Request Handlers
175175 Map <String , RequestHandler <?>> requestHandlers = new HashMap <>();
@@ -194,7 +194,7 @@ public class McpAsyncClient implements McpClient {
194194 // Tools Change Notification
195195 List <Function <List <McpSchema .Tool >, Mono <Void >>> toolsChangeConsumersFinal = new ArrayList <>();
196196 toolsChangeConsumersFinal
197- .add ((notification ) -> Mono .fromRunnable (() -> logger .debug ("Tools changed: {}" , notification )));
197+ .add ((notification ) -> Mono .fromRunnable (() -> logger .debug ("Tools changed: %s" . formatted ( notification ) )));
198198
199199 if (!Utils .isEmpty (features .toolsChangeConsumers ())) {
200200 toolsChangeConsumersFinal .addAll (features .toolsChangeConsumers ());
@@ -204,8 +204,8 @@ public class McpAsyncClient implements McpClient {
204204
205205 // Resources Change Notification
206206 List <Function <List <McpSchema .Resource >, Mono <Void >>> resourcesChangeConsumersFinal = new ArrayList <>();
207- resourcesChangeConsumersFinal
208- .add (( notification ) -> Mono . fromRunnable (() -> logger .debug ("Resources changed: {}" , notification )));
207+ resourcesChangeConsumersFinal . add (( notification ) -> Mono
208+ .fromRunnable (() -> logger .debug ("Resources changed: %s" . formatted ( notification ) )));
209209
210210 if (!Utils .isEmpty (features .resourcesChangeConsumers ())) {
211211 resourcesChangeConsumersFinal .addAll (features .resourcesChangeConsumers ());
@@ -216,8 +216,8 @@ public class McpAsyncClient implements McpClient {
216216
217217 // Prompts Change Notification
218218 List <Function <List <McpSchema .Prompt >, Mono <Void >>> promptsChangeConsumersFinal = new ArrayList <>();
219- promptsChangeConsumersFinal
220- . add (( notification ) -> Mono .fromRunnable (() -> logger .debug ("Prompts changed: {}" , notification )));
219+ promptsChangeConsumersFinal . add (
220+ ( notification ) -> Mono .fromRunnable (() -> logger .debug ("Prompts changed: %s" . formatted ( notification ) )));
221221 if (!Utils .isEmpty (features .promptsChangeConsumers ())) {
222222 promptsChangeConsumersFinal .addAll (features .promptsChangeConsumers ());
223223 }
@@ -226,7 +226,8 @@ public class McpAsyncClient implements McpClient {
226226
227227 // Utility Logging Notification
228228 List <Function <LoggingMessageNotification , Mono <Void >>> loggingConsumersFinal = new ArrayList <>();
229- loggingConsumersFinal .add ((notification ) -> Mono .fromRunnable (() -> logger .debug ("Logging: {}" , notification )));
229+ loggingConsumersFinal
230+ .add ((notification ) -> Mono .fromRunnable (() -> logger .debug ("Logging: %s" .formatted (notification ))));
230231 if (!Utils .isEmpty (features .loggingConsumers ())) {
231232 loggingConsumersFinal .addAll (features .loggingConsumers ());
232233 }
@@ -344,9 +345,9 @@ public Mono<McpSchema.InitializeResult> initialize() {
344345 this .serverInstructions = initializeResult .instructions ();
345346 this .serverInfo = initializeResult .serverInfo ();
346347
347- logger .info ("Server response with Protocol: {} , Capabilities: {} , Info: {} and Instructions {}" ,
348+ logger .info ("Server response with Protocol: %s , Capabilities: %s , Info: %s and Instructions %s" . formatted (
348349 initializeResult .protocolVersion (), initializeResult .capabilities (), initializeResult .serverInfo (),
349- initializeResult .instructions ());
350+ initializeResult .instructions ())) ;
350351
351352 if (!this .protocolVersions .contains (initializeResult .protocolVersion ())) {
352353 return Mono .error (new McpError (
@@ -414,7 +415,7 @@ public Mono<Void> addRoot(Root root) {
414415
415416 this .roots .put (root .uri (), root );
416417
417- logger .debug ("Added root: {}" , root );
418+ logger .debug ("Added root: %s" . formatted ( root ) );
418419
419420 if (this .clientCapabilities .roots ().listChanged ()) {
420421 if (this .isInitialized ()) {
@@ -445,7 +446,7 @@ public Mono<Void> removeRoot(String rootUri) {
445446 Root removed = this .roots .remove (rootUri );
446447
447448 if (removed != null ) {
448- logger .debug ("Removed Root: {}" , rootUri );
449+ logger .debug ("Removed Root: %s" . formatted ( rootUri ) );
449450 if (this .clientCapabilities .roots ().listChanged ()) {
450451 if (this .isInitialized ()) {
451452 return this .rootsListChangedNotification ();
0 commit comments