CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-springframework-ai--spring-ai-spring-boot-autoconfigure

Spring AI Spring Boot Auto Configuration modules providing automatic setup for AI models, vector stores, MCP, and retry capabilities

Overview
Eval results
Files

mcp-server-api.mddocs/reference/

Model Context Protocol (MCP) - Server Modules

MCP server autoconfiguration provides automatic setup for exposing Spring AI capabilities as MCP servers with support for multiple transport mechanisms and both synchronous and asynchronous operation modes.

Overview

MCP server modules enable Spring Boot applications to expose tools, prompts, and resources via the Model Context Protocol. The autoconfiguration handles server lifecycle, transport selection, and integration with Spring AI components with comprehensive annotation support and automatic registration.

Module Structure

MCP server functionality is split across three modules for flexibility:

  1. mcp-server-common: Core server configuration, tools/prompts/resources, stdio transport
  2. mcp-server-webflux: Spring WebFlux-based SSE and HTTP transports
  3. mcp-server-webmvc: Spring WebMvc-based SSE and HTTP transports (servlet)

Maven Coordinates

Common Module (Required)

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-autoconfigure-mcp-server-common</artifactId>
    <version>1.1.2</version>
</dependency>

WebFlux Transport (For Reactive Apps)

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-autoconfigure-mcp-server-webflux</artifactId>
    <version>1.1.2</version>
</dependency>

WebMvc Transport (For Servlet Apps)

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-autoconfigure-mcp-server-webmvc</artifactId>
    <version>1.1.2</version>
</dependency>

Capabilities

MCP Server AutoConfiguration

Main autoconfiguration for MCP server support.

/**
 * Autoconfigures Model Context Protocol (MCP) server support
 * 
 * Conditional Requirements:
 * - @ConditionalOnClass: io.modelcontextprotocol.spec.McpSchema
 * - @ConditionalOnProperty: spring.ai.mcp.server.enabled=true (default)
 * 
 * Configuration Properties: spring.ai.mcp.server.*
 * 
 * @AutoConfiguration
 * @ConditionalOnClass(McpSchema.class)
 * @EnableConfigurationProperties(McpServerProperties.class)
 */
@AutoConfiguration
@ConditionalOnClass(McpSchema.class)
@EnableConfigurationProperties(McpServerProperties.class)
class McpServerAutoConfiguration {
    // Bean definitions for MCP server infrastructure
}

/**
 * Stdio server transport provider
 * Only created when transport=STDIO
 * 
 * @Bean
 * @ConditionalOnProperty(prefix = "spring.ai.mcp.server", name = "transport", 
 *                        havingValue = "STDIO")
 * @return Stdio transport provider for process-based communication
 */
@Bean
@ConditionalOnProperty(prefix = "spring.ai.mcp.server", name = "transport", 
                       havingValue = "STDIO")
McpServerTransportProviderBase stdioServerTransport();

/**
 * Builder for server capabilities configuration
 * 
 * @Bean
 * @ConditionalOnMissingBean
 * @return Builder for customizing server capabilities
 */
@Bean
@ConditionalOnMissingBean
McpSchema.ServerCapabilities.Builder capabilitiesBuilder();

/**
 * Synchronous MCP server
 * Created when type=SYNC (default)
 * 
 * @Bean
 * @ConditionalOnProperty(prefix = "spring.ai.mcp.server", name = "type", 
 *                        havingValue = "SYNC", matchIfMissing = true)
 * @param transport Server transport provider (stdio, SSE, HTTP)
 * @param specFactory Factory for creating server specification from registered components
 * @param properties Server configuration properties
 * @return Configured McpSyncServer instance
 */
@Bean
@ConditionalOnProperty(prefix = "spring.ai.mcp.server", name = "type", 
                       havingValue = "SYNC", matchIfMissing = true)
McpSyncServer mcpSyncServer(
    McpServerTransportProviderBase transport,
    McpServerSpecificationFactory specFactory,
    McpServerProperties properties
);

/**
 * Asynchronous MCP server
 * Created when type=ASYNC
 * 
 * @Bean
 * @ConditionalOnProperty(prefix = "spring.ai.mcp.server", name = "type", 
 *                        havingValue = "ASYNC")
 * @param transport Server transport provider
 * @param specFactory Factory for creating server specification
 * @param properties Server configuration properties
 * @return Configured McpAsyncServer instance
 */
@Bean
@ConditionalOnProperty(prefix = "spring.ai.mcp.server", name = "type", 
                       havingValue = "ASYNC")
McpAsyncServer mcpAsyncServer(
    McpServerTransportProviderBase transport,
    McpServerSpecificationFactory specFactory,
    McpServerProperties properties
);

MCP Server ObjectMapper AutoConfiguration

Configures Jackson ObjectMapper for MCP server JSON serialization.

/**
 * Autoconfigures ObjectMapper for MCP server
 * 
 * @AutoConfiguration
 * @ConditionalOnClass(McpSchema.class)
 */
@AutoConfiguration
@ConditionalOnClass(McpSchema.class)
class McpServerObjectMapperAutoConfiguration {
    // Bean definitions for JSON serialization
}

/**
 * Configured Jackson ObjectMapper for MCP server
 * Can be overridden by providing a bean named "mcpServerObjectMapper"
 * 
 * @Bean
 * @ConditionalOnMissingBean(name = "mcpServerObjectMapper")
 * @return ObjectMapper with MCP-specific configuration
 */
@Bean
@ConditionalOnMissingBean(name = "mcpServerObjectMapper")
ObjectMapper mcpServerObjectMapper();

MCP Server Annotation Scanner

Scans for and registers MCP server tool/prompt/resource annotations.

