Content
[//]: # (# 模块化 MCP 客户端)
[//]: # ()
[//]: # (这是一个模块化、可扩展的 MCP (Model Control Protocol) 客户端实现,用于连接大模型 API 和多个工具服务器。)
## Structure Description:
1. **Configuration Management** (`config.py`)
- Responsible for loading and validating configurations from environment variables.
2. **MCP Server Type Connector** (`server_connector.py`)
- Responsible for connecting to and managing multiple MCP servers.
- Supports connecting to local scripts and NPX packages.
3. **Model Client** (`model_client.py`)
- Responsible for interacting with large model APIs.
- Handles streaming responses, tool calls, and result processing.
4. **Local MCP Service Storage (py)** (`mcpserver`)
- Stores local Python MCP services, which can be extended and developed.
5. **MCP Configuration Information Loader** (`mcp_config_loader.py`)
- Parses the configuration information from the `mcp_servers.json` file.
6. **MCP Configuration File** (`mcp_servers.json`)
- Configuration file with the same functionality as Cursor's MCP file.
7. **Main Application** (`main.py`)
- Integrates all the above modules.
- Provides a command-line interface and interactive chat.
[//]: # (## 特性)
[//]: # ()
[//]: # (- 支持连接多个 MCP 服务器)
[//]: # (- 模块化设计便于扩展)
[//]: # (- 统一的工具调用接口)
[//]: # (- 改进的错误处理和日志记录)
[//]: # (- 支持流式输出和推理过程显示)
## Usage
## Environment Configuration:
1. After pulling the project, navigate to the root directory:
```
# Create a virtual environment
uv venv
# Activate the virtual environment
.venv/bin/activate
# Install dependencies
uv pip install -r requirements.txt
uv add dotenv
```
2. In the root directory, copy `.env example` and rename it to `.env`, then set the necessary environment variables:
```
# apikey for 阿里百练 (Ali BaiLian)
DASHSCOPE_API_KEY=your_dashscope_api_key
# Address for 阿里百练 (Ali BaiLian)
BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
# Select the model
MODEL=xxxx
```
## Adding MCP
Unified management based on JSON files.
Copy `mcp_servers.json example` and rename it to `mcp_servers.json`.
1. If the newly added MCP service is a self-written `.py` file, refer to `weather_server.py`.
2. If it is another remote MCP, copy the corresponding MCP's JSON and add it to `mcp_servers.json` (consistent with Cursor's configuration).
```json
{
"mcpServers": {
"YourMcpName": {
"disabled": false,
"command": "xxx",
"args": ["xxx"],
"env": {}
}
}
}
```
### Running (Either 1 or 2 will work)
1. Command Line
After activating the virtual environment:
```bash
python src/main.py
```
2. PyCharm
Can also be run in PyCharm.
Connection Info
You Might Also Like
everything-claude-code
Complete Claude Code configuration collection - agents, skills, hooks,...
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
firecrawl
Firecrawl MCP Server enables web scraping, crawling, and content extraction.
servers
Model Context Protocol Servers
servers
Model Context Protocol Servers
cc-switch
All-in-One Assistant for Claude Code, Codex & Gemini CLI across platforms.