Detects Facebook API keys within code snippets and repositories to prevent credential leakage.
Scans GitHub repositories for secrets, offering tools for automated file traversal, risk scoring, and security analysis.
Identifies Google Cloud credentials and secrets within source code and repositories.
Detects Mailgun tokens and credentials to ensure secure communication service integration.
Scans for MongoDB connection strings and database credentials in codebases.
Identifies MySQL connection strings and sensitive database information.
Detects PayPal API keys and secret tokens within repositories and code snippets.
Scans for PostgreSQL connection strings and database secrets.
Identifies SendGrid tokens and API keys to prevent exposure of email service credentials.
Detects Slack tokens and integration credentials in source code.
Scans for Stripe API keys and payment processing secrets.
Identifies Twilio tokens and credentials to protect communication API access.
Leak Secure MCP Server
Copyright 2025 Chris Bunting
Enterprise-grade MCP (Model Context Protocol) server for detecting secrets and sensitive information in code repositories. This server provides AI agents with powerful tools to scan GitHub repositories and code snippets for over 35 types of secrets, including API keys, passwords, tokens, and credentials.
Features
35+ Secret Types Detection: Comprehensive pattern matching for AWS keys, GitHub tokens, database credentials, API keys, private keys, and more
GitHub Integration: Scan entire repositories or specific paths with automatic file traversal
Security Analysis: Risk scoring, compliance status, and detailed remediation recommendations
Enterprise-Grade Architecture: Production-ready with enterprise-level reliability and security
MCP Protocol: Standardized interface for AI agents to interact with security scanning tools
Enterprise-Grade Features
Rate Limiting: Token bucket algorithm for GitHub API calls with configurable limits (default: 5000/hour, burst: 100)
Retry Logic: Exponential backoff with jitter for automatic retry of failed requests (configurable: 3 retries, 1s-30s delays)
Circuit Breaker: Prevents cascading failures with automatic recovery detection (CLOSED/OPEN/HALF_OPEN states)
Timeout Handling: Configurable timeouts for API requests (30s) and scan operations (5 minutes)
Input Validation: Zod-based schema validation for all tool inputs with sanitization
Structured Logging: Enterprise logging system with automatic secret sanitization and log levels
Error Handling: Custom error types with operational vs programming error distinction
Memory Efficiency: Batch processing, file size limits, and maximum file count protection
Graceful Shutdown: Handles SIGTERM/SIGINT with proper cleanup and operation completion
Enhanced Security: Advanced secret masking, input sanitization, and secure error messages
Supported Secret Types
The server detects secrets across multiple categories:
Cloud Provider: AWS, Google Cloud, Azure credentials
Version Control: GitHub tokens, OAuth tokens
Database: PostgreSQL, MySQL, MongoDB connection strings
Payment: Stripe, PayPal API keys
Communication: Twilio, SendGrid, Mailgun, Slack tokens
Social Media: Twitter, Facebook API keys
Cryptography: RSA, SSH, ECDSA private keys
Authentication: JWT tokens, OAuth tokens, access tokens
Generic: API keys, secrets, passwords
Installation
Prerequisites
Node.js 18.0.0 or higher
npm or yarn
GitHub Personal Access Token (optional, for private repositories)
Install from npm (Recommended)
Install the package globally or locally:
The setup script will automatically run after installation and prompt you for your GitHub Personal Access Token. You can:
Enter your token when prompted (recommended)
Press Enter to skip and configure it later
Run
npm run setupmanually at any time to configure or update your token
Install from Source
Clone the repository:
Install dependencies:
The setup script will automatically run after installation and prompt you for your GitHub Personal Access Token.
Build the project:
Usage
Running the Server
The MCP server runs on stdio and communicates via the Model Context Protocol:
For development with auto-reload:
MCP Tools
The server provides the following tools:
1. scan_repository
Scan a GitHub repository for secrets with enterprise-grade reliability features including rate limiting, retry logic, and circuit breaker protection.
Parameters:
owner(required): GitHub repository owner (username or organization) - validated and sanitizedrepo(required): Repository name - validated and sanitizedbranch(optional): Branch to scan (default: "main") - validated formatpath(optional): Specific path within repository to scan
Features:
Automatic rate limiting to respect GitHub API limits
Retry logic with exponential backoff for transient failures
Circuit breaker protection against cascading failures
Batch processing for memory efficiency (50 files per batch)
Timeout protection (5 minute default)
Maximum file limit protection (10,000 files default)
Example:
2. scan_code
Scan a code snippet or file content for secrets with enhanced validation and false positive reduction.
Parameters:
code(required): Code content to scan (max 10MB) - validated sizefilePath(optional): File path for context - helps with false positive reduction
Features:
Input size validation (10MB maximum)
Enhanced false positive detection
Adaptive secret masking based on length
Performance optimizations (skips empty lines and comments)
Example:
3. analyze_security
Perform comprehensive security analysis on a repository with risk scoring, compliance status, and remediation steps.
Parameters:
owner(required): GitHub repository ownerrepo(required): Repository namebranch(optional): Branch to analyze (default: "main")
Returns:
Risk score (0-100)
Compliance status (compliant/at_risk/non_compliant)
Severity breakdown (critical/high/medium/low)
Detailed remediation steps
Security recommendations
4. get_secret_types
Get list of all supported secret types (35+ types) with categories, descriptions, and severity levels.
5. validate_secret
Validate if a detected secret is still active with structured recommendations.
Parameters:
secretType(required): Type of secret (validated against supported types)value(required): The secret value to validate (max 10KB, sanitized)
MCP Resources
The server provides the following resources:
leak-secure://secret-types: List of all supported secret typesleak-secure://patterns: Detection patterns and regular expressions
Configuration
Environment Variables
The server can be configured using environment variables in a .env file or system environment:
Required
GITHUB_TOKEN(optional): GitHub Personal Access Token for accessing repositories
Optional Configuration
Server Configuration:
NODE_ENV: Environment mode (development,production,test) - default:productionLOG_LEVEL: Logging level (DEBUG,INFO,WARN,ERROR) - default:INFO
Rate Limiting:
GITHUB_RATE_LIMIT_PER_HOUR: Maximum API calls per hour - default:5000GITHUB_RATE_LIMIT_BURST: Burst capacity for rate limiter - default:100
Timeouts (milliseconds):
GITHUB_REQUEST_TIMEOUT: Timeout for individual GitHub API requests - default:30000(30s)SCAN_TIMEOUT: Timeout for entire repository scans - default:300000(5 minutes)
Retry Configuration:
MAX_RETRIES: Maximum retry attempts for failed requests - default:3RETRY_DELAY_BASE: Base delay for exponential backoff (ms) - default:1000(1s)RETRY_DELAY_MAX: Maximum delay between retries (ms) - default:30000(30s)
File Processing:
MAX_FILE_SIZE: Maximum file size to process (bytes) - default:10485760(10MB)MAX_FILES_PER_SCAN: Maximum files to scan per repository - default:10000
Circuit Breaker:
CIRCUIT_BREAKER_THRESHOLD: Failure threshold before opening circuit - default:5CIRCUIT_BREAKER_TIMEOUT: Time before attempting recovery (ms) - default:60000(1 minute)
GitHub Token
A GitHub Personal Access Token is optional but recommended for:
Accessing private repositories
Higher rate limits (5000/hour vs 60/hour unauthenticated)
Better reliability and reduced rate limit errors
To create a token:
Go to https://github.com/settings/tokens
Click "Generate new token (classic)"
Select scopes:
repo(for private repos) orpublic_repo(for public repos)Copy the token and add it to your
.envfile:GITHUB_TOKEN=your_token_here
Configuration Example
Create a .env file in the project root:
Security Considerations
Secret Protection
Adaptive Secret Masking: Secrets are automatically masked with adaptive length (shows first 4-6 and last 4-6 characters based on secret length)
Log Sanitization: All secrets are automatically sanitized in logs - never logged in full
Secure Error Messages: Error messages never expose sensitive data or full secret values
Input Sanitization: All inputs are sanitized to prevent injection attacks
False Positive Reduction
Enhanced Validation: Multiple layers of validation to reduce false positives
Pattern-Specific Validators: Custom validators for specific secret types
Context-Aware Detection: File path context helps improve accuracy
Common False Positive Filtering: Filters out example, test, placeholder values
API Security
Rate Limiting: Automatic rate limiting respects GitHub API limits and prevents abuse
Retry Logic: Smart retry only for operational errors, prevents infinite loops
Circuit Breaker: Prevents cascading failures and protects against API outages
Timeout Protection: Prevents hanging requests and resource exhaustion
Access Control: Use GitHub tokens with minimal required permissions (principle of least privilege)
Operational Security
Structured Logging: All logs are structured and sanitized for security compliance
Error Classification: Distinguishes between operational and programming errors
Graceful Degradation: Server continues operating even when some operations fail
Memory Protection: Limits on file sizes and counts prevent memory exhaustion attacks
Development
Project Structure
Building
Linting
Testing
API Response Format
Scan Results
Security Analysis Results
Error Response Format
Performance & Reliability
Rate Limiting
Token Bucket Algorithm: Efficient rate limiting with automatic token refill
Configurable Limits: Adjustable per-hour and burst limits
Automatic Waiting: Server automatically waits for rate limit tokens when needed
Retry Logic
Exponential Backoff: Smart retry delays increase exponentially (1s → 2s → 4s → 8s...)
Jitter: Random jitter prevents thundering herd problems
Selective Retry: Only retries operational errors (network, timeouts, rate limits)
Maximum Retries: Configurable retry attempts (default: 3)
Circuit Breaker
Three States: CLOSED (normal), OPEN (failing), HALF_OPEN (testing recovery)
Automatic Recovery: Detects when service has recovered
Failure Threshold: Configurable failure count before opening circuit
Timeout Protection: Prevents hanging on unresponsive services
Memory Management
Batch Processing: Files processed in batches (50 per batch) to manage memory
File Size Limits: Configurable maximum file size (default: 10MB)
File Count Limits: Maximum files per scan (default: 10,000)
Efficient Scanning: Skips binary files, large files, and common directories
Timeout Protection
Request Timeouts: Individual API requests timeout after 30 seconds
Operation Timeouts: Full repository scans timeout after 5 minutes
Graceful Handling: Timeouts return proper error responses
Error Handling
The server implements comprehensive error handling with custom error types:
ValidationError: Input validation failures (400)
GitHubAPIError: GitHub API communication errors (502)
RateLimitError: Rate limit exceeded (429)
TimeoutError: Operation timeout (504)
RepositoryAccessError: Repository access denied (403)
CircuitBreakerError: Circuit breaker open (503)
All errors are:
Properly typed and classified
Sanitized (no sensitive data)
Structured for easy handling
Logged with appropriate levels
Contributing
This is an enterprise-grade, production-ready implementation. When contributing:
Code Quality: Maintain high code quality and security standards
Testing: Add comprehensive tests for new features
Documentation: Update documentation for all changes
TypeScript: Follow TypeScript best practices and strict typing
Security: Ensure all secrets are properly masked in outputs and logs
Error Handling: Use custom error types from
utils/errors.tsLogging: Use structured logging from
utils/logger.ts(never log secrets)Validation: Use Zod schemas from
utils/validation.tsfor all inputsConfiguration: Add new config options to
utils/config.tswith validationPerformance: Consider memory and performance implications of changes
License
MIT License
Support
For issues, questions, or contributions, please contact: cbuntingde@gmail.com
Architecture Highlights
Enterprise Patterns Implemented
Rate Limiting: Token bucket algorithm for API call management
Retry Logic: Exponential backoff with jitter for resilience
Circuit Breaker: Prevents cascading failures
Input Validation: Zod schemas for type-safe validation
Structured Logging: JSON logging with secret sanitization
Error Handling: Custom error types with proper classification
Configuration Management: Centralized, validated configuration
Graceful Shutdown: Proper cleanup and operation completion
Memory Management: Batch processing and resource limits
Timeout Protection: Prevents resource exhaustion
Security Features
Zero-trust secret handling (never logged, always masked)
Input sanitization and validation
Secure error messages (no sensitive data)
Rate limiting to prevent abuse
Memory protection against DoS attacks
Timeout protection against hanging operations
Acknowledgments
Built with:
Model Context Protocol SDK - MCP protocol implementation
Octokit - GitHub API integration
Zod - TypeScript-first schema validation
Enterprise security and reliability best practices