使用说明
mcp服务器客户端
基于Java的MCP(模型上下文协议)服务器和客户端实现的简单演示。服务器使用Spring Boot并公开符合MCP的端点,而客户端使用标准Java并通过Swagger支持完整的UI测试。
✨ 特性
- Spring Boot服务器:通过JSON-RPC承载MCP兼容端点
- JAVA客户端:发送A2A和MCP请求
- 邮递员测试:通过JSON-RPC内置对Postman请求的支持
- Swagger用户界面:用于测试客户端交互的完全交互式UI
🚀 快速开始
先决条件
- Java 17+
- 梅文
- 邮差(可选,用于服务器测试)
- 浏览器(用于Swagger UI测试)
克隆和构建
# Clone the repo
git clone https://github.com/BR1WA/mcp-server-client.git
cd mcp-server-client
# Build all modules
mvn clean install
运行服务器
cd server
mvn spring-boot:run
服务器运行时间: http://localhost:8877/
运行客户端
cd client
mvn spring-boot:run
Swagger用户界面可在以下网址获得: http://localhost:8086/swagger-ui/index.html
🔧 测试
✅ 通过邮递员提供服务器
服务器直接支持MCP请求。您可以使用Postman进行测试:
MCP请求示例:
POST http://localhost:8877/
Content-Type: application/json
{
"jsonrpc": "2.0",
"method": "tools/list",
"params": {},
"id": 1
}
您还可以测试其他方法,如 tools/call, initialize等等。
✅ 客户端通过Swagger UI
客户端运行后,请访问:
http://localhost:8086/swagger-ui/index.html
使用交互式页面可以:
- 发送消息
- 触发提示
- 模拟A2A或MCP消息流
📂 项目结构
mcp-server-client/
├── mcp-clit/ # Java client with Swagger UI
├── mcp-server/ # Spring Boot MCP server
├── pom.xml # Parent Maven file
└── README.md
