Dev.to Security 🔐 Cybersecurity 👁 0 📖 2 min read

How I check my MCP config files for leaked API keys (and unpinned npx servers)

AI coding agents have quietly added a new set of config files to my projects: .mcp.json, .cursor/mcp.json, .claude/settings.json, CLAUDE.md, AGENTS.md. They don't look like code, so they rarely get reviewed like code. Bu

AI coding agents have quietly added a new set of config files to my projects: .mcp.json, .cursor/mcp.json, .claude/settings.json, CLAUDE.md, AGENTS.md. They don't look like code, so they rarely get reviewed like code. But they decide which servers your agent launches, with which credentials, and what it's allowed to touch.

I built a small open-source tool to check them, agentconfig-audit-lite. Full disclosure: I wrote it. It's one Python file, standard library only (3.9+), read-only, MIT, no network calls.

[add your detail: one sentence on what made you build it. Only if it really happened.]

What it looks for

Point it at a project directory:

python3 agentconfig_audit_lite.py ~/code/my-app

Found 3 agent config / rule file(s):
settings .claude/settings.json
mcp .mcp.json
rules CLAUDE.md

3 finding(s):
FAIL [unpinned-server] .mcp.json: server 'github' runs npx @modelcontextprotocol/server-github with no version pin (pin e.g. [email protected] or pkg==1.2.3)
FAIL [plaintext-secret] .mcp.json: server 'github' env GITHUB_PERSONAL_ACCESS_TOKEN = ghp_****(40 chars) (GitHub token)
FAIL [migrations-not-denied] .claude/settings.json: project has a migrations dir but no Edit and Write deny rules for it and no PreToolUse hook

(That's the sample output from the README.)

The five checks:

  • plaintext-secret — known token formats (GitHub, sk- style keys, AWS, Slack, GitLab, Google, Stripe live, Bearer, private keys) in MCP env/headers/args and rule files, plus hardcoded values under names like*_TOKEN or *_PASSWORD. ${VAR} references are fine. Secrets are only ever printed as masked previews.
  • unpinned-server — npx, uvx or bunx MCP servers with no exact version. pkg, pkg@latest and pkg@^1.2 fail; [email protected] and pkg==1.2.3 pass. An unpinned server means every session can run whatever was published most recently.
  • env-not-denied — the project has a real .env and Claude Code settings have no Read(...env...) deny rule and no PreToolUse hook.
  • migrations-not-denied — there's a migrations dir and settings don't deny both Edit and Write on it.
  • secret-in-allow-rule — a token pasted into a permissions.allow rule. This one happens when you approve a command that had a key in it, and the key gets saved into your settings.

The design choice I care about most

A line in CLAUDE.md that says "don't touch .env" is not counted as protection. It's an instruction, not a permission. The agent will usually follow it, but nothing enforces it. Only a deny rule or a hook counts.

The honest limits: lite checks for the presence of a PreToolUse hook but not what the hook does, and JSON-with-comments files can't be parsed by the standard library, so they get a NOTE and a plain-text token scan only.

Using it in CI or cron

Exit codes are boring on purpose: 0 no findings, 1 at least one finding, 2 bad arguments. Configs that live outside the project can be added with --file:

python3 agentconfig_audit_lite.py . --file ~/.cursor/mcp.json --file ~/.claude/settings.json

Try it

pip install agentconfig-audit-lite
agentconfig-audit-lite .

What's in your MCP configs right now? I'm curious which checks people would add next.

Repo: https://github.com/alessio1999xx-debug/agentconfig-audit-lite
GitHub
GitHub - alessio1999xx-debug/agentconfig-audit-lite: Audit MCP config for secret...
Audit MCP config for secrets: plaintext tokens and unpinned npx/uvx servers in .mcp.json and CLAUDE.md. Stdlib, MIT. - alessio1999xx-debug/agentconfig-audit-lite

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.