依赖
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
<version>1.1.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-server-webmvc</artifactId>
</dependency>
</dependencies>
配置
spring: ai: mcp: server: # 从默认的 SSE 切换为 STATELESS(K8s多节点首选) protocol: STATELESS name: bpp-mcp-server version: 1.0.0 # MCP 统一端点,默认是 /mcp streamable-http: mcp-endpoint: /mcp
代码
@Tool(description = "搜索商品列表") public WrapperResp<List<OpenSearchCommodityResp>> searchRecommendCommodityList( @ToolParam(description = "搜索参数") CommoditySearchReq req ) { //编写业务代码 return null; } CommoditySearchReq的请求参数示例 @ToolParam(description = "最大价格", required = false) private BigDecimal max;
调用
请求URL:domain+/mcp 请求头:Accept:application/json, text/event-stream 请求方式:POST 请求体: { "jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": { "name": "getCommodityConfig", "arguments": { "materialNumber": "PAT10000CN"//具体请求参数 } } }
浙公网安备 33010602011771号