使用说明
模型上下文协议客户端
一个Spring Boot客户端应用程序,演示了与MCP服务器通信的不同传输方法(WebFlux SSE、Stdio)。
设置
- 创建一个
.env根目录中带有API密钥的文件:
BRAVE_SEARCH_API_KEY=your_brave_search_api_key_here
WEATHER_API_KEY=your_weather_api_key_here
-
克隆https://github.com/InnoBridge/ModelContextProtocolServer
-
Docker设置
- 更新docker-compose.yml中的卷映射:
modelcontextprotocolclient_application ... volumes: - .:/app - /var/run/docker.sock:/var/run/docker.sock - ./local/root:/root - ../{path to ModelContextProtocolServer repo}:/ModelContextProtocolServer- 启动Docker容器:
sudo docker compose up- 构建并运行mcp服务器:
# In a new terminal sudo docker exec -it modelcontextprotocolserver-application sh cd /app ./mvnw clean install ./mvnw spring-boot:run- 构建并运行客户端:
# In another new terminal docker exec -it modelcontextprotocolclient-application sh ./mvnw spring-boot:run
可用端点
WebFlux传输
GET /webflux/tools-列出所有可用工具POST /webflux/calculate-使用计算器工具进行计算curl -X POST "http://localhost:8080/webflux/calculate?operation=add&a=5&b=3"POST /webflux/weather-获取天气信息curl -X POST "http://localhost:8080/webflux/weather?location=San%20Francisco&format=celsius"
标准运输
GET /stdio/tools-列出所有可用工具POST /stdio/calculate-使用计算器工具进行计算curl -X POST "http://localhost:8080/stdio/calculate?operation=add&a=5&b=3"POST /stdio/weather-获取天气信息curl -X POST "http://localhost:8080/stdio/weather?location=San%20Francisco&format=celsius"
BraveSearch运输
GET /tools/bravesearch-列出可用工具POST /bravesearch-执行网络搜索curl -X POST "http://localhost:8080/bravesearch?query=spring%20boot"
配置
该应用程序支持多种传输配置:
-
WebFlux SSE传输(默认)
- 使用服务器发送事件与服务器通信
- 服务器必须在WebFlux模式下运行
-
标准运输
- 使用标准输入/输出与服务器通信
- 在stdio模式下自动启动服务器jar
-
BraveSearch运输
- 与BraveSearch API进行沟通
- 需要
BRAVE_SEARCH_API_KEY在……里面.env文件 - 从获取API密钥 勇敢搜索API
-
天气API
- WebFlux和Stdio传输都使用它来获取天气信息
- 需要
WEATHER_API_KEY在……里面.env文件 - 从获取API密钥 WeatherAPI