/**
 * Scans for MCP server annotations (@McpTool, @McpPrompt, @McpResource)
 * 
 * Conditional Requirements:
 * - @ConditionalOnClass: McpTool
 * - @ConditionalOnProperty: spring.ai.mcp.server.annotation-scanner.enabled=true (default)
 * 
 * @AutoConfiguration
 * @ConditionalOnClass(McpTool.class)
 */
@AutoConfiguration
@ConditionalOnClass(McpTool.class)
class McpServerAnnotationScannerAutoConfiguration {
    // Bean definitions for annotation scanning
}

/**
 * Registry for MCP server tools
 * Collects all @McpTool annotated methods
 * 
 * @Bean
 * @return Registry for server tools
 */
@Bean
ServerMcpToolsRegistry serverMcpToolsRegistry();

/**
 * Registry for MCP server prompts
 * Collects all @McpPrompt annotated methods
 * 
 * @Bean
 * @return Registry for server prompts
 */
@Bean
ServerMcpPromptsRegistry serverMcpPromptsRegistry();

/**
 * Registry for MCP server resources
 * Collects all @McpResource annotated methods
 * 
 * @Bean
 * @return Registry for server resources
 */
@Bean
ServerMcpResourcesRegistry serverMcpResourcesRegistry();

Configuration Properties

McpServerProperties

Configuration prefix: spring.ai.mcp.server

/**
 * Properties for MCP server configuration
 * 
 * @ConfigurationProperties(prefix = "spring.ai.mcp.server")
 */
class McpServerProperties {
    /** Enable/disable the MCP server (default: true) */
    private boolean enabled = true;
    
    /** Name of the MCP server instance (default: "spring-ai-mcp-server") */
    private String name = "spring-ai-mcp-server";
    
    /** Version of the MCP server instance (default: "1.0.0") */
    private String version = "1.0.0";
    
    /** Server type: SYNC or ASYNC (default: SYNC) */
    private ServerType type = ServerType.SYNC;
    
    /** Transport type: STDIO, SSE, or STREAMABLE_HTTP (default: STDIO) */
    private TransportType transport = TransportType.STDIO;
    
    /** Change notification configuration */
    private ChangeNotification changeNotification = new ChangeNotification();
    
    enum ServerType { SYNC, ASYNC }
    enum TransportType { STDIO, SSE, STREAMABLE_HTTP }
    
    static class ChangeNotification {
        /** Master switch for change notifications (default: true) */
        private boolean enabled = true;
        
        /** Enable tool list change notifications (default: true) */
        private boolean tools = true;
        
        /** Enable prompt list change notifications (default: true) */
        private boolean prompts = true;
        
        /** Enable resource list change notifications (default: true) */
        private boolean resources = true;
    }
}

Configuration Examples

Stdio Transport Configuration

# application.properties
spring.ai.mcp.server.enabled=true
spring.ai.mcp.server.type=SYNC
spring.ai.mcp.server.transport=STDIO
spring.ai.mcp.server.name=my-mcp-server
spring.ai.mcp.server.version=1.0.0

SSE Transport Configuration (WebFlux)

# application.yml
spring:
  ai:
    mcp:
      server:
        enabled: true
        type: SYNC
        transport: SSE
        name: my-mcp-server
        sse:
          endpoint: /mcp/sse

HTTP Streaming Transport Configuration (WebMvc)

spring.ai.mcp.server.enabled=true
spring.ai.mcp.server.type=SYNC
spring.ai.mcp.server.transport=STREAMABLE_HTTP
spring.ai.mcp.server.streamable-http.endpoint=/api/mcp

Usage Examples

Defining MCP Tools

import org.springframework.ai.mcp.server.annotation.McpTool;
import org.springframework.stereotype.Component;

@Component
public class FileSystemTools {
    
    @McpTool(
        name = "read_file",
        description = "Read contents of a file"
    )
    public String readFile(String path) {
        // Read file implementation
        return Files.readString(Path.of(path));
    }
    
    @McpTool(
        name = "list_directory",
        description = "List files in a directory"
    )
    public List<String> listDirectory(String path) {
        // List directory implementation
        return Arrays.stream(new File(path).listFiles())
            .map(File::getName)
            .collect(Collectors.toList());
    }
}

Defining MCP Prompts

import org.springframework.ai.mcp.server.annotation.McpPrompt;
import org.springframework.stereotype.Component;

@Component
public class CodePrompts {
    
    @McpPrompt(
        name = "code_review",
        description = "Generate a code review prompt"
    )
    public String codeReviewPrompt(String language, String code) {
        return String.format(
            "Review this %s code:\n\n%s\n\n" +
            "Provide feedback on:\n" +
            "1. Code quality\n" +
            "2. Best practices\n" +
            "3. Potential issues",
            language, code
        );
    }
}

Defining MCP Resources

import org.springframework.ai.mcp.server.annotation.McpResource;
import org.springframework.stereotype.Component;

@Component
public class DocumentationResources {
    
    @McpResource(
        uri = "docs://api/overview",
        description = "API documentation overview"
    )
    public String getApiOverview() {
        return "API Overview: This API provides...";
    }
    
    @McpResource(
        uri = "docs://api/{endpoint}",
        description = "Documentation for specific endpoint"
    )
    public String getEndpointDocs(String endpoint) {
        return "Documentation for: " + endpoint;
    }
}

Summary

MCP server autoconfiguration provides comprehensive support for exposing Spring AI capabilities as MCP servers with:

  • Multiple transport mechanisms (stdio, SSE, HTTP)
  • Synchronous and asynchronous operation modes
  • Annotation-based tool/prompt/resource registration
  • Flexible configuration and customization
  • Production-ready error handling and monitoring

Install with Tessl CLI

npx tessl i tessl/maven-org-springframework-ai--spring-ai-spring-boot-autoconfigure@1.1.0

docs

index.md

tile.json