mcp-policy-gateway
mcp-policy-gateway
一个策略优先的 MCP 服务器参考实现。它展示了如何为代理提供有用的工具,而不允许模型自行决定授权、跨越租户边界、泄露直接 PII,或自行执行高影响变更。
这是一个作品集/参考实现。所有记录都是合成的;它不是生产软件,也不声称与银行、支付处理器或客户系统集成。
为什么存在
常见的 MCP 演示将原始 API 暴露给模型,并将成功的工具调用视为安全模型。本项目采取相反的立场:
策略是确定性的。 模型不能自行授权。
租户边界在服务端强制执行。 工具参数不能切换租户。
工具输出最小化。 账户摘要故意排除所有者姓名和电子邮件。
高影响操作在审批门处停止。 冻结请求不会产生状态变更。
每个决策都可审计。 允许、拒绝和需要审批的结果都会创建结构化审计事件。
变更请求需要理由和幂等键。
Related MCP server: Aegis
架构
MCP client / agent
│ tool call
▼
FastMCP stdio adapter
│ verified principal (demo fixture here)
▼
GatewayService ──► PolicyEngine ──► allow / deny / require approval
│ │
▼ ▼
synthetic domain data structured audit event在生产部署中,主体将来自模型上下文之外的已验证身份/会话。切勿从工具参数或模型输出中接受 tenant_id、角色或作用域。
工具
工具 | 风险 | 行为 |
| 读取 | 仅允许调用者租户内具有正确作用域的案件。 |
| 读取 | 返回最小化摘要;绝不直接返回 PII。 |
| 变更 | 需要作用域、理由和幂等键,然后始终需要人工审批。 |
快速开始
需要 Python 3.11+。
python -m venv .venv
.venv/bin/pip install -e '.[dev]'
.venv/bin/pytest
.venv/bin/ruff check .作为 MCP stdio 服务器运行:
.venv/bin/mcp-policy-gateway适配器故意使用固定的演示主体进行本地探索。真实身份传播被有意记录为生产集成问题,而不是在这里伪造。
演示的滥用控制
测试证明网关:
拒绝来自
tenant_red的代理尝试读取tenant_blue数据;拒绝没有所需作用域的工具调用;
不通过摘要工具返回所有者姓名或电子邮件;
返回
require_approval而不是变更账户状态;以及拒绝省略理由或幂等键的变更状态请求。
威胁模型和非目标
参见 THREAT_MODEL.md。设计有意保持狭窄:它演示了围绕 MCP 工具的策略边界,而不是完整的身份基础设施、持久化审计存储、机密管理或支付/账本系统。
面试讲解
解释项目的一种简洁方式:
我设计了 MCP 边界,使模型能够基于安全、有作用域的数据进行推理,但不能决定访问权限或执行高影响操作。授权是确定性的,租户隔离在服务端强制执行,工具表面最小化 PII,敏感变更终止于可审计的人工审批门。
开发
.venv/bin/pytest
.venv/bin/ruff check .CI 在推送和拉取请求上运行这两项检查。
许可证
MIT。参见 LICENSE。
Available Tools
3 toolsget_account_summaryB
Return a minimized account summary; this tool never exposes direct PII.
Inputs: account_id (required).
get_caseA
Retrieve a support case inside the caller's tenant boundary.
Inputs: case_id (required).
request_account_freezeB
Request a high-impact account freeze. Policy always requires human approval.
Inputs: reason (required), account_id (required), idempotency_key (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 3 tools
Each tool targets a distinct resource/action: case retrieval, account summary (with PII restriction), and a freeze request. There is no overlap in purpose, and the descriptions clearly differentiate the operations.
All tool names follow a consistent verb_noun pattern (get_case, get_account_summary, request_account_freeze). The verbs are clear and the nouns identify the target, making the set predictable and easy to navigate.
With only 3 tools, the server is tightly scoped and each tool serves a distinct, essential function within the policy gateway context. This is within the typical 3-15 range and feels appropriately lean rather than sparse.
The tools cover core read operations and a high-impact action, but there are notable gaps: no listing of cases or accounts, no update/modification paths, and no way to track the status of a freeze request. Agents would need to work around these missing operations.
Maintenance
Related MCP Connectors
Governed MCP gateway: one endpoint for your tools, with credential custody and audit log.
Zero-secret MCP gateway for AI agents: risk-scored, audited calls with human-in-the-loop approval.
One MCP endpoint for your company's tools, with per-person sign-in, policy and audit.
Governed MCP gateway for business apps: roles, previews, approvals and one audit log.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnforces fine-grained, context-aware access control on MCP tool calls, with a tamper-evident, replayable audit log that records denials and verifies every decision.MIT
- AlicenseNot gradedqualityDmaintenanceEnables governing tenant-aware MCP tools with policy enforcement, scoped access, human approval workflows, and tamper-evident audit logging.MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents and MCP clients to safely access upstream MCP servers through centralized policy enforcement, including allow/deny/approval decisions, schema pinning, circuit breakers, and audit logging.MIT
- FlicenseNot gradedqualityCmaintenanceEnforces default-deny policies, budgets, and tamper-evident audit logging for MCP tool calls before they reach upstream servers.-