Skip to content

Commit cd74509

Browse files
committed
feat: adds mcp-schema-jackson
1 parent de986d2 commit cd74509

File tree

67 files changed

+2033
-1138
lines changed

Some content is hidden

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

67 files changed

+2033
-1138
lines changed

mcp-bom/pom.xml

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@
2929
<!-- MCP Spec -->
3030
<dependency>
3131
<groupId>io.modelcontextprotocol.sdk</groupId>
32-
<artifactId>mcp-reactor</artifactId>
32+
<artifactId>mcp-spi</artifactId>
33+
<version>${project.version}</version>
34+
</dependency>
35+
36+
<!-- MCP Jacson Schema -->
37+
<dependency>
38+
<groupId>io.modelcontextprotocol.sdk</groupId>
39+
<artifactId>mcp-schema-jackson</artifactId>
3340
<version>${project.version}</version>
3441
</dependency>
3542

mcp-reactor/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Java MCP SDK
22

3-
Java SDK implementation of the Model Context Protocol, enabling seamless integration with language models and AI tools.
3+
Java SDK Reactor implementation of the Model Context Protocol, enabling seamless integration with language models and AI tools.
44
For comprehensive guides and API documentation, visit the [MCP Java SDK Reference Documentation](https://modelcontextprotocol.io/sdk/java/mcp-overview).
55

mcp-reactor/pom.xml

+27-62
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
</parent>
1111
<artifactId>mcp-reactor</artifactId>
1212
<packaging>jar</packaging>
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>
13+
<name>Java SDK MCP Reactor</name>
14+
<description>Java SDK Reactor 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,42 +65,53 @@
6565
</build>
6666

6767
<dependencies>
68+
<!--MCP-->
6869
<dependency>
6970
<groupId>io.modelcontextprotocol.sdk</groupId>
7071
<artifactId>mcp-spi</artifactId>
7172
<version>${project.version}</version>
7273
</dependency>
73-
7474
<dependency>
75-
<groupId>org.slf4j</groupId>
76-
<artifactId>slf4j-api</artifactId>
77-
<version>${slf4j-api.version}</version>
75+
<groupId>io.modelcontextprotocol.sdk</groupId>
76+
<artifactId>mcp-schema-jackson</artifactId>
77+
<version>${project.version}</version>
7878
</dependency>
79-
79+
<!--Reactor-->
8080
<dependency>
81-
<groupId>com.fasterxml.jackson.core</groupId>
82-
<artifactId>jackson-databind</artifactId>
83-
<version>${jackson.version}</version>
81+
<groupId>org.reactivestreams</groupId>
82+
<artifactId>reactive-streams</artifactId>
8483
</dependency>
85-
8684
<dependency>
8785
<groupId>io.projectreactor</groupId>
8886
<artifactId>reactor-core</artifactId>
8987
</dependency>
9088

91-
89+
<!-- Used by the HttpServletSseServerTransport -->
9290
<dependency>
93-
<groupId>io.projectreactor.netty</groupId>
94-
<artifactId>reactor-netty-http</artifactId>
95-
<scope>test</scope>
91+
<groupId>jakarta.servlet</groupId>
92+
<artifactId>jakarta.servlet-api</artifactId>
93+
<version>${jakarta.servlet.version}</version>
94+
<scope>provided</scope>
9695
</dependency>
97-
96+
<!--Logs-->
97+
<dependency>
98+
<groupId>org.slf4j</groupId>
99+
<artifactId>slf4j-api</artifactId>
100+
<version>${slf4j-api.version}</version>
101+
</dependency>
102+
<!--For test-->
98103
<dependency>
99104
<groupId>org.assertj</groupId>
100105
<artifactId>assertj-core</artifactId>
101106
<version>${assert4j.version}</version>
102107
<scope>test</scope>
103108
</dependency>
109+
<dependency>
110+
<groupId>org.testcontainers</groupId>
111+
<artifactId>testcontainers</artifactId>
112+
<version>${testcontainers.version}</version>
113+
<scope>test</scope>
114+
</dependency>
104115
<dependency>
105116
<groupId>org.junit.jupiter</groupId>
106117
<artifactId>junit-jupiter-api</artifactId>
@@ -119,70 +130,24 @@
119130
<version>${mockito.version}</version>
120131
<scope>test</scope>
121132
</dependency>
122-
123-
<!-- Mockito cannot mock this class: class java.net.http.HttpClient. the bytebuddy helps. -->
124-
<dependency>
125-
<groupId>net.bytebuddy</groupId>
126-
<artifactId>byte-buddy</artifactId>
127-
<version>${byte-buddy.version}</version>
128-
<scope>test</scope>
129-
</dependency>
130133
<dependency>
131134
<groupId>io.projectreactor</groupId>
132135
<artifactId>reactor-test</artifactId>
133136
<scope>test</scope>
134137
</dependency>
135-
<dependency>
136-
<groupId>org.testcontainers</groupId>
137-
<artifactId>junit-jupiter</artifactId>
138-
<version>${testcontainers.version}</version>
139-
<scope>test</scope>
140-
</dependency>
141-
142138
<dependency>
143139
<groupId>org.awaitility</groupId>
144140
<artifactId>awaitility</artifactId>
145141
<version>${awaitility.version}</version>
146142
<scope>test</scope>
147143
</dependency>
148-
149-
<dependency>
150-
<groupId>ch.qos.logback</groupId>
151-
<artifactId>logback-classic</artifactId>
152-
<version>${logback.version}</version>
153-
<scope>test</scope>
154-
</dependency>
155-
156-
<dependency>
157-
<groupId>net.javacrumbs.json-unit</groupId>
158-
<artifactId>json-unit-assertj</artifactId>
159-
<version>${json-unit-assertj.version}</version>
160-
<scope>test</scope>
161-
</dependency>
162-
163-
164-
<!-- Used by the HttpServletSseServerTransport -->
165-
<dependency>
166-
<groupId>jakarta.servlet</groupId>
167-
<artifactId>jakarta.servlet-api</artifactId>
168-
<version>${jakarta.servlet.version}</version>
169-
<scope>provided</scope>
170-
</dependency>
171-
172144
<!-- Tomcat dependencies for testing -->
173145
<dependency>
174146
<groupId>org.apache.tomcat.embed</groupId>
175147
<artifactId>tomcat-embed-core</artifactId>
176148
<version>${tomcat.version}</version>
177149
<scope>test</scope>
178150
</dependency>
179-
<dependency>
180-
<groupId>org.apache.tomcat.embed</groupId>
181-
<artifactId>tomcat-embed-websocket</artifactId>
182-
<version>${tomcat.version}</version>
183-
<scope>test</scope>
184-
</dependency>
185-
186151
</dependencies>
187152

188153

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

+37-42
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@
1313
import java.util.concurrent.atomic.AtomicBoolean;
1414
import java.util.function.Function;
1515

16-
import com.fasterxml.jackson.core.type.TypeReference;
16+
import io.modelcontextprotocol.schema.McpType;
1717
import io.modelcontextprotocol.session.McpClientSession;
1818
import io.modelcontextprotocol.session.McpClientSession.NotificationHandler;
1919
import io.modelcontextprotocol.session.McpClientSession.RequestHandler;
2020
import io.modelcontextprotocol.spec.McpClientTransport;
2121
import io.modelcontextprotocol.spec.McpError;
22-
import io.modelcontextprotocol.spec.McpSchema;
23-
import io.modelcontextprotocol.spec.McpSchema.ClientCapabilities;
24-
import io.modelcontextprotocol.spec.McpSchema.CreateMessageRequest;
25-
import io.modelcontextprotocol.spec.McpSchema.CreateMessageResult;
26-
import io.modelcontextprotocol.spec.McpSchema.GetPromptRequest;
27-
import io.modelcontextprotocol.spec.McpSchema.GetPromptResult;
28-
import io.modelcontextprotocol.spec.McpSchema.ListPromptsResult;
29-
import io.modelcontextprotocol.spec.McpSchema.LoggingLevel;
30-
import io.modelcontextprotocol.spec.McpSchema.LoggingMessageNotification;
31-
import io.modelcontextprotocol.spec.McpSchema.PaginatedRequest;
32-
import io.modelcontextprotocol.spec.McpSchema.Root;
22+
import io.modelcontextprotocol.schema.McpSchema;
23+
import io.modelcontextprotocol.schema.McpSchema.ClientCapabilities;
24+
import io.modelcontextprotocol.schema.McpSchema.CreateMessageRequest;
25+
import io.modelcontextprotocol.schema.McpSchema.CreateMessageResult;
26+
import io.modelcontextprotocol.schema.McpSchema.GetPromptRequest;
27+
import io.modelcontextprotocol.schema.McpSchema.GetPromptResult;
28+
import io.modelcontextprotocol.schema.McpSchema.ListPromptsResult;
29+
import io.modelcontextprotocol.schema.McpSchema.LoggingLevel;
30+
import io.modelcontextprotocol.schema.McpSchema.LoggingMessageNotification;
31+
import io.modelcontextprotocol.schema.McpSchema.PaginatedRequest;
32+
import io.modelcontextprotocol.schema.McpSchema.Root;
3333
import io.modelcontextprotocol.spec.McpTransport;
3434
import io.modelcontextprotocol.util.Assert;
3535
import io.modelcontextprotocol.util.Utils;
@@ -80,8 +80,7 @@ public class McpAsyncClient {
8080

8181
private static final Logger logger = LoggerFactory.getLogger(McpAsyncClient.class);
8282

83-
private static TypeReference<Void> VOID_TYPE_REFERENCE = new TypeReference<>() {
84-
};
83+
private static final McpType<Void> VOID_TYPE_REFERENCE = McpType.of(Void.class);
8584

8685
protected final Sinks.One<McpSchema.InitializeResult> initializedSink = Sinks.one();
8786

@@ -337,8 +336,7 @@ public Mono<McpSchema.InitializeResult> initialize() {
337336
this.clientInfo); // @formatter:on
338337

339338
Mono<McpSchema.InitializeResult> result = this.mcpSession.sendRequest(McpSchema.METHOD_INITIALIZE,
340-
initializeRequest, new TypeReference<McpSchema.InitializeResult>() {
341-
});
339+
initializeRequest, McpType.of(McpSchema.InitializeResult.class));
342340

343341
return result.flatMap(initializeResult -> {
344342

@@ -389,8 +387,7 @@ private <T> Mono<T> withInitializationCheck(String actionName,
389387
*/
390388
public Mono<Object> ping() {
391389
return this.withInitializationCheck("pinging the server", initializedResult -> this.mcpSession
392-
.sendRequest(McpSchema.METHOD_PING, null, new TypeReference<Object>() {
393-
}));
390+
.sendRequest(McpSchema.METHOD_PING, null, McpType.of(Object.class)));
394391
}
395392

396393
// --------------------------
@@ -479,8 +476,7 @@ private RequestHandler<McpSchema.ListRootsResult> rootsListRequestHandler() {
479476
return params -> {
480477
@SuppressWarnings("unused")
481478
McpSchema.PaginatedRequest request = transport.unmarshalFrom(params,
482-
new TypeReference<McpSchema.PaginatedRequest>() {
483-
});
479+
McpType.of(McpSchema.PaginatedRequest.class));
484480

485481
List<Root> roots = this.roots.values().stream().toList();
486482

@@ -494,8 +490,7 @@ private RequestHandler<McpSchema.ListRootsResult> rootsListRequestHandler() {
494490
private RequestHandler<CreateMessageResult> samplingCreateMessageHandler() {
495491
return params -> {
496492
McpSchema.CreateMessageRequest request = transport.unmarshalFrom(params,
497-
new TypeReference<McpSchema.CreateMessageRequest>() {
498-
});
493+
McpType.of(McpSchema.CreateMessageRequest.class));
499494

500495
return this.samplingHandler.apply(request);
501496
};
@@ -504,11 +499,11 @@ private RequestHandler<CreateMessageResult> samplingCreateMessageHandler() {
504499
// --------------------------
505500
// Tools
506501
// --------------------------
507-
private static final TypeReference<McpSchema.CallToolResult> CALL_TOOL_RESULT_TYPE_REF = new TypeReference<>() {
508-
};
502+
private static final McpType<McpSchema.CallToolResult> CALL_TOOL_RESULT_TYPE_REF = McpType
503+
.of(McpSchema.CallToolResult.class);
509504

510-
private static final TypeReference<McpSchema.ListToolsResult> LIST_TOOLS_RESULT_TYPE_REF = new TypeReference<>() {
511-
};
505+
private static final McpType<McpSchema.ListToolsResult> LIST_TOOLS_RESULT_TYPE_REF = McpType
506+
.of(McpSchema.ListToolsResult.class);
512507

513508
/**
514509
* Calls a tool provided by the server. Tools enable servers to expose executable
@@ -570,14 +565,14 @@ private NotificationHandler asyncToolsChangeNotificationHandler(
570565
// Resources
571566
// --------------------------
572567

573-
private static final TypeReference<McpSchema.ListResourcesResult> LIST_RESOURCES_RESULT_TYPE_REF = new TypeReference<>() {
574-
};
568+
private static final McpType<McpSchema.ListResourcesResult> LIST_RESOURCES_RESULT_TYPE_REF = McpType
569+
.of(McpSchema.ListResourcesResult.class);
575570

576-
private static final TypeReference<McpSchema.ReadResourceResult> READ_RESOURCE_RESULT_TYPE_REF = new TypeReference<>() {
577-
};
571+
private static final McpType<McpSchema.ReadResourceResult> READ_RESOURCE_RESULT_TYPE_REF = McpType
572+
.of(McpSchema.ReadResourceResult.class);
578573

579-
private static final TypeReference<McpSchema.ListResourceTemplatesResult> LIST_RESOURCE_TEMPLATES_RESULT_TYPE_REF = new TypeReference<>() {
580-
};
574+
private static final McpType<McpSchema.ListResourceTemplatesResult> LIST_RESOURCE_TEMPLATES_RESULT_TYPE_REF = McpType
575+
.of(McpSchema.ListResourceTemplatesResult.class);
581576

582577
/**
583578
* Retrieves the list of all resources provided by the server. Resources represent any
@@ -712,11 +707,11 @@ private NotificationHandler asyncResourcesChangeNotificationHandler(
712707
// --------------------------
713708
// Prompts
714709
// --------------------------
715-
private static final TypeReference<McpSchema.ListPromptsResult> LIST_PROMPTS_RESULT_TYPE_REF = new TypeReference<>() {
716-
};
710+
private static final McpType<McpSchema.ListPromptsResult> LIST_PROMPTS_RESULT_TYPE_REF = McpType
711+
.of(McpSchema.ListPromptsResult.class);
717712

718-
private static final TypeReference<McpSchema.GetPromptResult> GET_PROMPT_RESULT_TYPE_REF = new TypeReference<>() {
719-
};
713+
private static final McpType<McpSchema.GetPromptResult> GET_PROMPT_RESULT_TYPE_REF = McpType
714+
.of(McpSchema.GetPromptResult.class);
720715

721716
/**
722717
* Retrieves the list of all prompts provided by the server.
@@ -781,8 +776,7 @@ private NotificationHandler asyncLoggingNotificationHandler(
781776

782777
return params -> {
783778
McpSchema.LoggingMessageNotification loggingMessageNotification = transport.unmarshalFrom(params,
784-
new TypeReference<McpSchema.LoggingMessageNotification>() {
785-
});
779+
McpType.of(McpSchema.LoggingMessageNotification.class));
786780

787781
return Flux.fromIterable(loggingConsumers)
788782
.flatMap(consumer -> consumer.apply(loggingMessageNotification))
@@ -804,8 +798,8 @@ public Mono<Void> setLoggingLevel(LoggingLevel loggingLevel) {
804798

805799
return this.withInitializationCheck("setting logging level", initializedResult -> {
806800
var params = new McpSchema.SetLevelRequest(loggingLevel);
807-
return this.mcpSession.sendRequest(McpSchema.METHOD_LOGGING_SET_LEVEL, params, new TypeReference<Object>() {
808-
}).then();
801+
return this.mcpSession.sendRequest(McpSchema.METHOD_LOGGING_SET_LEVEL, params, McpType.of(Object.class))
802+
.then();
809803
});
810804
}
811805

@@ -816,13 +810,14 @@ public Mono<Void> setLoggingLevel(LoggingLevel loggingLevel) {
816810
*/
817811
void setProtocolVersions(List<String> protocolVersions) {
818812
this.protocolVersions = protocolVersions;
813+
819814
}
820815

821816
// --------------------------
822817
// Completions
823818
// --------------------------
824-
private static final TypeReference<McpSchema.CompleteResult> COMPLETION_COMPLETE_RESULT_TYPE_REF = new TypeReference<>() {
825-
};
819+
private static final McpType<McpSchema.CompleteResult> COMPLETION_COMPLETE_RESULT_TYPE_REF = McpType
820+
.of(McpSchema.CompleteResult.class);
826821

827822
/**
828823
* Sends a completion/complete request to generate value suggestions based on a given

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
import java.util.function.Function;
1414

1515
import io.modelcontextprotocol.spec.McpClientTransport;
16-
import io.modelcontextprotocol.spec.McpSchema;
16+
import io.modelcontextprotocol.schema.McpSchema;
1717
import io.modelcontextprotocol.spec.McpTransport;
18-
import io.modelcontextprotocol.spec.McpSchema.ClientCapabilities;
19-
import io.modelcontextprotocol.spec.McpSchema.CreateMessageRequest;
20-
import io.modelcontextprotocol.spec.McpSchema.CreateMessageResult;
21-
import io.modelcontextprotocol.spec.McpSchema.Implementation;
22-
import io.modelcontextprotocol.spec.McpSchema.Root;
18+
import io.modelcontextprotocol.schema.McpSchema.ClientCapabilities;
19+
import io.modelcontextprotocol.schema.McpSchema.CreateMessageRequest;
20+
import io.modelcontextprotocol.schema.McpSchema.CreateMessageResult;
21+
import io.modelcontextprotocol.schema.McpSchema.Implementation;
22+
import io.modelcontextprotocol.schema.McpSchema.Root;
2323
import io.modelcontextprotocol.util.Assert;
2424
import reactor.core.publisher.Mono;
2525

mcp-reactor/src/main/java/io/modelcontextprotocol/client/McpClientFeatures.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import java.util.function.Consumer;
1313
import java.util.function.Function;
1414

15-
import io.modelcontextprotocol.spec.McpSchema;
15+
import io.modelcontextprotocol.schema.McpSchema;
1616
import io.modelcontextprotocol.util.Assert;
1717
import io.modelcontextprotocol.util.Utils;
1818
import reactor.core.publisher.Mono;

mcp-reactor/src/main/java/io/modelcontextprotocol/client/McpSyncClient.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
import java.time.Duration;
88

9-
import io.modelcontextprotocol.spec.McpSchema;
10-
import io.modelcontextprotocol.spec.McpSchema.ClientCapabilities;
11-
import io.modelcontextprotocol.spec.McpSchema.GetPromptRequest;
12-
import io.modelcontextprotocol.spec.McpSchema.GetPromptResult;
13-
import io.modelcontextprotocol.spec.McpSchema.ListPromptsResult;
9+
import io.modelcontextprotocol.schema.McpSchema;
10+
import io.modelcontextprotocol.schema.McpSchema.ClientCapabilities;
11+
import io.modelcontextprotocol.schema.McpSchema.GetPromptRequest;
12+
import io.modelcontextprotocol.schema.McpSchema.GetPromptResult;
13+
import io.modelcontextprotocol.schema.McpSchema.ListPromptsResult;
1414
import io.modelcontextprotocol.util.Assert;
1515
import org.slf4j.Logger;
1616
import org.slf4j.LoggerFactory;

0 commit comments

Comments
 (0)