MCP Servers

A collection of Model Context Protocol servers, templates, tools and more.

MCP Monitor 是一个智能工具调用监控系统,基于 Python 3.9+,支持跨平台运行。通过 RAG 检索、规则引擎和动态加载机制,实现高风险操作识别、自动确认与个性化建议,保障工具调用安全可靠。

Created 10/13/2025
Updated 2 months ago
Repository documentation and setup instructions

MCP Monitor

Python 3.9+ License MIT Platform Version

智能MCP工具调用监控系统
风险评估 • 历史学习 • 动态加载 • 跨平台支持


🌟 核心特性

🛡️ 智能风险评估

  • ✅ RAG检索历史反馈,识别高风险操作
  • ✅ 规则引擎检查黑名单和异常参数
  • ✅ 基于阈值的自动确认机制(可配置)
  • ✅ 动态prompt注入,提供个性化建议

🔄 动态工具加载

  • L1层: 高频核心工具(始终可用)
  • L2层: 领域专用工具(按需激活)
  • L3层: 高风险工具(需显式授权)

📊 MCP服务监控

  • 实时服务状态监控
  • 服务队列管理
  • 工具列表和说明展示
  • 健康检查和熔断机制

💾 数据持久化

  • PostgreSQL存储完整历史记录
  • Faiss向量数据库高效检索
  • 支持自定义存储路径

🌐 跨平台支持

  • ✅ macOS (Intel & Apple Silicon)
  • ✅ Windows 10/11
  • ✅ Linux (Ubuntu, Debian, CentOS, RHEL)

📋 系统架构

用户提问
   ↓
大模型生成工具调用草案
   ↓
→【RAG 检索历史反馈】→ 若高风险 → 插入确认提示
   ↓
→【规则引擎检查】→ 若命中黑名单/异常参数 → 强制确认
   ↓
→【风险评分】→ 若高于阈值 → 需要用户确认
   ↓
→【动态 prompt 注入】→ 说明"根据您过去偏好..."
   ↓
输出给用户(含确认请求)
   ↓
用户反馈 → 存入数据库 → 用于强化学习

🚀 快速开始

系统要求

  • Python: 3.9+
  • PostgreSQL: 12+
  • 内存: 4GB+ (推荐8GB)

0. 环境检查(推荐)

python scripts/check_environment.py

1. 安装依赖

pip install -r requirements.txt

如果遇到Faiss安装问题:

pip install faiss-cpu>=1.8.0
# 或使用conda
conda install -c pytorch faiss-cpu

2. 配置数据库

编辑 config/config.yaml

database:
  postgresql:
    host: "localhost"
    port: 5432
    database: "mcp_monitor"
    user: "your_user"
    password: "your_password"

3. 初始化数据库

python scripts/init_database.py

4. 启动服务

python main.py

5. 访问API

打开浏览器访问: 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']}")

注册MCP服务

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


🛠️ 技术栈

  • Web框架: FastAPI + Uvicorn
  • 数据库: PostgreSQL + SQLAlchemy
  • 向量检索: Faiss
  • 模型接口: OpenAI Compatible API
  • 异步: asyncio
  • 日志: loguru

📈 路线图

  • [ ] Web UI 管理界面
  • [ ] 更多模型适配器(Claude、Gemini等)
  • [ ] 工具调用可视化
  • [ ] 高级分析和报表
  • [ ] 多语言支持
  • [ ] 插件系统

🤝 贡献

欢迎贡献!请阅读 CONTRIBUTING.md 了解如何参与。

贡献者

感谢所有贡献者!


📝 许可证

本项目采用 MIT License 开源协议。


🙏 致谢

  • FastAPI - 现代、快速的Web框架
  • Faiss - 高效的向量检索库
  • PostgreSQL - 强大的关系型数据库

📧 联系方式


如果这个项目对你有帮助,请给它一个⭐️

Quick Setup
Installation guide for this server

Install Package (if required)

uvx mcp_monitor

Cursor configuration (mcp.json)

{ "mcpServers": { "malowking-mcp-monitor": { "command": "uvx", "args": [ "mcp_monitor" ] } } }