Class MpcServerAutoConfiguration

java.lang.Object
org.springframework.ai.autoconfigure.mcp.server.MpcServerAutoConfiguration

@AutoConfiguration @ConditionalOnClass({io.modelcontextprotocol.spec.McpSchema.class,io.modelcontextprotocol.server.McpSyncServer.class}) @EnableConfigurationProperties(McpServerProperties.class) @ConditionalOnProperty(prefix="spring.ai.mcp.server", name="enabled", havingValue="true") public class MpcServerAutoConfiguration extends Object
Auto-configuration for the Model Context Protocol (MCP) Server.

This configuration class sets up the core MCP server components with support for both synchronous and asynchronous operation modes. The server type is controlled through the spring.ai.mcp.server.type property, defaulting to SYNC mode.

Core features and capabilities include:

  • Tools: Extensible tool registration system supporting both sync and async execution
  • Resources: Static and dynamic resource management with optional change notifications
  • Prompts: Configurable prompt templates with change notification support
  • Transport: Flexible transport layer with built-in support for:
    • STDIO (default): Standard input/output based communication
    • WebMvc: HTTP-based transport when Spring MVC is available
    • WebFlux: Reactive transport when Spring WebFlux is available

The configuration is activated when:

  • The required MCP classes (McpSchema and McpSyncServer) are on the classpath
  • The spring.ai.mcp.server.enabled property is true (default)

Server configuration is managed through McpServerProperties with support for:

  • Server identification (name, version)
  • Transport selection
  • Change notification settings for tools, resources, and prompts
  • Sync/Async operation mode selection

WebMvc transport support is provided separately by MpcWebMvcServerAutoConfiguration.

Since:
1.0.0
Author:
Christian Tzolov
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    List<io.modelcontextprotocol.server.McpServerFeatures.AsyncToolRegistration>
     
    io.modelcontextprotocol.spec.McpSchema.ServerCapabilities.Builder
     
    io.modelcontextprotocol.server.McpAsyncServer
    mcpAsyncServer(io.modelcontextprotocol.spec.ServerMcpTransport transport, io.modelcontextprotocol.spec.McpSchema.ServerCapabilities.Builder capabilitiesBuilder, McpServerProperties serverProperties, org.springframework.beans.factory.ObjectProvider<List<io.modelcontextprotocol.server.McpServerFeatures.AsyncToolRegistration>> tools, org.springframework.beans.factory.ObjectProvider<List<io.modelcontextprotocol.server.McpServerFeatures.AsyncResourceRegistration>> resources, org.springframework.beans.factory.ObjectProvider<List<io.modelcontextprotocol.server.McpServerFeatures.AsyncPromptRegistration>> prompts, org.springframework.beans.factory.ObjectProvider<Consumer<List<io.modelcontextprotocol.spec.McpSchema.Root>>> rootsChangeConsumer)
     
    io.modelcontextprotocol.server.McpSyncServer
    mcpSyncServer(io.modelcontextprotocol.spec.ServerMcpTransport transport, io.modelcontextprotocol.spec.McpSchema.ServerCapabilities.Builder capabilitiesBuilder, McpServerProperties serverProperties, org.springframework.beans.factory.ObjectProvider<List<io.modelcontextprotocol.server.McpServerFeatures.SyncToolRegistration>> tools, org.springframework.beans.factory.ObjectProvider<List<io.modelcontextprotocol.server.McpServerFeatures.SyncResourceRegistration>> resources, org.springframework.beans.factory.ObjectProvider<List<io.modelcontextprotocol.server.McpServerFeatures.SyncPromptRegistration>> prompts, org.springframework.beans.factory.ObjectProvider<Consumer<List<io.modelcontextprotocol.spec.McpSchema.Root>>> rootsChangeConsumers)
     
    io.modelcontextprotocol.spec.ServerMcpTransport
     
    List<io.modelcontextprotocol.server.McpServerFeatures.SyncToolRegistration>
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MpcServerAutoConfiguration

      public MpcServerAutoConfiguration()
  • Method Details

    • stdioServerTransport

      @Bean @ConditionalOnMissingBean @ConditionalOnProperty(prefix="spring.ai.mcp.server", name="transport", havingValue="STDIO", matchIfMissing=true) public io.modelcontextprotocol.spec.ServerMcpTransport stdioServerTransport()
    • capabilitiesBuilder

      @Bean @ConditionalOnMissingBean public io.modelcontextprotocol.spec.McpSchema.ServerCapabilities.Builder capabilitiesBuilder()
    • syncTools

      @Bean @ConditionalOnProperty(prefix="spring.ai.mcp.server", name="type", havingValue="SYNC", matchIfMissing=true) public List<io.modelcontextprotocol.server.McpServerFeatures.SyncToolRegistration> syncTools(List<ToolCallback> toolCalls)
    • mcpSyncServer

      @Bean @ConditionalOnProperty(prefix="spring.ai.mcp.server", name="type", havingValue="SYNC", matchIfMissing=true) public io.modelcontextprotocol.server.McpSyncServer mcpSyncServer(io.modelcontextprotocol.spec.ServerMcpTransport transport, io.modelcontextprotocol.spec.McpSchema.ServerCapabilities.Builder capabilitiesBuilder, McpServerProperties serverProperties, org.springframework.beans.factory.ObjectProvider<List<io.modelcontextprotocol.server.McpServerFeatures.SyncToolRegistration>> tools, org.springframework.beans.factory.ObjectProvider<List<io.modelcontextprotocol.server.McpServerFeatures.SyncResourceRegistration>> resources, org.springframework.beans.factory.ObjectProvider<List<io.modelcontextprotocol.server.McpServerFeatures.SyncPromptRegistration>> prompts, org.springframework.beans.factory.ObjectProvider<Consumer<List<io.modelcontextprotocol.spec.McpSchema.Root>>> rootsChangeConsumers)
    • asyncTools

      @Bean @ConditionalOnProperty(prefix="spring.ai.mcp.server", name="type", havingValue="ASYNC") public List<io.modelcontextprotocol.server.McpServerFeatures.AsyncToolRegistration> asyncTools(List<ToolCallback> toolCalls)
    • mcpAsyncServer

      @Bean @ConditionalOnProperty(prefix="spring.ai.mcp.server", name="type", havingValue="ASYNC") public io.modelcontextprotocol.server.McpAsyncServer mcpAsyncServer(io.modelcontextprotocol.spec.ServerMcpTransport transport, io.modelcontextprotocol.spec.McpSchema.ServerCapabilities.Builder capabilitiesBuilder, McpServerProperties serverProperties, org.springframework.beans.factory.ObjectProvider<List<io.modelcontextprotocol.server.McpServerFeatures.AsyncToolRegistration>> tools, org.springframework.beans.factory.ObjectProvider<List<io.modelcontextprotocol.server.McpServerFeatures.AsyncResourceRegistration>> resources, org.springframework.beans.factory.ObjectProvider<List<io.modelcontextprotocol.server.McpServerFeatures.AsyncPromptRegistration>> prompts, org.springframework.beans.factory.ObjectProvider<Consumer<List<io.modelcontextprotocol.spec.McpSchema.Root>>> rootsChangeConsumer)