Skip to main content
Glama
jahao-18

AgentGuard MCP Server

by jahao-18

AgentGuard

AgentGuard 是面向 MCP Agent 的运行时安全网关。在工具发现、调用、审批恢复、审计和评测之间提供统一控制点。项目中的订单、文件、通知服务都是 Mock MCP Server,不连接真实支付、邮件或云资源。

项目解决的问题

当 Agent 想调用工具时,Gateway 会强制检查:

  • 用户和 Agent 是否有权发现和调用该工具;

  • 参数是否越权、包含 Secret 或危险文件路径;

  • 策略是否应当允许、拒绝、转换参数或要求人工审批;

  • 工具输出中的不可信内容是否诱导后续敏感读取或数据外发;

  • 当前任务是否超过工具调用次数或风险预算;

  • 整个过程是否可以通过 trace_id 进行脱敏审计回放。

Related MCP server: SINT Protocol

主要能力

模块

内容

MCP Gateway

代理并聚合 Order、File、Notification 三个 Mock MCP Server

身份与授权

JWT、RBAC、ABAC,以及发现/执行双重授权

策略引擎

YAML Policy-as-Code:allow、deny、transform、require_approval

风险控制

Secret、敏感路径、退款阈值、调用次数、风险预算、超时

人工审批

参数编辑、批准/拒绝、单次执行、LangGraph interrupt 恢复

不可信内容

工具输出标记、Prompt Injection 信号与危险调用链阻断

审计与评测

PostgreSQL 哈希链 Trace、50 条版本化攻防/可用性语料

技术栈

Python 3.12、FastAPI、MCP Python SDK、LangGraph、PostgreSQL、Redis、SQLAlchemy、Alembic、Docker Compose、pytest、ruff、mypy。

快速启动

前提:Docker Desktop。

Copy-Item .env.example .env
docker compose up --build -d
docker compose ps

服务

地址

Gateway 健康检查

http://127.0.0.1:8000/health/ready

MCP Streamable HTTP 入口

http://127.0.0.1:8000/mcp/

PostgreSQL

127.0.0.1:55432

Redis

127.0.0.1:56379

查看日志:

docker compose logs -f gateway

停止服务、保留数据:

docker compose down

本地源码开发

前提:Python 3.12、Docker Desktop,且已安装开发依赖。

docker compose up -d postgres redis
./.venv/Scripts/python.exe -m alembic upgrade head
./.venv/Scripts/python.exe -m scripts.seed_dev_data
./.venv/Scripts/python.exe -m uvicorn main:app --reload

如何使用

获取开发 JWT

$token = ./.venv/Scripts/python.exe -m scripts.issue_dev_token

运行示例 Agent

./.venv/Scripts/python.exe -m agent_demo.cli get_order --order-id ORD-N-1001 --token $token
./.venv/Scripts/python.exe -m agent_demo.cli read_faq --token $token

示例 Agent 只通过 Gateway 调用工具。成功响应带有 trace_id。

回放审计 Trace

./.venv/Scripts/python.exe -m scripts.show_trace <trace-id>

输出只包含脱敏后的参数/结果摘要、策略和审计事件。

运行策略与评测演示

./.venv/Scripts/python.exe -m scripts.week3_identity_smoke
./.venv/Scripts/python.exe -m scripts.week4_policy_smoke
./.venv/Scripts/python.exe -m scripts.run_evaluation --output-dir reports

评测报告保存为 reports/evaluation-report.json 与 reports/evaluation-report.md。

人工审批演示

大额退款会返回 APPROVAL_REQUIRED 和 approval_id。manager/admin 可编辑金额、批准并执行;恢复的 Agent 任务只使用已经批准的参数。

在 .env 启用本地审批台:

AG_MANAGEMENT_API_ENABLED=true
AG_MANAGEMENT_API_KEY=<至少 32 位随机值>

重启 Gateway 后,访问 http://127.0.0.1:8000/approvals/ 。页面需要管理 API Key 和 manager/admin Bearer JWT,仅允许 development/test 环境使用。完整演示见 Demo 脚本

配置说明

主要配置位于 .env,模板见 .env.example

  • AG_POSTGRES_*、AG_REDIS_*:基础设施连接;

  • AG_JWT_*:开发 JWT 签名和校验;

  • AG_TOOL_TIMEOUT_SECONDS:单次工具调用超时;

  • AG_MAX_TOOL_CALLS_PER_RUN、AG_MAX_RISK_BUDGET_PER_RUN:任务级限制;

  • AG_REFUND_APPROVAL_THRESHOLD_MINOR:退款审批阈值;

  • AG_MANAGEMENT_API_*:开发管理/审批接口。

不要把 .env 中的开发密钥用于共享或生产环境。

测试与质量检查

./.venv/Scripts/python.exe -m ruff format --check gateway mcp_servers agent_demo scripts tests main.py
./.venv/Scripts/python.exe -m ruff check gateway mcp_servers agent_demo scripts tests main.py
./.venv/Scripts/python.exe -m mypy gateway mcp_servers agent_demo scripts main.py
$env:AG_RUN_INFRASTRUCTURE_TESTS='1'; ./.venv/Scripts/python.exe -m pytest -q

CI 会执行格式、lint、类型检查、单元测试和评测语料校验。

项目结构

gateway/        Gateway、身份、策略、风险、审批、审计、Registry
mcp_servers/    订单、文件、通知 Mock MCP Server
agent_demo/     LangGraph 示例 Agent
policies/       YAML Policy-as-Code
scripts/        Seed、Trace、Smoke、评测脚本
tests/          单元、集成与安全回归测试
docs/           架构、威胁模型、使用与开发文档

安全边界

  • 这是参考实现,不承诺 100% 防 Prompt Injection;

  • 风险检测只提供信号;权限、参数校验、审批与执行边界才是强制控制;

  • 审批台和管理接口仅供 development/test;

  • LangGraph 当前使用内存 checkpoint,重启后恢复需要持久化 checkpointer;

  • 生产还需要 SSO、多租户、密钥管理、网络隔离和持久化任务存储。

进一步阅读

F
license - not found
-
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    B
    quality
    C
    maintenance
    Security gateway that wraps any MCP server with per-tool policies, approval gates, and optional Ed25519-signed decision receipts. Shadow mode logs every tool call without blocking; enforce mode applies block, rate-limit, and minimum-tier rules. Receipts are independently verifiable offline with no accounts needed.
    5
    378
    9
    MIT
  • A
    license
    A
    quality
    A
    maintenance
    Security-enforcing MCP proxy that sits between an AI agent and any number of downstream MCP servers, intercepting every tool call through a capability-token policy gateway that can allow, deny, or escalate to human approval before the call reaches any real tool. It also exposes built-in operator tools for approval workflows, audit trail queries, token management, voice/HUD output, and hierarchical
    21
    11
    Apache 2.0
  • F
    license
    -
    quality
    C
    maintenance
    MCP server that evaluates agent actions against a Policy State Machine, emits a tamper-evident audit trail, and dispatches approved transitions to internal or federated handlers.
  • A
    license
    A
    quality
    B
    maintenance
    Default-deny action registry, append-only spend ledger, and human sign-off audit trail (MCP tools).
    6
    MIT

View all related MCP servers

Related MCP Connectors

  • Remote MCP for A2A caller identity, scope policy, verdict receipts, and audit history.

  • Remote MCP for Android CLI agent build gate, structured receipts, audit logs, and reviewer-ready evi

  • Security tools for AI agents: scan MCP servers, validate HDP delegation chains, audit releases.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jahao-18/Agent_Guard'

If you have feedback or need assistance with the MCP directory API, please join our Discord server