btafoya/spamassassin-mcp
If you are the rightful owner of spamassassin-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The SpamAssassin MCP Server is a secure, containerized Model Context Protocol server that integrates SpamAssassin for defensive email security analysis.
SpamAssassin MCP Server
A secure, containerized Model Context Protocol (MCP) server that integrates SpamAssassin for defensive email security analysis. This server provides Claude Code with comprehensive email analysis capabilities while maintaining strict security boundaries.
š”ļø Security-First Design
Defensive Operations Only - This server exclusively provides security analysis capabilities:
- ā Email spam detection and analysis
- ā Sender reputation checking
- ā Rule testing and validation
- ā Configuration inspection
- ā NO email sending/relay capabilities
- ā NO malicious content generation
- ā NO offensive security tools
š Quick Start
Prerequisites
- Docker and Docker Compose
- Claude Code with MCP support
1. Build and Start
# Clone or create the project directory
cd spamassassin-mcp
# Optional: Copy and customize configuration
cp .env.example .env
# Edit .env to customize ports and settings
# Build and start the containers
docker compose up -d
# Check health
docker compose logs spamassassin-mcp
1. Alternative: Use Pre-built Image
# Pull the latest image from Docker Hub
docker pull your-dockerhub-username/spamassassin-mcp:latest
# Run the container
docker run -d \
--name spamassassin-mcp \
-p 8081:8080 \
your-dockerhub-username/spamassassin-mcp:latest
2. Connect Claude Code
# Connect to containerized server (SSE transport)
# Server URL: http://localhost:8081/mcp
# Or for direct connection (stdio transport)
./mcp-server
3. Test the Integration
# Scan a sample email
/scan_email --content "Subject: Test Email
This is a test email for spam analysis."
# Check sender reputation
/check_reputation --sender "test@example.com"
# Get current configuration
/get_config
š§ Available Tools
Email Analysis
scan_email
Analyze email content for spam probability and rule matches.
Parameters:
content
(required): Raw email content including headersheaders
(optional): Additional headers to analyzecheck_bayes
(optional): Include Bayesian analysisverbose
(optional): Return detailed rule explanations
Example:
{
"content": "Subject: Urgent Action Required\\n\\nClick here to claim your prize!",
"verbose": true,
"check_bayes": true
}
check_reputation
Check sender reputation and domain/IP blacklists.
Parameters:
sender
(required): Email sender addressdomain
(optional): Sender domainip
(optional): Sender IP address
explain_score
Explain how a spam score was calculated with detailed breakdown.
Configuration Management
get_config
Retrieve current SpamAssassin configuration and status.
update_rules
Update SpamAssassin rule definitions (defensive updates only).
Parameters:
source
(optional): Rule source (official/custom)force
(optional): Force update even if recent
Rule Testing
test_rules
Test custom rules against sample emails in a safe environment.
Parameters:
rules
(required): Custom rule definitionstest_emails
(required): Array of sample emails to test
š Project Structure
spamassassin-mcp/
āāā main.go # MCP server entry point
āāā go.mod # Go module definition
āāā Dockerfile # Multi-stage container build
āāā docker-compose.yml # Service orchestration
āāā internal/
ā āāā config/ # Configuration management
ā āāā handlers/ # MCP tool handlers
ā āāā spamassassin/ # SpamAssassin client wrapper
āāā configs/
ā āāā config.yaml # Server configuration
āāā scripts/
ā āāā entrypoint.sh # Container initialization
ā āāā health-check.sh # Health monitoring
āāā README.md
āļø Configuration
Environment Variables
Variable | Default | Description |
---|---|---|
SA_MCP_HOST_PORT | 8081 | Host port for container deployment |
SA_MCP_LOG_LEVEL | info | Logging level (debug, info, warn, error) |
SA_MCP_SERVER_BIND_ADDR | 0.0.0.0:8080 | Server bind address (container internal) |
SA_MCP_SPAMASSASSIN_HOST | localhost | SpamAssassin daemon host |
SA_MCP_SPAMASSASSIN_PORT | 783 | SpamAssassin daemon port |
SA_MCP_SPAMASSASSIN_THRESHOLD | 5.0 | Spam score threshold |
SA_MCP_SECURITY_MAX_EMAIL_SIZE | 10485760 | Max email size (10MB) |
UPDATE_RULES | false | Update SpamAssassin rules on startup |
MCP_TRANSPORT | auto | Transport mode (auto, stdio, sse) |
Security Settings
The server includes comprehensive security measures:
- Rate Limiting: 60 requests/minute with burst of 10
- Input Validation: Email format and size validation
- Content Sanitization: Safe handling of email content
- Container Security: Non-root execution, read-only filesystem
- Network Isolation: Custom bridge network
- Resource Limits: Memory and CPU constraints
š Usage Examples
Basic Email Scanning
# Simple spam check
/scan_email --content "$(cat suspicious_email.eml)"
# Detailed analysis with Bayes
/scan_email --content "$(cat email.eml)" --verbose --check_bayes
Reputation Analysis
# Check sender reputation
/check_reputation --sender "unknown@suspicious-domain.com"
# Check domain and IP
/check_reputation --domain "suspicious-domain.com" --ip "192.168.1.100"
Rule Development
# Test custom rules
/test_rules --rules "header LOCAL_TEST Subject =~ /test/i
describe LOCAL_TEST Test rule
score LOCAL_TEST 2.0" --test_emails '["Subject: test email\n\nThis is a test."]'
Score Analysis
# Get detailed score explanation
/explain_score --email_content "Subject: Free Money!\n\nClaim your prize now!"
š„ Health Monitoring
Health Check Endpoint
The container includes automated health checks:
# Check container health
docker-compose exec spamassassin-mcp /usr/local/bin/health-check.sh
# View health status
docker ps
Logs and Monitoring
# View server logs
docker compose logs -f spamassassin-mcp
# Monitor resource usage
docker stats spamassassin-mcp
# Test MCP connectivity (container mode)
curl -v http://localhost:8081/mcp
š Security Considerations
Defensive Posture
- Server exclusively provides analysis capabilities
- No email transmission or relay functionality
- Input validation and sanitization on all endpoints
- Rate limiting to prevent abuse
- Comprehensive logging for audit trails
Container Security
- Runs as non-root user (
spamassassin
) - Read-only root filesystem
- No new privileges allowed
- Resource limits enforced
- Network isolation
Data Handling
- No persistent storage of email content
- Temporary analysis only
- Configurable retention policies
- GDPR/privacy-compliant design
š§ Development
Building from Source
# Install dependencies
go mod download
# Build binary
go build -o mcp-server main.go
# Run locally (requires SpamAssassin)
./mcp-server
Testing
# Run with testing profile (includes spamd)
docker compose --profile testing up -d
# Test SpamAssassin connectivity
docker compose exec spamassassin-mcp timeout 2 bash -c 'echo >/dev/tcp/localhost/783'
# Test MCP server health
docker compose exec spamassassin-mcp /usr/local/bin/health-check.sh
š§ Troubleshooting
Common Issues
Container Restart Loop
Symptoms: Container continuously restarts with "read error: EOF"
- Cause: stdio transport expects stdin input in container environment
- Solution: Server automatically detects container mode and uses SSE transport
- Verification: Check logs show "Starting MCP server with SSE transport"
Port Conflicts
Symptoms: "bind: address already in use"
- Solution: Modify
SA_MCP_HOST_PORT
in.env
file - Default: Server uses port 8081 to avoid conflicts
Network Subnet Conflicts
Symptoms: "Pool overlaps with other one on this address space"
- Solution: docker-compose.yml uses 192.168.100.0/24 network
- Customization: Modify networks section if conflicts persist
Health Check Failures
Symptoms: Container marked unhealthy
- Verification: Run
/usr/local/bin/health-check.sh
manually - Common Fix: Ensure SpamAssassin daemon is running
- Debug: Check
docker compose logs spamassassin-mcp
š Documentation
- - Complete MCP tools documentation
- - Production deployment instructions
- - Security architecture and best practices
- - Contributing and development setup
- - Complete configuration options
š License
MIT License - See file for details.
š CI/CD with GitHub Actions
This project uses GitHub Actions for continuous integration and deployment:
- Docker Build and Push: Automatically builds and pushes Docker images to Docker Hub on pushes to
main
branch and tags - Test Docker Image: Runs tests on the Docker image to ensure it builds and runs correctly
- Update Docker Hub Overview: Automatically updates the Docker Hub repository description when README.md changes
Setting up Docker Hub Publishing
To use the Docker Hub publishing workflow:
-
Create a Docker Hub account if you don't already have one
-
Generate a Docker Hub access token:
- Log in to Docker Hub
- Go to Account Settings > Security
- Click "New Access Token"
- Give it a descriptive name (e.g., "GitHub Actions")
- Set permissions to "Read & Write"
- Copy the generated token (you won't see it again)
-
Set up Docker Hub credentials as GitHub Secrets:
- Go to your GitHub repository settings
- Click "Secrets and variables" > "Actions"
- Add two new repository secrets:
DOCKER_USERNAME
: Your Docker Hub usernameDOCKER_PASSWORD
: Your Docker Hub access token (the token you just created)
-
Push to the
main
branch or create a tag starting withv
(e.g.,v1.0.0
)- The workflow will automatically build and push the image to Docker Hub
The published images will be available at https://hub.docker.com/r/YOUR_USERNAME/spamassassin-mcp
where YOUR_USERNAME
is your Docker Hub username.
Image tags:
latest
- Latest build from the main branchvX.Y.Z
- Specific version tags for releasescommit-SHA
- Specific commit builds
Manual Docker Hub Overview Update
You can also manually generate the Docker Hub overview:
# Generate Docker Hub overview
./scripts/extract-dockerhub-info.sh
# Or use the manual update script with your credentials
./scripts/update-dockerhub-manual.sh your-docker-username your-docker-access-token
š¤ Contributing
Contributions welcome! Please read our and ensure all changes maintain the security-first, defensive-only design principles.
š Support
For issues and questions:
- First Steps: Check the
- Logs:
docker-compose logs spamassassin-mcp
- Health Check:
docker-compose exec spamassassin-mcp /usr/local/bin/health-check.sh
- SpamAssassin Status:
docker-compose exec spamassassin-mcp pgrep spamd
š Related Projects
- Model Context Protocol - Official MCP specifications
- Claude Code - Claude's official CLI
- SpamAssassin - Open source spam filtering
ā ļø Security Notice: This server is designed exclusively for defensive security analysis. It does not provide capabilities for sending emails, generating spam content, or any offensive security operations. All operations are logged and auditable.