跳到正文
cccskills
免费在 GitHub 公开

mcp-server

Use when exposing Spring Boot 3 application capabilities through Model Context Protocol tools, resources, or prompts. Covers Spring AI 1.x tool callback registration, transports, schemas, errors, security, and standalone MCP Java SDK compatibility.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(6)

  • SKILL.md4.9 KB
  • agents/openai.yaml186 B
  • examples/bad-order-tools.java195 B
  • examples/good-order-tools.java263 B
  • examples/OrderMcpTools.java3.5 KB
  • templates/mcp.json535 B

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

MCP Server - Spring Boot 3

Prefer the Spring AI MCP server starters in a Spring Boot application. Let the Spring AI BOM manage its MCP SDK dependency; do not force the standalone SDK version into a starter-based application.

Dependencies

<!-- 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 a raw SDK application without Spring AI, use the current MCP Java SDK 2.x release and follow its migration guide. Do not assume raw SDK examples match the version managed by Spring AI 1.x.

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

Spring AI 1.x tool callback integration

Spring AI 1.0.x exposes @Tool methods only through an explicit MethodToolCallbackProvider — a bare @Component with @Tool methods registers nothing. Spring AI 1.1.x additionally supports native @McpTool/@McpToolParam with spring.ai.mcp.server.annotation-scanner.enabled=true, imported from org.springaicommunity.mcp.annotation (Spring AI 2.0 moved them to org.springframework.ai.mcp.annotation). Pick one registration path per tool.

@Configuration
class McpToolsConfiguration {
    @Bean
    ToolCallbackProvider orderTools(OrderMcpTools tools) {
        return MethodToolCallbackProvider.builder()
            .toolObjects(tools)
            .build();
    }
}

@Component
final class OrderMcpTools {
    private final OrderService orderService;

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

    @Tool(description = "Get an order by UUID with line items and status history")
    OrderResponse getOrder(
            @ToolParam(description = "Order UUID") String orderId) {
        return OrderResponse.from(orderService.findById(UUID.fromString(orderId)));
    }
}
  • Return DTOs rather than serialized JPA entities.
  • Register each tool object once; duplicate providers create duplicate capabilities.
  • Keep tool names and descriptions stable because clients and models depend on them.
  • Bound result size, execution time, and downstream calls.
  • For raw SDK code, use builders such as CallToolResult.builder(); old 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

Use stdio when a local client launches the jar. Use the matching MVC or WebFlux starter and Streamable HTTP for a remote server when supported by the selected Spring AI 1.x release. Keep stdout clean in stdio mode because it carries JSON-RPC frames.

Security and verification

  • Authenticate and authorize remote MCP endpoints and every underlying domain operation.
  • Validate identifiers, enum values, pagination, and result limits.
  • Do not expose secrets, stack traces, persistence entities, or unrestricted administrative tools.
  • Test discovery, invalid arguments, authorization, timeouts, and shutdown with a real MCP client.
  • Review the selected Spring AI 1.x release notes before copying 2.0 annotation examples.

Examples

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

Official sources

Gotchas

  • Agent overrides the MCP SDK under Spring AI 1.x - let the Spring AI BOM manage it.
  • Agent copies Spring AI 2.0 org.springframework.ai.mcp.annotation imports into a 1.1 project - 1.1 uses org.springaicommunity.mcp.annotation, and 1.0 has no MCP annotations at all.
  • Agent expects @Tool methods on a plain @Component to appear as MCP tools in 1.x - register them through a ToolCallbackProvider bean.
  • Agent passes --spring.ai.mcp.server.transport=stdio - no such property; Boot ignores it silently. Use spring.ai.mcp.server.stdio=true.
  • Agent uses removed new CallToolResult(...) constructors in raw SDK code - use builders.
  • Agent logs to stdout in stdio mode - route logs to stderr or a file and disable the banner.
  • Agent registers the same tool object twice - keep one callback provider per capability.
  • Agent exposes entities or unbounded collections - return bounded DTO contracts.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Use when adding Spring AI-specific model observations, token usage, latency, externally configured cost attribution, advisor telemetry, or protected prompt and completion logging. Use production-observability for general service metrics, health, logs, and OTLP setup.

中文简介正在准备中。当前显示原文说明。

rrezartprebreza/spring-boot-skills3192026年10月17日 更新

Use when versioning Spring MVC or WebFlux APIs in Spring Boot 4 / Spring Framework 7. Covers built-in mapping versions, request version resolution, defaults, supported versions, and deprecation headers.

中文简介正在准备中。当前显示原文说明。

rrezartprebreza/spring-boot-skills3192026年10月17日 更新

Use when versioning Spring MVC or WebFlux APIs in Spring Boot 3 / Spring Framework 6. Covers explicit URL, header, and media-type strategies, compatibility rules, and deprecation handling.

中文简介正在准备中。当前显示原文说明。

rrezartprebreza/spring-boot-skills3192026年10月17日 更新

Use when introducing or correcting grouped Spring Boot configuration, typed property binding, validation, profiles or secret injection. Do not rewrite unrelated single-value configuration.

中文简介正在准备中。当前显示原文说明。

rrezartprebreza/spring-boot-skills3192026年10月17日 更新

Use when packaging a Spring Boot 3 application as an OCI image or GraalVM native executable. Covers buildpacks, layered images, JVM containers, AOT hints, probes, security, and verification.

中文简介正在准备中。当前显示原文说明。

rrezartprebreza/spring-boot-skills3192026年10月17日 更新

Use when packaging Spring Boot 4 as an OCI image, JVM container, AOT application, or GraalVM native executable. Covers buildpacks, layers, runtime hints, probes, security, and verification.

中文简介正在准备中。当前显示原文说明。

rrezartprebreza/spring-boot-skills3192026年10月17日 更新

查看 rrezartprebreza 的全部技能

报告此技能的问题