Building a Secure MCP Setup: Proxying, Logging and Auditing MCP Servers
Position MCP Shark as the observability layer for MCP. Learn about MCP audit logging, MCP observability, and best practices for securing your MCP infrastructure.
Why MCP Observability Matters
Model Context Protocol (MCP) servers have significant access to your development environment. Without proper observability, you're operating blind to:
- What tools are being called and when
- What data is being accessed or transmitted
- Which servers are communicating with your IDE
- Potential security threats or anomalies
- Performance bottlenecks or errors
MCP Shark provides comprehensive MCP observability, acting as an aggregation layer that combines multiple MCP servers and logs, audits, and monitors all MCP traffic while maintaining full functionality.
Architecture: MCP Shark as Your Observability Layer
MCP Shark sits between your IDE and MCP servers, providing:
1. Multi-Server Aggregation
MCP Shark aggregates multiple MCP servers (both HTTP and stdio-based) into one cohesive endpoint. Your IDE connects to MCP Shark, and MCP Shark forwards requests to the appropriate servers while capturing all traffic for analysis.
This approach means zero impact on functionality while providing complete visibility into all MCP communications.
2. Comprehensive Logging
All MCP communications are logged to SQLite (default location: ~/.mcp-shark/db/mcp-shark.sqlite) with:
- Request/Response Tracking: Full payload logging with correlation IDs
- Performance Metrics: Duration, latency, and timing information
- Error Tracking: Comprehensive error logging with stack traces
- Session Management: Session ID tracking for stateful interactions
- Server Identification: Track which external server handled each request
- Request Correlation: Match requests with their responses
This creates a complete audit trail of all MCP activity.
3. Real-Time Monitoring
MCP Shark's web interface provides real-time visibility into:
- Live traffic as it happens
- Search and filter capabilities
- Multiple view modes (by session, by server, chronological)
- Detailed inspection of individual requests
MCP Audit Logging Best Practices
1. Enable Continuous Logging
Always run MCP Shark when using MCP servers in production. This ensures you have a complete audit trail of all interactions, which is essential for:
- Security incident investigation
- Compliance requirements
- Debugging and troubleshooting
- Performance analysis
2. Regular Log Review
Schedule regular reviews of captured traffic:
- Weekly reviews for active development environments
- Daily reviews for production or sensitive environments
- Immediate review after any security concerns
- Post-incident analysis for troubleshooting
Use MCP Shark's export features to create reports for team reviews.
3. Archive and Retention
Export and archive logs regularly:
- Go to Traffic Capture tab
- Apply any filters (optional)
- Click Export and choose JSON format
- Store exported logs in secure, encrypted locations
- Maintain archives for compliance requirements
- Keep logs for at least 90 days (adjust based on your needs)
4. Secure Log Storage
Protect your audit logs:
- Store exported logs in secure, encrypted locations
- Limit access to logs to authorized personnel only
- Use version control or backup systems for log archives
- Consider log rotation to manage storage
MCP Observability Strategy
Baseline Establishment
Before deploying MCP servers to production:
- Use MCP Shark to capture baseline traffic patterns
- Use the MCP Playground to explore available tools and resources
- Document expected tool calls and resource access
- Establish normal traffic volumes and patterns
- Export baseline data for comparison later
Anomaly Detection
Use MCP Shark to identify:
- Unexpected tool calls or frequency changes
- Unusual resource access patterns
- Anomalous response sizes or timing
- Errors or failures that indicate problems
- Traffic from unknown or unexpected servers
Performance Monitoring
Track performance metrics using MCP Shark's built-in analytics:
- Response times for tool calls (shown in Traffic Capture)
- Traffic volume and patterns (Statistics view)
- Error rates and types (filter by status code)
- Server availability and reliability
Export data to analyze trends over time and identify optimization opportunities.
Security Hardening with MCP Shark
1. Server Whitelisting
Use MCP Shark to identify all MCP servers in use:
- Review the MCP Server Setup tab to see all configured servers
- Maintain a whitelist of approved servers
- Review and approve new servers before use
- Monitor for unexpected server connections in Traffic Capture
- Document server purposes and permissions
2. Tool Auditing
Regularly audit available tools:
- Use the MCP Playground to view all tools from all servers
- Review tool lists from each server
- Verify tools match their stated purposes
- Monitor for new tools appearing unexpectedly in Traffic Capture
- Document tool permissions and usage
3. Access Control
Use MCP Shark logs to:
- Track which servers are being accessed (filter by server name)
- Monitor resource access patterns (filter by
resources/read) - Identify unauthorized access attempts (review error logs)
- Enforce least-privilege principles (disable unnecessary servers in Setup)
4. Incident Response
When security incidents occur:
- Use filters to isolate suspicious activity in Traffic Capture
- Export relevant traffic logs immediately (choose JSON format)
- Trace sessions to understand attack vectors (use session grouping view)
- Document findings for post-incident review
Implementation Checklist
- □Install and configure MCP Shark as your MCP proxy
- □Update IDE configurations to use MCP Shark endpoint
- □Establish baseline traffic patterns for all MCP servers
- □Set up regular log review schedule
- □Create log export and archiving procedures
- □Document approved MCP servers and their purposes
- □Train team on using MCP Shark for monitoring
- □Establish incident response procedures
Next Steps
Continue building your secure MCP setup:
- Detecting Malicious MCP Servers - Security threat detection How to Capture and Inspect MCP Traffic - Setup guide
- MCP Shark Architecture - Understand how it works
Start building your secure MCP setup
Download MCP Shark and begin implementing MCP observability today.