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

+9-2
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

+8-27
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

+5-4
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

+1-1
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

+14-5
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
*

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import io.modelcontextprotocol.spec.McpSchema;
2222
import io.modelcontextprotocol.spec.McpSchema.JSONRPCMessage;
2323
import io.modelcontextprotocol.util.Assert;
24+
25+
import org.reactivestreams.Publisher;
2426
import org.slf4j.Logger;
2527
import org.slf4j.LoggerFactory;
2628
import reactor.core.publisher.Flux;
@@ -110,7 +112,7 @@ public StdioClientTransport(ServerParameters params, ObjectMapper objectMapper)
110112
* are null
111113
*/
112114
@Override
113-
public Mono<Void> connect(Function<Mono<JSONRPCMessage>, Mono<JSONRPCMessage>> handler) {
115+
public Mono<Void> connect(Function<Publisher<JSONRPCMessage>, Publisher<JSONRPCMessage>> handler) {
114116
return Mono.<Void>fromRunnable(() -> {
115117
handleIncomingMessages(handler);
116118
handleIncomingErrors();
@@ -218,7 +220,8 @@ private void startErrorProcessing() {
218220
});
219221
}
220222

221-
private void handleIncomingMessages(Function<Mono<JSONRPCMessage>, Mono<JSONRPCMessage>> inboundMessageHandler) {
223+
private void handleIncomingMessages(
224+
Function<Publisher<JSONRPCMessage>, Publisher<JSONRPCMessage>> inboundMessageHandler) {
222225
this.inboundSink.asFlux()
223226
.flatMap(message -> Mono.just(message)
224227
.transform(inboundMessageHandler)
@@ -333,6 +336,11 @@ protected void handleOutbound(Function<Flux<JSONRPCMessage>, Flux<JSONRPCMessage
333336
}).subscribe();
334337
}
335338

339+
@Override
340+
public void close() {
341+
this.closeGracefully().subscribe();
342+
}
343+
336344
/**
337345
* Gracefully closes the transport by destroying the process and disposing of the
338346
* schedulers. This method sends a TERM signal to the process and waits for it to exit

mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java renamed to mcp-reactor/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616

1717
import com.fasterxml.jackson.core.type.TypeReference;
1818
import com.fasterxml.jackson.databind.ObjectMapper;
19-
import io.modelcontextprotocol.spec.McpClientSession;
19+
import io.modelcontextprotocol.session.McpClientSession;
2020
import io.modelcontextprotocol.spec.McpError;
2121
import io.modelcontextprotocol.spec.McpSchema;
2222
import io.modelcontextprotocol.spec.McpSchema.CallToolResult;
2323
import io.modelcontextprotocol.spec.McpSchema.LoggingLevel;
2424
import io.modelcontextprotocol.spec.McpSchema.LoggingMessageNotification;
2525
import io.modelcontextprotocol.spec.McpSchema.SetLevelRequest;
2626
import io.modelcontextprotocol.spec.McpSchema.Tool;
27-
import io.modelcontextprotocol.spec.McpServerSession;
27+
import io.modelcontextprotocol.session.McpServerSession;
2828
import io.modelcontextprotocol.spec.McpServerTransportProvider;
2929
import io.modelcontextprotocol.util.Utils;
3030
import org.slf4j.Logger;
@@ -387,7 +387,7 @@ public McpSchema.Implementation getServerInfo() {
387387

388388
@Override
389389
public Mono<Void> closeGracefully() {
390-
return this.mcpTransportProvider.closeGracefully();
390+
return Mono.from(this.mcpTransportProvider.closeGracefully());
391391
}
392392

393393
@Override
@@ -468,7 +468,8 @@ public Mono<Void> removeTool(String toolName) {
468468

469469
@Override
470470
public Mono<Void> notifyToolsListChanged() {
471-
return this.mcpTransportProvider.notifyClients(McpSchema.METHOD_NOTIFICATION_TOOLS_LIST_CHANGED, null);
471+
return Mono
472+
.from(this.mcpTransportProvider.notifyClients(McpSchema.METHOD_NOTIFICATION_TOOLS_LIST_CHANGED, null));
472473
}
473474

474475
private McpServerSession.RequestHandler<McpSchema.ListToolsResult> toolsListRequestHandler() {
@@ -549,7 +550,8 @@ public Mono<Void> removeResource(String resourceUri) {
549550

550551
@Override
551552
public Mono<Void> notifyResourcesListChanged() {
552-
return this.mcpTransportProvider.notifyClients(McpSchema.METHOD_NOTIFICATION_RESOURCES_LIST_CHANGED, null);
553+
return Mono.from(this.mcpTransportProvider
554+
.notifyClients(McpSchema.METHOD_NOTIFICATION_RESOURCES_LIST_CHANGED, null));
553555
}
554556

555557
private McpServerSession.RequestHandler<McpSchema.ListResourcesResult> resourcesListRequestHandler() {
@@ -642,7 +644,8 @@ public Mono<Void> removePrompt(String promptName) {
642644

643645
@Override
644646
public Mono<Void> notifyPromptsListChanged() {
645-
return this.mcpTransportProvider.notifyClients(McpSchema.METHOD_NOTIFICATION_PROMPTS_LIST_CHANGED, null);
647+
return Mono.from(
648+
this.mcpTransportProvider.notifyClients(McpSchema.METHOD_NOTIFICATION_PROMPTS_LIST_CHANGED, null));
646649
}
647650

648651
private McpServerSession.RequestHandler<McpSchema.ListPromptsResult> promptsListRequestHandler() {
@@ -692,8 +695,8 @@ public Mono<Void> loggingNotification(LoggingMessageNotification loggingMessageN
692695
return Mono.empty();
693696
}
694697

695-
return this.mcpTransportProvider.notifyClients(McpSchema.METHOD_NOTIFICATION_MESSAGE,
696-
loggingMessageNotification);
698+
return Mono.from(this.mcpTransportProvider.notifyClients(McpSchema.METHOD_NOTIFICATION_MESSAGE,
699+
loggingMessageNotification));
697700
}
698701

699702
private McpServerSession.RequestHandler<Object> setLoggerRequestHandler() {

mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServerExchange.java renamed to mcp-reactor/src/main/java/io/modelcontextprotocol/server/McpAsyncServerExchange.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import io.modelcontextprotocol.spec.McpSchema;
1010
import io.modelcontextprotocol.spec.McpSchema.LoggingLevel;
1111
import io.modelcontextprotocol.spec.McpSchema.LoggingMessageNotification;
12-
import io.modelcontextprotocol.spec.McpServerSession;
12+
import io.modelcontextprotocol.session.McpServerSession;
1313
import io.modelcontextprotocol.util.Assert;
1414
import reactor.core.publisher.Mono;
1515

mcp/src/main/java/io/modelcontextprotocol/server/McpServerFeatures.java renamed to mcp-reactor/src/main/java/io/modelcontextprotocol/server/McpServerFeatures.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static AsyncToolSpecification fromSync(SyncToolSpecification tool) {
276276
* @param readHandler The function that handles resource read requests. The function's
277277
* first argument is an {@link McpAsyncServerExchange} upon which the server can
278278
* interact with the connected client. The second arguments is a
279-
* {@link io.modelcontextprotocol.spec.McpSchema.ReadResourceRequest}.
279+
* {@link McpSchema.ReadResourceRequest}.
280280
*/
281281
public record AsyncResourceSpecification(McpSchema.Resource resource,
282282
BiFunction<McpAsyncServerExchange, McpSchema.ReadResourceRequest, Mono<McpSchema.ReadResourceResult>> readHandler) {
@@ -321,8 +321,7 @@ static AsyncResourceSpecification fromSync(SyncResourceSpecification resource) {
321321
* @param promptHandler The function that processes prompt requests and returns
322322
* formatted templates. The function's first argument is an
323323
* {@link McpAsyncServerExchange} upon which the server can interact with the
324-
* connected client. The second arguments is a
325-
* {@link io.modelcontextprotocol.spec.McpSchema.GetPromptRequest}.
324+
* connected client. The second arguments is a {@link McpSchema.GetPromptRequest}.
326325
*/
327326
public record AsyncPromptSpecification(McpSchema.Prompt prompt,
328327
BiFunction<McpAsyncServerExchange, McpSchema.GetPromptRequest, Mono<McpSchema.GetPromptResult>> promptHandler) {
@@ -353,7 +352,7 @@ static AsyncPromptSpecification fromSync(SyncPromptSpecification prompt) {
353352
* @param completionHandler The asynchronous function that processes completion
354353
* requests and returns results. The first argument is an
355354
* {@link McpAsyncServerExchange} used to interact with the client. The second
356-
* argument is a {@link io.modelcontextprotocol.spec.McpSchema.CompleteRequest}.
355+
* argument is a {@link McpSchema.CompleteRequest}.
357356
*/
358357
public record AsyncCompletionSpecification(McpSchema.CompleteReference referenceKey,
359358
BiFunction<McpAsyncServerExchange, McpSchema.CompleteRequest, Mono<McpSchema.CompleteResult>> completionHandler) {
@@ -442,7 +441,7 @@ public record SyncToolSpecification(McpSchema.Tool tool,
442441
* @param readHandler The function that handles resource read requests. The function's
443442
* first argument is an {@link McpSyncServerExchange} upon which the server can
444443
* interact with the connected client. The second arguments is a
445-
* {@link io.modelcontextprotocol.spec.McpSchema.ReadResourceRequest}.
444+
* {@link McpSchema.ReadResourceRequest}.
446445
*/
447446
public record SyncResourceSpecification(McpSchema.Resource resource,
448447
BiFunction<McpSyncServerExchange, McpSchema.ReadResourceRequest, McpSchema.ReadResourceResult> readHandler) {
@@ -476,8 +475,7 @@ public record SyncResourceSpecification(McpSchema.Resource resource,
476475
* @param promptHandler The function that processes prompt requests and returns
477476
* formatted templates. The function's first argument is an
478477
* {@link McpSyncServerExchange} upon which the server can interact with the connected
479-
* client. The second arguments is a
480-
* {@link io.modelcontextprotocol.spec.McpSchema.GetPromptRequest}.
478+
* client. The second arguments is a {@link McpSchema.GetPromptRequest}.
481479
*/
482480
public record SyncPromptSpecification(McpSchema.Prompt prompt,
483481
BiFunction<McpSyncServerExchange, McpSchema.GetPromptRequest, McpSchema.GetPromptResult> promptHandler) {
@@ -490,7 +488,7 @@ public record SyncPromptSpecification(McpSchema.Prompt prompt,
490488
* @param completionHandler The synchronous function that processes completion
491489
* requests and returns results. The first argument is an
492490
* {@link McpSyncServerExchange} used to interact with the client. The second argument
493-
* is a {@link io.modelcontextprotocol.spec.McpSchema.CompleteRequest}.
491+
* is a {@link McpSchema.CompleteRequest}.
494492
*/
495493
public record SyncCompletionSpecification(McpSchema.CompleteReference referenceKey,
496494
BiFunction<McpSyncServerExchange, McpSchema.CompleteRequest, McpSchema.CompleteResult> completionHandler) {

mcp/src/main/java/io/modelcontextprotocol/server/McpSyncServerExchange.java renamed to mcp-reactor/src/main/java/io/modelcontextprotocol/server/McpSyncServerExchange.java

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package io.modelcontextprotocol.server;
66

77
import io.modelcontextprotocol.spec.McpSchema;
8-
import io.modelcontextprotocol.spec.McpSchema.LoggingLevel;
98
import io.modelcontextprotocol.spec.McpSchema.LoggingMessageNotification;
109

1110
/**

0 commit comments

Comments
 (0)