# spring-projects-experimental/spring-ai-mcp architecture

> Architecture diagram of the GitHub repository spring-projects-experimental/spring-ai-mcp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/spring-projects-experimental/spring-ai-mcp
- Repository: https://github.com/spring-projects-experimental/spring-ai-mcp

## Overview

##### Main components
- MCP Core (Java SDK): Represents the heart of the protocol implementation. It includes the primary packages (e.g., org.springframework.ai.mcp) for both client and server functionality, along with shared components (specification classes for sessions, transports, error handling, etc.).
- Transports: There are several transport mechanisms:
– Stdio transports (client & server) for process-based communication.
– HTTP Streaming via SSE with multiple variations:
▪ HttpClientSseClientTransport (SSE client using HttpClient).
▪ HttpServletSseServerTransport (Servlet-based SSE server).
▪ WebFluxSse* (both client and server) – using reactive Spring WebFlux.
▪ WebMvcSse* (server focused) – using Spring MVC’s traditional model.
- Spring Integration Module: The spring-ai-mcp module provides Spring-specific functionality and auto-configuration for integrating MCP into Spring applications.
- Test Modules: These include mcp-test and test resources within mcp, which show how the client/server and transport layers are validated.

##### Relationships and interactions
- The MCP Core is central, acting as both a client API and server framework. It relies on the protocol specification (with classes such as McpSession and McpSchema) to standardize communication.
- Transports plug into the core to enable different communication channels. For instance, a client can use either HttpClientSseClientTransport or StdioClientTransport to communicate with a corresponding server transport.
- The integrations with Spring (in spring-ai-mcp) illustrate how MCP’s core and transport functionalities are exposed in a Spring-friendly manner (for instance, via auto-configurations and function callback abstractions).

##### Architectural patterns and design principles to highlight
- Modular design: Modules like mcp, mcp-transport (with sub-modules for WebFlux and WebMvc) and spring-ai-mcp are organized as distinct Maven projects, promoting separation of concerns.
- Transport Abstraction: The design abstracts the underlying transport logic (Stdio, SSE with various implementations), allowing for flexibility in choosing communication protocols.
- Spring Integration: Emphasize how the MCP functionality is wrapped with Spring-friendly components, providing auto-configuration and integration points.

##### Additional details
- Supporting components like the documentation (mcp-docs) which provides architecture guides, and indicate its relation to the overall design.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "MCP Core Layer"
        mcpCore("MCP Core (Java SDK)"):::core
        mcpSpec("MCP Specification"):::core
    end

    subgraph "Transport Layer"
        subgraph "Stdio Transports"
            stdioClient("Stdio Client Transport"):::transport
            stdioServer("Stdio Server Transport"):::transport
        end
        subgraph "HTTP SSE Transports"
            sseHttpClient("HttpClient SSE Client Transport"):::transport
            sseHttpServlet("HttpServlet SSE Server Transport"):::transport
        end
        subgraph "WebFlux SSE Transports"
            webfluxSSE("WebFlux SSE Transports"):::transport
        end
        subgraph "WebMvc SSE Transport"
            webmvcSSE("WebMvc SSE Server Transport"):::transport
        end
    end

    subgraph "Integration & Presentation Layer"
        springIntegration("Spring Integration Module"):::integration
        documentation("Documentation Module"):::integration
    end

    subgraph "Test Modules"
        clientTest("MCP Test Module"):::test
        additionalTest("Additional Tests"):::test
    end

    mcpCore -->|"protocolReference"| mcpSpec
    mcpCore -->|"invokesStdioClient"| stdioClient
    mcpCore -->|"invokesHttpClientSse"| sseHttpClient
    mcpCore -->|"invokesWebFluxSse"| webfluxSSE
    mcpCore -->|"invokesWebMvcSse"| webmvcSSE
    springIntegration -->|"configuresCore"| mcpCore
    documentation -->|"documentsCore"| mcpCore
    stdioClient -->|"communicatesWith"| stdioServer
    sseHttpClient -->|"communicatesWith"| sseHttpServlet
    clientTest -->|"testsCore"| mcpCore
    additionalTest -->|"testsTransports"| stdioClient
    additionalTest -->|"testsTransports"| webmvcSSE

    click mcpCore "https://github.com/spring-projects-experimental/spring-ai-mcp/tree/main/mcp/src/main/java/org/springframework/ai/mcp"
    click mcpSpec "https://github.com/spring-projects-experimental/spring-ai-mcp/tree/main/mcp/src/main/java/org/springframework/ai/mcp/spec"
    click stdioClient "https://github.com/spring-projects-experimental/spring-ai-mcp/blob/main/mcp/src/main/java/org/springframework/ai/mcp/client/transport/StdioClientTransport.java"
    click stdioServer "https://github.com/spring-projects-experimental/spring-ai-mcp/blob/main/mcp/src/main/java/org/springframework/ai/mcp/server/transport/StdioServerTransport.java"
    click sseHttpClient "https://github.com/spring-projects-experimental/spring-ai-mcp/blob/main/mcp/src/main/java/org/springframework/ai/mcp/client/transport/HttpClientSseClientTransport.java"
    click sseHttpServlet "https://github.com/spring-projects-experimental/spring-ai-mcp/blob/main/mcp/src/main/java/org/springframework/ai/mcp/server/transport/HttpServletSseServerTransport.java"
    click webfluxSSE "https://github.com/spring-projects-experimental/spring-ai-mcp/tree/main/mcp-transport/mcp-webflux-sse-transport/src/main/java/org/springframework/ai/mcp"
    click webmvcSSE "https://github.com/spring-projects-experimental/spring-ai-mcp/blob/main/mcp-transport/mcp-webmvc-sse-transport/src/main/java/org/springframework/ai/mcp/server/transport/WebMvcSseServerTransport.java"
    click springIntegration "https://github.com/spring-projects-experimental/spring-ai-mcp/tree/main/spring-ai-mcp/src/main/java/org/springframework/ai/mcp/spring"
    click documentation "https://github.com/spring-projects-experimental/spring-ai-mcp/tree/main/mcp-docs"
    click clientTest "https://github.com/spring-projects-experimental/spring-ai-mcp/tree/main/mcp-test"
    click additionalTest "https://github.com/spring-projects-experimental/spring-ai-mcp/tree/main/mcp/src/test"

    classDef core fill:#BBF,stroke:#333,stroke-width:2px;
    classDef transport fill:#BFB,stroke:#333,stroke-width:2px;
    classDef integration fill:#FBB,stroke:#333,stroke-width:2px;
    classDef test fill:#FFB,stroke:#333,stroke-width:2px;
```
