diff --git a/mintlify-docs/docs/dependency-management.mdx b/mintlify-docs/docs/dependency-management.mdx new file mode 100644 index 00000000..204c51c8 --- /dev/null +++ b/mintlify-docs/docs/dependency-management.mdx @@ -0,0 +1,104 @@ +--- +title: Dependency Management +description: Guide to managing dependencies for the Model Context Protocol (MCP) Java SDK +--- + +# Dependency Management + +## Bill of Materials (BOM) + +The Bill of Materials (BOM) declares the recommended versions of all the dependencies used by a given release. +Using the BOM from your application's build script avoids the need for you to specify and maintain the dependency versions yourself. +Instead, the version of the BOM you're using determines the utilized dependency versions. +It also ensures that you're using supported and tested versions of the dependencies by default, unless you choose to override them. + +Add the BOM to your project: + + + +```xml + + + + org.modelcontextprotocol.sdk + mcp-bom + 0.6.0-SNAPSHOT + pom + import + + + +``` + + + +```groovy +dependencies { + implementation platform("org.modelcontextprotocol.sdk:mcp-bom:0.6.0-SNAPSHOT") + //... +} +``` + +Gradle users can also use the Spring AI MCP BOM by leveraging Gradle (5.0+) native support for declaring dependency constraints using a Maven BOM. +This is implemented by adding a 'platform' dependency handler method to the dependencies section of your Gradle build script. +As shown in the snippet below this can then be followed by version-less declarations of the Starter Dependencies for the one or more spring-ai modules you wish to use, e.g. spring-ai-openai. + + + +Replace the version number with the version of the BOM you want to use. + +## Available Dependencies + +The following dependencies are available and managed by the BOM: + +### Core Dependencies + +- `org.modelcontextprotocol.sdk:mcp` - Core MCP library providing the base functionality and APIs for Model Context Protocol implementation. + +### Transport Dependencies + +- `org.modelcontextprotocol.sdk:mcp-webflux-sse-transport` - WebFlux-based Server-Sent Events (SSE) transport implementation for reactive applications. +- `org.modelcontextprotocol.sdk:mcp-webmvc-sse-transport` - WebMVC-based Server-Sent Events (SSE) transport implementation for servlet-based applications. + +### Testing Dependencies + +- `org.modelcontextprotocol.sdk:mcp-test` - Testing utilities and support for MCP-based applications. + +### Milestone and Snapshot Repositories + +To use the Milestone and Snapshot version, you need to add references to the Spring Milestone and/or Snapshot repositories in your build file. +Add the following repository definitions to your Maven or Gradle build file: + + + +```xml + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + false + + + +``` + + + +```groovy +repositories { + maven { url 'https://repo.spring.io/milestone' } + maven { url 'https://repo.spring.io/snapshot' } +} +``` + + diff --git a/mintlify-docs/docs/mcp-capabilities.mdx b/mintlify-docs/docs/mcp-capabilities.mdx new file mode 100644 index 00000000..aceda05b --- /dev/null +++ b/mintlify-docs/docs/mcp-capabilities.mdx @@ -0,0 +1,139 @@ +--- +title: MCP Server Capabilities +description: Configure and manage Model Context Protocol (MCP) server capabilities including tools, resources, and prompts +--- + +# Model Context Protocol Server Capabilities + +The server can be configured with various capabilities: + +```java +var capabilities = ServerCapabilities.builder() + .resources(false, true) // Resource support with list changes notifications + .tools(true) // Tool support with list changes notifications + .prompts(true) // Prompt support with list changes notifications + .logging() // Enable logging support (enabled by default with loging level INFO) + .build(); +``` + +## Logging Support + +The server provides structured logging capabilities that allow sending log messages to clients with different severity levels: + +```java +// Send a log message to clients +server.loggingNotification(LoggingMessageNotification.builder() + .level(LoggingLevel.INFO) + .logger("custom-logger") + .data("Custom log message") + .build()); +``` + +Clients can control the minimum logging level they receive through the `mcpClient.setLoggingLevel(level)` request. Messages below the set level will be filtered out. +Supported logging levels (in order of increasing severity): DEBUG (0), INFO (1), NOTICE (2), WARNING (3), ERROR (4), CRITICAL (5), ALERT (6), EMERGENCY (7) + +## Tool Registration + + + +```java +// Sync tool registration +var syncToolRegistration = new McpServerFeatures.SyncToolRegistration( + new Tool("calculator", "Basic calculator", Map.of( + "operation", "string", + "a", "number", + "b", "number" + )), + arguments -> { + // Tool implementation + return new CallToolResult(result, false); + } +); +``` + + + +```java +// Async tool registration +var asyncToolRegistration = new McpServerFeatures.AsyncToolRegistration( + new Tool("calculator", "Basic calculator", Map.of( + "operation", "string", + "a", "number", + "b", "number" + )), + arguments -> { + // Tool implementation + return Mono.just(new CallToolResult(result, false)); + } +); +``` + + + +## Resource Registration + + + +```java +// Sync resource registration +var syncResourceRegistration = new McpServerFeatures.SyncResourceRegistration( + new Resource("custom://resource", "name", "description", "mime-type", null), + request -> { + // Resource read implementation + return new ReadResourceResult(contents); + } +); +``` + + + +```java +// Async resource registration +var asyncResourceRegistration = new McpServerFeatures.AsyncResourceRegistration( + new Resource("custom://resource", "name", "description", "mime-type", null), + request -> { + // Resource read implementation + return Mono.just(new ReadResourceResult(contents)); + } +); +``` + + + +## Prompt Registration + + + +```java +// Sync prompt registration +var syncPromptRegistration = new McpServerFeatures.SyncPromptRegistration( + new Prompt("greeting", "description", List.of( + new PromptArgument("name", "description", true) + )), + request -> { + // Prompt implementation + return new GetPromptResult(description, messages); + } +); +``` + + + +```java +// Async prompt registration +var asyncPromptRegistration = new McpServerFeatures.AsyncPromptRegistration( + new Prompt("greeting", "description", List.of( + new PromptArgument("name", "description", true) + )), + request -> { + // Prompt implementation + return Mono.just(new GetPromptResult(description, messages)); + } +); +``` + + + +# Error Handling + +The SDK provides comprehensive error handling through the McpError class, covering protocol compatibility, transport communication, JSON-RPC messaging, tool execution, resource management, prompt handling, timeouts, and connection issues. This unified error handling approach ensures consistent and reliable error management across both synchronous and asynchronous operations. diff --git a/mintlify-docs/docs/mcp-client.mdx b/mintlify-docs/docs/mcp-client.mdx new file mode 100644 index 00000000..0f78879e --- /dev/null +++ b/mintlify-docs/docs/mcp-client.mdx @@ -0,0 +1,232 @@ +--- +title: MCP Client +description: Learn how to use the Model Context Protocol (MCP) client to interact with MCP servers +--- + +# Model Context Protocol Client + +The MCP Client is a key component in the Model Context Protocol (MCP) architecture, responsible for establishing and managing connections with MCP servers. It implements the client-side of the protocol, handling: + +- Protocol version negotiation to ensure compatibility with servers +- Capability negotiation to determine available features +- Message transport and JSON-RPC communication +- Tool discovery and execution +- Resource access and management +- Prompt system interactions +- Optional features like roots management and sampling support + +The client provides both synchronous and asynchronous APIs for flexibility in different application contexts. + + + +```java +// Create a sync client with custom configuration +McpSyncClient client = McpClient.sync(transport) + .requestTimeout(Duration.ofSeconds(10)) + .capabilities(ClientCapabilities.builder() + .roots(true) // Enable roots capability + .sampling() // Enable sampling capability + .build()) + .sampling(request -> new CreateMessageResult(response)) + .build(); + +// Initialize connection +client.initialize(); + +// List available tools +ListToolsResult tools = client.listTools(); + +// Call a tool +CallToolResult result = client.callTool( + new CallToolRequest("calculator", + Map.of("operation", "add", "a", 2, "b", 3)) +); + +// List and read resources +ListResourcesResult resources = client.listResources(); +ReadResourceResult resource = client.readResource( + new ReadResourceRequest("resource://uri") +); + +// List and use prompts +ListPromptsResult prompts = client.listPrompts(); +GetPromptResult prompt = client.getPrompt( + new GetPromptRequest("greeting", Map.of("name", "Spring")) +); + +// Add/remove roots +client.addRoot(new Root("file:///path", "description")); +client.removeRoot("file:///path"); + +// Close client +client.closeGracefully(); +``` + + + +```java +// Create an async client with custom configuration +McpAsyncClient client = McpClient.async(transport) + .requestTimeout(Duration.ofSeconds(10)) + .capabilities(ClientCapabilities.builder() + .roots(true) // Enable roots capability + .sampling() // Enable sampling capability + .build()) + .sampling(request -> Mono.just(new CreateMessageResult(response))) + .toolsChangeConsumer(tools -> Mono.fromRunnable(() -> { + logger.info("Tools updated: {}", tools); + })) + .resourcesChangeConsumer(resources -> Mono.fromRunnable(() -> { + logger.info("Resources updated: {}", resources); + })) + .promptsChangeConsumer(prompts -> Mono.fromRunnable(() -> { + logger.info("Prompts updated: {}", prompts); + })) + .build(); + +// Initialize connection and use features +client.initialize() + .flatMap(initResult -> client.listTools()) + .flatMap(tools -> { + return client.callTool(new CallToolRequest( + "calculator", + Map.of("operation", "add", "a", 2, "b", 3) + )); + }) + .flatMap(result -> { + return client.listResources() + .flatMap(resources -> + client.readResource(new ReadResourceRequest("resource://uri")) + ); + }) + .flatMap(resource -> { + return client.listPrompts() + .flatMap(prompts -> + client.getPrompt(new GetPromptRequest( + "greeting", + Map.of("name", "Spring") + )) + ); + }) + .flatMap(prompt -> { + return client.addRoot(new Root("file:///path", "description")) + .then(client.removeRoot("file:///path")); + }) + .doFinally(signalType -> { + client.closeGracefully().subscribe(); + }) + .subscribe(); +``` + + + +## Client Features + +### Tool Execution + +Tools are server-side functions that can be discovered and executed by clients. The client provides methods to list available tools and execute them with parameters. + + + +```java +// List available tools +var tools = client.listTools(); +tools.forEach(tool -> System.out.println(tool.getName())); + +// Execute a tool +var result = client.executeTool("calculator", Map.of( + "operation", "add", + "a", 1, + "b", 2 +)); +``` + + + +```java +// List available tools +client.listTools() + .doOnNext(tools -> tools.forEach(tool -> + System.out.println(tool.getName()))) + .subscribe(); + +// Execute a tool +client.executeTool("calculator", Map.of( + "operation", "add", + "a", 1, + "b", 2 + )) + .subscribe(); +``` + + + +### Resource Access + +Resources are server-side data sources that can be accessed by clients using URI templates. The client provides methods to list available resources and retrieve their content. + + + +```java +// List available resources +var resources = client.listResources(); +resources.forEach(resource -> System.out.println(resource.getName())); + +// Get a resource +var content = client.getResource("file", Map.of( + "path", "/path/to/file.txt" +)); +``` + + + +```java +// List available resources +client.listResources() + .doOnNext(resources -> resources.forEach(resource -> + System.out.println(resource.getName()))) + .subscribe(); + +// Get a resource +client.getResource("file", Map.of( + "path", "/path/to/file.txt" + )) + .subscribe(); +``` + + + +### Prompt System + +The prompt system allows clients to interact with server-side prompt templates. The client provides methods to list available prompts and execute them with parameters. + + + +```java +// List available prompts +var prompts = client.listPrompts(); +prompts.forEach(prompt -> System.out.println(prompt.getName())); + +// Execute a prompt +var response = client.executePrompt("echo", Map.of( + "text", "Hello, World!" +)); +``` + + + +```java +// List available prompts +client.listPrompts() + .doOnNext(prompts -> prompts.forEach(prompt -> + System.out.println(prompt.getName()))) + .subscribe(); + +// Execute a prompt +client.executePrompt("echo", Map.of( + "text", "Hello, World!" + )) + .subscribe(); +``` + + diff --git a/mintlify-docs/docs/mcp-overview.mdx b/mintlify-docs/docs/mcp-overview.mdx new file mode 100644 index 00000000..68329fad --- /dev/null +++ b/mintlify-docs/docs/mcp-overview.mdx @@ -0,0 +1,85 @@ +--- +title: MCP Overview +description: Overview of the Model Context Protocol (MCP) architecture and key concepts +--- + +# Java MCP SDK + +Java SDK implementation of the [Model Context Protocol](https://modelcontextprotocol.io/introduction), enabling seamless integration with language models and AI tools. + +![Spring AI MCP Client Architecture](/images/spring-ai-mcp-client-architecture.jpg) +![Spring AI MCP Server Architecture](/images/spring-ai-mcp-server-architecture.jpg) + +## Features + +- Synchronous and Asynchronous MCP Client and MCP Server implementations +- Standard MCP operations support: + - Protocol [version compatibility negotiation](https://spec.modelcontextprotocol.io/specification/2024-11-05/basic/lifecycle/#initialization) + - [Tool](https://spec.modelcontextprotocol.io/specification/2024-11-05/server/tools/) discovery, execution, list change notifications + - [Resource](https://spec.modelcontextprotocol.io/specification/2024-11-05/server/resources/) management with URI templates + - [Roots](https://spec.modelcontextprotocol.io/specification/2024-11-05/client/roots/) list management and notifications + - [Prompt](https://spec.modelcontextprotocol.io/specification/2024-11-05/server/prompts/) handling and management + - [Sampling](https://spec.modelcontextprotocol.io/specification/2024-11-05/client/sampling/) support for AI model interactions +- Multiple transport implementations: + - Core transports: + - Stdio-based transport for process-based communication + - Java HttpClient-based SSE client transport for HTTP SSE Client-side streaming + - Servlet-based SSE server transport for HTTP SSE Server streaming + - Spring-based transports: + - WebFlux SSE transport for reactive HTTP streaming + - WebMVC SSE transport for servlet-based HTTP streaming + +## Architecture + +![MCP Stack Architecture](/images/mcp-stack.svg) + +The SDK follows a layered architecture with clear separation of concerns: + +- **Client/Server Layer**: Both use McpSession for sync/async operations, with McpClient handling client-side protocol operations and McpServer managing server-side protocol operations. +- **Session Layer (McpSession)**: Manages communication patterns and state using DefaultMcpSession implementation. +- **Transport Layer (McpTransport)**: Handles JSON-RPC message serialization/deserialization via: + - StdioTransport (stdin/stdout) in the core module + - HTTP SSE transports in dedicated transport modules (Java HttpClient, Spring WebFlux, Spring WebMVC) + +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. + +![MCP SDK Class Diagram](/images/spring-ai-mcp-uml-classdiagram.svg) + +Key Interactions: + +- **Client/Server Initialization**: Transport setup, protocol compatibility check, capability negotiation, and implementation details exchange. +- **Message Flow**: JSON-RPC message handling with validation, type-safe response processing, and error handling. +- **Resource Management**: Resource discovery, URI template-based access, subscription system, and content retrieval. + +## Dependencies + +Add the following dependency to your Maven project: + + + +The core MCP functionality: + +```xml + + org.modelcontextprotocol.sdk + mcp + +``` + +For HTTP SSE transport implementations, add one of the following dependencies: + +```xml + + + org.modelcontextprotocol.sdk + mcp-webflux-sse-transport + + + + + org.modelcontextprotocol.sdk + mcp-webmvc-sse-transport + +``` + + diff --git a/mintlify-docs/docs/mcp-server.mdx b/mintlify-docs/docs/mcp-server.mdx new file mode 100644 index 00000000..894e1f30 --- /dev/null +++ b/mintlify-docs/docs/mcp-server.mdx @@ -0,0 +1,98 @@ +--- +title: MCP Server +description: Learn how to implement and configure a Model Context Protocol (MCP) server +--- + +# Model Context Protocol Server + +The MCP Server is a foundational component in the Model Context Protocol (MCP) architecture that provides tools, resources, and capabilities to clients. It implements the server-side of the protocol, responsible for: + +- Exposing tools that clients can discover and execute +- Managing resources with URI-based access patterns +- Providing prompt templates and handling prompt requests +- Supporting capability negotiation with clients +- Implementing server-side protocol operations +- Managing concurrent client connections +- Providing structured logging and notifications + +The server supports both synchronous and asynchronous APIs, allowing for flexible integration in different application contexts. + + + +```java +// Create a server with custom configuration +McpSyncServer syncServer = McpServer.sync(transport) + .serverInfo("my-server", "1.0.0") + .capabilities(ServerCapabilities.builder() + .resources(true) // Enable resource support + .tools(true) // Enable tool support + .prompts(true) // Enable prompt support + .logging() // Enable logging support + .build()) + .build(); + +// Initialize the server +syncServer.initialize(); + +// Register tools, resources, and prompts +syncServer.registerTool(syncToolRegistration); +syncServer.registerResource(syncResourceRegistration); +syncServer.registerPrompt(syncPromptRegistration); + +// Send logging notifications +syncServer.loggingNotification(LoggingMessageNotification.builder() + .level(LoggingLevel.INFO) + .logger("custom-logger") + .data("Server initialized") + .build()); + +// Close the server when done +syncServer.close(); +``` + + + +```java +// Create an async server with custom configuration +McpAsyncServer asyncServer = McpServer.async(transport) + .serverInfo("my-server", "1.0.0") + .capabilities(ServerCapabilities.builder() + .resources(true) // Enable resource support + .tools(true) // Enable tool support + .prompts(true) // Enable prompt support + .logging() // Enable logging support + .build()) + .build(); + +// Initialize the server +asyncServer.initialize() + .doOnSuccess(v -> logger.info("Server initialized")) + .subscribe(); + +// Register tools, resources, and prompts +asyncServer.registerTool(asyncToolRegistration) + .doOnSuccess(v -> logger.info("Tool registered")) + .subscribe(); + +asyncServer.registerResource(asyncResourceRegistration) + .doOnSuccess(v -> logger.info("Resource registered")) + .subscribe(); + +asyncServer.registerPrompt(asyncPromptRegistration) + .doOnSuccess(v -> logger.info("Prompt registered")) + .subscribe(); + +// Send logging notifications +asyncServer.loggingNotification(LoggingMessageNotification.builder() + .level(LoggingLevel.INFO) + .logger("custom-logger") + .data("Server initialized") + .build()); + +// Close the server when done +asyncServer.close() + .doOnSuccess(v -> logger.info("Server closed")) + .subscribe(); +``` + + diff --git a/mintlify-docs/docs/mcp-transport.mdx b/mintlify-docs/docs/mcp-transport.mdx new file mode 100644 index 00000000..e0483d67 --- /dev/null +++ b/mintlify-docs/docs/mcp-transport.mdx @@ -0,0 +1,144 @@ +--- +title: MCP Transport +description: Understanding the Model Context Protocol (MCP) transport layer and available implementations +--- + +# Model Context Protocol Transport Layer + +The transport layer in the MCP SDK is responsible for handling the communication between clients and servers. It provides different implementations to support various communication protocols and patterns. The SDK includes several built-in transport implementations: + + + + + <> + Create in-process based transport: + + ```java + StdioServerTransport transport = new StdioServerTransport(new ObjectMapper()); + ``` + + Provides bidirectional JSON-RPC message handling over standard input/output streams with non-blocking message processing, serialization/deserialization, and graceful shutdown support. + + Key features: + + + + + + <> +

