Java & Spring MCP
Java SDK and Spring Framework integration for the Model Context Protocol, enabling standardized interaction with AI models and tools through both synchronous and asynchronous communication.
![Spring AI MCP Client Architecture](_images/spring-ai-mcp-clinet-architecture.jpg)
![Spring AI MCP Server Architecture](_images/spring-ai-mcp-server-architecture.jpg)
Core Components
MCP Java SDK
Core implementation of the Model Context Protocol specification, providing:
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 - Reactive HTTP streaming with Spring WebFlux (Client & Server)
-
WebMvc SSE Transport - Spring MVC based SSE transport (Server only). You can use the core
HttpClientSseClientTransport
transport as a SSE client.
-
Spring AI MCP
Spring integration features:
-
Spring AI tool/function calling system integration
-
Bidirectional conversion between Spring AI function callbacks and MCP tools
-
JSON schema generation for tool input validation
-
Automatic type conversion and error handling
-
Spring-friendly MCP client abstractions
-
Auto-configurations (WIP)
Getting Started
-
Maven
-
Gradle
<!-- Core MCP -->
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>mcp</artifactId>
</dependency>
<!-- Optional: WebFlux SSE transport -->
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>mcp-webflux-sse-transport</artifactId>
</dependency>
<!-- Optional: WebMVC SSE transport -->
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>mcp-webmvc-sse-transport</artifactId>
</dependency>
<!-- Optional: Spring AI integration -->
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-ai-mcp</artifactId>
</dependency>
Add Spring milestone repository:
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
dependencies {
implementation 'org.springframework.experimental:mcp' // Core
implementation 'org.springframework.experimental:mcp-webflux-sse-transport' // Optional
implementation 'org.springframework.experimental:mcp-webmvc-sse-transport' // Optional
implementation 'org.springframework.experimental:spring-ai-mcp' // Optional
}
repositories {
maven { url 'https://repo.spring.io/milestone' }
}
Reffer to the Dependency Management page for more information.
Examples
-
SQLite Simple - Basic LLM-database integration
-
SQLite Chatbot - Interactive database chatbot
-
Filesystem - LLM interaction with local files
-
Brave - Natural language Brave Search integration
-
Theme Park API - MCP server/client with Theme Park API tools
-
WebFlux SSE - WebFlux server/client implementation
-
WebMvc SSE - WebMvc server with HttpClient implementation
-
Servlet SSE - SSE Servlet server with HttpClient implementation
License
This project is licensed under the Apache License 2.0.