Skip to main content

mcp-policy-lint

ci license PyPI

English | 简体中文

Turn mcp.json into a readable, testable, PR-blocking permission policy — before you run any MCP server. Local, zero dependencies, no model key, no Docker.

pip install mcp-policy-lint   # installs the mcp-policy-lint command
mcp-policy-lint demo                  # 30 seconds, no network, no API key, no Docker
# from a checkout instead: pip install -e .
mcp-policy-lint demo — 2 servers scanned, 6 findings
no network, no API key, no Docker
(vs sample baseline: 3 drift rows — run `mcp-policy-lint diff` to inspect)

mcp-policy-lint 0.3.0 — 6 findings

ERROR  POL003  remote       /mcpServers/remote/url                 Plaintext HTTP to a remote endpoint
        http://api.example.com/mcp has no TLS, so tool descriptions and responses can be altered in transit
        fix: Use https:// and confirm the authentication settings
ERROR  POL001  shell        /mcpServers/shell/command              stdio command can start a shell
        shell runs its arguments through sh, so it can execute arbitrary commands
        fix: Call a concrete executable directly instead of assembling a command with -c
ERROR  POL002  shell        /mcpServers/shell/env/AWS_SECRET_ACCESS_KEY Likely real credential in config
        AWS_SECRET_ACCESS_KEY is not a placeholder; it can leak through logs or travel with the repository
        fix: Reference an environment variable or a secret manager; never put the value in mcp.json
ERROR  POL004  shell        /mcpServers/shell/roots/0              root outside the repository boundary
        root /home/me points at a home directory or escapes the repository
        fix: Narrow roots to the current project directory
WARN   POL005  shell        /mcpServers/shell/tools/0              Tool annotation contradicts its name or description
        delete_everything claims read-only or non-destructive, but its description contains write verbs
        fix: Fix the annotation or the name; a client may skip confirmation because of it
WARN   POL006  shell        /mcpServers/shell/tools/0              Tool input has no constraints
        delete_everything has an empty inputSchema or no properties, so argument boundaries cannot be checked
        fix: Complete the JSON Schema: declare required fields and enums

exit code: 1
mcp-policy-lint 0.3.0 coverage — 1 config(s), 2 server(s)

config           server  transport  modeled                       unmodeled
---------------  ------  ---------  ----------------------------  ---------
unsafe.mcp.json  shell   stdio      command,args,env,roots,tools  -
unsafe.mcp.json  remote  remote     url                           -

unmodeled fields: 0 — rules depending on them report unknown, not pass
unknown findings: 0
gate: --unknown error (default) fails the build on unknown

Three-step workflow

# 1. Record an approved baseline (commit it)
mcp-policy-lint init examples/safe.mcp.json --out policy.lock.json

# 2. Scan any client config
mcp-policy-lint scan examples/unsafe.mcp.json --format ndjson

# 3. CI gate: drift or findings -> non-zero exit code
mcp-policy-lint check examples/unsafe.mcp.json --baseline policy.lock.json --strict

