This version is still in development and is not considered stable yet. For the latest snapshot version, please use Spring AI 1.0.1! |
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.
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 AI MCP
extends the MCP Java SDK with Spring Boot integration, providing both client and server starters.
Bootstrap your AI applications with MCP support using Spring Initializer.
MCP Java SDK Architecture
This section provides an overview for the MCP Java SDK architecture. For the Spring AI MCP integration, refer to the Spring AI MCP Boot Starters documentation. |
The Java MCP implementation follows a three-layer architecture:
|
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:
|
![]() |
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:
|
![]() |
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 AI MCP Integration
Spring AI provides MCP integration through the following Spring Boot starters:
Client Starters
-
spring-ai-starter-mcp-client
- Core starter providingSTDIO
and HTTP-basedSSE
andStreamable-HTTP
support -
spring-ai-starter-mcp-client-webflux
- WebFlux-basedSSE
andStreamable-HTTP
transport implementation
Server Starters
WebMVC
Server Type |
Dependency |
Property |
|
|
|
|
|
|
|
|
Spring AI MCP Annotations
In addition to the programmatic MCP client & server configuration, Spring AI provides annotation-based method handling for MCP servers and clients through the MCP Annotations module. This approach simplifies the creation and registration of MCP operations using a clean, declarative programming model with Java annotations.
The MCP Annotations module enables developers to:
-
Create MCP tools, resources, and prompts using simple annotations
-
Handle client-side notifications and requests declaratively
-
Reduce boilerplate code and improve maintainability
-
Automatically generate JSON schemas for tool parameters
-
Access special parameters and context information
Key features include:
-
Server Annotations:
@McpTool
,@McpResource
,@McpPrompt
,@McpComplete
-
Client Annotations:
@McpLogging
,@McpSampling
,@McpElicitation
,@McpProgress
-
Special Parameters:
McpSyncServerExchange
,McpAsyncServerExchange
,McpTransportContext
,McpMeta
-
Automatic Discovery: Annotation scanning with configurable package inclusion/exclusion
-
Spring Boot Integration: Seamless integration with MCP Boot Starters