Code Mode Bridge
An MCP server that aggregates multiple upstream MCP tools into a single 'codemode' tool for unified orchestration and execution. It enables agents to run generated code in an isolated sandbox to interact with various connected services through a single interface.
README
Code Mode Bridge
An MCP (Model Context Protocol) server that connects to upstream MCP servers and exposes all their tools through a single codemode tool for unified orchestration and execution.
Features
- Multi-server bridging: Connect to multiple upstream MCP servers simultaneously
- Tool aggregation: Exposes all upstream tools through a single
codemodetool - Dynamic discovery: Auto-generated tool descriptions show agents exactly what's available
- Namespaced tools: Tools are automatically namespaced by server (e.g.,
kubernetes__pods_list) - Sandbox execution: Code runs in isolated vm2 sandbox with 30-second timeout
- CLI management: Easy command-line interface for server configuration
npx compatible: Run directly withnpx codemode-bridge
Quick Start
Installation
npm install -g codemode-bridge
# or use directly with npx
npx codemode-bridge --help
Basic Usage
List configured servers:
codemode-bridge config list
Add a new server:
codemode-bridge config add kubernetes --type stdio --command "npx" --args "-y,kubernetes-mcp-server@latest"
Start the bridge (loads all configured servers):
codemode-bridge run
Load specific servers:
codemode-bridge run --servers kubernetes,time
Configuration
Servers are stored in ~/.config/codemode-bridge/mcp.json:
{
"servers": {
"kubernetes": {
"type": "stdio",
"command": "npx",
"args": ["-y", "kubernetes-mcp-server@latest"]
},
"time": {
"type": "stdio",
"command": "uvx",
"args": ["mcp-server-time"]
},
"example-http": {
"type": "http",
"url": "https://example.com/mcp"
}
}
}
Server Types
- stdio: Execute a command that runs an MCP server via stdin/stdout
- http: Connect to an HTTP-based MCP server
How It Works
- Connection: Connects to all configured upstream MCP servers using Vercel AI SDK's MCP client
- Tool Collection: Gathers tools from all servers via the MCP protocol
- Tool Wrapping: Uses @cloudflare/codemode SDK to wrap all tools
- Code Generation: SDK auto-generates TypeScript type definitions for tools
- Exposure: Exposes a single
codemodeMCP tool that agents can call - Execution: Runs agent-generated code in isolated vm2 sandbox with tool access
Tool Discovery
When agents query the codemode tool schema, the auto-generated description includes:
- TypeScript type definitions for all available tools
- Complete function signatures
- Tool descriptions and parameter documentation
- Example usage patterns
This allows agents to discover the complete API surface by reading the tool description.
CLI Commands
# Start the bridge (default command)
codemode-bridge run [options]
--servers <names> Comma-separated list of servers to load
--config <path> Custom config file path
# Configuration management
codemode-bridge config list # Show all configured servers
codemode-bridge config show <name> # Show specific server config
codemode-bridge config add <name> # Add new server
codemode-bridge config remove <name> # Remove server
codemode-bridge config edit <name> # Edit server config
codemode-bridge config info # Show config file location
Examples
Using with mcporter
# Start the bridge
codemode-bridge run --servers kubernetes &
# List available tools
mcporter list codemode-bridge --schema
# Call the codemode tool
mcporter call codemode-bridge.codemode code='async () => {
const namespaces = await codemode.kubernetes__namespaces_list({});
return namespaces;
}'
Using with Claude or other LLMs
When connected as an MCP server, Claude can:
- See the
codemodetool in its tool list - Read auto-generated documentation about all available tools
- Write code that orchestrates multiple tools across servers
- Execute the code in an isolated sandbox
Example code an LLM might write:
// Get current time and convert to different timezone
const now = await codemode.time__get_current_time({ timezone: "America/New_York" });
const singapore = await codemode.time__convert_time({
source_timezone: "America/New_York",
target_timezone: "Asia/Singapore",
time: now
});
return { newYork: now, singapore };
Architecture
┌─────────────────────────────────────────────────────────┐
│ MCP Clients (Claude, mcporter, etc) │
└────────────────────┬────────────────────────────────────┘
│ MCP Protocol
│
┌────────────────────▼────────────────────────────────────┐
│ Code Mode Bridge (MCP Server) │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Single "codemode" Tool │ │
│ │ - Auto-generated type definitions │ │
│ │ - Sandbox code execution │ │
│ │ - Tool orchestration │ │
│ └──────────────────────────────────────────────────┘ │
└────────────────────┬────────────────────────────────────┘
│ @ai-sdk/mcp (MCP Client)
┌────────────┼────────────┬─────────────┐
│ │ │ │
┌────▼─────┐ ┌───▼────┐ ┌────▼──────┐ ┌───▼──────┐
│Kubernetes │ │ Time │ │ GitLab │ │ Memory │
│ Server │ │ Server │ │ Server │ │ Server │
└──────────┘ └────────┘ └───────────┘ └──────────┘
Project Structure
src/
├── cli/
│ ├── index.ts # CLI entry point (with #!/usr/bin/env node shebang)
│ ├── commands.ts # Command implementations
│ └── config-manager.ts # Configuration management
├── mcp/
│ ├── server.ts # MCP server + upstream connections
│ ├── executor.ts # VM2 sandbox executor implementation
│ ├── mcp-adapter.ts # Protocol adapter (AI SDK Tool → MCP)
│ └── config.ts # Configuration types
└── index.ts # Package main entry point
config/
└── mcporter.json # mcporter client configuration
dist/ # Compiled JavaScript (generated)
.gitignore # Git ignore patterns
package.json # NPM package configuration
tsconfig.json # TypeScript configuration
README.md # This file
Development
Build
npm run build
Test CLI locally
npm run dev:cli -- run --servers time
npm run dev:cli -- config list
npm run dev:cli -- config show kubernetes
Rebuild and test after changes
npm run build
npx codemode-bridge config list
Security
- Sandboxed execution: Code runs in isolated vm2 environment
- Timeout enforcement: 30-second limit prevents infinite loops
- No network access: Sandbox cannot make direct HTTP requests
- No file system access: Cannot read/write files on host
- Tool isolation: Only tools from configured servers are accessible
Prebuilt Servers
The bridge comes pre-configured with popular MCP servers:
- kubernetes - Kubernetes cluster operations
- swf_gitlab - GitLab integration (with SWF instance)
- time - Time operations and timezone conversion
- memory - Knowledge graph memory system
- code-sandbox - Sandboxed code execution
- mcp-git - Git operations
- sequential-thinking - Structured reasoning
- atlassian_cloud - Atlassian cloud integration (HTTP)
Run codemode-bridge config list to see all available servers.
AI Generated Code Disclosure
For anyone wondering, yes, this is almost entirely AI generated code. Though I consider it of fairly low risk given that it's sole purpose is to
- Run JS code in a VM2 environment.
- Bridge MCP servers to the VM2 sandbox.
- Most of this is built on top of existing libraries.
I have not (yet) tested this extensively to see what the VM2 sandbox capabilities are. This is more of an experiment I had going in the background during the workday to see if I could get cloudflare's Code Mode to work... without paying for workers.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.