scan renders text / ndjson / json / html; --html-out report.html writes a single self-contained file (no external assets, opens straight from file://). check and scan both render sarif (2.1.0) and accept --out for any non-text format. diff prints an add / remove / modify table on its own.

The baseline only moves when someone says why

A drift failure is a question, not an error. Answering it is a command with a receipt:

mcp-policy-lint check mcp.json --baseline policy.lock.json   # exit 2: config and baseline disagree
mcp-policy-lint approve mcp.json --baseline policy.lock.json \
  --reason "audited: read_anything only reads the docs repo"
mcp-policy-lint check mcp.json --baseline policy.lock.json   # exit 0: approved

approve refuses to run without --reason, rewrites the baseline, and appends an audit entry to policy.lock.json — id, at, by, reason, and the change kinds it accepted:

"approvals": [
  {
    "at": "2026-11-06T00:18:38Z",
    "by": "alice",
    "changes": [
      {"kind": "fingerprint_changed", "server": "c", "path": "/servers/c/fingerprint"},
      {"kind": "auto_approve_added", "server": "c", "path": "/servers/c/auto_approve"}
    ],
    "id": "ec0b40623fe9",
    "reason": "audited the new approval list"
  }
]

Who moved the baseline, and why, lands in the same review as the config change. No other subcommand writes to the baseline, and none edits a config.

Unknowns cost an exit code

Anything the tool cannot understand is reported as unknown, never quietly counted as a pass. Three cases all pay: an unrecognized file shape (POL000), a field that is not modeled (POL009), a transport that cannot be inferred (POL008).

mcp-policy-lint check mcp.json                  # default --unknown error: fail rather than guess
mcp-policy-lint check mcp.json --unknown warn   # downgrade to warn (still gated by --strict)
mcp-policy-lint check mcp.json --unknown ignore # say explicitly that you do not care
mcp-policy-lint coverage mcp.json               # which fields this run actually consumed

coverage is the one command that volunteers what it failed to understand: per server, the fields it modeled, the fields it did not, and the unknown findings that follow from them.

Verify it yourself, do not take my word

scripts/gate_selftest.py writes down which input must produce which exit code — 10 fixtures plus one drift case, zero dependencies, no install:

python scripts/gate_selftest.py
fixture                         argv                         want  got
safe.json                       (default)                       0    0  ok
unknown-shape.json              (default)                       1    1  ok
unmodeled-transport.json        (default)                       1    1  ok
unmodeled-transport.json        --unknown warn                  0    0  ok
unmodeled-transport.json        --unknown ignore                0    0  ok
windsurf-serverurl-http.json    (default)                       1    1  ok
cline-autoapprove.json          (default)                       0    0  ok
cline-autoapprove.json          --strict                        1    1  ok
cline-autoapprove-secret.json   (default)                       1    1  ok
localhost-http.json             (default)                       0    0  ok
cline-autoapprove-plus.json     (drift)                         2    2  ok

11/11 cases match

That table is the whole claim of this document: a config it cannot read fails (1), a baseline drift is caught (2), and plaintext HTTP on localhost is not a false positive (0). Change the severity of any rule and this table goes red first.

What it is not

does not who does
run MCP servers, sandbox them ToolHive
scan server source for malware mcp-scanner
proxy traffic, RBAC, JWT agentgateway
use an LLM as judge, judge prompt injection —
edit configs, auto-approve anything —

It answers three questions only: what permissions does the config declare, does that violate a least-privilege baseline, and what did this PR change. unknown is not safe, and every finding carries its JSON Pointer.

Exit codes

code meaning
0 pass
1 at least one error (including an unknown treated as error; warnings too under --strict)
2 drift from the policy baseline / incompatible schema
3 usage or config error (missing file, corrupt baseline)

Priority is 3 > 2 > 1 > 0, designed to be passed straight to sys.exit() in GitHub Actions.

Evidence a machine can read

mcp-policy-lint check mcp.json --format sarif --out mcplint.sarif   # SARIF 2.1.0
mcp-policy-lint scan mcp.json --format json                          # findings + exit code + source map

GitHub code scanning reads the SARIF file directly (github/codeql-action/upload-sarif@v3). Each result carries the rule id, the severity mapped to error / warning / note, the config file, the JSON Pointer as a logicalLocation, and a stable partialFingerprint so a finding survives renames instead of reopening. Drift rows use rule id DRIFT.

The GitHub Action takes the shorter path: it turns every finding into a pull-request annotation on the config file, named by rule and JSON Pointer.

::error file=mcp.json,line=1,title=POL003 remote::Plaintext HTTP to a remote endpoint: http://api.example.com/mcp has no TLS ...

Adding a rule is one function

from mcp_policy_lint.rules import register
from mcp_policy_lint.model import Finding

@register("POL100")
def no_root_ssh(server):
    if any(".ssh" in r for r in server.roots):
        return [Finding("POL100", "error", "root points at .ssh",
                        f"{server.name} exposes the SSH directory", server.name,
                        server.pointer + "/roots", "narrow roots to the repository")]
    return []

The rule registry, policy format, report renderers and config discovery are independent modules — see ARCHITECTURE.md.

Use it as a GitHub Action

- uses: ravenkernel/mcp-policy-lint@v1
  with:
    path: .                       # file or directory
    baseline: policy.lock.json    # optional; omit to only report findings
    unknown: error                # error (default) | warn | ignore
    strict: false
    annotations: true             # findings as pull-request annotations

The action installs mcp-policy-lint, runs mcp-policy-lint check, and fails the job with its own exit code — the same 0/1/2/3 you see locally. It writes nothing but the baseline you ask for, and it never edits a config file.

input default effect
path . config file or directory to check
baseline empty turns on drift detection against policy.lock.json
unknown error price of a field mcp-policy-lint cannot model
strict false warnings become failures
annotations true one pull-request annotation per finding and per drift row
extra-args empty appended to mcp-policy-lint check
version >=0.3.0,<0.4 pip requirement for the package

Status

0.3.0 adds the two things a reviewer was missing: approve --reason writes an explicit, auditable approval into the baseline instead of leaving "edit this JSON by hand" as the answer to drift, and --format sarif (plus pull-request annotations in the Action) puts every finding where code review already looks. No rule changed, no exit code changed.

0.2.0 is a rename: the command, the import package, the repository and the action are all mcp-policy-lint now, and rule ids moved from MCP001 to POL001. Nothing about behaviour changed — same rules, same exit codes. The reason is discoverability: mcplint was already a crowded name, and ids like MCP009 mean something else entirely in a neighbouring scanner. 0.1.3 ships the GitHub Action above and nothing else — same rules, same exit codes — so the PyPI page documents the way most teams will actually run it. 0.1.2: runs end to end, 9 built-in rules (POL001-006, POL008, POL009, POL010), covered by tests at both the CLI and library level. Lint messages are English as of 0.1.1 (0.1.0 shipped the same rules with Chinese messages). 0.1.2 is the first PyPI release, and it turns the crashes and false positives I found by hand into tests: a field with the wrong type is POL009 instead of an exception, a server name containing / produces a valid pointer (a~1b), two servers with the same name are POL011, git -c user.name=x is not read as a shell, and a mistyped --rule id or flag exits 3 instead of passing silently.

Config compatibility currently covers three top-level shapes (mcpServers / servers / mcp.servers) and the common fields of Claude Desktop, Cursor, VS Code, Cline and Windsurf. What is not covered is never reported as a pass: an unmodeled field always produces POL009, and --unknown (error by default) decides whether it blocks the merge; mcp-policy-lint coverage prints the full field-consumption table.

No sandbox, no gateway, no prompt-injection detection — those belong to the runtime layer. No claim of "secure by default".

Metadata

Release files for mcp-policy-lint 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-policy-lint 0.3.0
File Size Uploaded Provenance Actions
mcp_policy_lint-0.3.0.tar.gz 36.2 kB Without provenance Details for mcp_policy_lint-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mcp-policy-lint 0.3.0
File Interpreter ABI Platform Actions
mcp_policy_lint-0.3.0-py3-none-any.whl Python 3 none any Details for mcp_policy_lint-0.3.0-py3-none-any.whl

Total release size: 67.6 kB

Release files / mcp_policy_lint-0.3.0.tar.gz

Download URL mcp_policy_lint-0.3.0.tar.gz
Size 36.2 kB
Tags Source
SHA-256 checksum
How to use checksums
eaf1756a519761d3534632bfe1f6b52b52004b804db9918c839bfc546ef8d12e
BLAKE2b-256 checksum
How to use checksums
e29384fa6064645939a2728c4fdddbe97dfc160c0eb8d3486681e0a3f5820d4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.7

Release files / mcp_policy_lint-0.3.0-py3-none-any.whl

Download URL mcp_policy_lint-0.3.0-py3-none-any.whl
Size 31.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b0ed90fd03a43547cd5e5870b6622ee6267619547dcb320f27c9257cf98aae17
BLAKE2b-256 checksum
How to use checksums
12b56b81b42a001d864b26ef26b6a3d5dc8b87ec5af40ca77852ddf09e1356dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.7

Security for mcp-policy-lint 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page