Skip to main content Switch to mobile version mcp-guard-gateway 0.2.0 Inline security gateway for AI agents and MCP tool servers: RBAC, prompt-injection and tool-misuse checks, DLP redaction, SIEM-ready audit logs.
pip install mcp-guard-gateway Copy PIP instructions
Inline security gateway for AI agents and MCP tool servers. It sits between an agent and its tools and checks every tool listing, call and result, then allows, alerts, redacts, blocks or terminates by policy.
agent mcp-guard (policy + detectors + audit) tool server Either side can be stdio (local processes) or Streamable HTTP (remote): put it in front of a local server, a remote one, or serve a whole team's agents over HTTP.
Built in front of the ComplaintOps triage agent.
Every decision is written as one JSON line with Elastic Common Schema fields (@timestamp, event.*, user.*, rule.*) so a log forwarder can ship it to Elastic, Splunk or Microsoft Sentinel. Values that were redacted are never logged.
Quickstart: put it in front of your MCP server
pip install mcp-guard-gateway # or: pip install git+https://github.com/hardikbahri/mcp-guard # 1. discover your server's tools and write a starter policy (mcp-guard.yaml) mcp-guard init --upstream "python -m your_package.mcp_server" # or --upstream https://host/mcp # 2. review it (every setting: docs/policy.md): split tools into roles, tighten limits, read the REVIEW comments # leave tools out up front with --exclude run_report,notify_customer; then validate mcp-guard check --upstream "python -m your_package.mcp_server" # 3. point your MCP client at the gateway instead of the server (init prints this snippet) { "mcpServers": { "guarded-tools": { "command": "mcp-guard", "args": ["proxy"], "env": { "MCP_GUARD_UPSTREAM": "python -m your_package.mcp_server", "MCP_GUARD_POLICY": "/path/to/mcp-guard.yaml", "MCP_GUARD_USER": "my-agent", "MCP_GUARD_AUDIT_LOG": "/path/to/audit.jsonl" } } } } As an agent skill
skill/mcp-guard/ is a SKILL.md skill that walks a coding agent (Claude Code, Cursor, Copilot and others) through installing MCP Guard, generating and reviewing a policy with the user, and rewiring the client config, asking before each change.
The full policy reference, with every setting, action and environment variable, is docs/policy.md.
init builds the starter policy from the server's own tool schemas: string limits from maxLength, number ranges from minimum/maximum, enums kept. Tools whose names suggest sending data out (email, notify, post, upload, webhook) are marked egress: external with PII redaction, and the recipient field is allowed through. Tools whose names suggest destructive or code-running actions (delete, exec, run, write) get a one-call budget and a REVIEW comment. Every tool is pinned, so mcp-guard check --upstream ... reports a tool whose description or schema has changed.
check explains mistakes in plain language: a role granting a tool with no rules, a user with an undefined role, a tool no role can reach, a misspelt setting, an external tool without PII redaction.
pip install -e ".[dev]" # stdio gateway: point any MCP client at this instead of the real server MCP_GUARD_UPSTREAM="python -m mcp_guard.demo.complaint_server" MCP_GUARD_USER=triage-bot python -m mcp_guard.proxy # in front of a remote MCP server (Streamable HTTP) MCP_GUARD_UPSTREAM="https://tools.example.com/mcp" MCP_GUARD_UPSTREAM_TOKEN=... python -m mcp_guard.proxy # serve agents over HTTP at http://127.0.0.1:8090/mcp MCP_GUARD_UPSTREAM="python -m mcp_guard.demo.complaint_server" MCP_GUARD_JWT_SECRET=... mcp-guard proxy --http --port 8090 # HTTP policy decision point (FastAPI), optional JWT identity via MCP_GUARD_JWT_SECRET mcp-guard api --port 8080 # Docker (published image, or build it yourself) docker run -p 8080:8080 ghcr.io/hardikbahri/mcp-guard:latest docker build -t mcp-guard . && docker run -p 8080:8080 mcp-guard # tests and the attack suite pytest && python attacks/evaluate.py With MCP_GUARD_JWT_SECRET set, the API takes the user from the token's sub (claimed roles are kept only where the policy grants them), a session can only be used with a token for the same user, and /v1/audit needs a token with the audit scope.
CI runs the unit, API, proxy (stdio and HTTP) and attack-suite tests on Python 3.11 and 3.12, then builds the Docker image and checks that the container serves the API as a non-root user and blocks an out-of-role call. A third job builds the sandbox image and runs the compromised-server demo against a real container.
With ComplaintOps: ComplaintAgent(server_module="mcp_guard.proxy") with MCP_GUARD_UPSTREAM="python -m complaintops.mcp_server". In tests, a poisoned similar-complaint result reaches the agent's LLM without the gateway; through it, the planted instruction and the personal data are removed.
Remote servers and HTTP agents
Remote upstream. Set MCP_GUARD_UPSTREAM to a URL and the gateway connects over Streamable HTTP, with MCP_GUARD_UPSTREAM_TOKEN sent as a bearer token. A remote server runs on someone else's machine, so the risk shifts from host compromise to what you send it and what it sends back: the same DLP redaction (for tools marked egress: external), injection removal, RBAC and call budgets apply. The gateway refuses plain http:// to anything but this machine, and upstream_allowed_hosts: [tools.example.com] in the policy pins where tool traffic may go.
HTTP downstream. mcp-guard proxy --http serves MCP over Streamable HTTP. Each agent connection gets its own Guard session (call budget, violation count, termination). With MCP_GUARD_JWT_SECRET set, every request needs a bearer JWT and the user is its sub, so one gateway serves agents with different roles; a session cannot change user mid-way. The gateway refuses to listen beyond localhost without JWT identity.
The checks above see what crosses the MCP boundary. They cannot see what a tool server does inside its own process: a poisoned package or a bad update can read the host's API keys, write files or call out to the internet while its MCP traffic stays perfectly clean. With a sandbox: section in the policy, the gateway starts the tool server in a locked-down container instead of as a local process:
no network (--network none), read-only filesystem, all Linux capabilities dropped, no-new-privileges
non-root user, capped memory, CPU and process count, a small noexec /tmp
only the environment variables the policy names, passed by name so values never appear on a command line
sandbox: enabled: true image: mcp-guard-sandbox:demo network: none memory: 256m pids_limit: 64 env: [] # e.g. [COMPLAINTOPS_DB_URL] mcp_guard/demo/sandbox_demo.py runs the same compromised server (mcp_guard/demo/rogue_server.py) through the gateway twice. Both calls are allowed, because the MCP traffic is harmless; the table shows what the hidden payload managed to do. CI runs it on every push and fails if anything escapes the sandbox. Result from CI (GitHub Actions runner):
docker build -f Dockerfile.sandbox -t mcp-guard-sandbox:demo . python -m mcp_guard.demo.sandbox_demo Without the sandbox, a policy can still limit what an unsandboxed server inherits with upstream_env: [NAME, ...].
Detectors are rule-based and deterministic, so every decision is explainable and testable. The attack suite in attacks/ was written alongside the rules, so it shows coverage, not real-world accuracy; paraphrased or translated injections can get past regex rules. A learned classifier and an external benchmark are next.
Both files in this release have provenance metadata.
MIT View SPDX License List
mcp model context protocol ai agents llm security prompt injection guardrails owasp
Intended Audience Developers
Programming Language Python :: 3
Release files for mcp-guard-gateway 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
Built distribution (wheel)
Total release size: 86.4 kB
Release files / mcp_guard_gateway-0.2.0.tar.gz
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.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Security for mcp-guard-gateway 0.2.0
Both files in this release have been uploaded with provenance metadata.
With provenance mcp_guard_gateway-0.2.0.tar.gz Nov 28, 2026
Attestation for mcp_guard_gateway-0.2.0.tar.gz
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.
Release history Release notifications | RSS feed
Nov 28, 2026 2 release files Full provenance
"PyPI", "Python Package Index", and the blocks logos are registered trademarks of the Python Software Foundation.
© 2026 Python Software Foundation




