The MCP Server Code Execution Mode bridge is a functional implementation of the "Code Execution with MCP" pattern. It provides secure, isolated Python code execution with optional MCP server proxying. While the core functionality is complete, it requires additional operational work (testing, observability, policy controls) before production deployment.
Core Functionality:
- Single
run_pythonMCP tool exposed over stdio - Rootless container sandbox with strict security isolation
- Host-mediated MCP server proxying into sandbox
- JSON-framed stdio transport between sandbox and host for tool calls
- Persistent MCP client sessions (avoids cold starts)
- Timeout enforcement with proper error handling
- Tool responses surface a
CallToolResultwith mirroredstructuredContentand compact plain-textTextContent; setMCP_BRIDGE_OUTPUT_MODE=toonto emit TOON blocks when desired. - Discovery helpers (
discovered_servers(),query_tool_docs(), etc.) are advertised in a short sandbox summary so the LLM fetches tool metadata on demand instead of receiving every schema up front. - Persistent Memory System for cross-session state:
save_memory(key, value)/load_memory(key)for data persistenceupdate_memory(key, fn)for atomic read-modify-writelist_memories()/memory_exists(key)for discovery- Memory stored as JSON in
/projects/memory/(maps to~/MCPs/user_tools/memory/)
Security Model:
- Network disabled (
--network none) - Read-only root filesystem
- All capabilities dropped
- No new privileges enforcement
- Unprivileged user execution (65534:65534)
- Resource limits (memory, PIDs, CPU, timeout)
- Temporary workspace with tmpfs
Performance:
- 95%+ context reduction vs traditional MCP
- Persistent client sessions
- Efficient async execution
- Proper resource cleanup
Documentation:
- Comprehensive README with quick start
- Detailed user guide (GUIDE.md)
- Technical architecture documentation
- Complete evolution history
Priority 1 (Operational Readiness):
-
Expand automated testing suite
- Broaden coverage beyond existing unit tests (container command generation, discovery logic)
- Add stress cases for RPC error handling and timeout enforcement
- Integrate container-backed end-to-end tests (optional but recommended)
-
Observability
- Structured logging with request IDs
- Metrics and traces for container launches, exits, errors, and tool calls
- MCP proxy latency/failure tracking
-
Agent-visible discovery channel
- Host-proxied
mcp-find/mcp-addso agents can curate servers dynamically - Catalog-aware policy checks before enabling newly added servers
- Host-proxied
Priority 2 (Production Hardening):
-
Policy controls
- Allow/deny lists for MCP servers
- Per-request limits
- Concurrent usage caps
-
Runtime diagnostics
- Enhanced podman/docker detection
- Self-health checks
- Better error messages
Nice to Have:
- Connection pooling for MCP clients
- Web UI for monitoring and debugging
- Multi-language execution support
- Workflow orchestration features
- Advanced caching strategies
- Persistent and shareable code-mode artifacts that survive individual runs
The bridge delivers a secure and functional code execution environment suitable for:
- Development and testing
- Learning and experimentation
- Integration with MCP-compatible clients
- Building MCP-enabled applications
Note: While functional, the project explicitly avoids claiming "production-grade" status due to the operational gaps listed below.
Complete the In Progress items above, especially:
- Automated testing - builds confidence
- Observability - enables troubleshooting
- Policy controls - prevents abuse
The core architecture is sound and secure, but these operational features are essential for production use.
# Install
uv sync
# Run
uv run python mcp_server_code_execution_mode.py
# Register with Claude
# See README.md for configuration details- Review README.md for quick start
- Read GUIDE.md for comprehensive usage
- Check ARCHITECTURE.md for technical details
- Explore HISTORY.md for evolution context
- Extend automated tests (see tests/test_entrypoint.py)
- Implement structured logging
- Add policy controls
- Improve runtime diagnostics
- Enhance error messages
- Documentation: See README.md, GUIDE.md, ARCHITECTURE.md
- Issues: File in repository
- Questions: Review documentation first
- Anthropic - Original "Code Execution with MCP" concept
- Cloudflare - Code Mode implementation inspiration
- Model Context Protocol - The underlying protocol
- Community - Feedback and contributions
Status: Functional, secure, documented Maturity: Production-capable with operational enhancements needed Focus: Testing, observability, production hardening