The Spring AI MCP (Model Context Protocol) Server Boot Starter provides auto-configuration for setting up an MCP server in Spring Boot applications. It enables seamless integration of MCP server capabilities with Spring Boot’s auto-configuration system.
The MCP Server Boot Starter offers:
There has been a significant change in the Spring AI auto-configuration, starter modules' artifact names.
Please refer to the
upgrade notes
for more information.
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-server-webmvc</artifactId>
</dependency>
The starter activates the
McpWebMvcServerAutoConfiguration
and
McpServerAutoConfiguration
auto-configurations to provide:
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-server-webflux</artifactId>
</dependency>
The starter activates the
McpWebFluxServerAutoConfiguration
and
McpServerAutoConfiguration
auto-configurations to provide:
Due to Spring Boot’s default behavior, when both
org.springframework.web.servlet.DispatcherServlet
and
org.springframework.web.reactive.DispatcherHandler
are present on the classpath, Spring Boot will prioritize
DispatcherServlet
. As a result, if your project uses
spring-boot-starter-web
, it is recommended to use
spring-ai-starter-mcp-server-webmvc
instead of
spring-ai-starter-mcp-server-webflux
.
instructions
Optional instructions to provide guidance to the client on how to interact with this server
Server type (SYNC/ASYNC)
capabilities.resource
Enable/disable resource capabilities
capabilities.tool
Enable/disable tool capabilities
capabilities.prompt
Enable/disable prompt capabilities
capabilities.completion
Enable/disable completion capabilities
resource-change-notification
Enable resource change notifications
prompt-change-notification
Enable prompt change notifications
tool-change-notification
Enable tool change notifications
tool-response-mime-type
(optional) response MIME type per tool name. For example
spring.ai.mcp.server.tool-response-mime-type.generateImage=image/png
will associate the
image/png
mime type with the
generateImage()
tool name
sse-message-endpoint
Custom SSE Message endpoint path for web transport to be used by the client to send messages
/mcp/message
sse-endpoint
Custom SSE endpoint path for web transport
base-url
Optional URL prefix. For example
base-url=/api/v1
means that the client should access the sse endpoint at
/api/v1
+
sse-endpoint
and the message endpoint is
/api/v1
+
sse-message-endpoint
request-timeout
Duration to wait for server responses before timing out requests. Applies to all requests made through the client, including tool calls, resource access, and prompt operations.
20
seconds
Synchronous Server
- The default server type implemented using
McpSyncServer
.
It is designed for straightforward request-response patterns in your applications.
To enable this server type, set
spring.ai.mcp.server.type=SYNC
in your configuration.
When activated, it automatically handles the configuration of synchronous tool specifications.
Asynchronous Server
- The asynchronous server implementation uses
McpAsyncServer
and is optimized for non-blocking operations.
To enable this server type, configure your application with
spring.ai.mcp.server.type=ASYNC
.
This server type automatically sets up asynchronous tool specifications with built-in Project Reactor support.
Tools
- Enable/disable tool capabilities with
spring.ai.mcp.server.capabilities.tool=true|false
Resources
- Enable/disable resource capabilities with
spring.ai.mcp.server.capabilities.resource=true|false
Prompts
- Enable/disable prompt capabilities with
spring.ai.mcp.server.capabilities.prompt=true|false
Completions
- Enable/disable completion capabilities with
spring.ai.mcp.server.capabilities.completion=true|false
The MCP Server Boot Starter allows servers to expose tools, resources, and prompts to clients.
It automatically converts custom capability handlers registered as Spring beans to sync/async specifications based on server type:
Allows servers to expose tools that can be invoked by language models. The MCP Server Boot Starter provides:
Spring AI Tools
are automatically converted to sync/async specifications based on server type
Automatic tool specification through Spring beans:
public ToolCallbackProvider myTools(...) {
List<ToolCallback> tools = ...
return ToolCallbackProvider.from(tools);
or using the low-level API:
@Bean
public List<McpServerFeatures.SyncToolSpecification> myTools(...) {
List<McpServerFeatures.SyncToolSpecification> tools = ...
return tools;
The auto-configuration will automatically detect and register all tool callbacks from:
* Individual ToolCallback beans
* Lists of ToolCallback beans
* ToolCallbackProvider beans
Tools are de-duplicated by name, with the first occurrence of each tool name being used.
The ToolContext is supported, allowing contextual information to be passed to tool calls. It contains an McpSyncServerExchange instance under the exchange key, accessible via McpToolUtils.getMcpExchange(toolContext). See this example demonstrating exchange.loggingNotification(…) and exchange.createMessage(…).
@Bean
public List<McpServerFeatures.SyncResourceSpecification> myResources(...) {
var systemInfoResource = new McpSchema.Resource(...);
var resourceSpecification = new McpServerFeatures.SyncResourceSpecification(systemInfoResource, (exchange, request) -> {
try {
var systemInfo = Map.of(...);
String jsonContent = new ObjectMapper().writeValueAsString(systemInfo);
return new McpSchema.ReadResourceResult(
List.of(new McpSchema.TextResourceContents(request.uri(), "application/json", jsonContent)));
catch (Exception e) {
throw new RuntimeException("Failed to generate system info", e);
return List.of(resourceSpecification);
@Bean
public List<McpServerFeatures.SyncPromptSpecification> myPrompts() {
var prompt = new McpSchema.Prompt("greeting", "A friendly greeting prompt",
List.of(new McpSchema.PromptArgument("name", "The name to greet", true)));
var promptSpecification = new McpServerFeatures.SyncPromptSpecification(prompt, (exchange, getPromptRequest) -> {
String nameArgument = (String) getPromptRequest.arguments().get("name");
if (nameArgument == null) { nameArgument = "friend"; }
var userMessage = new PromptMessage(Role.USER, new TextContent("Hello " + nameArgument + "! How can I assist you today?"));
return new GetPromptResult("A personalized greeting message", List.of(userMessage));
return List.of(promptSpecification);
@Bean
public List<McpServerFeatures.SyncCompletionSpecification> myCompletions() {
var completion = new McpServerFeatures.SyncCompletionSpecification(
"code-completion",
"Provides code completion suggestions",
(exchange, request) -> {
// Implementation that returns completion suggestions
return new McpSchema.CompletionResult(List.of(
new McpSchema.Completion("suggestion1", "First suggestion"),
new McpSchema.Completion("suggestion2", "Second suggestion")
return List.of(completion);
@Bean
public BiConsumer<McpSyncServerExchange, List<McpSchema.Root>> rootsChangeHandler() {
return (exchange, roots) -> {
logger.info("Registering root resources: {}", roots);
version: 1.0.0
type: SYNC
instructions: "This server provides weather information tools and resources"
sse-message-endpoint: /mcp/messages
capabilities:
tool: true
resource: true
prompt: true
completion: true
name: webflux-mcp-server
version: 1.0.0
type: ASYNC # Recommended for reactive applications
instructions: "This reactive server provides weather information tools and resources"
sse-message-endpoint: /mcp/messages
capabilities:
tool: true
resource: true
prompt: true
completion: true
@Tool(description = "Get weather information by city name")
public String getWeather(String cityName) {
// Implementation
@SpringBootApplication
public class McpServerApplication {
private static final Logger logger = LoggerFactory.getLogger(McpServerApplication.class);
public static void main(String[] args) {
SpringApplication.run(McpServerApplication.class, args);
@Bean
public ToolCallbackProvider weatherTools(WeatherService weatherService) {
return MethodToolCallbackProvider.builder().toolObjects(weatherService).build();
The auto-configuration will automatically register the tool callbacks as MCP tools.
You can have multiple beans producing ToolCallbacks. The auto-configuration will merge them.
Apache®, Apache Tomcat®, Apache Kafka®, Apache Cassandra™, and Apache Geode™ are trademarks or registered trademarks of the Apache Software Foundation in the United States and/or other countries. Java™, Java™ SE, Java™ EE, and OpenJDK™ are trademarks of Oracle and/or its affiliates. Kubernetes® is a registered trademark of the Linux Foundation in the United States and other countries. Linux® is the registered trademark of Linus Torvalds in the United States and other countries. Windows® and Microsoft® Azure are registered trademarks of Microsoft Corporation. “AWS” and “Amazon Web Services” are trademarks or registered trademarks of Amazon.com Inc. or its affiliates. All other trademarks and copyrights are property of their respective owners and are only mentioned for informative purposes. Other names may be trademarks of their respective owners.