MCP Security Best Practices for Production Agents
MCP Security Best Practices for Production Agents
Model Context Protocol adoption is accelerating. By mid-2026, MCP will likely be the default way agents interact with external systems. This creates new attack surfaces that most implementations ignore.
The Four-Pillar Framework
Production MCP deployments need security across four dimensions:
Access Controls: Define ACLs per tool. Not every agent needs every capability. An agent that queries a database shouldn't also be able to delete records. Enforce this at the schema level, not just through prompting.
Progressive Authorization: Start with minimal scopes. Elevate privileges only when needed, and require explicit challenges for sensitive operations. An agent should earn trust incrementally, not receive blanket permissions at startup.
Session Management: Bind sessions to user identity. Use unpredictable IDs, enforce rotation, and set aggressive expiration. Sessions that persist indefinitely become targets.
Rate Limiting: Cap both request frequency and total operations per session. This protects against both abuse and runaway loops where agents consume resources without bounds.
Schema Validation
Every MCP tool needs strict input validation:
{
"name": "query_database",
"parameters": {
"type": "object",
"properties": {
"table": {
"type": "string",
"enum": ["users", "orders", "products"]
},
"limit": {
"type": "integer",
"minimum": 1,
"maximum": 100
}
},
"required": ["table"]
}
}
The enum constraint above prevents SQL injection through table name manipulation. The limit bounds prevent resource exhaustion. Schemas are your first line of defense.
Context Management
MCP enables rich context passing between tools. This creates drift risk: irrelevant context accumulates, tokens get wasted, and agents make decisions based on stale information.
Strategies that work: - Retain only the last N tool results (typically 3-5) - Extract key metadata, discard verbose outputs - Clear context on topic boundaries - Log context state for debugging
What MCP Isn't For
MCP excels at real-time, targeted queries. It's designed for context-aware chatbots and automation workflows.
It's poorly suited for: - Batch analytics - Large dataset processing - Operations that span thousands of records
For these, use traditional APIs. MCP overhead per call makes bulk operations expensive.
Security Checklist
Before deploying an MCP server to production:
- [ ] All inputs validated against JSON Schema
- [ ] Invalid POST requests return errors, not defaults
- [ ] CSRF protection on endpoints that modify state
- [ ] Iframe embedding blocked (X-Frame-Options)
- [ ] Rate limits implemented with exponential backoff
- [ ] Session tokens rotated on privilege changes
- [ ] Logging captures tool invocations with redacted parameters
Implementation Notes
Most MCP vulnerabilities come from three sources:
- Over-permissive tool definitions - Tools that can do more than documented
- Missing input validation - Trusting agent-provided parameters
- Context leakage - Sensitive data persisting across sessions
Address these three and you've eliminated the majority of risk surface.
References: modelcontextprotocol.io, Red Hat MCP Security Guide, Palo Alto Networks MCP Vulnerabilities Guide, CData MCP Best Practices 2026