This version is still in development and is not considered stable yet. For the latest snapshot version, please use Spring AI 1.0.1!spring-doc.cn

Stateless MCP Servers

Stateless MCP servers are designed for simplified deployments where session state is not maintained between requests. These servers are ideal for microservices architectures and cloud-native deployments.spring-doc.cn

Set the spring.ai.mcp.server.protocol=STATELESS property
Use the Streamable-HTTP clients to connect to the stateless servers.
The stateless servers don’t support message requests to the MCP client (e.g., elicitation, sampling, ping).

Stateless WebMVC Server

Use the spring-ai-starter-mcp-server-webmvc dependency:spring-doc.cn

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-starter-mcp-server-webmvc</artifactId>
</dependency>

and set the spring.ai.mcp.server.protocol property to STATLESS.spring-doc.cn

spring.ai.mcp.server.protocol=STATLESS

Stateless WebFlux Server

Use the spring-ai-starter-mcp-server-webflux dependency:spring-doc.cn

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-starter-mcp-server-webflux</artifactId>
</dependency>

and set the spring.ai.mcp.server.protocol property to STATLESS.spring-doc.cn

Configuration Properties

Common Properties

All Common properties are prefixed with spring.ai.mcp.server:spring-doc.cn

Property Description Default

enabledspring-doc.cn

Enable/disable the stateless MCP serverspring-doc.cn

truespring-doc.cn

protocolspring-doc.cn

MCP server protocolspring-doc.cn

Must be set to STATLESS to enable the stateless serverspring-doc.cn

tool-callback-converterspring-doc.cn

Enable/disable the conversion of Spring AI ToolCallbacks into MCP Tool specsspring-doc.cn

truespring-doc.cn

namespring-doc.cn

Server name for identificationspring-doc.cn

mcp-serverspring-doc.cn

versionspring-doc.cn

Server versionspring-doc.cn

1.0.0spring-doc.cn

instructionsspring-doc.cn

Optional instructions for client interactionspring-doc.cn

nullspring-doc.cn

typespring-doc.cn

Server type (SYNC/ASYNC)spring-doc.cn

SYNCspring-doc.cn

capabilities.resourcespring-doc.cn

Enable/disable resource capabilitiesspring-doc.cn

truespring-doc.cn

capabilities.toolspring-doc.cn

Enable/disable tool capabilitiesspring-doc.cn

truespring-doc.cn

capabilities.promptspring-doc.cn

Enable/disable prompt capabilitiesspring-doc.cn

truespring-doc.cn

capabilities.completionspring-doc.cn

Enable/disable completion capabilitiesspring-doc.cn

truespring-doc.cn

tool-response-mime-typespring-doc.cn

Response MIME type per tool namespring-doc.cn

-spring-doc.cn

request-timeoutspring-doc.cn

Request timeout durationspring-doc.cn

20 secondsspring-doc.cn

Stateless Connection Properties

All connection properties are prefixed with spring.ai.mcp.server.stateless:spring-doc.cn

Property Description Default

mcp-endpointspring-doc.cn

Custom MCP endpoint pathspring-doc.cn

/mcpspring-doc.cn

disallow-deletespring-doc.cn

Disallow delete operationsspring-doc.cn

falsespring-doc.cn

Features and Capabilities

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 the server type:spring-doc.cn

Tools

Allows servers to expose tools that can be invoked by language models. The MCP Server Boot Starter provides:spring-doc.cn

@Bean
public ToolCallbackProvider myTools(...) {
    List<ToolCallback> tools = ...
    return ToolCallbackProvider.from(tools);
}

or using the low-level API:spring-doc.cn

@Bean
public List<McpStatelessServerFeatures.SyncToolSpecification> myTools(...) {
    List<McpStatelessServerFeatures.SyncToolSpecification> tools = ...
    return tools;
}

The auto-configuration will automatically detect and register all tool callbacks from:spring-doc.cn

Tools are de-duplicated by name, with the first occurrence of each tool name being used.spring-doc.cn

You can disable the automatic detection and registration of all tool callbacks by setting the tool-callback-converter to false.
Tool Context Support is not applicable for stateless servers.

Resources

Provides a standardized way for servers to expose resources to clients.spring-doc.cn

@Bean
public List<McpStatelessServerFeatures.SyncResourceSpecification> myResources(...) {
    var systemInfoResource = new McpSchema.Resource(...);
    var resourceSpecification = new McpStatelessServerFeatures.SyncResourceSpecification(systemInfoResource, (context, 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);
}

Prompts

Provides a standardized way for servers to expose prompt templates to clients.spring-doc.cn

@Bean
public List<McpStatelessServerFeatures.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 McpStatelessServerFeatures.SyncPromptSpecification(prompt, (context, 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);
}

Completion

Provides a standardized way for servers to expose completion capabilities to clients.spring-doc.cn

  • Support for both sync and async completion specificationsspring-doc.cn

  • Automatic registration through Spring beans:spring-doc.cn

@Bean
public List<McpStatelessServerFeatures.SyncCompletionSpecification> myCompletions() {
    var completion = new McpStatelessServerFeatures.SyncCompletionSpecification(
        new McpSchema.PromptReference(
					"ref/prompt", "code-completion", "Provides code completion suggestions"),
        (exchange, request) -> {
            // Implementation that returns completion suggestions
            return new McpSchema.CompleteResult(List.of("python", "pytorch", "pyside"), 10, true);
        }
    );

    return List.of(completion);
}

Usage Examples

Stateless Server Configuration

spring:
  ai:
    mcp:
      server:
        protocol: STATELESS
        name: stateless-mcp-server
        version: 1.0.0
        type: ASYNC
        instructions: "This stateless server is optimized for cloud deployments"
        streamable-http:
          mcp-endpoint: /api/mcp

Creating a Spring Boot Application with MCP Server

@Service
public class WeatherService {

    @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, and the auto-configuration will merge them.spring-doc.cn