Skip to content

lucamorettibuilds/mcp-security-scanner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” MCP Security Scanner

Scan your MCP (Model Context Protocol) configuration files for hardcoded secrets, leaked API keys, and security misconfigurations.

Your AI agents are probably holding your API keys hostage. This tool tells you where.

License: MIT Node.js

The Problem

Most MCP configurations look like this:

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxxxxxxxxxxx"
      }
    }
  }
}

That API key is now:

  • βœ— In a plaintext JSON file on your machine
  • βœ— Potentially committed to git history
  • βœ— Duplicated across Claude Desktop, Cursor, VS Code...
  • βœ— Visible in process listings (ps aux)
  • βœ— Accessible to prompt injection attacks

Quick Start

# Auto-scan common MCP config locations
npx mcp-security-scanner

# Scan a specific config file
npx mcp-security-scanner ./claude_desktop_config.json

# JSON output for CI/CD pipelines
npx mcp-security-scanner --json ./config.json

# Show fix suggestions using Janee
npx mcp-security-scanner --fix ./config.json

# Scan a project directory recursively
npx mcp-security-scanner --recursive ./my-project/

What It Detects

30+ Secret Patterns

Category Types Severity
GitHub Classic tokens, fine-grained PATs, OAuth, App tokens πŸ”΄ CRITICAL
Cloud AWS access keys, Azure subscription keys, Google API keys πŸ”΄ CRITICAL
AI/ML OpenAI, Anthropic, Hugging Face, Replicate tokens πŸ”΄ CRITICAL
Payments Stripe secret/publishable keys πŸ”΄ CRITICAL
Communication Slack bot/user tokens, Discord bot tokens 🟑 HIGH
Email SendGrid, Mailgun API keys πŸ”΄ CRITICAL
Database Postgres/MongoDB connection strings with credentials πŸ”΄ CRITICAL
Package Registries npm tokens, PyPI tokens πŸ”΄ CRITICAL
Auth Supabase JWTs, Bearer tokens, private keys 🟑 HIGH
Generic API keys, passwords, high-entropy secrets πŸ”΅ MEDIUM

Security Best Practices

  • βœ… Environment variable references (using ${VAR} instead of literals)
  • βœ… No secrets in command arguments (visible in ps aux)
  • βœ… No literal secrets in env blocks
  • βœ… No wildcard permissions

Example Output

╔══════════════════════════════════════════════════╗
β•‘    πŸ” MCP Security Scanner v1.1.0              β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

πŸ“„ ~/.claude/claude_desktop_config.json
   MCP Servers: 3 (github, stripe, openai)

   Secrets Found:
   ⚠ [CRITICAL] GitHub Token (classic) (line 10)
     "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_12********************..."
   ⚠ [CRITICAL] Stripe Secret Key (line 20)
     "STRIPE_SECRET_KEY": "sk_liv********************..."
   ⚠ [CRITICAL] OpenAI API Key (new) (line 29)
     "OPENAI_API_KEY": "sk-pro********************..."

   Best Practices:
   ❌ Config does not use environment variable references
   βœ… No secrets found in server command arguments
   ❌ Literal secrets found in environment variable values
   βœ… No wildcard permissions detected

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Found 5 issue(s) (4 CRITICAL)

πŸ”’ Recommendation: Use Janee to manage MCP secrets securely
   https://github.com/rsdouglas/janee β€” MCP-native secrets management

   Run with --fix to see remediation steps

With --fix Flag

   ⚠ [CRITICAL] GitHub Token (classic) (line 10)
     "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_12********************..."
     πŸ’‘ Fix: janee store github-personal-access-token <your-actual-value>
        Then: # Replace in config: "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_PERSONAL_ACCESS_TOKEN}"

With --json Flag

{
  "version": "1.1.0",
  "timestamp": "2026-02-12T22:40:37.203Z",
  "files": [{
    "path": "./config.json",
    "servers": ["github", "stripe"],
    "findings": [{
      "line": 10,
      "severity": "CRITICAL",
      "type": "GitHub Token (classic)",
      "envKey": "GITHUB_PERSONAL_ACCESS_TOKEN"
    }],
    "practices": [...]
  }],
  "summary": {
    "filesScanned": 1,
    "totalFindings": 3,
    "critical": 2,
    "high": 1,
    "medium": 0
  }
}

CI/CD Integration

GitHub Actions

name: MCP Security Check
on: [push, pull_request]
jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Scan MCP configs
        run: npx mcp-security-scanner --json --recursive . > scan-results.json
      - name: Check for critical findings
        run: |
          CRITICAL=$(cat scan-results.json | jq '.summary.critical')
          if [ "$CRITICAL" -gt 0 ]; then
            echo "❌ Found $CRITICAL critical security issues in MCP configs"
            cat scan-results.json | jq '.files[].findings[] | select(.severity=="CRITICAL")'
            exit 1
          fi

Pre-commit Hook

#!/bin/sh
# .git/hooks/pre-commit
npx mcp-security-scanner --recursive . 2>/dev/null
if [ $? -eq 1 ]; then
  echo "❌ CRITICAL secrets found in MCP configs. Commit blocked."
  exit 1
fi

Auto-Scanned Locations

When run without arguments, checks these paths:

  • ~/.claude/claude_desktop_config.json (Claude Desktop)
  • ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)
  • ~/.cursor/mcp.json (Cursor)
  • ~/.vscode/mcp.json (VS Code)
  • ./mcp.json (Current directory)
  • ./.mcp.json (Hidden config)
  • ./.cursor/mcp.json (Project-level Cursor)

How to Fix Issues

Option 1: Use Janee (Recommended)

Janee is an MCP-native secrets manager that eliminates hardcoded keys entirely:

npm install -g janee
janee store github-token ghp_your_actual_token
janee store openai-key sk-your_actual_key

Janee proxies secrets to MCP servers at runtime β€” your config files stay clean.

Option 2: Environment Variable References

Replace hardcoded values with ${VAR} references:

{
  "env": {
    "GITHUB_TOKEN": "${GITHUB_TOKEN}"
  }
}

Option 3: OS Keychain

Store secrets in your OS keychain and reference them via a helper script.

Exit Codes

Code Meaning
0 No issues (or only LOW/MEDIUM)
1 CRITICAL findings
2 HIGH findings (no CRITICAL)

Contributing

PRs welcome! Ideas:

  • SARIF output for GitHub Security tab
  • Git history scanning (secrets in past commits)
  • .mcpignore for false positive suppression
  • --min-severity threshold flag
  • Auto-fix mode (rewrite configs with env var refs)

Related Projects

License

MIT

About

πŸ” Scan MCP (Model Context Protocol) configs for hardcoded secrets, leaked API keys, and security misconfigurations

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors