🧮 MCP SSE锈蚀计算器服务器
  
高性能 模型上下文协议(MCP) 用Rust实现的服务器,通过服务器发送事件(SSE)和JSON-RPC API提供计算器功能。
✨ 特性
- 🚀 高性能:采用Rust和Axum构建,以获得最佳性能
- 🔄 实时通信:服务器发送事件(SSE)支持
- 🧮 计算器工具:加法、乘法、平方和平方根运算
- 📡 JSON-RPC协议:符合MCP 2024-11-05规范
- 🌐 CORS已启用:跨来源资源共享支持
- 🧪 测试良好:包括全面的单元测试
- ⚡ 异步/等待:与Tokio完全异步实现
🛠️ 可用工具
| 工具 | 说明 | 参数 |
|---|---|---|
add | 将两个数字相加 | a: number, b: number |
multiply | 将两个数字相乘 | a: number, b: number |
square | 计算一个数的平方 | number: number |
sqrt | 计算一个数字的平方根 | number: number (非负) |
🚀 快速开始
先决条件
安装
- 克隆存储库
git clone https://github.com/SuyodhanJ6/mcp-sse-rust.git
cd mcp-sse-rust- 安装依赖项
cargo build- 运行服务器
cargo run服务器将于启动 http://localhost:3000 🎉
MCP与Cursor的集成
要将此服务器与Cursor IDE一起使用,请将以下内容添加到您的 ~/.cursor/mcp.json:
{
"mcpServers": {
"mcp-calculator-sse": {
"url": "http://127.0.0.1:3000/mcp",
"transport": "sse"
}
}
}添加配置后,重新启动Cursor以启用计算器工具。
发展
对于自动重新加载的开发:
cargo install cargo-watch
cargo watch -x run📖 API文档
端点
健康检查
GET /health返回服务器运行状况。
MCP端点(用于游标集成)
GET /mcp用于Cursor IDE集成的具有服务器发送事件的模型上下文协议端点。
JSON-RPC端点
POST /jsonrpc
Content-Type: application/json服务器发送的事件
GET /sse建立SSE连接以进行实时通信。
JSON-RPC方法
初始化
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {}
}列出工具
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list"
}呼叫工具
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "add",
"arguments": {
"a": 5,
"b": 3
}
}
}🧪 例子
使用curl
添加两个数字:
curl -X POST http://localhost:3000/jsonrpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "add",
"arguments": {"a": 10, "b": 5}
}
}'计算平方根:
curl -X POST http://localhost:3000/jsonrpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "sqrt",
"arguments": {"number": 16}
}
}'服务器发送的事件
连接到SSE端点:
curl -N http://localhost:3000/sse🧪 测试
运行测试套件:
cargo test使用输出运行测试:
cargo test -- --nocapture📁 项目结构
mcp-sse-rust/
├── src/
│ └── main.rs # Main server implementation
├── Cargo.toml # Dependencies and project metadata
├── Cargo.lock # Dependency lock file
├── LICENSE # MIT License
├── README.md # This file
└── .gitignore # Git ignore patterns🔧 配置
服务器在端口上运行 3000 默认情况下。您可以在 main() 功能在 src/main.rs.
🤝 贡献
欢迎投稿!请随时提交拉取请求。对于重大更改,请先打开一个问题来讨论您想要更改的内容。
- 分叉项目
- 创建功能分支(
git checkout -b feature/AmazingFeature) - 提交您的更改(
git commit -m 'Add some AmazingFeature') - 推到分支机构(
git push origin feature/AmazingFeature) - 打开拉取请求
📝 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
🙏 致谢
- 阿克苏姆 -Web应用程序框架
- 东京 -异步运行时
- Serde -序列化框架
- 模型上下文协议 -协议规范
- MCP SSE 生锈 -相关MCP服务器实现
由以下材料制成❤️ 在Rust Prashant Malge
