- Implement MCP server with async/sync support and builder pattern configuration - Add Server stdio/SSE transport layers with robust error handling - Convert McpClient and McpServer to interfaces for better extensibility - Add sampling capabilities for LLM interactions (text/image) - Implement dynamic root management and runtime tool management - Add comprehensive prompt and resource capabilities - Add support for dynamic root management (add/remove roots at runtime) Architecture Changes - Introduce registration records for tools, resources, and prompts - Improve thread safety with concurrent collections - Enhance resource template handling - Implement builder patterns for Server/Client capabilities - Add support for server capabilities and implementation info Transport Layer: - Implement SseServerTransport with SSE endpoints - Add StdioServerTransport for process-based communication - Reorganize transport packages for better organization - Improve transport error handling and shutdown processes Documentation: - Add detailed MCP reference documentation - Include architecture diagrams and API documentation - Add comprehensive test coverage for all components - Include sample projects demonstrating stdio/SSE transports BREAKING CHANGES: Transport Package Reorganization - Move StdioClientTransport to o.s.ai.mcp.client.transport - Move SseClientTransport to o.s.ai.mcp.client.transport - Move ServerParameters to o.s.ai.mcp.client.transport - StdioClientTransport.errorHandler changed to private with setter method Migration: Use setErrorHandler() method instead of direct field access API Changes - Replace static factory methods with builder pattern - Update ServerCapabilities to use builder pattern - Make StdioClientTransport.errorHandler private with setter - Replace rootsListProvider with direct root management - Remove deprecated static factory methods Resolves #27,#25,#24,#11 Related to #12
204 lines
4.8 KiB
Text
204 lines
4.8 KiB
Text
@startuml Core Components
|
|
|
|
' Core Interfaces
|
|
interface McpTransport {
|
|
+Mono<Void> connect(Function<Mono<JSONRPCMessage>, Mono<JSONRPCMessage>> handler)
|
|
+Mono<Void> sendMessage(JSONRPCMessage message)
|
|
+void close()
|
|
+Mono<Void> closeGracefully()
|
|
+<T> T unmarshalFrom(Object data, TypeReference<T> typeRef)
|
|
}
|
|
|
|
interface McpSession {
|
|
+<T> Mono<T> sendRequest(String method, Object requestParams, TypeReference<T> typeRef)
|
|
+Mono<Void> sendNotification(String method, Map<String, Object> params)
|
|
+Mono<Void> closeGracefully()
|
|
+void close()
|
|
}
|
|
|
|
' Core Implementation Classes
|
|
class DefaultMcpSession {
|
|
-McpTransport transport
|
|
-ObjectMapper objectMapper
|
|
+interface RequestHandler
|
|
+interface NotificationHandler
|
|
}
|
|
|
|
' Client Classes
|
|
class McpClient {
|
|
+{static} Builder using(McpTransport transport)
|
|
+{static} McpAsyncClient async(McpTransport transport)
|
|
+{static} McpSyncClient sync(McpTransport transport)
|
|
}
|
|
|
|
class McpAsyncClient {
|
|
+Mono<InitializeResult> initialize()
|
|
+Mono<CallToolResult> callTool(CallToolRequest request)
|
|
+Mono<ListToolsResult> listTools()
|
|
+Mono<ListResourcesResult> listResources()
|
|
+Mono<ReadResourceResult> readResource(ReadResourceRequest request)
|
|
+Mono<ListResourceTemplatesResult> listResourceTemplates()
|
|
+Mono<ListPromptsResult> listPrompts()
|
|
+Mono<GetPromptResult> getPrompt(GetPromptRequest request)
|
|
}
|
|
|
|
class McpSyncClient {
|
|
+InitializeResult initialize()
|
|
+CallToolResult callTool(CallToolRequest request)
|
|
+ListToolsResult listTools()
|
|
+ListResourcesResult listResources()
|
|
+ReadResourceResult readResource(ReadResourceRequest request)
|
|
+ListResourceTemplatesResult listResourceTemplates()
|
|
+ListPromptsResult listPrompts()
|
|
+GetPromptResult getPrompt(GetPromptRequest request)
|
|
}
|
|
|
|
' Server Classes
|
|
class McpServer {
|
|
+{static} Builder using(McpTransport transport)
|
|
}
|
|
|
|
class McpAsyncServer {
|
|
+Mono<Void> addTool(ToolHandler toolHandler)
|
|
+Mono<Void> removeTool(String toolName)
|
|
+Mono<Void> notifyToolsListChanged()
|
|
+Mono<Void> notifyResourcesListChanged()
|
|
+Mono<Void> notifyPromptsListChanged()
|
|
+interface ToolHandler
|
|
}
|
|
|
|
class McpSyncServer {
|
|
+void addTool(ToolHandler toolHandler)
|
|
+void removeTool(String toolName)
|
|
+void notifyToolsListChanged()
|
|
+void notifyResourcesListChanged()
|
|
+void notifyPromptsListChanged()
|
|
+McpAsyncServer getAsyncServer()
|
|
}
|
|
|
|
' Transport Implementations
|
|
class StdioClientTransport {
|
|
-Process serverProcess
|
|
-ServerParameters parameters
|
|
}
|
|
|
|
class SseClientTransport {
|
|
-WebClient webClient
|
|
}
|
|
|
|
class StdioServerTransport {
|
|
}
|
|
|
|
class SseServerTransport {
|
|
}
|
|
|
|
' Schema and Error Classes
|
|
class McpSchema {
|
|
+class ErrorCodes
|
|
+interface Request
|
|
+interface JSONRPCMessage
|
|
+interface ResourceContents
|
|
+interface Content
|
|
+interface ServerCapabilities
|
|
+{static} JSONRPCMessage deserializeJsonRpcMessage()
|
|
}
|
|
|
|
class McpError {
|
|
-int code
|
|
-String message
|
|
}
|
|
|
|
' Relationships
|
|
McpTransport <|.. StdioClientTransport
|
|
McpTransport <|.. SseClientTransport
|
|
McpTransport <|.. StdioServerTransport
|
|
McpTransport <|.. SseServerTransport
|
|
|
|
McpSession <|.. DefaultMcpSession
|
|
DefaultMcpSession --o McpAsyncClient
|
|
DefaultMcpSession --o McpAsyncServer
|
|
|
|
McpClient ..> McpAsyncClient : creates
|
|
McpClient ..> McpSyncClient : creates
|
|
McpSyncClient o-- McpAsyncClient
|
|
|
|
McpServer ..> McpAsyncServer : creates
|
|
McpServer ..> McpSyncServer : creates
|
|
McpSyncServer o-- McpAsyncServer
|
|
|
|
DefaultMcpSession o-- McpTransport
|
|
McpSchema <.. McpSession : uses
|
|
McpError ..> McpSession : throws
|
|
|
|
@enduml
|
|
|
|
@startuml Message Flow
|
|
|
|
package "MCP Schema" {
|
|
interface JSONRPCMessage {
|
|
+String jsonrpc()
|
|
}
|
|
|
|
interface Request {
|
|
}
|
|
|
|
class InitializeRequest
|
|
class CallToolRequest
|
|
class ListToolsRequest
|
|
class ListResourcesRequest
|
|
class ReadResourceRequest
|
|
class ListResourceTemplatesRequest
|
|
class ListPromptsRequest
|
|
class GetPromptRequest
|
|
}
|
|
|
|
package "Resource Types" {
|
|
interface ResourceContents {
|
|
+String uri()
|
|
+String mimeType()
|
|
}
|
|
|
|
class TextResourceContents
|
|
class BlobResourceContents
|
|
|
|
interface Content {
|
|
+String type()
|
|
}
|
|
|
|
class TextContent
|
|
class ImageContent
|
|
class EmbeddedResource
|
|
|
|
interface Annotated {
|
|
+Annotations annotations()
|
|
}
|
|
|
|
interface PromptOrResourceReference {
|
|
+String type()
|
|
}
|
|
|
|
class PromptReference
|
|
class ResourceReference
|
|
}
|
|
|
|
JSONRPCMessage <|.. Request
|
|
Request <|.. InitializeRequest
|
|
Request <|.. CallToolRequest
|
|
Request <|.. ListToolsRequest
|
|
Request <|.. ListResourcesRequest
|
|
Request <|.. ReadResourceRequest
|
|
Request <|.. ListResourceTemplatesRequest
|
|
Request <|.. ListPromptsRequest
|
|
Request <|.. GetPromptRequest
|
|
|
|
ResourceContents <|.. TextResourceContents
|
|
ResourceContents <|.. BlobResourceContents
|
|
|
|
Content <|.. TextContent
|
|
Content <|.. ImageContent
|
|
Content <|.. EmbeddedResource
|
|
|
|
PromptOrResourceReference <|.. PromptReference
|
|
PromptOrResourceReference <|.. ResourceReference
|
|
|
|
@enduml
|