Spring Boot Starter for building Model Context Protocol (MCP) servers with auto-configuration, annotation-based tool/resource/prompt definitions, and support for STDIO, SSE, and Streamable-HTTP transports
The Spring AI MCP Server Starter provides a comprehensive framework for building Model Context Protocol servers with Spring Boot. Understanding its architecture helps developers leverage the framework effectively.
The starter provides extensive auto-configuration that automatically sets up MCP server components based on classpath and configuration:
Multiple transport mechanisms are supported with dedicated auto-configurations:
STDIO Transport
spring.ai.mcp.server.stdio=trueSSE (Server-Sent Events) Transport
McpServerSseWebFluxAutoConfiguration, McpServerSseWebMvcAutoConfigurationStreamable HTTP Transport
McpServerStreamableHttpWebFluxAutoConfiguration, McpServerStreamableHttpWebMvcAutoConfigurationStateless Transport
McpServerStatelessAutoConfigurationThe framework uses a specification-based architecture where capabilities are defined as specifications before registration:
Server-side Specifications (for exposing functionality):
SyncToolSpecification / AsyncToolSpecification - Tool implementationsSyncResourceSpecification / AsyncResourceSpecification - Resource providersSyncResourceTemplateSpecification / AsyncResourceTemplateSpecification - Resource templates with URI placeholdersSyncPromptSpecification / AsyncPromptSpecification - Prompt generatorsSyncCompletionSpecification / AsyncCompletionSpecification - Auto-completion providersStateless Variants:
StatelessSyncToolSpecification / StatelessAsyncToolSpecificationStatelessSyncResourceSpecification / StatelessAsyncResourceSpecificationStatelessSyncPromptSpecification / StatelessAsyncPromptSpecificationThe annotation scanner discovers and converts annotated methods to specifications:
Process Flow:
Providers:
SyncMcpAnnotationProviders - Creates sync specifications from annotationsAsyncMcpAnnotationProviders - Creates async specifications from annotationsRequest contexts provide access to MCP features during execution:
Context Hierarchy:
McpTransportContext (lightweight, stateless-compatible)
├── McpSyncRequestContext (full sync context)
└── McpAsyncRequestContext (full async context)Context Features:
McpSyncServerExchange, McpAsyncServerExchange)Bridges Spring AI's ToolCallback interface with MCP:
Client-side (consuming remote MCP servers):
SyncMcpToolCallback / AsyncMcpToolCallback - Wrap remote MCP tools as Spring AI ToolCallbacksSyncMcpToolCallbackProvider / AsyncMcpToolCallbackProvider - Discover and provide tools from multiple serversServer-side (exposing tools via MCP):
spring.ai.mcp.server.tool-callback-converterClient Customizers:
McpSyncClientCustomizer - Customize synchronous client connectionsMcpAsyncClientCustomizer - Customize asynchronous client connectionsStrategy Interfaces:
McpToolFilter - Filter discovered toolsMcpToolNamePrefixGenerator - Generate unique tool namesToolContextToMcpMetaConverter - Convert Spring AI context to MCP metadataUtilities:
McpToolUtils - Helper methods for tool operationsSyncMcpAnnotationProviders / AsyncMcpAnnotationProviders - Manual annotation processingDefaultMcpToolNamePrefixGenerator - Default naming strategy with conflict resolutionspring.ai.mcp.server.type=SYNC (default)Mono<T>, Flux<T>, or any synchronous type (auto-wrapped)spring.ai.mcp.server.type=ASYNCCapabilities:
Context Types:
McpSyncRequestContext / McpAsyncRequestContextCapabilities:
Context Types:
McpTransportContext onlyLimitations:
The framework supports dynamic capability changes:
Server-to-Client Notifications:
spring.ai.mcp.server.tool-change-notification)spring.ai.mcp.server.resource-change-notification)spring.ai.mcp.server.prompt-change-notification)Event System:
McpToolsChangedEvent - Published when tools change on a connectionApplicationListener integration for automatic cache invalidationToolCallbackProvider implementations automatically respond to eventsCapabilities can be selectively enabled/disabled:
spring.ai.mcp.server.capabilities.tool=true # Tool calling
spring.ai.mcp.server.capabilities.resource=true # Resource access
spring.ai.mcp.server.capabilities.prompt=true # Prompt templates
spring.ai.mcp.server.capabilities.completion=true # Auto-completionThis allows servers to expose only required capabilities, reducing attack surface and simplifying deployment.
All components are Spring-managed beans:
@Component beans@Autowired, etc.)Externalized configuration using Spring Boot's property system:
application.properties, application.yml)@ConfigurationProperties binding with validationConditional auto-configuration based on:
spring.ai.mcp.server.enabled)CallToolRequestMcpSyncRequestContext, etc.)CallToolResultMcpToolFilter applies filtering rulesMcpToolNamePrefixGenerator creates unique namesSyncMcpToolCallback or AsyncMcpToolCallbackMcpToolCallbackProviderMcpToolsChangedEvent triggers cache invalidationGraalVM native image support via:
McpHints - Runtime hints for reflection