用户提问
↓
大模型生成工具调用草案
↓
→【RAG 检索历史反馈】→ 若高风险 → 插入确认提示
↓
→【规则引擎检查】→ 若命中黑名单/异常参数 → 强制确认
↓
→【风险评分】→ 若高于阈值 → 需要用户确认
↓
→【动态 prompt 注入】→ 说明"根据您过去偏好..."
↓
输出给用户(含确认请求)
↓
用户反馈 → 存入数据库 → 用于强化学习
python scripts/check_environment.py
pip install -r requirements.txt
如果遇到安装Faiss的问题:
pip install faiss-cpu>=1.8.0
# 或使用conda
conda install -c pytorch faiss-cpu
编辑 config/config.yaml:
database:
postgresql:
host: "localhost"
port: 5432
database: "mcp_monitor"
user: "your_user"
password: "your_password"
python scripts/init_database.py
python main.py
打开浏览器并访问:http://localhost:8000/docs
import httpx
async with httpx.AsyncClient() as client:
response = await client.post(
"http://localhost:8000/api/v1/query",
json={
"user_id": "user123",
"question": "帮我删除/tmp目录下的所有文件"
}
)
result = response.json()
if result["requires_confirmation"]:
print(f"⚠️ 风险分数: {result['risk_score']}")
print(f"📝 {result['tool_calls'][0]['confirmation_message']}")
await client.post(
"http://localhost:8000/api/v1/services/register",
json={
"service_name": "file_operations",
"service_url": "http://localhost:9000",
"description": "文件操作服务",
"tools": [...],
"layer": "L2",
"domain": "file"
}
)
完整示例:examples/usage_example.py
欢迎贡献!请阅读CONTRIBUTING.md了解如何参与。
感谢所有贡献者!
本项目采用MIT许可证开源许可。