Field Guide
MCP Security Best Practices: The 2026 Field Guide
MCP gives AI agents direct tool access. That access is an attack surface. This is the definitive reference for securing it — from authentication to audit logging, mapped against the OWASP MCP Top 10.
Updated March 2026 · ~12 min read
The Landscape
MCP Is Not an API. Stop Treating It Like One.
Traditional API security assumes human-driven, stateless requests. MCP traffic is fundamentally different: it is autonomous, multi-turn, and semantically rich. An AI agent does not just call endpoints — it reasons about tool descriptions, chains calls together, and acts on returned data without human review.
This means your threat model must account for behaviours that API security never anticipated. An agent might be tricked into calling a destructive tool through prompt injection in a seemingly benign tool response. A malicious MCP server might embed exfiltration instructions in its tool descriptions. A compromised server might change its tool schemas after initial trust is established.
WAFs, rate limiters, and API gateways are necessary but insufficient. MCP security requires a semantic layer that understands what an agent is doing and whether the data flowing through tool calls contains threats.
Layer 1
Authentication and Authorization
Every MCP connection must be authenticated. The MCP specification supports OAuth 2.1 with PKCE for remote servers, but many deployments still rely on static API keys passed as environment variables. This is the single most common misconfiguration we see in production.
Use short-lived tokens. OAuth 2.1 access tokens with 15-minute expiry and refresh token rotation. Never pass long-lived secrets as tool arguments — they end up in logs, in LLM context windows, and in training data.
Implement per-tool authorization. Not every agent needs access to every tool on a server. Use scoped tokens or role-based policies that restrict which tools an agent can discover and invoke. The MCP spec does not enforce this — you must build it at the gateway layer.
Validate both directions. Agents should authenticate to servers, but servers should also present verifiable identity to agents. Mutual TLS or signed server manifests prevent server impersonation attacks (OWASP MCP-05).
Layer 2
Sandboxing and Isolation
Every MCP server is third-party code executing on your infrastructure. Treat it with the same suspicion as a downloaded binary from an unknown source — because that is exactly what it is.
Container isolation is the minimum. Run each MCP server in its own Docker container with a read-only filesystem, no-new-privileges, and dropped capabilities. Network access should be explicitly allowlisted per server.
For higher assurance, use gVisor or Firecracker. gVisor intercepts syscalls through a user-space kernel, preventing container escapes. Firecracker provides full microVM isolation with sub-125ms boot times. Both are production-proven at scale.
CVE-2025-6514 demonstrated why this matters: a popular MCP server (437K downloads) contained an RCE vulnerability with a CVSS score of 9.6 that enabled data exfiltration. Without sandboxing, that vulnerability gave attackers full host access. With proper container isolation, the blast radius was limited to that single server's sandbox.
See our dedicated guide: Why You Should Sandbox Every MCP Server
Layer 3
Input Validation and Schema Enforcement
MCP tool calls carry structured JSON arguments. These arguments are generated by an LLM, which means they can contain anything — including payloads that exploit downstream systems. SQL injection, command injection, path traversal, and SSRF are all possible through agent-generated tool arguments.
Validate against JSON Schema at the gateway. Every tool declares an input schema. Enforce it before the call reaches the server. Reject arguments that do not match declared types, exceed length limits, or contain unexpected fields.
Scan for injection patterns. Beyond schema validation, inspect string arguments for SQL injection markers, shell metacharacters, path traversal sequences (../), and SSRF-indicative URLs (internal IPs, metadata endpoints). This catches attacks that are syntactically valid JSON but semantically malicious.
Validate tool responses too. Prompt injection often arrives through tool responses, not tool arguments. A database query might return a row containing hidden instructions. A web scraper might return a page with injected prompts. Scan both directions.
Layer 4
Data Loss Prevention
Agents interact with sensitive data constantly. They read files containing API keys, query databases with PII, and pass results between tools. Without DLP scanning, any of this data can leak through tool arguments, log entries, or LLM context that gets persisted.
Scan for secrets in every payload. AWS keys, GitHub tokens, database connection strings, private keys. Use regex-based detection with entropy analysis for high-entropy strings that match no known pattern. We scan for 90+ secret types at mistaike.ai.
Detect PII across regions. Names, emails, phone numbers, national IDs, credit card numbers, health records. PII detection must be locale-aware — a UK National Insurance number looks nothing like a US SSN. We detect 35+ PII entity types across 5 regulatory regions.
Block or redact, do not just log. Detection without enforcement is security theatre. When a tool call contains a leaked secret, block the call and return a structured error. When a response contains PII that violates policy, redact it before the agent sees it.
Layer 5
Audit Logging and Observability
If you cannot see what your agents are doing, you cannot secure them. Audit logging is not optional — it is a compliance requirement for any regulated industry and a debugging necessity for everyone else.
Log every tool call and response. Include the agent identity, the tool name, the arguments (with secrets redacted), the response status, scan results, and latency. This creates a complete execution trail that supports both security investigation and operational debugging.
Structured logs, not strings. JSON-formatted logs with consistent field names enable aggregation in your SIEM. Include correlation IDs that span the full agent session — from initial prompt to final tool call. This lets you reconstruct attack chains.
Alert on anomalies. Unusual tool call patterns, spikes in blocked requests, new tools being discovered, schema changes on known servers. These are early indicators of compromise. Feed your MCP audit logs into your existing alerting pipeline.
Reference
OWASP MCP Top 10 — Quick Mapping
Each OWASP MCP category maps to one or more of the defence layers above. For the full breakdown with mitigations, see The OWASP MCP Top 10 Explained.
Checklist
MCP Security Checklist
Use this as a pre-deployment review. Every item should be verified before exposing MCP servers to production agent traffic.
Authentication
- ☐OAuth 2.1 with PKCE for remote MCP servers — API keys with rotation as a simpler alternative
- ☐Short-lived access tokens (15 min max)
- ☐Refresh token rotation enabled
- ☐Rotate API keys regularly — prefer OAuth where supported
- ☐Mutual TLS or signed manifests for server identity
- ☐Per-tool scoped authorization policies
Sandboxing
- ☐Each MCP server runs in its own container
- ☐Read-only filesystem enabled
- ☐No-new-privileges flag set
- ☐Network access explicitly allowlisted
- ☐Non-root user in container
- ☐Resource limits (CPU, memory, disk) configured
Input Validation
- ☐JSON Schema validation on all tool arguments
- ☐String length limits enforced
- ☐SQL injection pattern scanning
- ☐Command injection detection
- ☐Path traversal prevention
- ☐SSRF-indicative URL blocking
- ☐Tool response scanning for prompt injection
Data Loss Prevention
- ☐Secret scanning on all payloads (both directions)
- ☐PII detection with locale-aware rules
- ☐Block mode enabled (not just detect)
- ☐Redaction for PII in responses
- ☐High-entropy string analysis
Audit and Monitoring
- ☐Structured JSON logs for all tool calls
- ☐Correlation IDs across agent sessions
- ☐SIEM integration configured
- ☐Anomaly alerting on tool call patterns
- ☐Schema change detection on connected servers
- ☐Retention policy meets compliance requirements
Start Scanning MCP Traffic Today
mistaike.ai implements all five security layers as an inline MCP proxy. One endpoint change, full defence-in-depth.