|
4 | 4 |
|
5 | 5 | package io.modelcontextprotocol.client; |
6 | 6 |
|
7 | | -import java.time.Duration; |
8 | | -import java.util.ArrayList; |
9 | | -import java.util.HashMap; |
10 | | -import java.util.List; |
11 | | -import java.util.Map; |
12 | | -import java.util.function.Consumer; |
13 | | -import java.util.function.Function; |
14 | | -import java.util.function.Supplier; |
15 | | - |
16 | | -import io.modelcontextprotocol.json.schema.JsonSchemaValidator; |
17 | 7 | import io.modelcontextprotocol.common.McpTransportContext; |
| 8 | +import io.modelcontextprotocol.json.schema.JsonSchemaValidator; |
18 | 9 | import io.modelcontextprotocol.spec.McpClientTransport; |
19 | 10 | import io.modelcontextprotocol.spec.McpSchema; |
20 | 11 | import io.modelcontextprotocol.spec.McpSchema.ClientCapabilities; |
|
28 | 19 | import io.modelcontextprotocol.util.Assert; |
29 | 20 | import reactor.core.publisher.Mono; |
30 | 21 |
|
| 22 | +import java.time.Duration; |
| 23 | +import java.util.ArrayList; |
| 24 | +import java.util.HashMap; |
| 25 | +import java.util.List; |
| 26 | +import java.util.Map; |
| 27 | +import java.util.function.Consumer; |
| 28 | +import java.util.function.Function; |
| 29 | +import java.util.function.Supplier; |
| 30 | + |
31 | 31 | /** |
32 | 32 | * Factory class for creating Model Context Protocol (MCP) clients. MCP is a protocol that |
33 | 33 | * enables AI models to interact with external tools and resources through a standardized |
@@ -346,6 +346,22 @@ public SyncSpec resourcesChangeConsumer(Consumer<List<McpSchema.Resource>> resou |
346 | 346 | return this; |
347 | 347 | } |
348 | 348 |
|
| 349 | + /** |
| 350 | + * Adds a consumer to be notified when a specific resource is updated. This allows |
| 351 | + * the client to react to changes in individual resources, such as updates to |
| 352 | + * their content or metadata. |
| 353 | + * @param resourcesUpdateConsumer A consumer function that processes the updated |
| 354 | + * resource and returns a Mono indicating the completion of the processing. Must |
| 355 | + * not be null. |
| 356 | + * @return This builder instance for method chaining. |
| 357 | + * @throws IllegalArgumentException If the resourcesUpdateConsumer is null. |
| 358 | + */ |
| 359 | + public SyncSpec resourcesUpdateConsumer(Consumer<List<McpSchema.ResourceContents>> resourcesUpdateConsumer) { |
| 360 | + Assert.notNull(resourcesUpdateConsumer, "Resources update consumer must not be null"); |
| 361 | + this.resourcesUpdateConsumers.add(resourcesUpdateConsumer); |
| 362 | + return this; |
| 363 | + } |
| 364 | + |
349 | 365 | /** |
350 | 366 | * Adds a consumer to be notified when the available prompts change. This allows |
351 | 367 | * the client to react to changes in the server's prompt templates, such as new |
|
0 commit comments