Skip to content

jaesuphwang/mcp_security

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

MCP Security Guardian πŸ›‘οΈ

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.

πŸš€ Overview

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.

πŸ”₯ Key Features

Core Security Capabilities

  • 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

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              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         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Python 3.10+ (tested with Python 3.10+)
  • Virtual environment (recommended)
  • Git (for cloning)

Installation

  1. Clone the repository

    git clone https://github.com/jaesuphwang/mcp_security.git
    cd mcp_security
  2. Create and activate virtual environment

    python3 -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Test the basic server

    python test_mcp_basic.py
  5. Run the full security server

    python mcp_server.py

Integration with Claude Desktop

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.

Using with Smithery

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"]
    }
  }
}

πŸ”§ Available Tools

The MCP Security Guardian provides the following tools:

1. analyze_instruction

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

2. scan_connection

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

3. revoke_token

Revoke compromised or suspicious tokens.

{
  "token": "eyJhbGciOiJIUzI1NiIs...",
  "reason": "compromised",
  "description": "Token found in public repository"
}

Reasons:

  • compromised: Token has been exposed
  • expired: Token past validity period
  • misused: Suspicious usage patterns
  • suspicious: Potential security risk

4. audit_capabilities

Audit MCP server capabilities for security issues.

{
  "server_url": "https://api.example.com",
  "capabilities": ["read_files", "execute_commands"]
}

5. distribute_alert

Distribute security alerts through the threat intelligence network.

{
  "alert_type": "malicious_instruction",
  "severity": "high",
  "message": "Detected SQL injection attempt",
  "tlp_level": "amber"
}

πŸ“Š Resources

Access security resources:

  • security://threat-patterns - Known threat signatures database
  • security://revoked-tokens - List of revoked authentication tokens
  • security://alerts - Active security alerts and notifications

πŸ”’ Security Features

1. Multi-Layer Detection Engine

  • 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

2. Vulnerability Scanning

  • 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

3. Token Revocation System

  • Real-time Revocation: Instant token blacklisting
  • Bulk Operations: Multiple token revocation support
  • Distribution Network: Automatic alert propagation
  • Audit Trail: Complete revocation history tracking

4. Alert Distribution

  • TLP-based Sharing: Traffic Light Protocol classification
  • Real-time Notifications: Instant security updates
  • Categorized Alerts: Structured threat information
  • Network Effect: Collaborative security improvement

πŸ§ͺ Testing

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

πŸ”§ Development

Local Development Setup

  1. Set up development environment

    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
  2. Code Quality Tools

    # Linting
    ruff check src/
    
    # Type checking  
    mypy src/
    
    # Security scanning
    bandit -r src/
  3. Running Tests

    # Basic server test
    python test_mcp_basic.py
    
    # Full server test
    python mcp_server.py

Project Structure

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

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

How to Contribute

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

πŸ“‹ Troubleshooting

Common Issues

1. Import Errors

# Make sure virtual environment is activated
source venv/bin/activate

# Reinstall dependencies
pip install -r requirements.txt

2. MCP Connection Issues

# Verify Claude Desktop configuration
cat ~/Library/Application\ Support/Claude/claude_desktop_config.json

# Check server is running
python mcp_server.py

3. Missing Dependencies

# Install specific missing packages
pip install mcp sqlalchemy redis motor

# Or reinstall all requirements
pip install -r requirements.txt --force-reinstall

πŸ“ˆ Performance & Monitoring

  • Logging: Structured JSON logging with configurable levels
  • Metrics: Built-in performance monitoring
  • Health Checks: Endpoint status monitoring
  • Error Tracking: Comprehensive error reporting

🚨 Security Considerations

  1. Keep dependencies updated - Run pip install -U -r requirements.txt regularly
  2. Monitor security alerts - Check logs for suspicious patterns
  3. Audit configurations - Review MCP server settings periodically
  4. Test security features - Run security tests before deployment

πŸ“„ License

Apache License 2.0 - See LICENSE for details.

πŸ™ Acknowledgments

  • 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.

About

MCP (Model Context Protocol) communications, featuring comprehensive security enhancements and enterprise-grade protection.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages