MCP Server Security Gateway: Injection, PII & Access Control

    by Hardik Bahri

    1

    Secure MCP tool servers with role-based access, prompt injection filtering, and PII redaction.

    Free

    Security scanned

    Works with the AI Agents you already use

    MCP Server Security Gateway: Injection, PII & Access Control

    Example session with this skill installed

    Secure the "complaints" MCP server in my .mcp.json with MCP Guard. The agent only triages complaints: it must not email customers or run database reports, and I want every tool call logged.

    • Read your context and instructions
    • Compiled the mcp server security
    • Generated the document

    Summary

    The complaints server now runs behind MCP Guard. Your agent can use 3 of its 5 tools; notify_customer and run_report are hidden and blocked, and every decision is written to audit.jsonl.

    What I did

    1. Installed the gateway: pip install mcp-guard-gateway
    2. Generated a starter policy, leaving out the two tools you don't want:
      mcp-guard init --upstream "python -m complaints.mcp_server" --exclude notify_customer,run_report
    3. Reviewed it with you and tightened the limits:
    roles:
      agent: [classify_complaint, search_similar_complaints, flag_for_review]
    users:
      my-agent: [agent]
    
    # Excluded at init, so hidden and blocked: notify_customer, run_report
    tools:
      search_similar_complaints:
        args:
          text: {max_length: 5000}     # was 10000
          k: {min: 1, max: 5}          # was unlimited
          product: {max_length: 200}
        on_injection_in_args: alert    # complaint text is customer-written
        on_injection_in_result: redact # planted instructions are cut from results
        redact_pii_in_result: true
        max_calls_per_session: 20
    pins:
      search_similar_complaints: a429ec3d...   # a later change to the tool hides it
    
    1. Validated it: mcp-guard check --upstream ... -> 0 error(s), 2 warning(s) (both warnings confirm the excluded tools stay blocked).
    2. Backed up .mcp.json to .mcp.json.bak, then pointed the entry at the gateway, with your approval:
    "complaints": {
      "command": "mcp-guard", "args": ["proxy"],
      "env": {
        "MCP_GUARD_UPSTREAM": "python -m complaints.mcp_server",
        "MCP_GUARD_POLICY": "/repo/mcp-guard.yaml",
        "MCP_GUARD_USER": "my-agent",
        "MCP_GUARD_AUDIT_LOG": "/repo/audit.jsonl"
      }
    }
    

    Verified

    • After a restart, the agent lists 3 tools; notify_customer and run_report are gone.
    • A test call to search_similar_complaints with k: 50 was refused: [mcp-guard] blocked call to search_similar_complaints: 50 is outside [1, 5] [ASI02].
    • audit.jsonl has one JSON line per decision (mcp_guard.decision, mcp_guard.tool, user.name).

    Next steps

    • Keep mcp-guard.yaml in git and run mcp-guard check in CI.
    • If you install third-party MCP servers, consider the sandbox: section (no network, read-only, non-root).

    mcp-server-security-gateway-injection-pi.pdf

    PDF · document

    Generated

    Example file from a real run - the skill writes it into your workspace.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Exposing an agent to untrusted tool servers or external data sources invites prompt injection, PII leaks, and runaway sessions. This skill implements a security gateway between your agent and its MCP tool servers to enforce least-privilege access and content safety.

    What it does

    • Role-Based Access Control restricts agents to a specific subset of tools, blocking and hiding unlisted ones by default.
    • Injection Detection identifies and strips planted instructions from tool arguments and results before they reach the agent.
    • Data Redaction prevents PII and secrets from leaving the environment through external tools like email or API uploaders.
    • Argument Contracts enforces strict schemas for tool calls, including character lengths, numeric ranges, and enums.
    • Tool Pinning prevents "rug pull" attacks by disabling tools if their description or schema changes after your initial review.
    • Audit Logging generates JSON Lines logs mapped to the OWASP Top 10 for Agentic Applications for compliance and debugging.

    How it works

    1. Environment Setup installs the gateway and locates your current MCP client configuration files.
    2. Policy Initialization scans the upstream server to generate a starter YAML policy with default-deny rules.
    3. Security Review walks through tool roles, egress points, and call budgets to tighten the configuration.
    4. Validation runs a check against the policy to fix schema errors or insecure defaults.
    5. Gateway Activation updates the client config to proxy tool traffic through the secured gateway.

    Frameworks & tools

    This tool requires Python 3.11 or higher and integrates with any MCP-compliant client. It supports local stdio servers, remote HTTP servers, and optional Docker sandboxing for untrusted local packages.

    Why this beats prompting it yourself

    Standard system prompts cannot physically block a tool call or redact text once it enters the context window. This skill operates at the protocol layer, providing a hard boundary that functions even if the agent is fully compromised by an injection.

    Use cases

    • Secure a third-party MCP server that requires local execution.
    • Prevent PII from being sent to external notification or messaging tools.
    • Limit a specific agent's permissions to read-only tools in a production database.
    • Monitor and log all agent tool interactions for security auditing.

    Known limitations

    Detection is rule-based and may not catch all reworded or translated injections. It secures the MCP traffic channel but cannot inspect the internal operations of a remote server.

    Open source

    MCP Guard itself is free and open source (MIT), installed with pip install mcp-guard-gateway. This skill is the guided setup on top of it.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Free to use

    No account required to browse

    Trust & safety

    Security scan

    Security scan passed 7 days ago

    • Free with an Agensi account

    Software
    Python 3.11+Guard Gateway MCP
    Optional
    Docker (only for the optional sandbox)

    Permissions

    Terminal / Shell
    Read Files
    Write Files
    Network Access

    Terminal: installs MCP Guard with pip and runs mcp-guard init / check. Read/write files: reads the MCP client config and writes mcp-guard.yaml; it backs up and asks before editing the client config. Network: pip install and connecting to the user's own MCP server.

    Listed7 days ago

    What's inside

    Creator

    Hardik Bahri

    Hardik Bahri

    Frequently Asked Questions

    MCP Guard acts as a security middleware that intercepts traffic between your agent and its tools, providing physical barriers like PII redaction and tool-blocking that system prompts alone cannot enforce.

    The skill runs in agents that can run shell commands and edit files, such as Claude Code, Cursor, Codex CLI and VS Code Copilot. The gateway it sets up then protects any MCP client, including Claude Desktop, for both local (stdio) and remote (HTTP) MCP servers.

    Yes, if the database's MCP server exposes reads and writes as separate tools: the skill helps you grant only the read tools to the agent's role, and the write tools are hidden and blocked. MCP Guard works per tool, so it cannot tell a read from a write inside a single 'run any SQL' tool; for that, use a read-only database user.

    The skill uses a rule-based engine and argument contracts to identify common injection patterns and schema deviations, though it is recommended to use it alongside robust model-side safety settings for defense-in-depth.

    The skill: SKILL.md plus reference guides for every policy setting, where each MCP client keeps its config, and troubleshooting. MCP Guard itself is free and open source (MIT), installed from PyPI as mcp-guard-gateway.

    New in Security

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Security.

    Free