# mcp-bridge Connect zut to [MCP (Model Context Protocol)](https://modelcontextprotocol.io) servers. This extension reads MCP server configurations from standard locations (same format as Claude Desktop, Cursor, Cline, etc.) and bridges their tools into zut so the LLM can call them directly. ## Features - **Standard config format** — same JSON as Claude Desktop, Cursor, Cline - **On-demand tool discovery** — only `mcp__search_tools` is advertised initially; matching MCP schemas load when needed instead of bloating every model request - **Smart lazy loading** — cached definitions register as deferred tools at startup, servers wake for refresh or tool calls, then auto-sleep after idle time - **Auto-respawn** — calling a loaded tool on a sleeping server wakes it up automatically - **Multi-transport** — stdio, streamable-http, and SSE transports - **Multi-server** — connect to any number of MCP servers simultaneously - **Tool namespacing** — tools appear as `mcp____` to avoid collisions - **Tool annotations** — read-only, destructive, idempotent hints surfaced to LLM - **Configurable timeouts** — per-server connect, request, and idle timeouts - **Custom headers** — auth tokens and other headers for HTTP servers - **Slash commands** — `/mcp` to check status, start/stop/restart servers - **Better error messages** — context-aware errors with actionable suggestions ## Quick Start 1. **Build the extension:** ```bash cd examples/extensions/mcp-bridge go build -o mcp-bridge . ``` 2. **Create a project config file:** ```bash mkdir -p .zut cat > .zut/mcp.json << 'EOF' { "mcpServers": { "filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "."] }, "context7": { "command": "npx", "args": ["-y", "@upstash/context7-mcp@latest"] } } } EOF ``` 3. **Install the extension:** ```bash zut ext install . ``` 4. **Restart zut.** On first run the extension refreshes its tool cache in the background. When zut shows `MCP tool cache changed`, run `/reload-ext` once. Future launches register the cached MCP tools immediately as deferred definitions. The model initially sees one small loader tool, `mcp__search_tools`. It searches cached MCP tool names and descriptions locally, activates up to eight relevant definitions by default, and then calls the selected MCP tool normally. This keeps large MCP installations compatible with providers that limit request or tool-schema size. ## Configuration Config files are loaded from two locations (project overrides global per-server): | Location | Scope | |---|---| | `$ZUT_HOME/mcp.json` | Global (`$XDG_STATE_HOME/zut/mcp.json` when `XDG_STATE_HOME` is set) | | `.zut/mcp.json` | Project-level (in your project root) | ### Config Format Standard MCP config — same as Claude Desktop, with zut-specific extensions: ```jsonc { "mcpServers": { // ── Stdio transport (local subprocess) ─────────────────────────────────── "filesystem": { "command": "npx", // executable to spawn "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"], "env": { // extra environment variables "NODE_ENV": "production" }, "connectTimeout": 30, // connection timeout (seconds) "requestTimeout": 60, // per-request timeout (seconds) "idleTimeout": 300 // idle timeout before stopping (seconds) }, // ── Streamable HTTP transport (modern HTTP) ───────────────────────────── "supabase": { "transport": "streamable-http", "url": "https://mcp.supabase.com/mcp", "headers": { // custom HTTP headers "Authorization": "Bearer YOUR_TOKEN" } }, // ── SSE transport (legacy HTTP) ───────────────────────────────────────── "legacy-server": { "transport": "sse", "url": "https://example.com/sse" } } } ``` ### Configuration Options | Field | Type | Default | Description | |---|---|---|---| | `command` | string | — | Executable to spawn (stdio only) | | `args` | string[] | [] | Arguments for the command | | `env` | object | — | Extra environment variables | | `transport` | string | "stdio" | Transport: "stdio", "streamable-http", or "sse" | | `url` | string | — | Server URL (HTTP transports only) | | `headers` | object | — | Custom HTTP headers (HTTP transports only) | | `connectTimeout` | number | 30 | Connection timeout in seconds | | `requestTimeout` | number | 60 | Per-request timeout in seconds | | `idleTimeout` | number | 300 | Idle timeout before stopping in seconds | ### Example: Multiple Servers ```jsonc { "mcpServers": { // Filesystem access (stdio) "filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/projects"] }, // Grep.app - Search GitHub (streamable-http) "grep": { "transport": "streamable-http", "url": "https://mcp.grep.app/" }, // Database queries (stdio) "sqlite": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-sqlite", "test.db"] }, // Documentation lookup (stdio) "context7": { "command": "npx", "args": ["-y", "@upstash/context7-mcp@latest"] } } } ``` ## How It Works ``` ┌──────────────────────────────────────────────────────────────┐ │ zut agent │ │ │ │ ┌──────────┐ tool_call ┌──────────────┐ │ │ │ LLM │───────────────▶│ mcp-bridge │ │ │ │ │◀───────────────│ (extension) │ │ │ └──────────┘ tool_result └──────┬───────┘ │ │ │ │ │ ┌──────────┼──────────┐ │ │ ▼ ▼ ▼ │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ MCP │ │ MCP │ │ MCP │ │ │ │ server 1 │ │ server 2 │ │ server 3 │ │ │ │ (stdio) │ │ (stdio) │ │ (stdio) │ │ │ └──────────┘ └──────────┘ └──────────┘ │ └──────────────────────────────────────────────────────────────┘ ``` 1. **Startup**: mcp-bridge reads config and registers tools from `mcp-tools-cache.json` 2. **Background refresh**: starts configured MCP servers, calls `tools/list`, and updates the cache when definitions change 3. **Reload**: if the cache changed, run `/reload-ext` once so zut rebuilds the tool registry with the new definitions 4. **Naming**: tools appear as `mcp____` (e.g., `mcp__filesystem__read_file`) 5. **Idle timeout**: servers not used for 5 minutes are automatically stopped 6. **Auto-respawn**: calling a tool on a stopped server wakes it up 7. **Routing**: tool calls are forwarded to the appropriate MCP server ## Slash Commands | Command | Description | |---|---| | `/mcp` | Show status of all configured servers | | `/mcp help` | Show available MCP commands | | `/mcp ` | Show detailed status for one server | | `/mcp start ` | Manually start a server | | `/mcp stop ` | Manually stop a server | | `/mcp restart` | Restart all servers | | `/mcp start all` | Manually start all servers | | `/mcp stop all` | Manually stop all servers | | `/mcp setup templates` | Show available setup templates | | `/mcp setup add