|
23 | 23 | import io.modelcontextprotocol.spec.McpSchema.Implementation;
|
24 | 24 | import io.modelcontextprotocol.spec.McpSchema.Root;
|
25 | 25 | import io.modelcontextprotocol.util.Assert;
|
| 26 | +import io.modelcontextprotocol.util.Utils; |
26 | 27 | import reactor.core.publisher.Mono;
|
27 | 28 |
|
28 | 29 | /**
|
@@ -161,6 +162,12 @@ class SyncSpec {
|
161 | 162 |
|
162 | 163 | private Duration initializationTimeout = Duration.ofSeconds(20);
|
163 | 164 |
|
| 165 | + /** |
| 166 | + * List of JSON-RPC methods that can be ignored. These methods will not be |
| 167 | + * processed and will not generate errors if received |
| 168 | + */ |
| 169 | + private final List<String> ignorableJsonRpcMethods = new ArrayList<>(Utils.DEFAULT_IGNORABLE_JSON_RPC_METHODS); |
| 170 | + |
164 | 171 | private ClientCapabilities capabilities;
|
165 | 172 |
|
166 | 173 | private Implementation clientInfo = new Implementation("Java SDK MCP Client", "1.0.0");
|
@@ -215,6 +222,36 @@ public SyncSpec initializationTimeout(Duration initializationTimeout) {
|
215 | 222 | return this;
|
216 | 223 | }
|
217 | 224 |
|
| 225 | + /** |
| 226 | + * Sets the list of JSON-RPC methods that can be ignored by the client. These |
| 227 | + * methods will not be processed and will not generate errors if received. |
| 228 | + * @param ignorableJsonRpcMethods A list of JSON-RPC method names to ignore. Must |
| 229 | + * not be null. |
| 230 | + * @return This builder instance for method chaining |
| 231 | + * @throws IllegalArgumentException if ignorableJsonRpcMethods is null |
| 232 | + */ |
| 233 | + public SyncSpec ignorableJsonRpcMethods(List<String> ignorableJsonRpcMethods) { |
| 234 | + Assert.notNull(ignorableJsonRpcMethods, "Ignorable JSON-RPC methods must not be null"); |
| 235 | + this.ignorableJsonRpcMethods.addAll(ignorableJsonRpcMethods); |
| 236 | + return this; |
| 237 | + } |
| 238 | + |
| 239 | + /** |
| 240 | + * Sets the list of JSON-RPC methods that can be ignored by the client. These |
| 241 | + * methods will not be processed and will not generate errors if received. |
| 242 | + * @param ignorableJsonRpcMethods An array of JSON-RPC method names to ignore. |
| 243 | + * Must not be null. |
| 244 | + * @return This builder instance for method chaining |
| 245 | + * @throws IllegalArgumentException if ignorableJsonRpcMethods is null |
| 246 | + */ |
| 247 | + public SyncSpec ignorableJsonRpcMethods(String... ignorableJsonRpcMethods) { |
| 248 | + Assert.notNull(ignorableJsonRpcMethods, "Ignorable JSON-RPC methods must not be null"); |
| 249 | + for (String method : ignorableJsonRpcMethods) { |
| 250 | + this.ignorableJsonRpcMethods.add(method); |
| 251 | + } |
| 252 | + return this; |
| 253 | + } |
| 254 | + |
218 | 255 | /**
|
219 | 256 | * Sets the client capabilities that will be advertised to the server during
|
220 | 257 | * connection initialization. Capabilities define what features the client
|
@@ -422,8 +459,8 @@ public McpSyncClient build() {
|
422 | 459 |
|
423 | 460 | McpClientFeatures.Async asyncFeatures = McpClientFeatures.Async.fromSync(syncFeatures);
|
424 | 461 |
|
425 |
| - return new McpSyncClient( |
426 |
| - new McpAsyncClient(transport, this.requestTimeout, this.initializationTimeout, asyncFeatures)); |
| 462 | + return new McpSyncClient(new McpAsyncClient(transport, this.requestTimeout, this.initializationTimeout, |
| 463 | + asyncFeatures, this.ignorableJsonRpcMethods)); |
427 | 464 | }
|
428 | 465 |
|
429 | 466 | }
|
@@ -452,6 +489,12 @@ class AsyncSpec {
|
452 | 489 |
|
453 | 490 | private Duration initializationTimeout = Duration.ofSeconds(20);
|
454 | 491 |
|
| 492 | + /** |
| 493 | + * List of JSON-RPC methods that can be ignored. These methods will not be |
| 494 | + * processed and will not generate errors if received |
| 495 | + */ |
| 496 | + private final List<String> ignorableJsonRpcMethods = new ArrayList<>(Utils.DEFAULT_IGNORABLE_JSON_RPC_METHODS); |
| 497 | + |
455 | 498 | private ClientCapabilities capabilities;
|
456 | 499 |
|
457 | 500 | private Implementation clientInfo = new Implementation("Spring AI MCP Client", "0.3.1");
|
@@ -506,6 +549,36 @@ public AsyncSpec initializationTimeout(Duration initializationTimeout) {
|
506 | 549 | return this;
|
507 | 550 | }
|
508 | 551 |
|
| 552 | + /** |
| 553 | + * Sets the list of JSON-RPC methods that can be ignored by the client. These |
| 554 | + * methods will not be processed and will not generate errors if received. |
| 555 | + * @param ignorableJsonRpcMethods A list of JSON-RPC method names to ignore. Must |
| 556 | + * not be null. |
| 557 | + * @return This builder instance for method chaining |
| 558 | + * @throws IllegalArgumentException if ignorableJsonRpcMethods is null |
| 559 | + */ |
| 560 | + public AsyncSpec ignorableJsonRpcMethods(List<String> ignorableJsonRpcMethods) { |
| 561 | + Assert.notNull(ignorableJsonRpcMethods, "Ignorable JSON-RPC methods must not be null"); |
| 562 | + this.ignorableJsonRpcMethods.addAll(ignorableJsonRpcMethods); |
| 563 | + return this; |
| 564 | + } |
| 565 | + |
| 566 | + /** |
| 567 | + * Sets the list of JSON-RPC methods that can be ignored by the client. These |
| 568 | + * methods will not be processed and will not generate errors if received. |
| 569 | + * @param ignorableJsonRpcMethods An array of JSON-RPC method names to ignore. |
| 570 | + * Must not be null. |
| 571 | + * @return This builder instance for method chaining |
| 572 | + * @throws IllegalArgumentException if ignorableJsonRpcMethods is null |
| 573 | + */ |
| 574 | + public AsyncSpec ignorableJsonRpcMethods(String... ignorableJsonRpcMethods) { |
| 575 | + Assert.notNull(ignorableJsonRpcMethods, "Ignorable JSON-RPC methods must not be null"); |
| 576 | + for (String method : ignorableJsonRpcMethods) { |
| 577 | + this.ignorableJsonRpcMethods.add(method); |
| 578 | + } |
| 579 | + return this; |
| 580 | + } |
| 581 | + |
509 | 582 | /**
|
510 | 583 | * Sets the client capabilities that will be advertised to the server during
|
511 | 584 | * connection initialization. Capabilities define what features the client
|
@@ -730,7 +803,8 @@ public McpAsyncClient build() {
|
730 | 803 | new McpClientFeatures.Async(this.clientInfo, this.capabilities, this.roots,
|
731 | 804 | this.toolsChangeConsumers, this.resourcesChangeConsumers, this.resourcesUpdateConsumers,
|
732 | 805 | this.promptsChangeConsumers, this.loggingConsumers, this.progressConsumers,
|
733 |
| - this.samplingHandler, this.elicitationHandler)); |
| 806 | + this.samplingHandler, this.elicitationHandler), |
| 807 | + this.ignorableJsonRpcMethods); |
734 | 808 | }
|
735 | 809 |
|
736 | 810 | }
|
|
0 commit comments