# MCP Server Security Gateway: Injection, PII & Access Control

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

MCP Server Security Gateway: Injection, PII & Access Control is a free AI agent skill on Agensi by Hardik Bahri, in Security. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [Hardik Bahri](https://www.agensi.io/creators/hardik-bahri)
- Category: [Security](https://www.agensi.io/skills/security)
- Version: 1.0
- Last updated: 2026-11-28
- Security: scan passed (2026-11-28); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/mcp-server-security-gateway-injection-pii-access-control
- Tags: security, llm-ops, mcp-server, python, audit-logging

## 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.

## Requires

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

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the MCP Server Security Gateway: Injection, PII & Access Control skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### How does MCP Guard provide better security than just using a system prompt?

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.

### Which AI agents can I use this skill with?

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.

### Can I use this to limit an agent to read-only access on a production database?

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.

### Does the injection filtering protect against all types of prompt injection?

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.

### What exactly is included in the purchase of this skill?

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.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
