Skip to main content

Security scanner for MCP (Model Context Protocol) server configurations and AI agent tool permissions.

Project description

๐Ÿ”’ MCP-Scan

Security scanner for MCP server configurations and AI agent tool permissions.

Detect dangerous shell commands, exposed API keys, over-permissive file access, high-risk tools, and prompt injection patterns โ€” before they reach production.

PyPI version Python License: MIT CI

Quick Start ยท Example Output ยท Rules ยท Library API ยท Dashboard ยท CI/CD ยท Contributing


๐Ÿšจ The Problem

AI agents are now connecting to tools, files, GitHub, Slack, Gmail, Notion, databases, and internal systems via MCP (Model Context Protocol). This creates serious security risk:

  • ๐Ÿ”“ Unrestricted shell access (bash -c "$USER_INPUT")
  • ๐Ÿ”‘ API keys and tokens hard-coded in configuration files
  • ๐Ÿ“ Over-permissive file system access (/, /etc/shadow, ~/.ssh)
  • ๐Ÿ“ง Tools that can send emails, delete files, or drop database tables with no confirmation
  • ๐Ÿ’‰ Prompt injection patterns that could hijack agent behavior
  • โš ๏ธ Binaries running from untrusted paths (/tmp/Downloads/sketchy-tool)

OWASP now has an MCP Top 10 covering tool poisoning, excessive agency, and context spoofing. GitHub added secret scanning support for MCP workflows. The attack surface is real and growing.

MCP-Scan catches these risks in seconds.


โšก Quick Start

Install

pip install mcp-scan

Scan

mcp-scan scan ./mcp-config.json

That's it. 3 lines.


๐Ÿ“ฅ Example Input

Here's a dangerous MCP configuration:

{
  "mcpServers": {
    "terminal.run": {
      "command": "bash",
      "args": ["-c", "eval $USER_INPUT"],
      "env": {
        "OPENAI_API_KEY": "sk-proj-abc123def456ghi789jkl012mno"
      }
    },
    "gmail.send": {
      "command": "node",
      "args": ["gmail-mcp-server", "--no-confirm"],
      "env": {
        "GMAIL_TOKEN": "ya29.a0AfH6SMBx_FAKE_TOKEN"
      }
    },
    "filesystem": {
      "command": "/tmp/Downloads/sketchy-binary",
      "args": ["/", "/etc/shadow", "/root/.ssh"]
    }
  }
}

๐Ÿ“Š Example Output

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  MCP Security Scan Report                                โ”‚
โ”‚  File: mcp-config.json                                   โ”‚
โ”‚  Version: 0.1.0                                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Findings: 8 HIGH | 3 MEDIUM | 3 LOW  (14 total)        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

 Severity โ”‚ Rule    โ”‚ Server         โ”‚ Message
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 HIGH     โ”‚ MCP-001 โ”‚ terminal.run   โ”‚ Uses dangerous command: "bash"
 HIGH     โ”‚ MCP-002 โ”‚ terminal.run   โ”‚ OpenAI API key exposed in env
 HIGH     โ”‚ MCP-006 โ”‚ gmail.send     โ”‚ High-risk tool: email sending
 HIGH     โ”‚ MCP-008 โ”‚ filesystem     โ”‚ Binary from untrusted path: /tmp/
 MEDIUM   โ”‚ MCP-003 โ”‚ filesystem     โ”‚ Access to sensitive path: /etc/shadow
 MEDIUM   โ”‚ MCP-003 โ”‚ filesystem     โ”‚ Access to sensitive path: /root/.ssh
 LOW      โ”‚ MCP-005 โ”‚ terminal.run   โ”‚ No allowedTools defined

๐Ÿ” Scanning Rules

Rule Name Severity What it catches
MCP-001 Dangerous Shell Commands ๐Ÿ”ด HIGH bash, powershell, eval, sudo, ssh, piped curl
MCP-002 Exposed Secrets ๐Ÿ”ด HIGH OpenAI keys, GitHub PATs, AWS keys, Slack tokens, private keys
MCP-003 Over-permissive Paths ๐ŸŸก MEDIUM /, /etc, ~/.ssh, C:\Windows\System32
MCP-004 Untrusted MCP Server ๐ŸŸก MEDIUM Binaries from /tmp, Downloads, unverified sources
MCP-005 Missing Tool Allowlist ๐Ÿ”ต LOW No allowedTools restriction โ†’ full agent access
MCP-006 High-Risk Tools ๐Ÿ”ด HIGH Email send, file delete, DB write, Slack post without gates
MCP-007 Prompt Injection ๐ŸŸก MEDIUM "Ignore previous instructions", template injection, jailbreaks
MCP-008 Unsafe Binary Execution ๐Ÿ”ด HIGH Executing from /tmp/, Downloads/, .cache/

๐Ÿ Python Library API

Use mcp-scan programmatically in your own tools:

from mcp_scan import scan_config, scan_file, ScanPolicy

# Scan a config dictionary
result = scan_config({
    "mcpServers": {
        "my-server": {
            "command": "bash",
            "args": ["-c", "rm -rf /"]
        }
    }
})

print(result.has_errors)        # True
print(result.highest_severity)  # "HIGH"
print(result.total_findings)    # 3

for finding in result.findings:
    print(f"[{finding.severity}] {finding.rule_id}: {finding.message}")

