MCP Server Configuration with Embedded Secret
Detects Model Context Protocol (MCP) server configuration files that hold a secret in plain text: an API key, token or password in a server's env block, or a bearer token or API key in its headers. These files (claude_desktop_config.json, .mcp.json, ~/.claude.json, .cursor/mcp.json, .vscode/mcp.json and similar) tell an AI client which tool servers to start and how to authenticate to them, are often committed or shared, and were collected by infostealers and npm supply-chain worms in 2026. A config that references a variable (${VAR}, ${env:NAME}, ${input:id}) or carries no secret does not match. This pattern finds stored secrets; ai-mcp-connector-risk covers over-broad scope wording.
- Type
- regex
- Engine
- boost_regex
- Confidence
- medium
- Confidence justification
- Medium confidence. The mcpServers schema (command, args and env for local servers; type, url and headers for remote ones) is documented by the Model Context Protocol project, Claude Code, Cursor and VS Code, and a literal value under a secret-named key inside that structure is almost always a real credential. The value itself is an opaque string with no fixed format, so the regex cannot validate it, and the same member names appear in other JSON configuration. Enforce tiers therefore require MCP context as well as the secret-shaped member.
- Jurisdictions
- global
- Regulations
- Criminal Code Act 1995 (Cth), Computer Fraud and Abuse Act, Computer Misuse Act 1990
- Frameworks
- CIS Controls, ISO 27001, NIST CSF, SOC 2
- Data categories
- credentials, security
- Scope
- narrow
- Risk rating
- 8
- Platform compatibility
- Purview: Compatible, GCP DLP: Unsupported, Macie: Unsupported, Zscaler: Compatible, CrowdStrike DLP: Unsupported, Palo Alto: Unsupported, Netskope: Unsupported
Pattern
(?i)("[A-Za-z0-9_]{0,60}(?:API_?KEY|ACCESS_KEY|SECRET_KEY|PRIVATE_KEY|AUTH_KEY|TOKEN|SECRET|PASSWORD|PASSWD)"\s*:\s*"(?![<$/~.]|[^"]{0,40}(?:your|xxxx|\*{3}|redacted|placeholder|changeme))[^"\s$<>{}]{12,}")
Corroborative evidence keywords
mcpServers, mcp.json, claude_desktop_config.json, @modelcontextprotocol/, env, headers, Authorization
Proximity: 3000 characters
Should match
"BRAVE_API_KEY": "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"— Exact 65 probe - secret-named JSON member with no MCP context{ "mcpServers": { "brave-search": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-brave-search"], "env": { "BRAVE_API_KEY": "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345" } } } }— Exact 85 probe - pretty-printed local (stdio) server with an API key in env{ "mcpServers": { "tracker": { "type": "http", "url": "https://tracker.internal.corp/mcp", "headers": { "Authorization": "Bearer ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef0123456789" } } } }— Exact 85 probe - pretty-printed remote server with a bearer token in headers{"mcpServers":{"search":{"type":"sse","url":"https://search.internal.corp/sse","headers":{"X-API-Key":"0123456789ABCDEFGHIJKLMNOPQRSTUV"}}}}— Exact 85 probe - compact JSON with an X-API-Key header{"servers": {"issues": {"type": "http", "url": "https://issues.internal.corp/mcp", "headers": {"Authorization": "Bearer ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef0123456789"}}}}— Exact 75 probe - VS Code mcp.json, which uses a servers key; the /mcp endpoint supplies the context"github": {"command": "npx", "args": ["-y", "@modelcontextprotocol/server-github"], "env": {"GITHUB_PERSONAL_ACCESS_TOKEN": "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef0123456789"}}— Exact 75 probe - a later server entry, out of range of the mcpServers key, with a package marker{"mcpServers": {"wiki": {"command": "wiki-bridge", "args": ["--header", "Authorization: Bearer ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef0123456789"]}}}— Exact 85 probe - header passed to the server as a command argument
Should not match
{"mcpServers": {"filesystem": {"command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/username/Desktop"]}}}— MCP configuration with no secret values{"mcpServers": {"api-server": {"type": "http", "url": "https://api.internal.corp/mcp", "headers": {"Authorization": "Bearer ${API_KEY}"}}}}— Claude Code variable expansion in a header, not a stored secret{"mcpServers": {"local-tools": {"command": "python", "args": ["server.py"], "env": {"API_KEY": "${env:MY_API_KEY}"}}}}— Cursor ${env:NAME} interpolation in env{"servers": {"tools": {"type": "stdio", "command": "npx", "args": ["-y", "mcp-server-tools"], "env": {"API_KEY": "${input:api-key}"}}}}— VS Code ${input:id} reference in env{"mcpServers": {"brave-search": {"command": "npx", "env": {"BRAVE_API_KEY": "YOUR_API_KEY_HERE"}}}}— Upper-case placeholder left in a copied configuration{"mcpServers": {"events": {"type": "ws", "url": "wss://events.internal.corp/mcp", "headers": {"Authorization": "Bearer YOUR_TOKEN"}}}}— Placeholder bearer value as printed in client documentation{"mcpServers": {"db": {"command": "uvx", "args": ["mcp-server-sqlite"], "env": {"DB_PATH": "/var/lib/app/data.sqlite", "LOG_LEVEL": "debug", "API_TOKEN_FILE": "/run/secrets/api-token", "VAULT_TOKEN": "/run/secrets/vault-token"}}}}— Env values that are file paths, including one under a secret-named key{"service": {"API_KEY": "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"}}— Secret-named member in JSON with no MCP context (discovery only)Tutorial: {"mcpServers": {"brave-search": {"command": "npx", "env": {"BRAVE_API_KEY": "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"}}}}— Complete configuration with a literal key, vetoed on every tier by the tutorial framing
Known false positives
- Documentation and README snippets that show an MCP configuration with an invented key that is not one of the recognised placeholder forms. Mitigation: The regex rejects values containing your, xxxx, starred runs, redacted, placeholder or changeme, and values that start with $ or <; the shared template exclusion vetoes tutorial and documentation framing. Review remaining hits against the named service.
- Secret-named members whose value is not a secret, such as a long non-path identifier under a key ending in TOKEN. Mitigation: Values that start with /, ~ or a dot (file paths) are rejected and the value must be at least 12 characters. Confirm remaining hits with the server's owner.
- Other JSON configuration that pairs a secret-named member with a nearby /mcp path or mcp-server string. Mitigation: That text still stores a secret in configuration. The 85 tier requires the mcpServers object and a server entry field, which separates genuine MCP client files from incidental matches.
References
- Model Context Protocol docs, Connect to local MCP servers (claude_desktop_config.json; mcpServers with command, args and an env block holding an API key)
- Claude Code docs, MCP (.mcp.json and ~/.claude.json; type, url and headers for remote servers; Authorization Bearer and X-API-Key headers; ${VAR} expansion in command, args, env, url and headers)
- Cursor docs, MCP (.cursor/mcp.json with mcpServers; env and headers; ${env:NAME} interpolation; keep secrets out of the file)
- VS Code docs, MCP configuration reference (servers key in mcp.json; env and headers; ${input:id} for secrets; do not store literal credentials)
- StepSecurity, ChainDrop npm worm, 4 August 2026 (lists AI-tool configuration files, including .claude.json and an mcp.json, among those harvested)
- SpyCloud, 30 October 2026 (infostealers taking tokens for connected MCP servers)