Class McpServerModernAutoConfiguration

java.lang.Object
org.springframework.ai.mcp.server.common.autoconfigure.McpServerModernAutoConfiguration

@AutoConfiguration(after=McpServerJsonMapperAutoConfiguration.class) @ConditionalOnClass(io.modelcontextprotocol.modern.server.McpServer.class) @EnableConfigurationProperties({McpServerProperties.class,McpServerModernProperties.class}) @Conditional(EnabledModernServerCondition.class) public class McpServerModernAutoConfiguration extends Object
Auto-configuration for a 2026-07-28 ("modern") MCP server, active when spring.ai.mcp.server.protocol=MODERN.

Each primitive is served by a repository bean: McpSyncToolRepository, McpSyncResourceRepository and McpSyncPromptRepository, or their McpAsync*Repository twins. A user-defined repository bean of either flavour takes precedence; otherwise an in-memory repository is created and fed by every List<McpSyncTool>, List<SyncResourceRegistration>, List<SyncResourceTemplateRegistration> and List<McpSyncPrompt> bean (or, for spring.ai.mcp.server.type=ASYNC, the McpAsync* and Async*Registration lists), which is how annotated beans and ToolCallbacks reach the server. Completions travel with their prompt or resource template, so the prompt and resource repositories serve them too; spring.ai.mcp.server.capabilities.completion=false turns them off. The in-memory repositories are beans themselves, so tools can be added or removed at runtime; changes are broadcast to subscriptions/listen clients through the McpChangeFeed bean. An application that wants to filter or decorate a repository per request defines its own repository bean, typically one that builds the in-memory repository from the same list beans and wraps it.

The type property only picks the in-memory defaults and the annotation providers: the server accepts a repository bean of either flavour for each primitive, and fails at startup when both are defined for the same one.

