本项目是一个基于MCP协议的学习项目,主要聚焦于MCP Server的实现学习。它包含API服务接口模拟、单元测试程序以及MCP Server的不同实现方式,能帮助开发者深入理解MCP协议。
pip install fastapi uvicorn pytest
cd api_server && python main.py
cd mcp_server && python remote_server.py
pip install fastapi uvicorn pytest
主要就是本地调用,本地运行的方式,主要实现包含在server.py代码中。 使用方式可以使用cline插件进行调用,下面附上cline调用的cfg配置
{
"mcpServers": {
"math": {
"timeout": 60,
"command": "mcp",
"args": [
"run",
"\mcp_server\server.py"
],
"transportType": "stdio",
"disabled": true
}
}
}
#进入api_server目录下
python main.py
#启动api 服务
#配置好cline的cfg后
#在cline中测试mcp server
使用uvicon生成一个服务,使用cline插件的remote server方式进行配置连接。 主要功能包含在remote_server.py中,下面附上cline的cfg配置
{
"mcpServers": {
"calculate": {
"autoApprove": [
"calculate_sum",
"calculate_subtract",
"calculate_multiply",
"calculate_divide"
],
"disabled": false,
"timeout": 60,
"url": "http://127.0.0.1:8001/sse",
"transportType": "sse"
}
}
}
#进入api_server目录下
python main.py
#启动api 服务
#进入mcp_server目录下
python remote_server.py
#启动mcp server
#配置好cline的cfg后
#在cline中测试mcp server
本项目是一个基于MCP协议的学习项目,主要用于学习MCP Server如何实现。 api_server目录内是一个使用FastAPI库实现的一组API服务接口,用来模拟现有系统的java后端服务,本项目内只是实现了加减乘除四则运算。 tests目录下是一个针对api_server的单元测试程序,用来熟悉pytest功能。 mcp_server目录下是MCP的server内容,包含MCP的两种实现方式。
graph LR
Client-->|SSE 流式传输| MCP_Server["MCP Server (Port 8001)"]
MCP_Server-->|HTTP RPC| API_Server["API Server (Port 8000)"]
API_Server-.->|调用函数| FUNC[(计算函数)]
subgraph 计算服务
API_Server
end