spring-ai 第十三mcp client 调用入门
官网
spring-ai网址【https://docs.spring.io/spring-ai/reference/api/mcp/mcp-overview.html】
两种客户端模式
基于标准
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-client</artifactId>
</dependency>
基于WebFlux
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-client-webflux</artifactId>
</dependency>
场景配置属性
spring:
application:
name: mcp-client-demo
ai:
zhipuai:
api-key: ${ZHIPUAI_API_KEY}
chat:
options:
model: glm-4-plus
mcp:
client:
#启用/禁用MCP客户端
enabled: true
# 传输协议
transport: STREAMABLE_HTTP
# 客户端类型(SYNC 或 ASYNC)。所有客户端必须是SYNC或ASYNC之一;不支持混合使用
type: SYNC
# 添加初始化超时配置
initialization-timeout: 30s
# 启用工具发现日志
request-timeout: 60s
# 连接配置
streamable-http:
connections:
# Server 端 HTTP 地址
weather-server:
url: http://localhost:8083/mcp
# server2:
# url: http://otherserver:8081
# endpoint: /custom-sse
mcp client源码示例 基于标准(mcp-client)客户端
https://gitee.com/kcnf_open/spring-ai-sample/tree/master/spring-ai/spring-ai-sample10-mcp/spring-ai-sample10-mcp-client
验证结果
- 检查
http://127.0.0.1:8082/check-tools
- 测试
http://127.0.0.1:8082/chat



