🧠 e2e MCP服务器
📘 目的
这个项目实现了一个小 MCP(模块化连接器协议) 公开一个名为的工具的服务器 get_docs.
🔧 这 get_docs 工具执行:
- 🔍 通过以下方式搜索文档网站 Serper
- 🌐 获取匹配的网页
- 🧹 将HTML转换并清除为文本 *(可选通过LLM)*
- 🏷️ 退货 标记的源代码片段
______________________________________________________________________
📂 感兴趣的文件
| 文件 | 描述 |
|---|---|
mcp_server.py / mcp_Server.py | MCP服务器和工具注册(重复文件--保留一个) |
client.py | 调用的stdio客户端示例 get_docs |
utils.py | 辅助功能: clean_html_to_text, get_response_from_llm |
.env | 环境变量(未提交) |
______________________________________________________________________
🧩 需求
- Python 3.10+ (该项目使用现代打字和异步功能)
- 推荐套餐:
- fastmcp - httpx - python-dotenv - trafilatura *(或类似)* - groq *(或您选择的法学硕士客户)* - uv *(可选跑步者)*
______________________________________________________________________
⚙️ 快速设置(macOS)
1.️⃣ 克隆存储库
cd /Users/haseebahmed/Desktop/LLM/e2e-mcp-server2.️⃣ 创建和激活虚拟环境
python -m venv .venv
source .venv/bin/activate3.️⃣ 再进行
如果使用pyproject.toml
pip install --upgrade pip
pip install .或者手动安装最小依赖项
pip install fastmcp httpx python-dotenv trafilatura uv添加您的LLM客户端包,例如:
pip安装groq
🔐 环境变量/API键
在项目根目录中创建.env文件(此仓库的.gitignore已将其排除在外)。
示例.env
SERPER_API_KEY=your_SERPER_API_KEY_here GROQ_API_KEY=your_GROQ_API_KEY_here#或LLM客户端密钥
备注
• 🚫 Do not commit .env or real API keys.
• 🔁 Rotate keys if they are ever leaked.
• 🧭 Adjust variable names if your LLM client uses different names.🚀 运行MCP服务器
选项A——使用Python运行
python mcpserver.py
或者(如果使用备用文件名)
python mcp_Server.py
选项B——使用紫外线运行
(适用于生成服务器的客户端示例)
确保安装了“uv”
uv运行mcpserver.py
或
uv运行mcp_Server.py
💻 运行示例客户端
启动服务器(或让客户端生成它),然后运行:
python客户端.py
示例客户端演示了: •列出工具 •通过stdio调用get_doc
🧰 故障排除和提示
• ❗ If network calls fail → wrap httpx calls in try/except and inspect errors.
• ✅ Validate Serper response shape before indexing ["organic"].
• ⚙️ Use uv only if installed; otherwise run Python directly.
• 🔁 Consider adding retry/backoff and logging for production use.⚖️ 许可证和安全 • 🔒 切勿提交API密钥或敏感凭据。 • 📄 适当遵守依赖许可条款。
