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.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。