🏓 MCP乒乓服务器远程调用
一个实验性和教育性的乒乓球服务器,通过FastAPI演示MCP(模型上下文协议)调用。
特性
- ✅ 通过API端点或SSE进行远程MCP调用的FastAPI/FastMCP后端
- 🔄 MCP集成用于指挥处理
- 🔐 线程安全会话管理
快速开始
安装
要安装依赖项,请运行:
poetry install1.通过API调用MCP工具
运行服务器
使用以下命令启动FastAPI服务器:
python mcp-api-server.py服务器将在以下时间启动 http://localhost:8080.
用户界面
打开 mcp-api-client.html 在浏览器中与UI交互。
API终点
- `GET /ping-pong?prompt_name=
`:检索指定的提示。
POST /ping-pong:调用MCP工具命令(ping,pong,count).
2.通过SSE传输调用MCP工具
以下示例演示了如何使用服务器发送事件(SSE)与MCP服务器进行通信。
运行SSE服务器
python mcp-sse-server.py运行SSE客户端
python mcp-sse-client.py样本输出
Type a command (e.g., 'ping', 'pong', 'count') or 'exit' to quit:
>>> ping
Sending command: ping
Result: pong
>>> pong
Sending command: pong
Result: ping
>>> count
Sending command: count
Result: 2参考文献
📄 许可证
麻省理工学院