Since:
2.1.0
Author:
Christian Tzolov
  • Constructor Details

    • McpServerModernAutoConfiguration

      public McpServerModernAutoConfiguration()
  • Method Details

    • mcpChangeFeed

      @Bean @ConditionalOnMissingBean public io.modelcontextprotocol.modern.server.feature.McpChangeFeed mcpChangeFeed()
    • mcpModernToolRepository

      @Bean @ConditionalOnMissingBean({io.modelcontextprotocol.modern.server.feature.McpSyncToolRepository.class,io.modelcontextprotocol.modern.server.feature.McpAsyncToolRepository.class}) @ConditionalOnProperty(prefix="spring.ai.mcp.server",name="type",havingValue="SYNC",matchIfMissing=true) @ConditionalOnProperty(prefix="spring.ai.mcp.server",name="capabilities.tool",havingValue="true",matchIfMissing=true) public InMemorySyncToolRepository mcpModernToolRepository(org.springframework.beans.factory.ObjectProvider<List<io.modelcontextprotocol.modern.server.feature.McpSyncTool>> tools, io.modelcontextprotocol.modern.server.feature.McpChangeFeed changeFeed, McpServerModernProperties modernProperties)
    • mcpModernResourceRepository

      @Bean @ConditionalOnMissingBean({io.modelcontextprotocol.modern.server.feature.McpSyncResourceRepository.class,io.modelcontextprotocol.modern.server.feature.McpAsyncResourceRepository.class}) @ConditionalOnProperty(prefix="spring.ai.mcp.server",name="type",havingValue="SYNC",matchIfMissing=true) @ConditionalOnProperty(prefix="spring.ai.mcp.server",name="capabilities.resource",havingValue="true",matchIfMissing=true) public InMemorySyncResourceRepository mcpModernResourceRepository(org.springframework.beans.factory.ObjectProvider<List<SyncResourceRegistration>> resources, org.springframework.beans.factory.ObjectProvider<List<SyncResourceTemplateRegistration>> resourceTemplates, io.modelcontextprotocol.modern.server.feature.McpChangeFeed changeFeed, McpServerProperties serverProperties, McpServerModernProperties modernProperties)
    • mcpModernPromptRepository

      @Bean @ConditionalOnMissingBean({io.modelcontextprotocol.modern.server.feature.McpSyncPromptRepository.class,io.modelcontextprotocol.modern.server.feature.McpAsyncPromptRepository.class}) @ConditionalOnProperty(prefix="spring.ai.mcp.server",name="type",havingValue="SYNC",matchIfMissing=true) @ConditionalOnProperty(prefix="spring.ai.mcp.server",name="capabilities.prompt",havingValue="true",matchIfMissing=true) public InMemorySyncPromptRepository mcpModernPromptRepository(org.springframework.beans.factory.ObjectProvider<List<io.modelcontextprotocol.modern.server.feature.McpSyncPrompt>> prompts, io.modelcontextprotocol.modern.server.feature.McpChangeFeed changeFeed, McpServerProperties serverProperties, McpServerModernProperties modernProperties)
    • mcpModernAsyncToolRepository

      @Bean @ConditionalOnMissingBean({io.modelcontextprotocol.modern.server.feature.McpSyncToolRepository.class,io.modelcontextprotocol.modern.server.feature.McpAsyncToolRepository.class}) @ConditionalOnProperty(prefix="spring.ai.mcp.server",name="type",havingValue="ASYNC") @ConditionalOnProperty(prefix="spring.ai.mcp.server",name="capabilities.tool",havingValue="true",matchIfMissing=true) public InMemoryAsyncToolRepository mcpModernAsyncToolRepository(org.springframework.beans.factory.ObjectProvider<List<io.modelcontextprotocol.modern.server.feature.McpAsyncTool>> tools, io.modelcontextprotocol.modern.server.feature.McpChangeFeed changeFeed, McpServerModernProperties modernProperties)
    • mcpModernAsyncResourceRepository

      @Bean @ConditionalOnMissingBean({io.modelcontextprotocol.modern.server.feature.McpSyncResourceRepository.class,io.modelcontextprotocol.modern.server.feature.McpAsyncResourceRepository.class}) @ConditionalOnProperty(prefix="spring.ai.mcp.server",name="type",havingValue="ASYNC") @ConditionalOnProperty(prefix="spring.ai.mcp.server",name="capabilities.resource",havingValue="true",matchIfMissing=true) public InMemoryAsyncResourceRepository mcpModernAsyncResourceRepository(org.springframework.beans.factory.ObjectProvider<List<AsyncResourceRegistration>> resources, org.springframework.beans.factory.ObjectProvider<List<AsyncResourceTemplateRegistration>> resourceTemplates, io.modelcontextprotocol.modern.server.feature.McpChangeFeed changeFeed, McpServerProperties serverProperties, McpServerModernProperties modernProperties)
    • mcpModernAsyncPromptRepository

      @Bean @ConditionalOnMissingBean({io.modelcontextprotocol.modern.server.feature.McpSyncPromptRepository.class,io.modelcontextprotocol.modern.server.feature.McpAsyncPromptRepository.class}) @ConditionalOnProperty(prefix="spring.ai.mcp.server",name="type",havingValue="ASYNC") @ConditionalOnProperty(prefix="spring.ai.mcp.server",name="capabilities.prompt",havingValue="true",matchIfMissing=true) public InMemoryAsyncPromptRepository mcpModernAsyncPromptRepository(org.springframework.beans.factory.ObjectProvider<List<io.modelcontextprotocol.modern.server.feature.McpAsyncPrompt>> prompts, io.modelcontextprotocol.modern.server.feature.McpChangeFeed changeFeed, McpServerProperties serverProperties, McpServerModernProperties modernProperties)
    • mcpModernServer

      @Bean @ConditionalOnMissingBean public io.modelcontextprotocol.modern.server.McpServer mcpModernServer(@Qualifier("mcpServerJsonMapper") tools.jackson.databind.json.JsonMapper jsonMapper, McpServerProperties serverProperties, McpServerModernProperties modernProperties, org.springframework.beans.factory.ObjectProvider<io.modelcontextprotocol.modern.server.feature.McpSyncToolRepository> toolRepository, org.springframework.beans.factory.ObjectProvider<io.modelcontextprotocol.modern.server.feature.McpAsyncToolRepository> asyncToolRepository, org.springframework.beans.factory.ObjectProvider<io.modelcontextprotocol.modern.server.feature.McpSyncResourceRepository> resourceRepository, org.springframework.beans.factory.ObjectProvider<io.modelcontextprotocol.modern.server.feature.McpAsyncResourceRepository> asyncResourceRepository, org.springframework.beans.factory.ObjectProvider<io.modelcontextprotocol.modern.server.feature.McpSyncPromptRepository> promptRepository, org.springframework.beans.factory.ObjectProvider<io.modelcontextprotocol.modern.server.feature.McpAsyncPromptRepository> asyncPromptRepository, io.modelcontextprotocol.modern.server.feature.McpChangeFeed changeFeed, org.springframework.beans.factory.ObjectProvider<io.modelcontextprotocol.modern.server.RequestStateCodec> requestStateCodec, org.springframework.beans.factory.ObjectProvider<McpServerCustomizer<io.modelcontextprotocol.modern.server.McpServer.Builder>> customizers, org.springframework.beans.factory.ListableBeanFactory beanFactory)
    • mcpModernStdioTransport

      @Bean @ConditionalOnMissingBean @ConditionalOnProperty(prefix="spring.ai.mcp.server", name="stdio", havingValue="true") public io.modelcontextprotocol.modern.server.transport.StdioMcpTransport mcpModernStdioTransport(io.modelcontextprotocol.modern.server.McpServer mcpServer, @Qualifier("mcpServerJsonMapper") tools.jackson.databind.json.JsonMapper jsonMapper)
    • mcpModernStdioTransportLifecycle

      @Bean @ConditionalOnProperty(prefix="spring.ai.mcp.server", name="stdio", havingValue="true") public McpServerModernAutoConfiguration.StdioMcpTransportLifecycle mcpModernStdioTransportLifecycle(io.modelcontextprotocol.modern.server.transport.StdioMcpTransport stdioTransport)