Zero-Secret mcp.json Hardening: Eliminating Plaintext API Key Leaks in AI IDEs
How developers accidentally leak sk-ant, ghp_, and production PostgreSQL URIs inside .cursor/mcp.json—and how to enforce secret-free manifests.
Executive Architecture Summary (TL;DR)
Workspace-level .cursor/mcp.json and .vscode/mcp.json files are frequently committed to Git repositories with hardcoded env credentials. Production teams must replace literal secrets with environment variable interpolation, OS keyring wrappers, and pre-commit schema linting.
Thousands of public repositories accidentally expose live Stripe, GitHub, and database credentials inside committed .cursor/mcp.json manifests. Even when repositories are private, feeding raw credentials into workspace files allows prompt-injected filesystem tools to exfiltrate keys.
1. Enforcing Environment Interpolation & Wrapper Scripts
Instead of embedding sk-live-... inside JSON env blocks, reference host-injected variables (${STRIPE_RESTRICTED_KEY}) or invoke a keychain wrapper such as 1password-cli or HashiCorp Vault leases. Validate every config before committing using the SyndiPath mcp.json Security Auditor.
2. Isolating Prompt Injection Blast Radius
Combine secret-free manifests with read-only database roles and strict domain egress rules, following threat models analyzed in NeuroBulletin's AI safety and cognitive security digests.
Production Benchmark & Trade-off Matrix
| Engineering Dimension | Naive Setup | Hardened Production Pattern | Impact |
|---|---|---|---|
| Secret Storage | Plaintext env in .cursor/mcp.json | OS Keyring / ${ENV_VAR} interpolation | Eliminates Git leaks |
| Package Pinning | npx -y unpinned@latest | Exact semver + SHA-512 lock verification | Blocks supply-chain hijack |
| Database Privilege | Superuser postgres DSN | Read-only role + 5s statement_timeout | Zero destructive SQL risk |
Frequently Asked Technical Questions
Can an LLM read the env block of its own MCP server?
Not via the MCP protocol itself, unless a filesystem MCP tool is simultaneously granted read access to ~/.cursor/mcp.json or the project root without secret-file denylists.
Why is npx @latest risky in MCP configs?
Auto-installing @latest executes arbitrary upstream postinstall scripts on every IDE restart; pinning exact versions prevents sudden typosquatting or compromised minor releases.