Creates WebFlux-based SSE server transport.
Requires the mcp-webflux-sse-transport dependency.

+ +
+      
+        {`@Configuration
+class McpConfig {
+    @Bean
+    WebFluxSseServerTransport webFluxSseServerTransport(ObjectMapper mapper) {
+        return new WebFluxSseServerTransport(mapper, "/mcp/message");
+    }
+
+    @Bean
+    RouterFunction mcpRouterFunction(WebFluxSseServerTransport transport) {
+        return transport.getRouterFunction();
+    }
+}`}
+      
+    
+ +

Implements the MCP HTTP with SSE transport specification, providing:

+ + +
+ + + + <> +

Creates WebMvc-based SSE server transport.
Requires the mcp-webmvc-sse-transport dependency.

+ +
+      
+        {`@Configuration
+@EnableWebMvc
+class McpConfig {
+    @Bean
+    WebMvcSseServerTransport webMvcSseServerTransport(ObjectMapper mapper) {
+        return new WebMvcSseServerTransport(mapper, "/mcp/message");
+    }
+
+    @Bean
+    RouterFunction mcpRouterFunction(WebMvcSseServerTransport transport) {
+        return transport.getRouterFunction();
+    }
+}`}
+      
+    
+ +

Implements the MCP HTTP with SSE transport specification, providing:

+ + +
+ + + + <> +

+ Creates a Servlet-based SSE server transport.
+ Included in the core mcp module.
+ The HttpServletSseServerTransport can be used with any Servlet container. + To use it with a Spring Web application, you can register it as a Servlet bean: +

+ +
+      
+        {`@Configuration
+@EnableWebMvc
+public class McpServerConfig implements WebMvcConfigurer {
+
+    @Bean
+    public HttpServletSseServerTransport servletSseServerTransport() {
+        return new HttpServletSseServerTransport(new ObjectMapper(), "/mcp/message");
+    }
+
+    @Bean
+    public ServletRegistrationBean customServletBean(HttpServletSseServerTransport servlet) {
+        return new ServletRegistrationBean(servlet);
+    }
+}`}
+      
+    
+ +

+ Implements the MCP HTTP with SSE transport specification using the traditional Servlet API, providing: +

+ + +
+ +
diff --git a/mintlify-docs/docs/overview.mdx b/mintlify-docs/docs/overview.mdx new file mode 100644 index 00000000..66240326 --- /dev/null +++ b/mintlify-docs/docs/overview.mdx @@ -0,0 +1,55 @@ +--- +title: Overview +description: Introduction to the Model Context Protocol (MCP) Java SDK +--- + +# Java & Spring MCP + +Java SDK and Spring Framework integration for the [Model Context Protocol](https://modelcontextprotocol.org/docs/concepts/architecture), enabling standardized interaction with AI models and tools through both synchronous and asynchronous communication. + +![Spring AI MCP Client Architecture](/images/spring-ai-mcp-client-architecture.jpg) +![Spring AI MCP Server Architecture](/images/spring-ai-mcp-server-architecture.jpg) + +## Core Components + +### [MCP Java SDK](/docs/mcp) +Core implementation of the Model Context Protocol specification, providing: + +- Synchronous and asynchronous [Client](/docs/mcp#mcp-client) and [Server](/docs/mcp#mcp-server) implementations +- Tool discovery and execution +- Resource management with URI templates +- Prompt handling and management +- Structured logging +- Request and Notification handling + +### MCP Transports + +#### Core Transports +- Stdio-based (`StdioClientTransport`, `StdioServerTransport`) for process-based communication +- Java HttpClient-based SSE client (`HttpClientSseClientTransport`) for HTTP SSE Client-side streaming +- Servlet-based SSE server (`HttpServletSseServerTransport`) for HTTP SSE Server streaming using traditional Servlet API + +#### Optional SSE Transports +- [WebFlux SSE Transport](https://github.com/modelcontextprotocol/java-sdk/tree/main/mcp-transport/mcp-webflux-sse-transport) - Reactive HTTP streaming with Spring WebFlux (Client & Server) +- [WebMvc SSE Transport](https://github.com/modelcontextprotocol/java-sdk/tree/main/mcp-transport/mcp-webmvc-sse-transport) - Spring MVC based SSE transport (Server only). +You can use the core `HttpClientSseClientTransport` transport as a SSE client. + +## Getting Started + + + +```xml + + + org.modelcontextprotocol.sdk + mcp + + + + + org.modelcontextprotocol.sdk + mcp-webflux-sse-transport + +``` + + diff --git a/mintlify-docs/favicon.svg b/mintlify-docs/favicon.svg new file mode 100644 index 00000000..03d9f85d --- /dev/null +++ b/mintlify-docs/favicon.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/mintlify-docs/images/class-diagrams.puml b/mintlify-docs/images/class-diagrams.puml new file mode 100644 index 00000000..5b08c738 --- /dev/null +++ b/mintlify-docs/images/class-diagrams.puml @@ -0,0 +1,282 @@ +@startuml Core Components + +' Core Interfaces +interface McpTransport { + +Mono connect(Function, Mono> handler) + +Mono sendMessage(JSONRPCMessage message) + +void close() + +Mono closeGracefully() + + T unmarshalFrom(Object data, TypeReference typeRef) +} + +interface McpSession { + + Mono sendRequest(String method, Object requestParams, TypeReference typeRef) + +Mono sendNotification(String method, Map params) + +Mono closeGracefully() + +void close() +} + +' Core Implementation Classes +class DefaultMcpSession { + +interface RequestHandler + +interface NotificationHandler +} + +' Client Classes +class McpClient { + +{static} Builder using(ClientMcpTransport transport) +} + +class McpAsyncClient { + +Mono initialize() + +ServerCapabilities getServerCapabilities() + +Implementation getServerInfo() + +ClientCapabilities getClientCapabilities() + +Implementation getClientInfo() + +void close() + +Mono closeGracefully() + +Mono ping() + +Mono addRoot(Root root) + +Mono removeRoot(String rootUri) + +Mono rootsListChangedNotification() + +Mono callTool(CallToolRequest request) + +Mono listTools() + +Mono listResources() + +Mono readResource(ReadResourceRequest request) + +Mono listResourceTemplates() + +Mono subscribeResource(SubscribeRequest request) + +Mono unsubscribeResource(UnsubscribeRequest request) + +Mono listPrompts() + +Mono getPrompt(GetPromptRequest request) + +Mono setLoggingLevel(LoggingLevel level) +} + +class McpSyncClient { + +InitializeResult initialize() + +ServerCapabilities getServerCapabilities() + +Implementation getServerInfo() + +ClientCapabilities getClientCapabilities() + +Implementation getClientInfo() + +void close() + +boolean closeGracefully() + +Object ping() + +void addRoot(Root root) + +void removeRoot(String rootUri) + +void rootsListChangedNotification() + +CallToolResult callTool(CallToolRequest request) + +ListToolsResult listTools() + +ListResourcesResult listResources() + +ReadResourceResult readResource(ReadResourceRequest request) + +ListResourceTemplatesResult listResourceTemplates() + +void subscribeResource(SubscribeRequest request) + +void unsubscribeResource(UnsubscribeRequest request) + +ListPromptsResult listPrompts() + +GetPromptResult getPrompt(GetPromptRequest request) + +void setLoggingLevel(LoggingLevel level) +} + +' Server Classes +class McpServer { + +{static} Builder using(ServerMcpTransport transport) +} + +class McpAsyncServer { + + +ServerCapabilities getServerCapabilities() + +Implementation getServerInfo() + +ClientCapabilities getClientCapabilities() + +Implementation getClientInfo() + +void close() + +Mono closeGracefully() + + ' Tool Management + +Mono addTool(ToolRegistration toolRegistration) + +Mono removeTool(String toolName) + +Mono notifyToolsListChanged() + + ' Resource Management + +Mono addResource(ResourceRegistration resourceHandler) + +Mono removeResource(String resourceUri) + +Mono notifyResourcesListChanged() + + ' Prompt Management + +Mono addPrompt(PromptRegistration promptRegistration) + +Mono removePrompt(String promptName) + +Mono notifyPromptsListChanged() + + ' Logging + +Mono loggingNotification(LoggingMessageNotification notification) + + ' Sampling + +Mono createMessage(CreateMessageRequest request) +} + +class McpSyncServer { + +McpAsyncServer getAsyncServer() + + +ServerCapabilities getServerCapabilities() + +Implementation getServerInfo() + +ClientCapabilities getClientCapabilities() + +Implementation getClientInfo() + +void close() + +void closeGracefully() + + ' Tool Management + +void addTool(ToolRegistration toolHandler) + +void removeTool(String toolName) + +void notifyToolsListChanged() + + ' Resource Management + +void addResource(ResourceRegistration resourceHandler) + +void removeResource(String resourceUri) + +void notifyResourcesListChanged() + + ' Prompt Management + +void addPrompt(PromptRegistration promptRegistration) + +void removePrompt(String promptName) + +void notifyPromptsListChanged() + + ' Logging + +void loggingNotification(LoggingMessageNotification notification) + + ' Sampling + +CreateMessageResult createMessage(CreateMessageRequest request) +} + +' Transport Implementations +class StdioClientTransport implements ClientMcpTransport { + +void setErrorHandler(Consumer errorHandler) + +Sinks.Many getErrorSink() +} + +class StdioServerTransport implements ServerMcpTransport { +} + + +class HttpServletSseServerTransport implements ServerMcpTransport { +} + + +class HttpClientSseClientTransport implements ClientMcpTransport { +} + + +class WebFluxSseClientTransport implements ClientMcpTransport { +} + + +class WebFluxSseServerTransport implements ServerMcpTransport { + +RouterFunction getRouterFunction() +} + +class WebMvcSseServerTransport implements ServerMcpTransport { + +RouterFunction getRouterFunction() +} + + +' Schema and Error Classes +class McpSchema { + +class ErrorCodes + +interface Request + +interface JSONRPCMessage + +interface ResourceContents + +interface Content + +interface ServerCapabilities + +{static} JSONRPCMessage deserializeJsonRpcMessage() +} + +class McpError { +} + +' Relationships +McpTransport <|.. ClientMcpTransport +McpTransport <|.. ServerMcpTransport + +McpSession <|.. DefaultMcpSession +DefaultMcpSession --o McpAsyncClient +DefaultMcpSession --o McpAsyncServer + +McpClient ..> McpAsyncClient : creates +McpClient ..> McpSyncClient : creates +McpSyncClient --> McpAsyncClient : delegates to + +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 diff --git a/mintlify-docs/images/mcp-stack.svg b/mintlify-docs/images/mcp-stack.svg new file mode 100644 index 00000000..3847eaa8 --- /dev/null +++ b/mintlify-docs/images/mcp-stack.svg @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mintlify-docs/images/spring-ai-mcp-client-architecture.jpg b/mintlify-docs/images/spring-ai-mcp-client-architecture.jpg new file mode 100644 index 00000000..f858b8d5 Binary files /dev/null and b/mintlify-docs/images/spring-ai-mcp-client-architecture.jpg differ diff --git a/mintlify-docs/images/spring-ai-mcp-server-architecture.jpg b/mintlify-docs/images/spring-ai-mcp-server-architecture.jpg new file mode 100644 index 00000000..c6ebea0c Binary files /dev/null and b/mintlify-docs/images/spring-ai-mcp-server-architecture.jpg differ diff --git a/mintlify-docs/images/spring-ai-mcp-uml-classdiagram.svg b/mintlify-docs/images/spring-ai-mcp-uml-classdiagram.svg new file mode 100644 index 00000000..f83a586e --- /dev/null +++ b/mintlify-docs/images/spring-ai-mcp-uml-classdiagram.svg @@ -0,0 +1 @@ +McpTransportMono<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)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()DefaultMcpSessioninterface RequestHandlerinterface NotificationHandlerMcpClientBuilder using(ClientMcpTransport transport)McpAsyncClientMono<InitializeResult> initialize()ServerCapabilities getServerCapabilities()Implementation getServerInfo()ClientCapabilities getClientCapabilities()Implementation getClientInfo()void close()Mono<Void> closeGracefully()Mono<Object> ping()Mono<Void> addRoot(Root root)Mono<Void> removeRoot(String rootUri)Mono<Void> rootsListChangedNotification()Mono<CallToolResult> callTool(CallToolRequest request)Mono<ListToolsResult> listTools()Mono<ListResourcesResult> listResources()Mono<ReadResourceResult> readResource(ReadResourceRequest request)Mono<ListResourceTemplatesResult> listResourceTemplates()Mono<Void> subscribeResource(SubscribeRequest request)Mono<Void> unsubscribeResource(UnsubscribeRequest request)Mono<ListPromptsResult> listPrompts()Mono<GetPromptResult> getPrompt(GetPromptRequest request)Mono<Void> setLoggingLevel(LoggingLevel level)McpSyncClientInitializeResult initialize()ServerCapabilities getServerCapabilities()Implementation getServerInfo()ClientCapabilities getClientCapabilities()Implementation getClientInfo()void close()boolean closeGracefully()Object ping()void addRoot(Root root)void removeRoot(String rootUri)void rootsListChangedNotification()CallToolResult callTool(CallToolRequest request)ListToolsResult listTools()ListResourcesResult listResources()ReadResourceResult readResource(ReadResourceRequest request)ListResourceTemplatesResult listResourceTemplates()void subscribeResource(SubscribeRequest request)void unsubscribeResource(UnsubscribeRequest request)ListPromptsResult listPrompts()GetPromptResult getPrompt(GetPromptRequest request)void setLoggingLevel(LoggingLevel level)McpServerBuilder using(ServerMcpTransport transport)McpAsyncServerServerCapabilities getServerCapabilities()Implementation getServerInfo()ClientCapabilities getClientCapabilities()Implementation getClientInfo()void close()Mono<Void> closeGracefully() Mono<Void> addTool(ToolRegistration toolRegistration)Mono<Void> removeTool(String toolName)Mono<Void> notifyToolsListChanged() Mono<Void> addResource(ResourceRegistration resourceHandler)Mono<Void> removeResource(String resourceUri)Mono<Void> notifyResourcesListChanged() Mono<Void> addPrompt(PromptRegistration promptRegistration)Mono<Void> removePrompt(String promptName)Mono<Void> notifyPromptsListChanged() Mono<Void> loggingNotification(LoggingMessageNotification notification) Mono<CreateMessageResult> createMessage(CreateMessageRequest request)McpSyncServerMcpAsyncServer getAsyncServer() ServerCapabilities getServerCapabilities()Implementation getServerInfo()ClientCapabilities getClientCapabilities()Implementation getClientInfo()void close()void closeGracefully() void addTool(ToolRegistration toolHandler)void removeTool(String toolName)void notifyToolsListChanged() void addResource(ResourceRegistration resourceHandler)void removeResource(String resourceUri)void notifyResourcesListChanged() void addPrompt(PromptRegistration promptRegistration)void removePrompt(String promptName)void notifyPromptsListChanged() void loggingNotification(LoggingMessageNotification notification) CreateMessageResult createMessage(CreateMessageRequest request)StdioClientTransportvoid setErrorHandler(Consumer<String> errorHandler)Sinks.Many<String> getErrorSink()ClientMcpTransportStdioServerTransportServerMcpTransportHttpServletSseServerTransportHttpClientSseClientTransportWebFluxSseClientTransportWebFluxSseServerTransportRouterFunction<?> getRouterFunction()WebMvcSseServerTransportRouterFunction<?> getRouterFunction()McpSchemaclass ErrorCodesinterface Requestinterface JSONRPCMessageinterface ResourceContentsinterface Contentinterface ServerCapabilitiesJSONRPCMessage deserializeJsonRpcMessage()McpErrorcreatescreatesdelegates tocreatescreatesusesthrows \ No newline at end of file diff --git a/mintlify-docs/mint.json b/mintlify-docs/mint.json new file mode 100644 index 00000000..eb4ddaae --- /dev/null +++ b/mintlify-docs/mint.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://mintlify.com/schema.json", + "name": "Model Context Protocol Java SDK", + "logo": { + "dark": "/logo/dark.svg", + "light": "/logo/light.svg" + }, + "favicon": "/favicon.svg", + "colors": { + "primary": "#09090b", + "light": "#FAFAFA", + "dark": "#09090b" + }, + "topbarLinks": [], + "topbarCtaButton": { + "name": "GitHub", + "url": "https://github.com/modelcontextprotocol/java-sdk" + }, + "search": { + "location": "top" + }, + "navigation": [ + { + "group": "Getting Started", + "pages": [ + "docs/overview", + "docs/dependency-management" + ] + }, + { + "group": "MCP SDK Reference", + "pages": [ + "docs/mcp-overview", + "docs/mcp-client", + "docs/mcp-server", + "docs/mcp-transport", + "docs/mcp-capabilities" + ] + } + ] +}