MCP Server Boot Starter :: Spring AI Reference (original) (raw)

Model Context Protocol (MCP) Servers are programs that expose specific capabilities to AI applications through standardized protocol interfaces. Each server provides focused functionality for a particular domain.

The Spring AI MCP Server Boot Starters provide auto-configuration for setting up MCP Servers in Spring Boot applications. They enable seamless integration of MCP server capabilities with Spring Boot’s auto-configuration system.

The MCP Server Boot Starters offer:

MCP Server Boot Starters

MCP Servers support multiple protocol and transport mechanisms. Use the dedicated starter and the correct spring.ai.mcp.server.protocol property to configure your server:

WebMVC

Server Type Dependency Property
SSE WebMVC spring-ai-starter-mcp-server-webmvc spring.ai.mcp.server.protocol=SSE or empty
Streamable-HTTP WebMVC spring-ai-starter-mcp-server-webmvc spring.ai.mcp.server.protocol=STREAMABLE
Stateless WebMVC spring-ai-starter-mcp-server-webmvc spring.ai.mcp.server.protocol=STATELESS

WebMVC (Reactive)

Server Type Dependency Property
SSE WebFlux spring-ai-starter-mcp-server-webflux spring.ai.mcp.server.protocol=SSE or empty
Streamable-HTTP WebFlux spring-ai-starter-mcp-server-webflux spring.ai.mcp.server.protocol=STREAMABLE
Stateless WebFlux spring-ai-starter-mcp-server-webflux spring.ai.mcp.server.protocol=STATELESS

Server Capabilities

Depending on the server and transport types, MCP Servers can support various capabilities, such as:

All capabilities are enabled by default. Disabling a capability will prevent the server from registering and exposing the corresponding features to clients.

Server Protocols

MCP provides several protocol types including:

Sync/Async Server API Options

The MCP Server API supports imperative (i.e. synchronous) and reactive (e.g. asynchronous) programming models.

NOTE: The SYNC server will register only synchronous MCP annotated methods. Asynchronous methods will be ignored.

NOTE: The ASYNC server will register only asynchronous MCP annotated methods. Synchronous methods will be ignored.

MCP Server Annotations

The MCP Server Boot Starters provide comprehensive support for annotation-based server development, allowing you to create MCP servers using declarative Java annotations instead of manual configuration.

Key Annotations

Special Parameters

Simple Example

@Component
public class CalculatorTools {

    @McpTool(name = "add", description = "Add two numbers together")
    public int add(
            @McpToolParam(description = "First number", required = true) int a,
            @McpToolParam(description = "Second number", required = true) int b) {
        return a + b;
    }

    @McpResource(uri = "config://{key}", name = "Configuration")
    public String getConfig(String key) {
        return configData.get(key);
    }
}

Auto-Configuration

With Spring Boot auto-configuration, annotated beans are automatically detected and registered:

@SpringBootApplication
public class McpServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(McpServerApplication.class, args);
    }
}

The auto-configuration will:

  1. Scan for beans with MCP annotations
  2. Create appropriate specifications
  3. Register them with the MCP server
  4. Handle both sync and async implementations based on configuration

Configuration Properties

Configure the server annotation scanner:

spring:
  ai:
    mcp:
      server:
        type: SYNC  # or ASYNC
        annotation-scanner:
          enabled: true

Example Applications

Additional Resources