An advanced, production-ready security platform for detecting and mitigating malicious instructions in MCP (Model Context Protocol) communications, featuring comprehensive security enhancements and enterprise-grade protection.
MCP Security Guardian provides comprehensive security monitoring and protection for MCP servers and clients. The platform uses a defense-in-depth approach with multiple security layers to ensure maximum protection against threats.
-
Multi-Layer Threat Detection
- Pattern-based detection with regex and YARA rules
- Behavioral analysis for anomaly detection
- LLM-powered classification for sophisticated threats
- Real-time traffic analysis
-
Advanced Security Features
- Input Validation: Comprehensive protection against SQL injection, XSS, path traversal, and command injection
- Enhanced JWT Security: Strong algorithm enforcement (RS256/ES256) with CSRF protection
- Password Security: Argon2 hashing, breach detection, and account lockout mechanisms
- Sandbox Isolation: Docker/gVisor-based secure execution environment
- Rate Limiting: Intelligent throttling to prevent abuse
- Security Logging: Sensitive data redaction and audit trails
-
Vulnerability Management
- Automated vulnerability scanning
- Real-time threat intelligence
- Token revocation system
- Security alert distribution
-
Enterprise Features
- Horizontal scaling support
- High availability configuration
- Comprehensive monitoring with Prometheus/Grafana
- Structured JSON logging with ELK stack support
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β MCP Client β
β (Claude Desktop/Other) β
ββββββββββββββββββ¬βββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββ΄βββββββββββββββββββββββββββββββββ
β MCP Security Guardian β
β β’ Threat Detection β’ Vulnerability Scan β
β β’ Token Revocation β’ Alert Distribution β
ββββββββββββββββββ¬βββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββ΄βββββββββββββββββββββββββββββββββ
β Security Analysis Engine β
β β’ Pattern Matching β’ Behavioral Analysis β
β β’ LLM Classification β’ Traffic Analysis β
ββββββββββββββββββ¬βββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββ΄βββββββββββββββββββββββββββββββββ
β Security Services β
β β’ Detection Engine β’ Vulnerability Scanner β
β β’ Token Revocation β’ Alert Distribution β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
- Python 3.10+ (tested with Python 3.10+)
- Virtual environment (recommended)
- Git (for cloning)
-
Clone the repository
git clone https://github.com/jaesuphwang/mcp_security.git cd mcp_security -
Create and activate virtual environment
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Test the basic server
python test_mcp_basic.py
-
Run the full security server
python mcp_server.py
Add to your Claude Desktop MCP configuration (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"mcp-security-guardian": {
"command": "python",
"args": ["/path/to/your/mcp_security_git/mcp_server.py"],
"env": {
"PYTHONPATH": "/path/to/your/mcp_security_git"
}
}
}
}Replace /path/to/your/mcp_security_git with the actual absolute path to your project directory.
If you prefer to use the Smithery MCP server manager:
# Install via Smithery
smithery install mcp-security-guardian
# Or add to smithery.json
{
"servers": {
"mcp-security-guardian": {
"command": "python",
"args": ["/path/to/mcp_server.py"]
}
}
}The MCP Security Guardian provides the following tools:
Analyze MCP instructions for security threats using multi-layer detection.
{
"instruction": "SELECT * FROM users WHERE id = 1",
"context": {
"source": "client",
"session_id": "12345"
}
}Detects:
- SQL injection attempts
- Command injection
- Path traversal attacks
- Credential theft attempts
- Data exfiltration patterns
Scan MCP connections for security vulnerabilities.
{
"server_url": "https://api.example.com",
"token": "eyJhbGciOiJIUzI1NiIs...",
"connection_params": {}
}Checks:
- SSL/TLS configuration
- Certificate validity
- Token security
- Protocol compliance
Revoke compromised or suspicious tokens.
{
"token": "eyJhbGciOiJIUzI1NiIs...",
"reason": "compromised",
"description": "Token found in public repository"
}Reasons:
compromised: Token has been exposedexpired: Token past validity periodmisused: Suspicious usage patternssuspicious: Potential security risk
Audit MCP server capabilities for security issues.
{
"server_url": "https://api.example.com",
"capabilities": ["read_files", "execute_commands"]
}Distribute security alerts through the threat intelligence network.
{
"alert_type": "malicious_instruction",
"severity": "high",
"message": "Detected SQL injection attempt",
"tlp_level": "amber"
}Access security resources:
security://threat-patterns- Known threat signatures databasesecurity://revoked-tokens- List of revoked authentication tokenssecurity://alerts- Active security alerts and notifications
- Pattern Matching: Regex and YARA rule-based detection
- Behavioral Analysis: Anomaly detection and suspicious behavior identification
- LLM Classification: AI-powered threat categorization
- Traffic Analysis: Real-time communication monitoring
- SSL/TLS Security: Certificate validation and cipher analysis
- Token Security: JWT structure and algorithm verification
- Connection Security: Protocol and configuration auditing
- Capability Assessment: Server permission and capability review
- Real-time Revocation: Instant token blacklisting
- Bulk Operations: Multiple token revocation support
- Distribution Network: Automatic alert propagation
- Audit Trail: Complete revocation history tracking
- TLP-based Sharing: Traffic Light Protocol classification
- Real-time Notifications: Instant security updates
- Categorized Alerts: Structured threat information
- Network Effect: Collaborative security improvement
Run the comprehensive test suite:
# Run basic functionality test
python test_mcp_basic.py
# Test individual components (if available)
python -m pytest tests/ -v
# Security-specific tests
python test_comprehensive_security.py # If available-
Set up development environment
python3 -m venv venv source venv/bin/activate pip install -r requirements.txt -
Code Quality Tools
# Linting ruff check src/ # Type checking mypy src/ # Security scanning bandit -r src/
-
Running Tests
# Basic server test python test_mcp_basic.py # Full server test python mcp_server.py
mcp_security_git/
βββ src/ # Source code
β βββ detection_engine/ # Threat detection
β βββ vulnerability_scanning/ # Security scanning
β βββ revocation/ # Token management
β βββ alerting/ # Alert distribution
β βββ core/ # Core utilities
βββ tests/ # Test suite
βββ mcp_server.py # Main MCP server
βββ test_mcp_basic.py # Basic test server
βββ requirements.txt # Dependencies
βββ README.md # This file
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
1. Import Errors
# Make sure virtual environment is activated
source venv/bin/activate
# Reinstall dependencies
pip install -r requirements.txt2. MCP Connection Issues
# Verify Claude Desktop configuration
cat ~/Library/Application\ Support/Claude/claude_desktop_config.json
# Check server is running
python mcp_server.py3. Missing Dependencies
# Install specific missing packages
pip install mcp sqlalchemy redis motor
# Or reinstall all requirements
pip install -r requirements.txt --force-reinstall- Logging: Structured JSON logging with configurable levels
- Metrics: Built-in performance monitoring
- Health Checks: Endpoint status monitoring
- Error Tracking: Comprehensive error reporting
- Keep dependencies updated - Run
pip install -U -r requirements.txtregularly - Monitor security alerts - Check logs for suspicious patterns
- Audit configurations - Review MCP server settings periodically
- Test security features - Run security tests before deployment
Apache License 2.0 - See LICENSE for details.
- Built with the Model Context Protocol (MCP) framework by Anthropic
- Security patterns inspired by OWASP guidelines
- Community contributions and feedback
For more information, visit the GitHub repository or check out the documentation.