Spring Framework integration for Model Context Protocol (MCP), providing Spring AI function calling capabilities and Spring-friendly abstractions for MCP clients and MCP servers
Spring AI MCP provides Spring Framework integration for the Model Context Protocol (MCP), enabling AI models to interact with external tools and resources through a standardized protocol.
spring-ai-mcporg.springframework.ai<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-mcp</artifactId>
<version>1.1.2</version>
</dependency>implementation 'org.springframework.ai:spring-ai-mcp:1.1.2'import org.springframework.ai.mcp.SyncMcpToolCallbackProvider;
// Create provider
SyncMcpToolCallbackProvider provider = SyncMcpToolCallbackProvider.builder()
.mcpClients(mcpClient)
.build();
// Get tool callbacks
ToolCallback[] callbacks = provider.getToolCallbacks();import org.springframework.ai.mcp.AsyncMcpToolCallbackProvider;
// Create async provider
AsyncMcpToolCallbackProvider provider = AsyncMcpToolCallbackProvider.builder()
.mcpClients(asyncClient)
.build();
// Get tool callbacks
ToolCallback[] callbacks = provider.getToolCallbacks();| Component | Purpose | Documentation |
|---|---|---|
| SyncMcpToolCallback | Wrap individual MCP tools (blocking) | Reference |
| AsyncMcpToolCallback | Wrap individual MCP tools (reactive) | Reference |
| SyncMcpToolCallbackProvider | Auto-discover tools (blocking) | Reference |
| AsyncMcpToolCallbackProvider | Auto-discover tools (reactive) | Reference |
| McpToolUtils | Utility methods for conversions | Reference |
| McpToolFilter | Filter discovered tools | Reference |
| McpToolNamePrefixGenerator | Generate unique tool names | Reference |
| ToolContextToMcpMetaConverter | Convert context to metadata | Reference |
The library provides three architectural layers:
ToolCallback instancesSee Architecture Reference for details.
// Tool callbacks
import org.springframework.ai.mcp.SyncMcpToolCallback;
import org.springframework.ai.mcp.AsyncMcpToolCallback;
// Tool providers
import org.springframework.ai.mcp.SyncMcpToolCallbackProvider;
import org.springframework.ai.mcp.AsyncMcpToolCallbackProvider;
// Utilities and strategies
import org.springframework.ai.mcp.McpToolUtils;
import org.springframework.ai.mcp.McpToolFilter;
import org.springframework.ai.mcp.McpToolNamePrefixGenerator;
import org.springframework.ai.mcp.ToolContextToMcpMetaConverter;
// MCP SDK (required dependency)
import io.modelcontextprotocol.client.McpSyncClient;
import io.modelcontextprotocol.client.McpAsyncClient;
import io.modelcontextprotocol.spec.McpSchema;SyncMcpToolCallback.builder()
.mcpClient(McpSyncClient) // required
.tool(McpSchema.Tool) // required
.prefixedToolName(String) // optional
.toolContextToMcpMetaConverter(...) // optional
.build();AsyncMcpToolCallback.builder()
.mcpClient(McpAsyncClient) // required
.tool(McpSchema.Tool) // required
.prefixedToolName(String) // optional
.toolContextToMcpMetaConverter(...) // optional
.build();SyncMcpToolCallbackProvider.builder()
.mcpClients(List<McpSyncClient>) // required
.toolFilter(McpToolFilter) // optional
.toolNamePrefixGenerator(...) // optional
.toolContextToMcpMetaConverter(...) // optional
.build();AsyncMcpToolCallbackProvider.builder()
.mcpClients(List<McpAsyncClient>) // required
.toolFilter(McpToolFilter) // optional
.toolNamePrefixGenerator(...) // optional
.toolContextToMcpMetaConverter(...) // optional
.build();| Feature | Sync | Async |
|---|---|---|
| Execution | Blocking | Non-blocking (Reactor) |
| Client Type | McpSyncClient | McpAsyncClient |
| Best For | Simple operations (< 5s) | Long operations (> 5s) |
| Concurrency | Thread-per-request | Event loop |
| Backpressure | No | Yes (Mono/Flux) |
| Thread Model | Blocking threads | Scheduler threads |
SyncMcpToolCallbackProvider provider = SyncMcpToolCallbackProvider.builder()
.mcpClients(client1, client2, client3)
.toolNamePrefixGenerator(new DefaultMcpToolNamePrefixGenerator())
.build();McpToolFilter filter = (connectionInfo, tool) ->
!tool.name().startsWith("internal_") &&
!tool.description().contains("deprecated");
provider = SyncMcpToolCallbackProvider.builder()
.mcpClients(client)
.toolFilter(filter)
.build();provider.invalidateCache(); // Force re-discovery
ToolCallback[] updated = provider.getToolCallbacks();// Automatic cache invalidation on tool changes
eventPublisher.publishEvent(
new McpToolsChangedEvent("serverName", tools)
);All tool execution errors are wrapped in ToolExecutionException:
try {
String result = callback.call(input);
} catch (ToolExecutionException e) {
ToolDefinition failedTool = e.getToolDefinition();
System.err.println("Tool failed: " + e.getMessage());
}<!-- MCP SDK (required) -->
<dependency>
<groupId>io.modelcontextprotocol</groupId>
<artifactId>mcp-client</artifactId>
<version>1.0.0</version>
</dependency>
<!-- Spring AI Core -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-core</artifactId>
<version>1.0.0</version>
</dependency>
<!-- Project Reactor (for async) -->
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</dependency>| Spring AI MCP | Spring Boot | Java | MCP SDK |
|---|---|---|---|
| 1.1.2 | 3.2+ | 17+ | 1.0+ |
| 1.1.x | 3.1+ | 17+ | 1.0+ |
| 1.0.x | 3.0+ | 17+ | 1.0+ |
spring-ai-mcp-annotations: Annotation-based MCP server creation (separate artifact)
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-mcp-annotations</artifactId>
<version>1.1.2</version>
</dependency>Install with Tessl CLI
npx tessl i tessl/maven-org-springframework-ai--spring-ai-mcp@1.1.0