Spring AI MCP Server 集成指南与源码解析
Model Context Protocol (MCP) 正在成为连接大模型与外部数据的标准接口。在 Java 生态中,Spring AI 提供了便捷的 MCP Server 实现,让我们能轻松将本地服务暴露给 AI 使用。
MCP Java SDK 基础
MCP 官方提供了 Java SDK,并支持基于 Spring WebFlux 及 MVC 的 SSE 传输实现。引入依赖时,建议先管理 BOM 版本,再按需选择传输层。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.modelcontextprotocol.sdk</groupId>
<artifactId>mcp-bom</artifactId>
<version>0.8.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>io.modelcontextprotocol.sdk</groupId>
<artifactId>mcp</artifactId>
</dependency>
<!-- Spring WebFlux-based SSE client and server transport -->
<dependency>
io.modelcontextprotocol.sdk
mcp-spring-webflux
io.modelcontextprotocol.sdk
mcp-spring-webmvc


