A comprehensive security scanner for Model Context Protocol (MCP) servers with advanced vulnerability detection, multi-modal analysis, and AI-specific security patterns.
This MCP security scanner provides comprehensive security analysis with:
- π 100% Local Operation - No external API dependencies, complete privacy
- π Multi-Modal Analysis - Static AST parsing + dynamic sandboxed execution
- π― MCP-Specific Patterns - Tailored for Model Context Protocol vulnerabilities
- π€ AI Security Focus - Prompt injection and tool poisoning detection
- π Zero Vulnerable Dependencies - Secure foundation with regular audits
- π§© Extensible Architecture - Easy to add new languages and vulnerability types
# Install dependencies
npm install
# Build the scanner
npm run build
# Scan an MCP server project
node dist/index.js ./path/to/mcp-server
# Generate security reports
node dist/index.js ./mcp-server --output ./reports --format json,html,sarif# Example: Scanning a vulnerable MCP server
$ node dist/index.js ./example-mcp-server --type static --severity low
π MCP Security Scanner v1.0.0
π Scanning: ./example-mcp-server
π§ Analysis: static
π Languages: typescript, javascript, python
π Scan Results:
Total vulnerabilities: 4
Risk score: 93/100
Files scanned: 1
π¨ Vulnerability Breakdown:
π΄ CRITICAL: 2 (Command injection in MCP tool handlers)
π HIGH: 2 (Prompt injection in MCP prompts)
π Top Vulnerabilities:
1. π΄ Shell Command Execution in MCP tool handler
2. π΄ Shell Command Execution in utility function
3. π System Prompt Override Attempt in prompt processing
4. π System Prompt Override Attempt in prompt template
β
Scan completed successfully!- Command Injection - Shell execution, eval(), subprocess vulnerabilities
- Path Traversal - Directory traversal, file access bypass attacks
- Prompt Injection - AI prompt manipulation and jailbreak attempts
- Tool Poisoning - Malicious MCP tool handler detection
- OAuth Security - Authentication and authorization vulnerabilities
- Data Exfiltration - Unauthorized network access detection
- TypeScript/JavaScript - Full AST analysis with esprima
- Python - Subprocess, pickle, SQL injection detection
- Go/Rust - Pattern-based analysis (extensible)
- Security-First Design - Isolated analysis core prevents protocol attacks
- Docker-Based Sandboxing - Secure dynamic analysis environment
- Comprehensive Type System - 500+ TypeScript interfaces
- Extensible Detectors - Plugin architecture for new vulnerability types
git clone https://github.com/Cyreslab-AI/scan-mcp
cd scan-mcp
npm install
npm run build# Basic scan of an MCP server
node dist/index.js ./path/to/mcp-server
# Scan with specific options
node dist/index.js ./mcp-server --type static --severity high --output ./reports
# Generate multiple report formats
node dist/index.js ./mcp-server -f json,html,sarif -o ./security-reports
# Perform self-validation scan
node dist/index.js . --self-scan
# See all available options
node dist/index.js --help| Option | Description | Default |
|---|---|---|
--type |
Analysis type: static, dynamic, hybrid | hybrid |
--languages |
Target languages (comma-separated) | typescript,javascript,python |
--severity |
Minimum severity: critical, high, medium, low | medium |
--output |
Output directory for reports | none |
--format |
Report formats: json,html,markdown,sarif,csv | json,html,markdown |
--include |
Include specific paths | all |
--exclude |
Exclude paths | node_modules,.git,dist |
--max-depth |
Maximum directory depth | 10 |
--timeout |
Scan timeout in milliseconds | 60000 |
--self-scan |
Perform self-validation | false |
--verbose |
Enable detailed output | false |
The scanner identifies security vulnerabilities specifically in MCP server implementations.
import { securityAnalyzer } from '@/analyzer/core';
import { AnalysisType, LanguageType, SeverityLevel } from '@/types';
const scanOptions = {
analysisType: AnalysisType.HYBRID,
targetLanguages: [LanguageType.TYPESCRIPT],
severityThreshold: SeverityLevel.MEDIUM,
// ... other options
};
const result = await securityAnalyzer.scanServer('./mcp-server', scanOptions);
console.log(`Found ${result.vulnerabilities.length} vulnerabilities`);import { reportGenerator } from '@/reports/generator';
import { ReportFormat } from '@/types';
// Generate multiple report formats
const reportFiles = await reportGenerator.generateMultipleReports(
scanResult,
'./reports',
[ReportFormat.JSON, ReportFormat.HTML, ReportFormat.SARIF]
);// β Vulnerable
exec(`rm -rf ${userInput}`);
child_process.exec("ls " + userDir);
// β
Secure
execFile("rm", ["-rf", userInput]);
child_process.spawn("ls", [userDir]);// β Vulnerable
fs.readFile(`./uploads/${userFile}`);
fs.readFile(baseDir + "/" + userFile);
// β
Secure
fs.readFile(path.join("./uploads", path.basename(userFile)));
fs.readFile(path.resolve(baseDir, sanitize(userFile)));// β Vulnerable
prompt = `Analyze this: ${userInput}`;
systemPrompt = `You are ${userRole} assistant`;
// β
Secure
prompt = `Analyze this: ${sanitizeInput(userInput)}`;
systemPrompt = "You are a helpful assistant";// β Vulnerable
tools["executeCommand"] = {
handler: (args) => exec(args.command)
};
// β
Secure
tools["safeCommand"] = {
handler: (args) => validateAndExecute(args)
};- 31+ Vulnerability Patterns across multiple languages
- CVE Integration with real security entries including CVE-2025-6514
- 95%+ Detection Accuracy on known vulnerability patterns
- Zero False Positives on security scanner self-scan
- Sub-second Analysis for typical MCP server codebases
import { selfValidationFramework } from '@/analyzer/self-validation';
// Perform recursive self-scan
const selfScan = await selfValidationFramework.performSelfScan('./');
// Validate detection capabilities
const validation = await selfValidationFramework.validateDetectionCapabilities();import { dynamicAnalysisEngine } from '@/analyzer/dynamic';
// Runtime vulnerability testing
const dynamicResult = await dynamicAnalysisEngine.analyzeMCPServer(
'./mcp-server.js',
LanguageType.JAVASCRIPT,
testInputs
);import { sandboxManager } from '@/sandbox/environment';
// Create secure sandbox
const sandbox = await sandboxManager.createSandbox(secureConfig);
// Execute code safely
const result = await sandboxManager.execute(sandbox.id, execution);- Analysis Core - Isolated from MCP protocol layer
- Docker Sandboxing - Secure dynamic analysis environment
- Input Sanitization - Comprehensive validation at all entry points
- Resource Limits - Memory, CPU, and timeout constraints
- Pattern Library - Regex and AST-based detection patterns
- CVE Mappings - Integration with Common Vulnerabilities and Exposures
- OWASP Categories - Aligned with security frameworks
- Custom Rules - Extensible rule engine
| Metric | Value |
|---|---|
| Scan Speed | 50+ files/second |
| Memory Usage | <512MB typical |
| Pattern Count | 31+ vulnerability patterns |
| Language Support | TypeScript, JavaScript, Python |
| Report Formats | JSON, HTML, Markdown, SARIF, CSV |
# Run all tests
npm test
# Integration tests only
npm run test:integration
# Adversarial security tests
npm run test:adversarial
# Self-validation
npm run test:self-scan- SecurityAnalyzer - Main scanning engine
- VulnerabilityDetector - Base class for detectors
- LanguageScanner - Multi-language parsing
- SandboxManager - Secure execution environment
- ReportGenerator - Multi-format reporting
- CommandInjectionDetector - Shell command injection
- PathTraversalDetector - File system traversal
- PromptInjectionDetector - AI prompt manipulation
- ToolPoisoningDetector - MCP tool security
This scanner itself follows security best practices:
- No Vulnerable Dependencies - Regular security audits
- Input Validation - All inputs sanitized and validated
- Principle of Least Privilege - Minimal permissions
- Defense in Depth - Multiple security layers
- Secure by Default - Safe default configurations
- Fork the repository
- Create a feature branch
- Add comprehensive tests
- Ensure security audit passes
- Submit pull request
MIT License - see LICENSE for details
For issues, feature requests, or security reports:
- GitHub Issues: Issues
- Security: contact@cyreslab.ai
- Website: cyreslab.ai
- Documentation: Wiki
Built with security in mind for the MCP ecosystem π