Spring Boot starter providing auto-configuration for Model Context Protocol (MCP) client with Spring WebFlux, enabling reactive AI applications to connect to MCP servers via SSE and Streamable HTTP transports
Spring Boot starter providing auto-configuration for Model Context Protocol (MCP) client with Spring WebFlux, enabling reactive AI applications to connect to MCP servers.
| Component | Purpose | Documentation |
|---|---|---|
| SSE Transport | Server-Sent Events streaming | Reference |
| Streamable HTTP | Bidirectional HTTP streaming | Reference |
| Stdio Transport | Local process communication | Reference |
| MCP Clients | Direct server interaction | Reference |
| Tool Callbacks | Spring AI integration | Reference |
| Events | Server change notifications | Reference |
| Customization | Client behavior customization | Reference |
| Annotations | Declarative handlers | Reference |
| Configuration | All properties | Reference |
Maven:
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-client-webflux</artifactId>
<version>1.1.2</version>
</dependency>Gradle:
implementation 'org.springframework.ai:spring-ai-starter-mcp-client-webflux:1.1.2'SSE (Server-Sent Events): Unidirectional streaming from server to client. Ideal for push notifications and live updates.
Streamable HTTP: Bidirectional HTTP streaming. Suitable for request-response patterns with streaming.
Stdio: Local process communication via stdin/stdout. Perfect for local tools and development.
Synchronous (McpSyncClient): Blocking API for traditional code. Default type.
Asynchronous (McpAsyncClient): Reactive API using Project Reactor for high concurrency.
The starter automatically:
See Quick Start Guide for step-by-step setup.
Basic Configuration:
spring.ai.mcp.client:
sse:
connections:
my-server:
url: http://localhost:8080Inject and Use:
@Service
public class MyService {
private final List<McpSyncClient> clients;
public MyService(List<McpSyncClient> clients) {
this.clients = clients;
}
public void listTools() {
clients.forEach(client -> {
List<Tool> tools = client.listTools();
// Use tools...
});
}
}Common Settings:
spring.ai.mcp.client:
enabled: true # Enable MCP client (default: true)
type: SYNC # SYNC or ASYNC (default: SYNC)
request-timeout: 20s # Request timeout
toolcallback:
enabled: true # Spring AI integration (default: true)Transport Configuration:
Complete reference: Configuration Properties
MCP tools automatically integrate with Spring AI:
@Service
public class AiService {
private final ChatClient chatClient;
public AiService(ChatClient.Builder builder) {
this.chatClient = builder.build();
}
public String ask(String question) {
return chatClient.prompt()
.user(question)
.call()
.content();
}
}MCP tools are automatically discovered and available to the AI. See Tool Callbacks for details.
Configure multiple connections across different transport types:
spring.ai.mcp.client:
stdio:
connections:
local-server:
command: node
args: [./server.js]
sse:
connections:
remote-server:
url: http://localhost:8080
streamable-http:
connections:
api-server:
url: http://localhost:9000See MCP Clients for complete API.
React to server changes:
@Component
public class ToolListener {
@EventListener
public void onToolsChanged(McpToolsChangedEvent event) {
// Handle tool list changes
}
}See Events for details.
Customize client behavior:
@Bean
public McpSyncClientCustomizer customizer() {
return (name, spec) -> {
spec.requestTimeout(Duration.ofMinutes(2));
spec.loggingConsumer(log ->
System.out.println("[" + name + "] " + log)
);
};
}See Customization for options.
Declarative event handling:
@Component
public class McpHandlers {
@McpLogging
public void handleLogging(String connection, String level, String message) {
// Handle MCP logs
}
@McpToolListChanged
public void handleToolChange(String connection, List<Tool> tools) {
// Handle tool changes
}
}See Annotation Scanner for all annotations.
Spring Application
├─→ MCP Clients (Sync/Async)
│ ├─→ Transports (SSE/HTTP/Stdio)
│ │ └─→ MCP Servers
│ └─→ Tool Callbacks
│ └─→ Spring AI ChatClient
├─→ Event System (McpToolsChangedEvent)
└─→ Annotation Handlers (@McpLogging, etc.)spring.ai.mcp.client:
sse:
connections:
weather: {url: "http://localhost:8080"}
database: {url: "http://localhost:9000"}@Bean
public McpToolFilter toolFilter() {
return (info, tool) -> {
// Filter dangerous tools
return !tool.name().startsWith("delete_");
};
}@Bean
public McpToolNamePrefixGenerator prefixGenerator() {
return (info, tool) -> {
String server = info.initializeResult().serverInfo().name();
return server + "_" + tool.name();
};
}@Bean
public McpSyncClientCustomizer timeoutCustomizer() {
return (name, spec) -> {
Duration timeout = switch (name) {
case "slow-server" -> Duration.ofMinutes(5);
case "fast-server" -> Duration.ofSeconds(5);
default -> Duration.ofSeconds(30);
};
spec.requestTimeout(timeout);
};
}Synchronous Clients:
Asynchronous Clients:
Transport Performance:
Common Exceptions:
McpException: MCP protocol errorsTimeoutException: Request timeoutIOException: Transport errorsJsonProcessingException: JSON errorsExample:
try {
var result = client.callTool(request);
} catch (McpException e) {
log.error("MCP error: {}", e.getMessage());
} catch (TimeoutException e) {
log.error("Timeout after {}s", timeout);
}Fully supported with automatic AOT processing:
No Clients Created:
spring.ai.mcp.client.enabled=trueConnection Failures:
Tool Not Found:
client.listTools() to verify tools existPerformance Issues:
For detailed troubleshooting, see respective reference pages.
tessl i tessl/maven-org-springframework-ai--spring-ai-starter-mcp-client-webflux@1.1.0