Skip to content

Commit c469f79

Browse files
committed
refactor: Improve MCP documentation and transport interfaces
- Add ClientMcpTransport and ServerMcpTransport marker interfaces - Update client/server implementations to use appropriate transport interfaces - Reorganize documentation structure and improve content clarity - Move documentation images to mcp-docs/antora directory - Update README files with links to online documentation Resolves modelcontextprotocol#44
1 parent 13bafbd commit c469f79

35 files changed

+407
-750
lines changed

README.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,27 @@
11
# Java & Spring MCP
22

3-
Java SDK for the Model Context Protocol (MCP), providing seamless integration between Java and Spring applications and MCP-compliant AI resources and tools.
3+
Set of projects that provide Java SDK and Spring Framework integration for the [Model Context Protocol](https://modelcontextprotocol.org/docs/concepts/architecture).
4+
It enables Java applications to interact with AI models and tools through a standardized interface, supporting both synchronous and asynchronous communication patterns.
45

5-
## Overview
6+
<img src="mcp-docs/src/main/antora/modules/ROOT/images/spring-ai-mcp-architecture.jpg" width="600">
67

7-
Provides Java and Spring Framework integration for the [Model Context Protocol](https://modelcontextprotocol.org/docs/concepts/architecture). It enables Java applications to interact with AI models and tools through a standardized interface, supporting both synchronous and asynchronous communication patterns.
8+
## Projects
89

9-
<img src="docs/spring-ai-mcp-architecture.jpg" width="600">
10-
11-
## Modules
12-
13-
The project consists of two main modules:
14-
15-
### [mcp](./mcp/README.md)
10+
### [MCP Java SDK](https://docs.spring.io/spring-ai-mcp/reference/mcp.html)
1611

1712
Java implementation of the Model Context Protocol specification. It includes:
1813
- Synchronous and asynchronous [MCP Client](https://github.com/spring-projects-experimental/spring-ai-mcp/blob/main/mcp/README.md#client-usage-examples) and [MCP Server](https://github.com/spring-projects-experimental/spring-ai-mcp/blob/main/mcp/README.md#server-usage-examples) implementations
1914
- Standard MCP operations support (tool discovery, resource management, prompt handling, structured logging). Support for request and notification handling.
2015
- [Stdio](https://spec.modelcontextprotocol.io/specification/basic/transports/#stdio) and [SSE](https://spec.modelcontextprotocol.io/specification/basic/transports/#http-with-sse) transport implementations.
2116
- [Find more](./mcp/README.md).
2217

23-
### [spring-ai-mcp](./spring-ai-mcp/README.md)
18+
### [Spring AI MCP](https://docs.spring.io/spring-ai-mcp/reference/spring-mcp.html)
2419

2520
The Spring integration module provides Spring-specific functionality:
2621
- Integration with Spring AI's function calling system
2722
- Spring-friendly abstractions for MCP clients
2823
- Auto-configurations (WIP)
2924

30-
## Requirements
31-
32-
- Java 17 or later
33-
- Maven 3.6 or later
34-
- Spring AI 1.0.0-M4 or later
3525

3626
## Installation
3727

@@ -53,6 +43,23 @@ Add the following dependencies to your Maven project:
5343
</dependency>
5444
```
5545

46+
This is a milestone release, not available on Maven Central.
47+
Add this repository to your POM:
48+
49+
```xml
50+
<repositories>
51+
<repository>
52+
<id>spring-milestones</id>
53+
<name>Spring Milestones</name>
54+
<url>https://repo.spring.io/libs-milestone-local</url>
55+
<snapshots>
56+
<enabled>false</enabled>
57+
</snapshots>
58+
</repository>
59+
</repositories>
60+
```
61+
62+
5663
## Example Demos
5764

5865
Explore these MCP examples in the [spring-ai-examples/model-context-protocol](https://github.com/spring-projects/spring-ai-examples/tree/main/model-context-protocol) repository:
@@ -71,24 +78,18 @@ Explore these MCP examples in the [spring-ai-examples/model-context-protocol](ht
7178

7279
## Development
7380

74-
### Building from Source
81+
- Building from Source
7582

7683
```bash
7784
mvn clean install
7885
```
7986

80-
### Running Tests
87+
- Running Tests
8188

8289
```bash
8390
mvn test
8491
```
8592

86-
## Project Information
87-
88-
- **Group ID**: org.springframework.experimental
89-
- **Version**: 0.4.0-SNAPSHOT
90-
- **Java Version**: 17
91-
- **Spring AI Version**: 1.0.0-M4
9293

9394
## Contributing
9495

docs/MCP-layers.svg

Lines changed: 0 additions & 181 deletions
This file was deleted.

docs/spring-ai-mcp-architecture.jpg

-736 KB
Binary file not shown.

docs/spring-ai-mcp-uml-classdiagram.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,267 @@
1+
@startuml Core Components
2+
3+
' Core Interfaces
4+
interface McpTransport {
5+
+Mono<Void> connect(Function<Mono<JSONRPCMessage>, Mono<JSONRPCMessage>> handler)
6+
+Mono<Void> sendMessage(JSONRPCMessage message)
7+
+void close()
8+
+Mono<Void> closeGracefully()
9+
+<T> T unmarshalFrom(Object data, TypeReference<T> typeRef)
10+
}
11+
12+
interface McpSession {
13+
+<T> Mono<T> sendRequest(String method, Object requestParams, TypeReference<T> typeRef)
14+
+Mono<Void> sendNotification(String method, Map<String, Object> params)
15+
+Mono<Void> closeGracefully()
16+
+void close()
17+
}
18+
19+
' Core Implementation Classes
20+
class DefaultMcpSession {
21+
+interface RequestHandler
22+
+interface NotificationHandler
23+
}
24+
25+
' Client Classes
26+
class McpClient {
27+
+{static} Builder using(ClientMcpTransport transport)
28+
}
29+
30+
class McpAsyncClient {
31+
+Mono<InitializeResult> initialize()
32+
+ServerCapabilities getServerCapabilities()
33+
+Implementation getServerInfo()
34+
+ClientCapabilities getClientCapabilities()
35+
+Implementation getClientInfo()
36+
+void close()
37+
+Mono<Void> closeGracefully()
38+
+Mono<Object> ping()
39+
+Mono<Void> addRoot(Root root)
40+
+Mono<Void> removeRoot(String rootUri)
41+
+Mono<Void> rootsListChangedNotification()
42+
+Mono<CallToolResult> callTool(CallToolRequest request)
43+
+Mono<ListToolsResult> listTools()
44+
+Mono<ListResourcesResult> listResources()
45+
+Mono<ReadResourceResult> readResource(ReadResourceRequest request)
46+
+Mono<ListResourceTemplatesResult> listResourceTemplates()
47+
+Mono<Void> subscribeResource(SubscribeRequest request)
48+
+Mono<Void> unsubscribeResource(UnsubscribeRequest request)
49+
+Mono<ListPromptsResult> listPrompts()
50+
+Mono<GetPromptResult> getPrompt(GetPromptRequest request)
51+
+Mono<Void> setLoggingLevel(LoggingLevel level)
52+
}
53+
54+
class McpSyncClient {
55+
+InitializeResult initialize()
56+
+ServerCapabilities getServerCapabilities()
57+
+Implementation getServerInfo()
58+
+ClientCapabilities getClientCapabilities()
59+
+Implementation getClientInfo()
60+
+void close()
61+
+boolean closeGracefully()
62+
+Object ping()
63+
+void addRoot(Root root)
64+
+void removeRoot(String rootUri)
65+
+void rootsListChangedNotification()
66+
+CallToolResult callTool(CallToolRequest request)
67+
+ListToolsResult listTools()
68+
+ListResourcesResult listResources()
69+
+ReadResourceResult readResource(ReadResourceRequest request)
70+
+ListResourceTemplatesResult listResourceTemplates()
71+
+void subscribeResource(SubscribeRequest request)
72+
+void unsubscribeResource(UnsubscribeRequest request)
73+
+ListPromptsResult listPrompts()
74+
+GetPromptResult getPrompt(GetPromptRequest request)
75+
+void setLoggingLevel(LoggingLevel level)
76+
}
77+
78+
' Server Classes
79+
class McpServer {
80+
+{static} Builder using(ServerMcpTransport transport)
81+
}
82+
83+
class McpAsyncServer {
84+
85+
+ServerCapabilities getServerCapabilities()
86+
+Implementation getServerInfo()
87+
+ClientCapabilities getClientCapabilities()
88+
+Implementation getClientInfo()
89+
+void close()
90+
+Mono<Void> closeGracefully()
91+
92+
' Tool Management
93+
+Mono<Void> addTool(ToolRegistration toolRegistration)
94+
+Mono<Void> removeTool(String toolName)
95+
+Mono<Void> notifyToolsListChanged()
96+
97+
' Resource Management
98+
+Mono<Void> addResource(ResourceRegistration resourceHandler)
99+
+Mono<Void> removeResource(String resourceUri)
100+
+Mono<Void> notifyResourcesListChanged()
101+
102+
' Prompt Management
103+
+Mono<Void> addPrompt(PromptRegistration promptRegistration)
104+
+Mono<Void> removePrompt(String promptName)
105+
+Mono<Void> notifyPromptsListChanged()
106+
107+
' Logging
108+
+Mono<Void> loggingNotification(LoggingMessageNotification notification)
109+
110+
' Sampling
111+
+Mono<CreateMessageResult> createMessage(CreateMessageRequest request)
112+
}
113+
114+
class McpSyncServer {
115+
+McpAsyncServer getAsyncServer()
116+
117+
+ServerCapabilities getServerCapabilities()
118+
+Implementation getServerInfo()
119+
+ClientCapabilities getClientCapabilities()
120+
+Implementation getClientInfo()
121+
+void close()
122+
+void closeGracefully()
123+
124+
' Tool Management
125+
+void addTool(ToolRegistration toolHandler)
126+
+void removeTool(String toolName)
127+
+void notifyToolsListChanged()
128+
129+
' Resource Management
130+
+void addResource(ResourceRegistration resourceHandler)
131+
+void removeResource(String resourceUri)
132+
+void notifyResourcesListChanged()
133+
134+
' Prompt Management
135+
+void addPrompt(PromptRegistration promptRegistration)
136+
+void removePrompt(String promptName)
137+
+void notifyPromptsListChanged()
138+
139+
' Logging
140+
+void loggingNotification(LoggingMessageNotification notification)
141+
142+
' Sampling
143+
+CreateMessageResult createMessage(CreateMessageRequest request)
144+
}
145+
146+
' Transport Implementations
147+
class StdioClientTransport implements ClientMcpTransport {
148+
+void setErrorHandler(Consumer<String> errorHandler)
149+
+Sinks.Many<String> getErrorSink()
150+
}
151+
152+
class SseClientTransport implements ClientMcpTransport {
153+
}
154+
155+
class StdioServerTransport implements ServerMcpTransport {
156+
}
157+
158+
class SseServerTransport implements ServerMcpTransport {
159+
+RouterFunction<?> getRouterFunction()
160+
}
161+
162+
' Schema and Error Classes
163+
class McpSchema {
164+
+class ErrorCodes
165+
+interface Request
166+
+interface JSONRPCMessage
167+
+interface ResourceContents
168+
+interface Content
169+
+interface ServerCapabilities
170+
+{static} JSONRPCMessage deserializeJsonRpcMessage()
171+
}
172+
173+
class McpError {
174+
}
175+
176+
' Relationships
177+
McpTransport <|.. ClientMcpTransport
178+
McpTransport <|.. ServerMcpTransport
179+
180+
McpSession <|.. DefaultMcpSession
181+
DefaultMcpSession --o McpAsyncClient
182+
DefaultMcpSession --o McpAsyncServer
183+
184+
McpClient ..> McpAsyncClient : creates
185+
McpClient ..> McpSyncClient : creates
186+
McpSyncClient --> McpAsyncClient : delegates to
187+
188+
McpServer ..> McpAsyncServer : creates
189+
McpServer ..> McpSyncServer : creates
190+
McpSyncServer o-- McpAsyncServer
191+
192+
DefaultMcpSession o-- McpTransport
193+
McpSchema <.. McpSession : uses
194+
McpError ..> McpSession : throws
195+
196+
@enduml
197+
198+
@startuml Message Flow
199+
200+
package "MCP Schema" {
201+
interface JSONRPCMessage {
202+
+String jsonrpc()
203+
}
204+
205+
interface Request {
206+
}
207+
208+
class InitializeRequest
209+
class CallToolRequest
210+
class ListToolsRequest
211+
class ListResourcesRequest
212+
class ReadResourceRequest
213+
class ListResourceTemplatesRequest
214+
class ListPromptsRequest
215+
class GetPromptRequest
216+
}
217+
218+
package "Resource Types" {
219+
interface ResourceContents {
220+
+String uri()
221+
+String mimeType()
222+
}
223+
224+
class TextResourceContents
225+
class BlobResourceContents
226+
227+
interface Content {
228+
+String type()
229+
}
230+
231+
class TextContent
232+
class ImageContent
233+
class EmbeddedResource
234+
235+
interface Annotated {
236+
+Annotations annotations()
237+
}
238+
239+
interface PromptOrResourceReference {
240+
+String type()
241+
}
242+
243+
class PromptReference
244+
class ResourceReference
245+
}
246+
247+
JSONRPCMessage <|.. Request
248+
Request <|.. InitializeRequest
249+
Request <|.. CallToolRequest
250+
Request <|.. ListToolsRequest
251+
Request <|.. ListResourcesRequest
252+
Request <|.. ReadResourceRequest
253+
Request <|.. ListResourceTemplatesRequest
254+
Request <|.. ListPromptsRequest
255+
Request <|.. GetPromptRequest
256+
257+
ResourceContents <|.. TextResourceContents
258+
ResourceContents <|.. BlobResourceContents
259+
260+
Content <|.. TextContent
261+
Content <|.. ImageContent
262+
Content <|.. EmbeddedResource
263+
264+
PromptOrResourceReference <|.. PromptReference
265+
PromptOrResourceReference <|.. ResourceReference
266+
267+
@enduml

mcp-docs/src/main/antora/modules/ROOT/images/spring-ai-mcp-uml-classdiagram.svg

Lines changed: 1 addition & 1 deletion
Loading

mcp-docs/src/main/antora/modules/ROOT/pages/mcp.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ image::MCP-layers.svg[width=400,align=center]
4141

4242
Following class diagram illustrates the layered architecture of the MCP SDK, showing the relationships between core interfaces (McpTransport, McpSession), their implementations, and the client/server components. It highlights how the transport layer connects to sessions, which in turn support both synchronous and asynchronous client/server implementations.
4343

44-
image::spring-ai-mcp-uml-classdiagram.svg[width=800]
44+
image::spring-ai-mcp-uml-classdiagram.svg[width=1000]
4545

4646
Key Interactions:
4747

0 commit comments

Comments
 (0)