@@ -157,11 +157,13 @@ class SyncSpec {
157
157
158
158
private Duration requestTimeout = Duration .ofSeconds (20 ); // Default timeout
159
159
160
+ private boolean connectOnInit = true ; // Default true, for backward compatibility
161
+
160
162
private Duration initializationTimeout = Duration .ofSeconds (20 );
161
163
162
164
private ClientCapabilities capabilities ;
163
165
164
- private Implementation clientInfo = new Implementation ("Java SDK MCP Client" , "1.0 .0" );
166
+ private Implementation clientInfo = new Implementation ("Java SDK MCP Sync Client" , "0.10 .0" );
165
167
166
168
private final Map <String , Root > roots = new HashMap <>();
167
169
@@ -195,6 +197,17 @@ public SyncSpec requestTimeout(Duration requestTimeout) {
195
197
return this ;
196
198
}
197
199
200
+ /**
201
+ * Sets whether to connect to the server during the initialization phase (open an
202
+ * SSE stream).
203
+ * @param connectOnInit true to open an SSE stream during the initialization
204
+ * @return This builder instance for method chaining
205
+ */
206
+ public SyncSpec withConnectOnInit (final boolean connectOnInit ) {
207
+ this .connectOnInit = connectOnInit ;
208
+ return this ;
209
+ }
210
+
198
211
/**
199
212
* @param initializationTimeout The duration to wait for the initialization
200
213
* lifecycle step to complete.
@@ -368,8 +381,8 @@ public McpSyncClient build() {
368
381
369
382
McpClientFeatures .Async asyncFeatures = McpClientFeatures .Async .fromSync (syncFeatures );
370
383
371
- return new McpSyncClient (
372
- new McpAsyncClient ( transport , this .requestTimeout , this . initializationTimeout , asyncFeatures ));
384
+ return new McpSyncClient (new McpAsyncClient ( transport , this . requestTimeout , this . initializationTimeout ,
385
+ asyncFeatures , this .connectOnInit ));
373
386
}
374
387
375
388
}
@@ -396,11 +409,13 @@ class AsyncSpec {
396
409
397
410
private Duration requestTimeout = Duration .ofSeconds (20 ); // Default timeout
398
411
412
+ private boolean connectOnInit = true ; // Default true, for backward compatibility
413
+
399
414
private Duration initializationTimeout = Duration .ofSeconds (20 );
400
415
401
416
private ClientCapabilities capabilities ;
402
417
403
- private Implementation clientInfo = new Implementation ("Spring AI MCP Client" , "0.3.1 " );
418
+ private Implementation clientInfo = new Implementation ("Java SDK MCP Async Client" , "0.10.0 " );
404
419
405
420
private final Map <String , Root > roots = new HashMap <>();
406
421
@@ -434,6 +449,17 @@ public AsyncSpec requestTimeout(Duration requestTimeout) {
434
449
return this ;
435
450
}
436
451
452
+ /**
453
+ * Sets whether to connect to the server during the initialization phase (open an
454
+ * SSE stream).
455
+ * @param connectOnInit true to open an SSE stream during the initialization
456
+ * @return This builder instance for method chaining
457
+ */
458
+ public AsyncSpec withConnectOnInit (final boolean connectOnInit ) {
459
+ this .connectOnInit = connectOnInit ;
460
+ return this ;
461
+ }
462
+
437
463
/**
438
464
* @param initializationTimeout The duration to wait for the initialization
439
465
* lifecycle step to complete.
@@ -606,7 +632,8 @@ public McpAsyncClient build() {
606
632
return new McpAsyncClient (this .transport , this .requestTimeout , this .initializationTimeout ,
607
633
new McpClientFeatures .Async (this .clientInfo , this .capabilities , this .roots ,
608
634
this .toolsChangeConsumers , this .resourcesChangeConsumers , this .promptsChangeConsumers ,
609
- this .loggingConsumers , this .samplingHandler ));
635
+ this .loggingConsumers , this .samplingHandler ),
636
+ this .connectOnInit );
610
637
}
611
638
612
639
}
0 commit comments