Comprehensive security scanner for Model Context Protocol (MCP) servers
Combines static code analysis, runtime probing, and cryptographic verification to detect vulnerabilities in MCP servers before and after deployment.
AST-based Python code scanning (JavaScript support planned):
- PY001: Shell injection detection (
os.system,subprocesswithshell=True) - PY002: Path traversal patterns (
../in file operations) - PY003: Hardcoded secrets (AWS keys, API tokens, passwords)
- PY004: Dangerous eval/exec usage
- PY005: Insecure deserialization (
pickle.loads, unsafeyaml.load)
Live server probing via HTTP transport:
- RT001: Dangerous capabilities without input constraints
- RT002: Prompt injection patterns in tool descriptions
- RT003: Resource path traversal vulnerabilities
- DNS/DNSSEC: Verify domain ownership via
_mcp.<domain>TXT records - Nostr (Planned): NIP-05/NIP-89 decentralized verification
- JSON: Machine-readable for CI/CD integration
- Text: Color-coded terminal output with severity indicators
- Exit Codes: 0 for clean, 1 for issues found
- Python 3.10+
- Poetry (recommended) or pip
git clone https://github.com/ca7ai/mcp-sec-scanner.git
cd mcp-sec-scanner
poetry installgit clone https://github.com/ca7ai/mcp-sec-scanner.git
cd mcp-sec-scanner
pip install -e .poetry run mcp-scanner scan ./mcp-server/
# Output
================================================================================
MCP Security Scan Results: ./mcp-server/
================================================================================
Summary:
Total Issues: 3
By Severity:
HIGH: 2
CRITICAL: 1
[CRITICAL] PY003: Hardcoded AWS Access Key detected
File: server.py:15:8
Fix: Use environment variables or secret managementpoetry run mcp-scanner probe http://localhost:3000
# Output
[HIGH] RT001: Found 2 tools with dangerous capabilities lacking constraints
[MEDIUM] RT002: Found 1 tools with potential prompt injection patternspoetry run mcp-scanner verify example.com
# Output
✅ DNS Verified: Yes
✅ DNSSEC Valid: Yes
Trust Level: MEDIUMpoetry run mcp-scanner audit example.com --code ./server/# Scan single file
poetry run mcp-scanner scan server.py
# Scan directory
poetry run mcp-scanner scan ./mcp-server/
# JSON output for CI/CD
poetry run mcp-scanner scan ./server/ --format json --output results.json
# Filter by severity
poetry run mcp-scanner scan ./server/ --min-severity high# Probe HTTP server
poetry run mcp-scanner probe http://localhost:3000
# Save results
poetry run mcp-scanner probe http://localhost:3000 --output probe.json# Verify DNS/DNSSEC
poetry run mcp-scanner verify example.com# Scan fails build if issues found (exit code 1)
poetry run mcp-scanner scan ./server/ --format json --output security-report.json| Rule ID | Severity | Detection |
|---|---|---|
| PY001 | HIGH | Shell injection via os.system(), subprocess.call(shell=True) |
| PY002 | HIGH | Path traversal with ../ patterns |
| PY003 | CRITICAL | Hardcoded secrets (AWS keys, API tokens, passwords) |
| PY004 | CRITICAL | Dangerous eval(), exec(), compile() |
| PY005 | HIGH | Insecure deserialization (pickle.loads, yaml.load) |
| Rule ID | Severity | Detection |
|---|---|---|
| RT001 | HIGH | Tools with dangerous capabilities (exec, shell, delete) lacking input validation |
| RT002 | MEDIUM | Prompt injection patterns in tool descriptions |
| RT003 | HIGH | Resource URIs exposing sensitive paths or path traversal |
mcp-sec-scanner/
├── src/mcp_scanner/
│ ├── core/ # Pydantic models, exceptions
│ ├── analyzers/ # Static analysis engines
│ │ └── static/ # Python AST analyzer
│ ├── runtime/ # Runtime security checks
│ │ ├── checks.py # RT001-RT003 implementations
│ │ └── probe.py # Runtime orchestrator
│ ├── transports/ # HTTP/WebSocket clients
│ │ └── http_client.py # MCP JSON-RPC over HTTP
│ ├── verification/ # DNS/DNSSEC verifier
│ ├── rules/ # Security rule definitions
│ ├── outputs/ # JSON and text formatters
│ └── cli.py # Command-line interface
└── tests/ # Unit and integration tests
Key Design Patterns:
- Plugin System: Extensible rule engine with dependency resolution
- Transport Abstraction: HTTP, WebSocket, stdio support
- Immutable Models: Pydantic with frozen config for audit integrity
- Fail-Safe Execution: One plugin failure doesn't stop entire scan
poetry run pytest -v
poetry run pytest --cov=src/mcp_scannerpoetry run mypy src/mcp_scannerpoetry run black src/ tests/
poetry run ruff check src/ tests/- ✅ Python static analysis (5 rules)
- ✅ Runtime probing (3 checks)
- ✅ DNS/DNSSEC verification
- ✅ HTTP transport
- ✅ JSON + text output
- Nostr verification (NIP-05/NIP-89)
- JavaScript/TypeScript static analysis
- WebSocket transport
- 10+ additional runtime checks
- Exploit payload fuzzing
- SARIF output format
- VS Code extension
- GitHub Action
- Custom rule authoring
- Web dashboard
- Integration with CI/CD platforms
Unique Features:
- Only scanner combining static, runtime, and verification
- MCP-specific threat detection (not generic)
- Trust scoring via cryptographic verification
PolyForm Noncommercial License 1.0.0
Summary:
- ✅ Free for noncommercial use
- ✅ Personal research and education
- ✅ Open source contributions
- ❌ Commercial use requires separate license
For commercial licensing inquiries, contact the maintainer.
- Built for the Model Context Protocol ecosystem
- Uses patterns from Bandit, Semgrep, and ESLint
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Security: Report vulnerabilities privately via GitHub Security Advisories