MCP Server Security Gateway: Injection, PII & Access Control
by Hardik Bahri
Secure MCP tool servers with role-based access, prompt injection filtering, and PII redaction.
Free
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
- Installed the gateway:
pip install mcp-guard-gateway - 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 - 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
- Validated it:
mcp-guard check --upstream ...->0 error(s), 2 warning(s)(both warnings confirm the excluded tools stay blocked). - Backed up
.mcp.jsonto.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_customerandrun_reportare gone. - A test call to
search_similar_complaintswithk: 50was refused:[mcp-guard] blocked call to search_similar_complaints: 50 is outside [1, 5] [ASI02]. audit.jsonlhas one JSON line per decision (mcp_guard.decision,mcp_guard.tool,user.name).
Next steps
- Keep
mcp-guard.yamlin git and runmcp-guard checkin 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
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
- Environment Setup installs the gateway and locates your current MCP client configuration files.
- Policy Initialization scans the upstream server to generate a starter YAML policy with default-deny rules.
- Security Review walks through tool roles, egress points, and call budgets to tighten the configuration.
- Validation runs a check against the policy to fix schema errors or insecure defaults.
- 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
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
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 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: 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.
What's inside
Creator
Hardik Bahri
Frequently Asked Questions
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.