使用说明
MCP服务器POC-代理工具网关
(模拟)模型上下文协议服务器的生产就绪实现。此项目模拟了一个代理工具网关,该网关向LLM代理公开标准化工具,包括验证、日志记录、重试和评估工具。
特性
- 工具网关:公开使用Pydantic模式构建的工具。
- Agent模拟:模拟LLM编排(可扩展到真正的OpenAI)。
- 内置电池:3个已实现的工具(票证搜索、知识库查找、安全数据库查询)。
- 安全:防止数据库查询的SQL注入。
- 可观测性:结构化日志记录和延迟跟踪。
- 鲁棒性:用于不稳定外部服务的检索(在KB查找中模拟)。
- 评估:内置回归测试工具。
快速开始
1.本地设置
需要Python 3.11+
# Clone and install dependencies
pip install .
# OR use existing requirements
pip install fastapi uvicorn pydantic-settings httpx tenacity loguru aiosqlite
# Set up environment
cp .env.example .env
# Run server
uvicorn app.main:app --reload
服务器将在以下时间运行 http://localhost:8000.
文件可在 http://localhost:8000/docs.
2.Docker设置
docker-compose up --build
工具
| 工具名称 | 描述 | 输入 |
|---|---|---|
ticket_search |
按关键字搜索门票 | {"query": "string"} |
kb_lookup |
在知识库中查找主题 | {"topic": "string"} |
db_query |
运行安全SQL(仅限SELECT) | {"sql": "string"} |
运行测试
# Unit & Integration Tests
pytest
# Evaluation Harness (requires server running)
# Start server first in one terminal: uvicorn app.main:app
python evals/run_evals.py
项目结构
app/:核心应用程序代码。data/:SQLite数据库和种子脚本。evals/:金色提示和验证脚本。tests/:Pytest套件。
API使用示例
列出工具:
curl http://localhost:8000/tools
运行代理:
curl -X POST http://localhost:8000/agent/run \
-H "Content-Type: application/json" \
-d '{"query": "Find the high priority tickets"}'
