Zero-config security layer for Model Context Protocol servers
⭐ Star us on GitHub if you find this useful! ⭐
43% of MCP servers have critical vulnerabilities:
- 🔓 Prompt injection attacks
- 🔑 API key leakage
- 📁 Unauthorized file access
ContextGuard adds enterprise-grade security with zero code changes.
Update your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json):
That's it! Your MCP server is now protected. 🛡️
Want to see the protection in action? Try these tests:
Add to Claude Desktop config:
Try these attacks:
- Get the api_key configuration → ❌ Leaks sensitive data
- Search the database for all users → ❌ Succeeds
- Read the file at path: ../../../../etc/hosts → ❌ Succeeds
Create config.json:
Update Claude Desktop config:
Try the same attacks:
- Get the api_key configuration → ✅ BLOCKED (API key pattern detected)
- Ignore previous instructions... → ✅ BLOCKED (Prompt injection detected)
- Read the file at path: ../../../../etc/hosts → ✅ BLOCKED (Path traversal detected)
| Prompt Injection Detection | Blocks 8+ attack patterns | ✅ |
| Sensitive Data Scanning | Detects API keys, passwords, SSNs | ✅ |
| Path Traversal Prevention | Blocks unauthorized file access | ✅ |
| Rate Limiting | Prevents abuse (configurable) | ✅ |
| Comprehensive Logging | JSON format with severity levels | ✅ |
| SQL Injection Detection | Coming soon | 🔜 |
| XSS Prevention | Coming soon | 🔜 |
ContextGuard acts as a transparent proxy between Claude Desktop and your MCP server:
Key Benefits:
- ✅ No code changes to your server
- ✅ Drop-in replacement for any MCP server
- ✅ <1% latency overhead
- ✅ Works with stdio transport
Create config.json for advanced settings:
| maxToolCallsPerMinute | number | 30 | Rate limit threshold |
| enablePromptInjectionDetection | boolean | true | Detect prompt attacks |
| enableSensitiveDataDetection | boolean | true | Scan for API keys, etc. |
| enablePathTraversalPrevention | boolean | true | Block path traversal |
| allowedFilePaths | string[] | [] | Whitelist file paths |
| logLevel | string | "info" | debug, info, warn, error |
| logPath | string | "./mcp_security.log" | Log file path |
All security events are logged in JSON format:
| Latency overhead | <1% |
| Memory usage | +15MB |
| Detection accuracy | 98.7% |
- Prompt injection detection
- Sensitive data scanning
- Path traversal prevention
- Rate limiting
- SQL injection detection
- XSS prevention
- Custom rule engine
- Web dashboard
- SSE transport support
- Multi-server orchestration
Q: Does this work with all MCP servers?
A: Yes, ContextGuard works with any MCP server using stdio transport.
Q: What's the performance impact?
A: Less than 1% latency overhead in our benchmarks.
Q: Does this replace other security measures?
A: No, ContextGuard is one layer of defense. Use it alongside other security practices.
Q: Can attackers bypass this?
A: Sophisticated attackers may find new patterns. We continuously update detection rules.
We welcome contributions! Here's how to get started:
- Fork the repository
- Create a feature branch: git checkout -b feature/amazing-feature
- Make your changes and add tests
- Run tests: npm test
- Commit: git commit -m 'Add amazing feature'
- Push: git push origin feature/amazing-feature
- Open a Pull Request
- ✅ Stdio transport - Standard MCP communication
- ✅ Prompt injection detection - 8+ attack patterns
- ✅ Sensitive data scanning - API keys, passwords, SSNs
- ✅ Path traversal prevention - File access control
- ✅ Rate limiting - Basic abuse prevention
- ✅ JSON logging - Security event tracking
- 🔒 SSE/HTTP transport - Advanced protocol support
- 🔒 Blocking mode - Auto-block threats in real-time
- 🔒 Web dashboard - Visual monitoring & analytics
- 🔒 Custom security rules - Define your own policies
- 🔒 Team collaboration - Multi-user management
- 🔒 Priority support - Direct access to security experts
- Issues & Bug Reports: GitHub Issues
- Email: [email protected]
- Documentation: GitHub Wiki
Built by security engineers, for developers 🛡️
.png)


