Security blueprint for auditing MCP servers, enforcing least-privilege command execution, sanitizing path traversal vulnerabilities, and isolating token scope.
Model Context Protocol (MCP) Server Security Hardening & Zero-Trust Audit Guide
Overview
As agents adopt Model Context Protocol (MCP) servers to read databases, execute shell commands, and query APIs, securing these servers against malicious prompts and privilege escalation is paramount.
Security Controls & Audit Checklist
1. Scope Filesystem Boundaries
Never point filesystem MCP servers at root (/) or home (~) directories. Always sandbox to the specific workspace folder:
"args": ["-y", "@modelcontextprotocol/server-filesystem", "./project-sandbox"]
2. Enforce Read-Only Database Roles
Create restricted PostgreSQL database users for DB MCP servers:
CREATE USER mcp_agent_reader WITH PASSWORD 'secure_password';
GRANT CONNECT ON DATABASE myapp DB TO mcp_agent_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO mcp_agent_reader;
3. Sanitize Input Arguments Against Command Injection
Ensure shell arguments passed into MCP tools are sanitized and bound to strict parameter arrays rather than string concatenated in bash.