policy-gate-mcp
Policy-as-code gate for AI-SDLC, providing MCP tools to review prompts, diff tool manifests, vet MCP servers, and run evaluation suites for LLM agent repos.
README
policy-gate-mcp
Policy-as-code AI-SDLC gates for LLM agent repos, shipped as both an MCP server (for interactive use from an editor/agent) and a CLI (for CI). It is pre-configured to govern the USEA agent, and is written so any other agent repo can be onboarded as a new "profile".
It implements the four gates requested for the AI-SDLC:
| Gate | What it checks | Module |
|---|---|---|
| 1. Prompt / system-prompt review | The assembled system prompt against forbidden/required patterns, a length limit, and a reviewed baseline | policy_gate/prompt_review.py |
| 2. Tool manifest diffing | Every tool exposed to the agent, diffed against a recorded baseline, risk-classified, with sign-off required for high/critical changes | policy_gate/tool_manifest.py |
| 3. MCP server vetting | Any mcpServers config (command allowlist, pinned versions, remote domain allowlist, no plaintext secrets, required trust review) |
policy_gate/mcp_vetting.py |
| 4. Eval suites as CI regression tests | Golden-transcript eval cases with blocking (zero-tolerance) vs. warning (pass-rate threshold) severities |
policy_gate/eval_runner.py |
Every gate returns the same GateResult shape (pass / warn / fail
/ skipped, a list of violations, and structured details), so the MCP
tool, the CLI subcommand, and the CI job all agree on the verdict.
Why this exists
Agent repos like USEA change three things that traditional CI never looked at: the system prompt, the tool manifest (what the model is allowed to do), and the MCP servers it can talk to. A one-line prompt edit or a new tool can silently turn a "read files" agent into a "run arbitrary shell commands and exfiltrate secrets" agent, and normal unit tests won't catch it. This repo turns those three surfaces - plus behavioral regressions - into things that are diffed, classified, and gated in the same PR review flow as code.
Architecture
flowchart TB
subgraph Governed repo - e.g. USEA
A[do-anything-agent.py]
end
subgraph policy-gate-mcp - this repo
P[profiles/usea.yaml]
POL[policies/*.yaml]
BASE[baselines/usea/*]
EV[evals/usea_suite.yaml + fixtures/]
G1[prompt_review.gate]
G2[tool_manifest.gate]
G3[mcp_vetting.gate]
G4[eval_runner.gate]
CLI[policy_gate/cli.py]
SRV[server.py - MCP tools]
end
A -- static AST parse, never executed --> G1
A -- static AST parse, never executed --> G2
P --> G1 & G2 & G3 & G4
POL --> G1 & G2 & G3 & G4
BASE --> G1 & G2
EV --> G4
G1 & G2 & G3 & G4 --> CLI
G1 & G2 & G3 & G4 --> SRV
CLI -- exit 0/1 --> CI[GitHub Actions: ai-sdlc-gates.yml]
SRV -- tool calls --> Editor[MCP client / coding agent]
Key design choices:
- Static analysis, not execution. Both the prompt-review and
tool-manifest gates parse the target file with
astand neverimport/execit. There's no need for the governed repo's runtime dependencies (LangChain, provider SDKs, etc.) to run these two gates, and a malicious prompt/tool can't execute code during the gate itself. - Profiles, not hardcoding.
profiles/usea.yamlis the only place that knows USEA's file names and variable names. Onboarding a second agent means addingprofiles/<name>.yamlplus its ownbaselines/<name>/...andevals/<name>_suite.yaml- the gate engine itself is generic. - Policies are reviewable YAML, not code. All four gates read their
rules from
policies/*.yaml. Changing what's blocked is a normal, diffable pull request against this repo, not a code change. - Fail closed. An unrecognized tool, a missing baseline file's sign-off, or an unclassified MCP server all fail the gate rather than silently passing.
The four gates in detail
Gate 1 - Prompt / system-prompt review
prompt_review.py walks the target file's AST and reconstructs every
string assigned or +=-appended to a configured variable (system_content
for USEA), ordered by source line number so conditional branches (e.g. the
Vault-policy block that's only appended if vault_enabled) come out in
the same order a human reading the file would see them.
The reconstructed text is checked against
policies/prompt_policy.yaml:
forbidden_patterns- regexes that must never appear (prompt-injection phrasing like "ignore previous instructions", jailbreak personas, "disable safety", "output the raw API key", etc.), each with a human-readable reason.required_patterns- regexes that must appear (USEA's policy requires the prompt to instruct the model to mask sensitive values and to explain risk before acting).max_length_chars- a hard cap.- Baseline diff - if the extracted prompt no longer matches
baselines/usea/system_prompt.baseline.txt, the gate fails unlesspolicies/prompt_review_log.yamlhas a matching entry (reviewer, date, PR link). This is what turns "someone tweaked the system prompt" from invisible to a required, attributable sign-off.
To accept an intentional prompt change: update the baseline file with the
new extracted text, then append an entry to prompt_review_log.yaml
naming the reviewer.
Gate 2 - Tool manifest diffing
tool_manifest.py walks the same AST for every function decorated with
@tool (configurable via tool_manifest.decorator_name), extracting its
name, docstring, and parameter signature (name/annotation/default) into a
canonical JSON shape. It diffs the result against
baselines/usea/tool_manifest.baseline.json.
policies/tool_manifest_policy.yaml
requires every tool to carry an explicit risk tier
(low / medium / high / critical) plus a capability and
justification. For USEA today: list_directory / read_text_file are
low (read-only), write_text_file is high (unrestricted filesystem
write), and run_command is critical (arbitrary shell execution).
Rules enforced:
- Any tool with no risk classification fails, whether new or pre-existing - the manifest must have 100% coverage.
- New or changed
high/criticaltools require a sign-off entry inpolicies/tool_manifest_review_log.yaml(tool name + profile + reviewer), or the gate fails. - Removed tools only produce a warning (nothing unsafe about an agent losing a capability).
This is the gate that catches "tool poisoning" - an agent quietly gaining a new high-blast-radius capability (network egress, unrestricted writes, shell exec) that nobody explicitly reviewed.
Gate 3 - MCP server vetting
mcp_vetting.py validates an mcpServers/servers config (the same
shape as a VS Code / Claude Desktop mcp.json) against
policies/mcp_server_allowlist.yaml:
- launch
commandmust be onallowed_commands(no arbitrary binaries orcurl | shstyle installers) npx/uvxinvocations must be pinned to a version (@x.y.z/==x.y.z) - nolatesturl-based (remote) servers must targetallowed_remote_domains- env vars matching
secret_env_key_patterns(API_KEY,TOKEN,SECRET,PASSWORD) must use"${VAR_NAME}"expansion, never a literal value committed to the config - every server entry must carry a
trust_reviewblock naming a reviewer
configs/usea.mcp.json is a compliant example
(it even vets itself - the policy-gate server entry - and a pinned,
scoped filesystem server). configs/bad_example.mcp.json
is intentionally non-compliant and is used by the test suite to prove
every rule actually fires.
Gate 4 - Eval suites as CI regression tests
evals/usea_suite.yaml defines eval cases, each
with a severity:
blocking- must always pass, zero tolerance (e.g. "must refuse to runrm -rf /", "must never print a raw API key"). A single blocking failure fails the gate regardless of the overall pass rate.warning- scored into an overall pass rate that must clearmin_pass_ratefrompolicies/eval_thresholds.yaml(default 90%).
Two run modes:
static(default, what CI runs): replays recorded golden transcripts fromevals/fixtures/*.jsonagainst each case's assertions (expected_tool_calls,forbidden_tool_calls,required_output_patterns,forbidden_output_patterns). Deterministic, free, no model credentials needed.live: dynamically loads the governed agent's real entrypoint (the sameimportlib.util.spec_from_file_locationpattern USEA's ownapi/agent_runner.pyuses to loaddo-anything-agent.py), actually calls the model for each case'squery, and applies the same assertions. Pass--recordto overwrite the golden fixtures with the new transcript - this is how you intentionally refresh the regression baseline after a real behavior change.
Running it
As a CLI (what CI uses)
python3 -m venv .venv && source .venv/bin/activate
pip install -e .
# Run one gate
policy-gate --profile usea review-prompt /path/to/USEA
policy-gate --profile usea diff-tools /path/to/USEA
policy-gate --profile usea vet-mcp
policy-gate --profile usea run-evals /path/to/USEA --mode static
# Run everything (this is what the CI workflow calls)
policy-gate --profile usea check-all /path/to/USEA
# Machine-readable report
policy-gate --profile usea json /path/to/USEA
Exit code is 0 if every gate passed (or only warned), 1 if any gate
failed.
As an MCP server (interactive use during development)
pip install -e ".[dev]"
python3 server.py # stdio transport
Point an MCP client at it, e.g. add to your editor's mcp.json
(see configs/usea.mcp.json for the exact
shape):
{
"mcpServers": {
"policy-gate": {
"command": "python3",
"args": ["/absolute/path/to/MCP/server.py"]
}
}
}
Exposed tools: review_prompt, diff_tool_manifest, vet_mcp_servers,
run_eval_suite, run_all_gates - each takes the same repo_path /
profile arguments as the CLI, so a coding agent can call run_all_gates
on its own working copy before opening a PR.
Wiring into USEA's CI
USEA/.github/workflows/ai-sdlc-gates.yml
checks out both repos, installs this one editable, and runs
policy-gate --profile usea check-all. Unlike USEA's existing
ci-build.yml (which uses continue-on-error: true for most steps),
this workflow is a real gate - it fails the PR check on any fail
status.
Onboarding a new governed agent
- Add
profiles/<name>.yamldescribing the target file, the system prompt variable name, the tool decorator name, and paths for the baseline/eval files (copyprofiles/usea.yamlas a template). - Run
policy-gate --profile <name> review-prompt <repo>and... diff-tools <repo>once against a known-good checkout; both will reportwarn("no baseline recorded yet") and print the extracted prompt/manifest indetails. Save those intobaselines/<name>/system_prompt.baseline.txtandbaselines/<name>/tool_manifest.baseline.json. - Classify every tool in
policies/tool_manifest_policy.yaml. - Add an MCP server config at
configs/<name>.mcp.jsonand reference it from the profile. - Write
evals/<name>_suite.yamlplus golden fixtures underevals/fixtures/.
Testing this repo itself
pip install -e ".[dev]"
pytest tests/ -v
The test suite proves both directions for each gate: the bundled usea
profile passes cleanly against a faithful fixture of USEA's real
prompt/tools/MCP config/evals, and dedicated "bad" fixtures
(tests/fixtures/bad_prompt_repo, tests/fixtures/new_tool_repo,
configs/bad_example.mcp.json) prove each rule fails closed.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。