# Scan with a custom policy
policy = ScanPolicy(
    allowed_commands=["node", "python"],
    trusted_servers=["@modelcontextprotocol/"],
    ignored_rules=["MCP-005"],
)
result = scan_config(config, policy=policy)

# Scan a file directly
result = scan_file("./mcp-config.json")

# Export to SARIF
from mcp_scan import to_sarif_json
print(to_sarif_json(result))

๐ŸŒ Web Dashboard

Start the built-in dashboard:

pip install mcp-scan[server]
mcp-scan serve

Open http://localhost:8000 โ€” paste your config, click Scan Now, and get instant visual results with severity cards, findings table, and SARIF export.


๐Ÿณ Docker

cd docker
docker compose up --build

Dashboard available at http://localhost:8000. Mount your config files:

docker run --rm -v $(pwd):/configs mcp-scan mcp-scan scan /configs/mcp-config.json

โš™๏ธ CI/CD Integration

GitHub Actions

- name: Install mcp-scan
  run: pip install mcp-scan

- name: Scan MCP configs
  run: mcp-scan scan ./mcp-config.json --fail-on HIGH

- name: Upload SARIF (optional)
  run: mcp-scan scan ./mcp-config.json --output sarif > results.sarif
  
- uses: github/codeql-action/upload-sarif@v3
  with:
    sarif_file: results.sarif

The scanner exits with code 1 when HIGH-severity findings are detected, automatically failing your CI pipeline.


๐Ÿ“‹ Custom Scanning Policy

Create mcp-policy.yaml to customize behavior:

trusted_servers:
  - "@modelcontextprotocol/"
  - "npx"

allowed_commands:
  - "node"
  - "python"

ignored_rules:
  - "MCP-005"

max_severity: HIGH
mcp-scan scan ./config.json --policy ./mcp-policy.yaml

๐Ÿ—๏ธ Architecture

Input (CLI / API / Library)
    โ†“
Parser (JSON / YAML โ†’ Pydantic McpConfig)
    โ†“
Engine (8 security rules + policy filtering)
    โ†“
Output (Rich terminal / JSON / SARIF / Dashboard)

See docs/architecture.md for the full architecture diagram and threat model.


๐ŸŽฏ Real Use Cases

  • AI coding agents โ€” Teams using Cursor, Windsurf, or Claude Code with MCP servers need to audit tool permissions before granting agents access to codebases and infrastructure.
  • Enterprise AI deployments โ€” Companies rolling out Claude, GPT, or Gemini with tool use need security gates for email, Slack, database, and file system access.
  • Platform engineering โ€” Platform teams can run mcp-scan in CI/CD to enforce security policies across all MCP configurations in the org.
  • Compliance โ€” Security teams can generate SARIF reports for audit trails and integrate with GitHub Advanced Security.

๐Ÿ—บ๏ธ Roadmap

  • Custom rule engine โ€” Write your own rules in YAML
  • Continuous monitoring โ€” Watch config files for changes and alert
  • Slack/Discord alerts โ€” Send notifications when new risks are found
  • VS Code extension โ€” Inline warnings in your editor
  • MCP runtime analysis โ€” Monitor actual tool invocations at runtime
  • Organization-wide policies โ€” Centralized policy management
  • SBOM integration โ€” Software Bill of Materials for MCP server dependencies

๐Ÿค Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

Development Setup

git clone https://github.com/martian7777/mcp-agent-security-scanner.git
cd mcp-scan
pip install -e ".[all]"
pytest

Adding a New Rule

  1. Add your detection function to mcp_scan/engine.py
  2. Register it in the ALL_RULES list
  3. Add tests in tests/test_engine.py
  4. Update the rule table in this README

๐Ÿท๏ธ Good First Issues

Looking to contribute? Start here:

  1. Add GitLab CI template โ€” Create a .gitlab-ci.yml example for GitLab users
  2. Add --config-format auto-detection โ€” Detect JSON vs YAML from file content, not just extension
  3. Add Slack webhook rule โ€” Detect Slack webhook URLs (https://hooks.slack.com/...) in configs
  4. Improve remediation messages โ€” Make fix suggestions more specific and actionable
  5. Add --quiet flag โ€” Only print findings, no header/footer

๐Ÿ“„ License

MIT โ€” see LICENSE.


Built for teams shipping AI agents safely.

โญ Star on GitHub ยท Report a Bug ยท Request a Feature

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_agent_security_scanner-0.1.0.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_agent_security_scanner-0.1.0-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file mcp_agent_security_scanner-0.1.0.tar.gz.

File metadata

File hashes

Hashes for mcp_agent_security_scanner-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4a26d52ec62044819cb2bb5f22e25852c1ab6f10f4d89f125895d0bb1a08e5d5
MD5 d1009619ab69b2e0b36149100e7a8b52
BLAKE2b-256 32cfb9fb395f560c854f5e5319b0eac63e3b4aa240d47699d8081fc1cc6e1cd8

See more details on using hashes here.

File details

Details for the file mcp_agent_security_scanner-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_agent_security_scanner-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 961f2c7426d312cbcd45ba7eed07f8e03b4dbe12347feee9784019584ae06bb1
MD5 d4e33d2639e8298b9896d62c1f2ca1e7
BLAKE2b-256 486c92c3b33a697e54e84f4dc109d21eeff079976a2f1b6e1906a979560e15a7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page