Skip to content

Commit c91f731

Browse files
committed
feat: adds mcp-spi
1 parent 261554b commit c91f731

File tree

73 files changed

+499
-255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+499
-255
lines changed

mcp-bom/pom.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,17 @@
2626

2727
<dependencyManagement>
2828
<dependencies>
29-
<!-- Core MCP -->
29+
<!-- MCP Spec -->
3030
<dependency>
3131
<groupId>io.modelcontextprotocol.sdk</groupId>
32-
<artifactId>mcp</artifactId>
32+
<artifactId>mcp-reactor</artifactId>
33+
<version>${project.version}</version>
34+
</dependency>
35+
36+
<!-- MCP Reactor -->
37+
<dependency>
38+
<groupId>io.modelcontextprotocol.sdk</groupId>
39+
<artifactId>mcp-reactor</artifactId>
3340
<version>${project.version}</version>
3441
</dependency>
3542

File renamed without changes.

mcp/pom.xml renamed to mcp-reactor/pom.xml

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
<artifactId>mcp-parent</artifactId>
99
<version>0.10.0-SNAPSHOT</version>
1010
</parent>
11-
<artifactId>mcp</artifactId>
11+
<artifactId>mcp-reactor</artifactId>
1212
<packaging>jar</packaging>
13-
<name>Java MCP SDK</name>
14-
<description>Java SDK implementation of the Model Context Protocol, enabling seamless integration with language models and AI tools</description>
13+
<name>Java MCP Reactor SDK</name>
14+
<description>Java Reactor SDK implementation of the Model Context Protocol, enabling seamless integration with language models and AI tools</description>
1515
<url>https://github.com/modelcontextprotocol/java-sdk</url>
1616

1717
<scm>
@@ -65,6 +65,11 @@
6565
</build>
6666

6767
<dependencies>
68+
<dependency>
69+
<groupId>io.modelcontextprotocol.sdk</groupId>
70+
<artifactId>mcp-spi</artifactId>
71+
<version>${project.version}</version>
72+
</dependency>
6873

6974
<dependency>
7075
<groupId>org.slf4j</groupId>
@@ -83,37 +88,13 @@
8388
<artifactId>reactor-core</artifactId>
8489
</dependency>
8590

86-
<dependency>
87-
<groupId>org.springframework</groupId>
88-
<artifactId>spring-webmvc</artifactId>
89-
<version>${springframework.version}</version>
90-
<scope>test</scope>
91-
</dependency>
92-
9391

9492
<dependency>
9593
<groupId>io.projectreactor.netty</groupId>
9694
<artifactId>reactor-netty-http</artifactId>
9795
<scope>test</scope>
9896
</dependency>
9997

100-
<!-- The Spring Context is required due to the reactor-netty connector being dependent on
101-
the Spring Lifecycle, as discussed here:
102-
https://github.com/spring-projects/spring-framework/issues/31180 -->
103-
<dependency>
104-
<groupId>org.springframework</groupId>
105-
<artifactId>spring-context</artifactId>
106-
<version>${springframework.version}</version>
107-
<scope>test</scope>
108-
</dependency>
109-
110-
<dependency>
111-
<groupId>org.springframework</groupId>
112-
<artifactId>spring-test</artifactId>
113-
<version>${springframework.version}</version>
114-
<scope>test</scope>
115-
</dependency>
116-
11798
<dependency>
11899
<groupId>org.assertj</groupId>
119100
<artifactId>assertj-core</artifactId>

mcp/src/main/java/io/modelcontextprotocol/client/McpAsyncClient.java renamed to mcp-reactor/src/main/java/io/modelcontextprotocol/client/McpAsyncClient.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
import java.util.function.Function;
1515

1616
import com.fasterxml.jackson.core.type.TypeReference;
17-
import io.modelcontextprotocol.spec.McpClientSession;
18-
import io.modelcontextprotocol.spec.McpClientSession.NotificationHandler;
19-
import io.modelcontextprotocol.spec.McpClientSession.RequestHandler;
17+
import io.modelcontextprotocol.session.McpClientSession;
18+
import io.modelcontextprotocol.session.McpClientSession.NotificationHandler;
19+
import io.modelcontextprotocol.session.McpClientSession.RequestHandler;
2020
import io.modelcontextprotocol.spec.McpClientTransport;
2121
import io.modelcontextprotocol.spec.McpError;
2222
import io.modelcontextprotocol.spec.McpSchema;
@@ -471,7 +471,8 @@ public Mono<Void> removeRoot(String rootUri) {
471471
*/
472472
public Mono<Void> rootsListChangedNotification() {
473473
return this.withInitializationCheck("sending roots list changed notification",
474-
initResult -> this.mcpSession.sendNotification(McpSchema.METHOD_NOTIFICATION_ROOTS_LIST_CHANGED));
474+
initResult -> (Mono<Void>) this.mcpSession
475+
.sendNotification(McpSchema.METHOD_NOTIFICATION_ROOTS_LIST_CHANGED));
475476
}
476477

477478
private RequestHandler<McpSchema.ListRootsResult> rootsListRequestHandler() {

mcp/src/main/java/io/modelcontextprotocol/client/McpClient.java renamed to mcp-reactor/src/main/java/io/modelcontextprotocol/client/McpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ class AsyncSpec {
400400

401401
private ClientCapabilities capabilities;
402402

403-
private Implementation clientInfo = new Implementation("Spring AI MCP Client", "0.3.1");
403+
private Implementation clientInfo = new Implementation("Java Reactor AI MCP Client", "0.3.1");
404404

405405
private final Map<String, Root> roots = new HashMap<>();
406406

mcp/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java renamed to mcp-reactor/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,20 @@
2222
import io.modelcontextprotocol.spec.McpClientTransport;
2323
import io.modelcontextprotocol.spec.McpError;
2424
import io.modelcontextprotocol.spec.McpSchema;
25+
import io.modelcontextprotocol.spec.McpTransport;
2526
import io.modelcontextprotocol.spec.McpSchema.JSONRPCMessage;
2627
import io.modelcontextprotocol.util.Assert;
2728
import io.modelcontextprotocol.util.Utils;
29+
30+
import org.reactivestreams.Publisher;
2831
import org.slf4j.Logger;
2932
import org.slf4j.LoggerFactory;
33+
3034
import reactor.core.publisher.Mono;
3135

3236
/**
33-
* Server-Sent Events (SSE) implementation of the
34-
* {@link io.modelcontextprotocol.spec.McpTransport} that follows the MCP HTTP with SSE
35-
* transport specification, using Java's HttpClient.
37+
* Server-Sent Events (SSE) implementation of the {@link McpTransport} that follows the
38+
* MCP HTTP with SSE transport specification, using Java's HttpClient.
3639
*
3740
* <p>
3841
* This transport implementation establishes a bidirectional communication channel between
@@ -337,7 +340,7 @@ public HttpClientSseClientTransport build() {
337340
* @return a Mono that completes when the connection is established
338341
*/
339342
@Override
340-
public Mono<Void> connect(Function<Mono<JSONRPCMessage>, Mono<JSONRPCMessage>> handler) {
343+
public Mono<Void> connect(Function<Publisher<JSONRPCMessage>, Publisher<JSONRPCMessage>> handler) {
341344
CompletableFuture<Void> future = new CompletableFuture<>();
342345
connectionFuture.set(future);
343346

@@ -358,7 +361,8 @@ public void onEvent(SseEvent event) {
358361
}
359362
else if (MESSAGE_EVENT_TYPE.equals(event.type())) {
360363
JSONRPCMessage message = McpSchema.deserializeJsonRpcMessage(objectMapper, event.data());
361-
handler.apply(Mono.just(message)).subscribe();
364+
Publisher<McpSchema.JSONRPCMessage> result = handler.apply(Mono.just(message));
365+
Mono.from(result).subscribe();
362366
}
363367
else {
364368
logger.error("Received unrecognized SSE event type: {}", event.type());
@@ -435,6 +439,11 @@ public Mono<Void> sendMessage(JSONRPCMessage message) {
435439
}
436440
}
437441

442+
@Override
443+
public void close() {
444+
this.closeGracefully().subscribe();
445+
}
446+
438447
/**
439448
* Gracefully closes the transport connection.
440449
*

0 commit comments

Comments
 (0)