This version is still in development and is not considered stable yet. For the latest snapshot version, please use Spring AI 1.0.0-SNAPSHOT!spring-doc.cn

Model Context Protocol (MCP)

The Model Context Protocol (MCP) is a standardized protocol that enables AI models to interact with external tools and resources in a structured way. It supports multiple transport mechanisms to provide flexibility across different environments.spring-doc.cn

MCP Java SDK

The MCP Java SDK provides a Java implementation of the Model Context Protocol, enabling standardized interaction with AI models and tools through both synchronous and asynchronous communication patterns.spring-doc.cn

The Java MCP implementation follows a three-layer architecture:spring-doc.cn

MCP Stack Architecture
  • Client/Server Layer: The McpClient handles client-side operations while the McpServer manages server-side protocol operations. Both utilize McpSession for communication management.spring-doc.cn

  • Session Layer (McpSession): Manages communication patterns and state through the DefaultMcpSession implementation.spring-doc.cn

  • Transport Layer (McpTransport): Handles JSON-RPC message serialization and deserialization with support for multiple transport implementations.spring-doc.cn

MCP 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:spring-doc.cn

Java MCP Client Architecture
MCP 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:spring-doc.cn

Java MCP Server Architecture

For detailed implementation guidance, using the low-level MCP Client/Server APIs, refer to the MCP Java SDK documentation. For simplified setup using Spring Boot, use the MCP Boot Starters described below.spring-doc.cn

Spring AI MCP Integration

Spring AI provides MCP integration through the following Spring Boot starters:spring-doc.cn

Client Starters

  • spring-ai-mcp-client-spring-boot-starter - Core starter providing STDIO and HTTP-based SSE supportspring-doc.cn

  • spring-ai-mcp-client-webflux-spring-boot-starter - WebFlux-based SSE transport implementationspring-doc.cn

Server Starters

  • spring-ai-mcp-server-spring-boot-starter - Core server with STDIO transport supportspring-doc.cn

  • spring-ai-mcp-server-webmvc-spring-boot-starter - Spring MVC-based SSE transport implementationspring-doc.cn

  • spring-ai-mcp-server-webflux-spring-boot-starter - WebFlux-based SSE transport implementationspring-doc.cn