Skip to content

Commit a0c8ef0

Browse files
authored
Merge branch 'main' into deprecate-customizeRequest
2 parents a3b0cfa + cbb235f commit a0c8ef0

File tree

20 files changed

+986
-258
lines changed

20 files changed

+986
-258
lines changed

conformance-tests/client-jdk-http-client/pom.xml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.modelcontextprotocol.sdk</groupId>
88
<artifactId>conformance-tests</artifactId>
9-
<version>1.1.0-SNAPSHOT</version>
9+
<version>2.0.0-SNAPSHOT</version>
1010
</parent>
1111
<artifactId>client-jdk-http-client</artifactId>
1212
<packaging>jar</packaging>
@@ -16,19 +16,19 @@
1616

1717
<scm>
1818
<url>https://github.com/modelcontextprotocol/java-sdk</url>
19-
<connection>git://github.com/modelcontextprotocol/java-sdk.git</connection>
20-
<developerConnection>git@github.com/modelcontextprotocol/java-sdk.git</developerConnection>
19+
<connection>scm:git:git://github.com/modelcontextprotocol/java-sdk.git</connection>
20+
<developerConnection>scm:git:ssh://git@github.com/modelcontextprotocol/java-sdk.git</developerConnection>
2121
</scm>
2222

2323
<properties>
2424
<maven.deploy.skip>true</maven.deploy.skip>
2525
</properties>
26-
26+
2727
<dependencies>
2828
<dependency>
2929
<groupId>io.modelcontextprotocol.sdk</groupId>
3030
<artifactId>mcp</artifactId>
31-
<version>1.1.0-SNAPSHOT</version>
31+
<version>2.0.0-SNAPSHOT</version>
3232
</dependency>
3333

3434
<!-- Logging -->
@@ -57,7 +57,8 @@
5757
<transformers>
5858
<transformer
5959
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
60-
<mainClass>io.modelcontextprotocol.conformance.client.ConformanceJdkClientMcpClient</mainClass>
60+
<mainClass>
61+
io.modelcontextprotocol.conformance.client.ConformanceJdkClientMcpClient</mainClass>
6162
</transformer>
6263
<transformer
6364
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
@@ -79,4 +80,4 @@
7980
</plugins>
8081
</build>
8182

82-
</project>
83+
</project>

conformance-tests/client-spring-http-client/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.modelcontextprotocol.sdk</groupId>
88
<artifactId>conformance-tests</artifactId>
9-
<version>1.1.0-SNAPSHOT</version>
9+
<version>2.0.0-SNAPSHOT</version>
1010
</parent>
1111
<artifactId>client-spring-http-client</artifactId>
1212
<packaging>jar</packaging>
@@ -16,8 +16,8 @@
1616

1717
<scm>
1818
<url>https://github.com/modelcontextprotocol/java-sdk</url>
19-
<connection>git://github.com/modelcontextprotocol/java-sdk.git</connection>
20-
<developerConnection>git@github.com/modelcontextprotocol/java-sdk.git</developerConnection>
19+
<connection>scm:git:git://github.com/modelcontextprotocol/java-sdk.git</connection>
20+
<developerConnection>scm:git:ssh://git@github.com/modelcontextprotocol/java-sdk.git</developerConnection>
2121
</scm>
2222

2323
<properties>
@@ -106,4 +106,4 @@
106106
</repository>
107107
</repositories>
108108

109-
</project>
109+
</project>

conformance-tests/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.modelcontextprotocol.sdk</groupId>
88
<artifactId>mcp-parent</artifactId>
9-
<version>1.1.0-SNAPSHOT</version>
9+
<version>2.0.0-SNAPSHOT</version>
1010
</parent>
1111
<artifactId>conformance-tests</artifactId>
1212
<packaging>pom</packaging>
@@ -16,18 +16,18 @@
1616

1717
<scm>
1818
<url>https://github.com/modelcontextprotocol/java-sdk</url>
19-
<connection>git://github.com/modelcontextprotocol/java-sdk.git</connection>
20-
<developerConnection>git@github.com/modelcontextprotocol/java-sdk.git</developerConnection>
19+
<connection>scm:git:git://github.com/modelcontextprotocol/java-sdk.git</connection>
20+
<developerConnection>scm:git:ssh://git@github.com/modelcontextprotocol/java-sdk.git</developerConnection>
2121
</scm>
2222

2323
<properties>
2424
<maven.deploy.skip>true</maven.deploy.skip>
2525
</properties>
26-
26+
2727
<modules>
2828
<module>client-jdk-http-client</module>
2929
<module>client-spring-http-client</module>
3030
<module>server-servlet</module>
3131
</modules>
3232

33-
</project>
33+
</project>

conformance-tests/server-servlet/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.modelcontextprotocol.sdk</groupId>
88
<artifactId>conformance-tests</artifactId>
9-
<version>1.1.0-SNAPSHOT</version>
9+
<version>2.0.0-SNAPSHOT</version>
1010
</parent>
1111
<artifactId>server-servlet</artifactId>
1212
<packaging>jar</packaging>
@@ -16,8 +16,8 @@
1616

