đ MCP Learning Project âĄ
This project is a learning project based on the MCP protocol, primarily designed to learn how to implement an MCP Server.
The api_server
directory contains a set of API service interfaces implemented using the FastAPI library, which are used to simulate the Java backend services of an existing system. In this project, only the four arithmetic operations of addition, subtraction, multiplication, and division are implemented.
The tests
directory contains a unit test program for the api_server
, which is used to familiarize with the pytest functionality.
The mcp_server
directory contains the content of the MCP server, including two implementation methods of MCP.
đ First Method: STDIO
This is mainly for local calls and local operations. The main implementation is included in the server.py
code. You can use the cline
plugin to make calls. Here is the cfg
configuration for cline
calls:
{
"mcpServers": {
"math": {
"timeout": 60,
"command": "mcp",
"args": [
"run",
"\mcp_server\server.py"
],
"transportType": "stdio",
"disabled": true
}
}
}
đ STDIO Operation Mode
# Enter the api_server directory
python main.py
# Start the API service
# After configuring the cline cfg
# Test the mcp server in cline
đ Second Method: SSE
Use uvicorn
to generate a service and configure the connection using the remote server
method of the cline
plugin. The main functionality is included in the remote_server.py
. Here is the cline
cfg
configuration:
{
"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"
}
}
}
đ SSE Operation Mode
# Enter the api_server directory
python main.py
# Start the API service
# Enter the mcp_server directory
python remote_server.py
# Start the mcp server
# After configuring the cline cfg
# Test the mcp server in cline
đ ī¸ System Architecture
The Client communicates with the MCP Server via SSE, and the MCP Server calls the API Server through HTTP RPC for calculations.
⨠Features
- Four Arithmetic Operations Toolkit: Implements basic arithmetic operations such as addition, subtraction, multiplication, and division.
- SSE-based Real-time Transmission: Supports Server-Sent Events.
- Asynchronous Support: Improves the system's response speed and processing capabilities.
- Strongly-typed Input Validation: Ensures data validity and security.
đ§ Technical Stack
- Starlette: A lightweight ASGI framework for building high-performance web applications.
- Uvicorn: A fast ASGI server that supports asynchronous processing.
- HTTPX: An asynchronous HTTP client library for sending HTTP requests.
- MCP Protocol: Implements streaming data transmission through Server-Sent Events.
đ Quick Start
pip install -r requirements.txt
Start the API service:
# Enter the api_server directory
python main.py
Start the MCP Server (depending on the chosen implementation method):
# For the stdio method
cd mcp_server
python server.py
# For the sse method
cd mcp_server
python remote_server.py
Configure and use cline
for testing.
Through this project, you can learn how to implement a distributed computing service based on the MCP protocol and master the relevant technical stack and development methods.







