Spring Boot Skills
GitHub
AI & MCP

MCP Server

Use when exposing Spring Boot 4 application capabilities through Model Context Protocol tools, resources, or prompts. Covers Spring AI 2.0 MCP annotations, transport selection, schemas, errors, security, and the standalone MCP Java SDK 2.x.

View SKILL.md

Prefer Spring AI's MCP server starters and native annotations in Spring Boot applications. Use the standalone SDK only when Spring integration is intentionally not required.

Dependencies

Let the Spring AI BOM manage every Spring AI and MCP transitive dependency. Do not override its MCP SDK version independently.

<!-- Pick exactly one transport starter. -->
<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-starter-mcp-server</artifactId>
</dependency>
<!-- Remote MVC: spring-ai-starter-mcp-server-webmvc -->
<!-- Remote reactive: spring-ai-starter-mcp-server-webflux -->

For an application that uses the raw SDK without Spring AI, use the current 2.x release and follow its 2.0 migration guide. MCP Java SDK 2.0 tracks the 2025-11-25 protocol and prefers Streamable HTTP; SSE transports are deprecated.

<dependency>
    <groupId>io.modelcontextprotocol.sdk</groupId>
    <artifactId>mcp</artifactId>
    <version>2.0.0</version>
</dependency>

Native Spring AI MCP tools

Use @McpTool and @McpToolParam for server capabilities. @Tool is Spring AI's model tool-calling API; it is not the native MCP server annotation.

@Component
final class OrderMcpTools {
    private final OrderService orderService;

    OrderMcpTools(OrderService orderService) {
        this.orderService = orderService;
    }

    @McpTool(
        name = "get_order",
        description = "Get an order by UUID with line items and status history",
        generateOutputSchema = true,
        annotations = @McpTool.McpAnnotations(
            readOnlyHint = true,
            destructiveHint = false,
            idempotentHint = true))
    OrderResponse getOrder(
            @McpToolParam(description = "Order UUID", required = true) String orderId) {
        return OrderResponse.from(orderService.findById(UUID.fromString(orderId)));
    }
}
  • Return DTOs or records, not persistence entities.
  • Set tool hints accurately; clients must still treat them as untrusted metadata.
  • Use stable, specific descriptions because the model uses them to select tools.
  • Align return types with server mode: synchronous methods for SYNC, reactive types for ASYNC.
  • For expected failures, return a stable structured result. Do not expose stack traces or secrets.
  • Use MCP SDK builders such as CallToolResult.builder(); legacy result constructors were removed.

Transport configuration

spring:
  main:
    banner-mode: "off"
  ai:
    mcp:
      server:
        name: order-service-mcp
        version: 1.0.0
        type: SYNC
        stdio: true
        annotation-scanner:
          enabled: true

For a remote server, select the MVC or WebFlux starter and set spring.ai.mcp.server.protocol=STREAMABLE or STATELESS. Use SSE only for compatibility with an older client. A stdio server must keep stdout free of banners, logs, and System.out output because stdout carries JSON-RPC frames.

Security and operations

  • Authenticate and authorize remote MCP endpoints like any other privileged application API.
  • Validate tool arguments and apply domain authorization inside every capability.
  • Keep destructive tools narrow and require explicit business preconditions.
  • Bound execution time, result size, pagination, and downstream fan-out.
  • Log tool name, outcome, duration, and authenticated actor without recording secrets or full data.
  • Test initialization, discovery, invalid arguments, authorization, cancellation, and shutdown with a real MCP client.

Examples

  • See examples/OrderMcpTools.java, examples/good-order-tools.java, and examples/bad-order-tools.java.

Official sources

Gotchas

  • Agent uses @Tool for native server registration - use @McpTool and @McpToolParam.
  • Agent overrides the MCP SDK under a Spring AI starter - let the Spring AI BOM manage it.
  • Agent uses removed new CallToolResult(...) constructors - use CallToolResult.builder().
  • Agent configures SSE for a new remote server - prefer Streamable HTTP.
  • Agent logs to stdout in stdio mode - route logs to stderr or a file and disable the banner.
  • Agent mixes synchronous methods with an asynchronous server - the annotation scanner filters mismatched methods.
  • Agent exposes entities or unbounded collections - return bounded DTO contracts.
  • Agent trusts tool hints as authorization - enforce authorization in application code.
FROM THE REPOSITORY

Examples & templates

bad-order-tools.javaexamples
Source on GitHub
@Tool(description = "Run anything") // model tool annotation, not native MCP registration
String execute(String command) {
    System.out.println("Executing " + command); // corrupts stdio transport
    return shell.run(command);
}
good-order-tools.javaexamples
Source on GitHub
@Component
final class ReadOnlyOrderMcpTools {
    @McpTool(name = "get_order", description = "Get an order by UUID", generateOutputSchema = true)
    OrderResponse getOrder(
            @McpToolParam(description = "Order UUID", required = true) String orderId) {
        return OrderResponse.from(orderService.findById(UUID.fromString(orderId)));
    }
}
OrderMcpTools.javaexamples
Source on GitHub
package com.example.mcp;

import java.time.Instant;
import java.util.List;
import java.util.UUID;

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

@Component
public final class OrderMcpTools {

    private final OrderService orderService;

    public OrderMcpTools(OrderService orderService) {
        this.orderService = orderService;
    }

    @McpTool(
        name = "get_order",
        description = "Get an order by UUID with line items, status, and creation time",
        generateOutputSchema = true,
        annotations = @McpTool.McpAnnotations(
            readOnlyHint = true,
            destructiveHint = false,
            idempotentHint = true))
    public OrderResponse getOrder(
            @McpToolParam(description = "Order UUID", required = true) String orderId) {
        return OrderResponse.from(orderService.findById(UUID.fromString(orderId)));
    }
}

interface OrderService {
    Order findById(UUID id);
}

record Order(UUID id, String status, List<String> lineItems, Instant createdAt) { }

record OrderResponse(UUID id, String status, List<String> lineItems, Instant createdAt) {
    static OrderResponse from(Order order) {
        return new OrderResponse(order.id(), order.status(), List.copyOf(order.lineItems()), order.createdAt());
    }
}
mcp.jsontemplates
Source on GitHub
{
  "mcpServers": {
    "order-service": {
      "command": "java",
      "args": [
        "-jar",
        "/path/to/your/order-service.jar",
        "--spring.profiles.active=mcp",
        "--spring.ai.mcp.server.stdio=true"
      ],
      "env": {
        "SPRING_DATASOURCE_URL": "jdbc:postgresql://localhost:5432/orders",
        "SPRING_DATASOURCE_USERNAME": "postgres",
        "SPRING_DATASOURCE_PASSWORD": "your-password",
        "ANTHROPIC_API_KEY": "sk-ant-..."
      }
    }
  }
}

Verification scope

Compiled sources
Boot 4 OrderMcpTools
Runtime checks
Compilation only; no protocol session tests

Coverage describes checked-in fixtures, not a guarantee for every snippet or project.

Coverage matrix & agent evidence
ADD TO YOUR AGENT

Install Boot 4 skills

claude plugin marketplace add rrezartprebreza/spring-boot-skills
claude plugin install spring-boot-4-skills@spring-boot-skills