About MCP Server Demo 项目文档
This is a Spring Boot and Spring AI MCP server example for developers learning or building MCP services. It includes number and weather service templates and demonstrates both STDIO and SSE connection modes.
Key features
- 01Built on Spring Boot 3.4.4
- 02Check parity and detect prime numbers
- 03Includes a weather service example
- 04Supports STDIO and SSE modes
- 05Expose tools and parameters with annotations
Use cases
- 01Study a Spring AI MCP server structure
- 02Test different MCP connection modes
- 03Extend the example with new tools
MCP support
The project exposes tools and parameters through `@Tool` and `@ToolParam`, and compatible clients can connect using STDIO or SSE.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEMCP Server Demo 项目文档
项目简介
这是一个基于Spring Boot 3.4.4的MCP(Model Control Protocol)服务示例项目,集成Spring AI工具链实现智能服务功能。项目包含基础数值运算、天气查询等服务的实现模板。
核心功能
1. 数字服务(NumberService)
- 奇偶数判断
- 素数检测(已实现)
- 扩展建议:可添加质因数分解、斐波那契计算等
2. 天气服务(WeatherService)
- 天气数据接口(当前使用随机数伪代码。真实需对接第三方API实现,可参考OpenWeatherMap API)
3. MCP工具支持
- 通过
@Tool注解暴露服务为标准化工具 - 通过
@ToolParam注解定义服务参数
项目结构
src
|-- main
| |-- java
| | `-- cn
| | `-- liqingdong
| | `-- mcp
| | `-- server
| | |-- McpApplication.java
| | `-- service
| | |-- NumberService.java
| | `-- WeatherService.java
| `-- resources
| `-- application.yml
`-- test
`-- java
`-- cn
`-- liqingdong
`-- mcp
`-- server
|-- McpApplicationTest.java
`-- SSEMcpTest.java
`-- STDIOMcpTest.java
快速开始
环境要求
- JDK 17
- Maven 3.8+
- IDE(推荐IntelliJ IDEA)
运行步骤
1. 克隆仓库
git clone https://github.com/liqingdong/mcp-server-demo.git
2. 构建项目
mvn clean install
3. 使用服务
3.1 使用STDIO模式
3.1.1 配置启动命令
java -jar -Dspring.ai.mcp.server.stdio=true target/mcp-server-demo-0.0.1-SNAPSHOT.jar
3.1.2 使用支持MCP工具的客户端,例如:Cherry Studio 进行测试
3.2 使用SSE模式
3.2.1 配置启动命令(默认访问地址为:http://localhost:8081/sse)
java -jar target/mcp-server-demo-0.0.1-SNAPSHOT.jar
核心测试类
| 测试类名 | 测试内容 |
|---|---|
McpApplicationTest | 应用上下文加载验证 |
SSEMcpTest/StdioMcpTest | 不同协议的MCP服务测试 |
开发规范
- 代码风格:遵循Spring官方编码规范
- 工具注解:所有服务方法需用
@Tool标注,参数需用@ToolParam标注 - 测试覆盖率:核心功能需达到80%+单元测试覆盖
贡献指南
- Fork仓库 → 创建功能分支
- 实现新功能/修复问题
- 添加对应单元测试
- 提交Pull Request至
main分支
项目状态
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.