Content
# Tool List
## Project Introduction
This project is used to learn and master the **interaction protocol process between MCP Host and MCP Server**.
Project core idea:
- `weather.py` provides an MCP Server (based on FastMCP)
- `mcp_logger.py` acts as a "transparent relay agent" inserted between the Host and the real Server
- All communication content between Host ↔ Server is recorded in the log, making it easy to learn protocol interaction details
The log records of the entire interaction process are stored in:
- `mcp_traffic.log`
> Reference example (official documentation):
> https://modelcontextprotocol.io/docs/develop/build-server
## Project Structure
```text
mcp-protocol/
├── weather.py # MCP weather server, providing weather query tools
├── mcp_logger.py # MCP communication relay and log recording agent
├── mcp_traffic.log # Communication log generated/appended after running
├── mcp_interaction_flow.md # MCP Host and Server interaction flow chart
└── requirements.txt # Dependency list
```
## Interaction Process Description
To learn the interaction process between MCP Host and MCP Server, in the MCP Server startup command, do not directly execute:
```bash
uv --directory /ABSOLUTE/PATH/TO/PARENT/FOLDER/weather run weather.py
```
Instead, modify it to go through `mcp_logger.py` first:
```bash
python3 /ABSOLUTE/PATH/TO/PARENT/FOLDER/weather/mcp_logger.py \
uv --directory /ABSOLUTE/PATH/TO/PARENT/FOLDER/weather run weather.py
```
This way, `mcp_logger.py` will be responsible for:
1. Receiving stdin messages sent by MCP Host to Server
2. Forwarding to the real MCP Server
3. Receiving stdout messages returned by Server to Host
4. Recording all messages (with timestamps) in `mcp_traffic.log`
### Overall Architecture Diagram
```mermaid
graph TD
A[MCP Host] -->|①JSON-RPC Request| B[mcp_logger.py]
B -->|②Forward Request| C[MCP Server<br/>weather.py]
C -->|③JSON-RPC Response| B
B -->|④Forward Response| A
B -->|Record Log| D[mcp_traffic.log]
```
### Interaction Flowchart
We provide a detailed interaction flowchart that shows the complete interaction process between MCP Host and MCP Server:
- [View detailed interaction flowchart](MCP_INTERACTION_FLOW.md)
The main interaction stages include:
1. **Initialization Stage**: Host and Server establish a connection, exchange protocol versions, and capability information
2. **Capability Discovery Stage**: Host obtains tools, resources, and prompts provided by Server
3. **Tool Invocation Stage**: Host invokes specific tools, and Server executes and returns results
## MCP Configuration Example
On the MCP Host side, configure as follows:
```json
{
"mcpServers": {
"weather": {
"disabled": false,
"timeout": 60,
"type": "stdio",
"command": "python3",
"args": [
"/ABSOLUTE/PATH/TO/PARENT/FOLDER/weather/mcp_logger.py",
"uv",
"--directory",
"/ABSOLUTE/PATH/TO/PARENT/FOLDER/weather",
"run",
"weather.py"
]
}
}
}
```
> Key point: Add `mcp_logger.py` before `uv run weather.py` to enable data relay and log recording.
## Dependency Installation
Project dependencies are listed in `requirements.txt`, please install them first.
### 1) Install uv
```bash
curl -LsSf https://astral.sh/uv/install.sh | sh
```
### 2) Install Python Dependencies
Choose one of the following methods:
```bash
pip install -r requirements.txt
```
or (recommended, using uv):
```bash
uv pip install -r requirements.txt
```
## Running and Learning Suggestions
1. Start the `weather` server according to the MCP configuration above.
2. Call tools like `get_alerts` and `get_forecast` in the Host.
3. Open `mcp_traffic.log` to observe the complete **JSON-RPC** round-trip process.
4. Focus on the request and response structures of initialize, tools/list, tools/call, etc.
5. Refer to the [interaction flowchart](MCP_INTERACTION_FLOW.md) to understand the complete interaction process.
Through this process, you can visually see the protocol interaction details between MCP Host and MCP Server.
### Log Analysis Example
Typical interaction patterns can be seen in `mcp_traffic.log`:
**Initialization Request**:
```json
{"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"Cline","version":"3.78.0"}},"jsonrpc":"2.0","id":0}
```
**Initialization Response**:
```json
{"jsonrpc":"2.0","id":0,"result":{"protocolVersion":"2025-11-25","capabilities": {...},"serverInfo":{"name":"weather","version":"1.27.0"}}}
```
**Tool Invocation Request**:
```json
{"method":"tools/call","params":{"name":"get_forecast","arguments":{"latitude":40.7128,"longitude":-74.006}},"jsonrpc":"2.0","id":5}
```
**Tool Invocation Response**:
```json
{"jsonrpc":"2.0","id":5,"result":{"content":[{"type":"text","text":"...weather forecast data..."}],"structuredContent":{"result":"..."},"isError":false}}
```
## Environment Requirements
- Python >= 3.8 (recommended 3.11+)
- httpx >= 0.28.1
- mcp[cli] >= 1.27.0
## License
This repository uses the MIT license, see [LICENSE](LICENSE) for details.