这是一个基于 Model Context Protocol (MCP) 的 AI 助手客户端项目。
- Python 3.12+
- macOS/Linux/Windows
git clone <your-repo-url>
cd mcp-project# 创建虚拟环境
python3 -m venv venv
# 激活虚拟环境
# macOS/Linux:
source venv/bin/activate
# Windows:
# venv\Scripts\activatepip install openai python-dotenv mcp创建 .env 文件并添加以下配置:
DASHSCOPE_API_KEY=your_api_key_here
BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
MODEL=qwen-plus# 方法1: 使用启动脚本
./run_client.sh
# 方法2: 手动运行
source venv/bin/activate
python3 client.py项目已包含 .vscode/settings.json 配置,会自动使用虚拟环境中的 Python 解释器。
如果仍然遇到导入错误:
- 按
Cmd+Shift+P(macOS) 或Ctrl+Shift+P(Windows/Linux) - 输入 "Python: Select Interpreter"
- 选择
./venv/bin/python3
- 打开项目设置 (File > Settings)
- 转到 Project > Python Interpreter
- 选择 "Add Interpreter" > "Existing Environment"
- 选择
./venv/bin/python3
mcp-project/
├── client.py # MCP 客户端主程序
├── server.py # MCP 服务器脚本
├── main.py # 主程序入口
├── pyproject.toml # 项目配置
├── requirements.txt # 依赖列表
├── .env # 环境变量配置
├── .gitignore # Git 忽略文件
├── run_client.sh # 启动脚本
├── test_imports.py # 导入测试脚本
├── venv/ # 虚拟环境目录
├── llm_outputs/ # LLM 输出文件
├── sentiment_reports/ # 情感分析报告
└── google_news/ # 新闻数据
如果遇到 "无法解析导入" 错误:
-
确保虚拟环境已激活:
source venv/bin/activate -
检查包是否已安装:
pip list | grep -E "(openai|mcp|dotenv)"
-
重新安装依赖:
pip install --force-reinstall openai python-dotenv mcp
-
运行测试脚本:
python3 test_imports.py
- 确保 IDE 使用正确的 Python 解释器
- 重启 IDE 以应用新的解释器设置
- 清除 IDE 缓存
- 启动客户端后,输入自然语言查询
- 系统会自动选择合适的工具处理您的请求
- 结果会保存到相应的输出目录
- 输入 'quit' 退出程序
MIT License