1717
<scm>
1818
<url>https://github.com/modelcontextprotocol/java-sdk</url>
19-
<connection>git://github.com/modelcontextprotocol/java-sdk.git</connection>
20-
<developerConnection>git@github.com/modelcontextprotocol/java-sdk.git</developerConnection>
19+
<connection>scm:git:git://github.com/modelcontextprotocol/java-sdk.git</connection>
20+
<developerConnection>scm:git:ssh://git@github.com/modelcontextprotocol/java-sdk.git</developerConnection>
2121
</scm>
2222

2323
<properties>
@@ -28,7 +28,7 @@
2828
<dependency>
2929
<groupId>io.modelcontextprotocol.sdk</groupId>
3030
<artifactId>mcp</artifactId>
31-
<version>1.1.0-SNAPSHOT</version>
31+
<version>2.0.0-SNAPSHOT</version>
3232
</dependency>
3333

3434
<dependency>

docs/client.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,49 @@ Resources represent server-side data sources that clients can access using URI t
408408
.subscribe();
409409
```
410410

411+
### Resource Subscriptions
412+
413+
When the server advertises `resources.subscribe` support, clients can subscribe to individual resources and receive a callback whenever the server pushes a `notifications/resources/updated` notification for that URI. The SDK automatically re-reads the resource on notification and delivers the updated contents to the registered consumer.
414+
415+
Register a consumer on the client builder, then subscribe/unsubscribe at any time:
416+
417+
=== "Sync API"
418+
419+
```java
420+
McpSyncClient client = McpClient.sync(transport)
421+
.resourcesUpdateConsumer(contents -> {
422+
// called with the updated resource contents after each notification
423+
System.out.println("Resource updated: " + contents);
424+
})
425+
.build();
426+
427+
client.initialize();
428+
429+
// Subscribe to a specific resource URI
430+
client.subscribeResource(new McpSchema.SubscribeRequest("custom://resource"));
431+
432+
// ... later, stop receiving updates
433+
client.unsubscribeResource(new McpSchema.UnsubscribeRequest("custom://resource"));
434+
```
435+
436+
=== "Async API"
437+
438+
```java
439+
McpAsyncClient client = McpClient.async(transport)
440+
.resourcesUpdateConsumer(contents -> Mono.fromRunnable(() -> {
441+
System.out.println("Resource updated: " + contents);
442+
}))
443+
.build();
444+
445+
client.initialize()
446+
.then(client.subscribeResource(new McpSchema.SubscribeRequest("custom://resource")))
447+
.subscribe();
448+
449+
// ... later, stop receiving updates
450+
client.unsubscribeResource(new McpSchema.UnsubscribeRequest("custom://resource"))
451+
.subscribe();
452+
```
453+
411454
### Prompt System
412455

413456
The prompt system enables interaction with server-side prompt templates. These templates can be discovered and executed with custom parameters, allowing for dynamic text generation based on predefined patterns.

docs/server.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ The server supports both synchronous and asynchronous APIs, allowing for flexibl
3333
McpSyncServer syncServer = McpServer.sync(transportProvider)
3434
.serverInfo("my-server", "1.0.0")
3535
.capabilities(ServerCapabilities.builder()
36-
.resources(false, true) // Enable resource support with list changes
36+
.resources(false, true) // Resource support: subscribe=false, listChanged=true
3737
.tools(true) // Enable tool support with list changes
3838
.prompts(true) // Enable prompt support with list changes
3939
.completions() // Enable completions support
@@ -57,7 +57,7 @@ The server supports both synchronous and asynchronous APIs, allowing for flexibl
5757
McpAsyncServer asyncServer = McpServer.async(transportProvider)
5858
.serverInfo("my-server", "1.0.0")
5959
.capabilities(ServerCapabilities.builder()
60-
.resources(false, true) // Enable resource support with list changes
60+
.resources(false, true) // Resource support: subscribe=false, listChanged=true
6161
.tools(true) // Enable tool support with list changes
6262
.prompts(true) // Enable prompt support with list changes
6363
.completions() // Enable completions support
@@ -319,7 +319,7 @@ The server can be configured with various capabilities:
319319

320320
```java
321321
var capabilities = ServerCapabilities.builder()
322-
.resources(false, true) // Resource support (subscribe, listChanged)
322+
.resources(true, true) // Resource support: subscribe=true, listChanged=true
323323
.tools(true) // Tool support with list changes notifications
324324
.prompts(true) // Prompt support with list changes notifications
325325
.completions() // Enable completions support
@@ -438,6 +438,42 @@ Resources provide context to AI models by exposing data such as: File contents,
438438
);
439439
```
440440

441+
### Resource Subscriptions
442+
443+
When the `subscribe` capability is enabled, clients can subscribe to specific resources and receive targeted `notifications/resources/updated` notifications when those resources change. Only sessions that have explicitly subscribed to a given URI receive the notification — not every connected client.
444+
445+
Enable subscription support in the server capabilities:
446+
447+
```java
448+
McpSyncServer server = McpServer.sync(transportProvider)
449+
.serverInfo("my-server", "1.0.0")
450+
.capabilities(ServerCapabilities.builder()
451+
.resources(true, false) // subscribe=true, listChanged=false
452+
.build())
453+
.resources(myResourceSpec)
454+
.build();
455+
```
456+
457+
When a subscribed resource changes, notify only the interested sessions:
458+
459+
=== "Sync"
460+
461+
```java
462+
server.notifyResourcesUpdated(
463+
new McpSchema.ResourcesUpdatedNotification("custom://resource")
464+
);
465+
```
466+
467+
=== "Async"
468+
469+
```java
470+
server.notifyResourcesUpdated(
471+
new McpSchema.ResourcesUpdatedNotification("custom://resource")
472+
).subscribe();
473+
```
474+
475+
If no sessions are subscribed to the given URI the call completes immediately without sending any messages. Subscription state is automatically cleaned up when a client session closes.
476+
441477
### Resource Template Specification
442478

443479
Resource templates allow servers to expose parameterized resources using URI templates:

mcp-bom/pom.xml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>io.modelcontextprotocol.sdk</groupId>
99
<artifactId>mcp-parent</artifactId>
10-
<version>1.1.0-SNAPSHOT</version>
10+
<version>2.0.0-SNAPSHOT</version>
1111
</parent>
1212

1313
<artifactId>mcp-bom</artifactId>
@@ -16,13 +16,13 @@
1616
<name>Java SDK MCP BOM</name>
1717
<description>Java SDK MCP Bill of Materials</description>
1818

19-
<url>https://github.com/modelcontextprotocol/java-sdk</url>
19+
<url>https://github.com/modelcontextprotocol/java-sdk</url>
2020

21-
<scm>
22-
<url>https://github.com/modelcontextprotocol/java-sdk</url>
23-
<connection>git://github.com/modelcontextprotocol/java-sdk.git</connection>
24-
<developerConnection>git@github.com/modelcontextprotocol/java-sdk.git</developerConnection>
25-
</scm>
21+
<scm>
22+
<url>https://github.com/modelcontextprotocol/java-sdk</url>
23+
<connection>scm:git:git://github.com/modelcontextprotocol/java-sdk.git</connection>
24+
<developerConnection>scm:git:ssh://git@github.com/modelcontextprotocol/java-sdk.git</developerConnection>
25+
</scm>
2626

2727
<dependencyManagement>
2828
<dependencies>
@@ -47,6 +47,13 @@
4747
<version>${project.version}</version>
4848
</dependency>
4949

50+
<!-- MCP JSON Jackson -->
51+
<dependency>
52+
<groupId>io.modelcontextprotocol.sdk</groupId>
53+
<artifactId>mcp-json-jackson3</artifactId>
54+
<version>${project.version}</version>
55+
</dependency>
56+
5057
<!-- MCP Test -->
5158
<dependency>
5259
<groupId>io.modelcontextprotocol.sdk</groupId>

mcp-core/pom.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.modelcontextprotocol.sdk</groupId>
88
<artifactId>mcp-parent</artifactId>
9-
<version>1.1.0-SNAPSHOT</version>
9+
<version>2.0.0-SNAPSHOT</version>
1010
</parent>
1111
<artifactId>mcp-core</artifactId>
1212
<packaging>jar</packaging>
@@ -16,8 +16,8 @@
1616

1717
<scm>
1818
<url>https://github.com/modelcontextprotocol/java-sdk</url>
19-
<connection>git://github.com/modelcontextprotocol/java-sdk.git</connection>
20-
<developerConnection>git@github.com/modelcontextprotocol/java-sdk.git</developerConnection>
19+
<connection>scm:git:git://github.com/modelcontextprotocol/java-sdk.git</connection>
20+
<developerConnection>scm:git:ssh://git@github.com/modelcontextprotocol/java-sdk.git</developerConnection>
2121
</scm>
2222

2323
<build>
@@ -164,14 +164,14 @@
164164
<scope>test</scope>
165165
</dependency>
166166

167-
<!-- Test-only JSON library for the Gson-based McpJsonMapper example -->
168-
<dependency>
169-
<groupId>com.google.code.gson</groupId>
170-
<artifactId>gson</artifactId>
171-
<version>2.10.1</version>
172-
<scope>test</scope>
173-
</dependency>
167+
<!-- Test-only JSON library for the Gson-based McpJsonMapper example -->
168+
<dependency>
169+
<groupId>com.google.code.gson</groupId>
170+
<artifactId>gson</artifactId>
171+
<version>2.10.1</version>
172+
<scope>test</scope>
173+
</dependency>
174174
</dependencies>
175175

176176

177-
</project>
177+
</project>

0 commit comments

Comments
 (0)