claude-mcp-bridge 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +131 -216
  2. package/dist/annotations.d.ts +24 -0
  3. package/dist/annotations.d.ts.map +1 -0
  4. package/dist/annotations.js +53 -0
  5. package/dist/annotations.js.map +1 -0
  6. package/dist/descriptions.d.ts +15 -0
  7. package/dist/descriptions.d.ts.map +1 -0
  8. package/dist/descriptions.js +56 -0
  9. package/dist/descriptions.js.map +1 -0
  10. package/dist/index.js +255 -143
  11. package/dist/index.js.map +1 -1
  12. package/dist/tools/ping.d.ts +2 -0
  13. package/dist/tools/ping.d.ts.map +1 -1
  14. package/dist/tools/ping.js +10 -2
  15. package/dist/tools/ping.js.map +1 -1
  16. package/dist/tools/review.d.ts +9 -0
  17. package/dist/tools/review.d.ts.map +1 -1
  18. package/dist/tools/review.js +50 -12
  19. package/dist/tools/review.js.map +1 -1
  20. package/dist/utils/git.d.ts +22 -0
  21. package/dist/utils/git.d.ts.map +1 -1
  22. package/dist/utils/git.js +40 -0
  23. package/dist/utils/git.js.map +1 -1
  24. package/dist/utils/meta.d.ts +18 -0
  25. package/dist/utils/meta.d.ts.map +1 -0
  26. package/dist/utils/meta.js +29 -0
  27. package/dist/utils/meta.js.map +1 -0
  28. package/dist/utils/progress.d.ts +37 -0
  29. package/dist/utils/progress.d.ts.map +1 -0
  30. package/dist/utils/progress.js +49 -0
  31. package/dist/utils/progress.js.map +1 -0
  32. package/dist/utils/session.d.ts +58 -0
  33. package/dist/utils/session.d.ts.map +1 -0
  34. package/dist/utils/session.js +98 -0
  35. package/dist/utils/session.js.map +1 -0
  36. package/dist/utils/spawn.d.ts +6 -0
  37. package/dist/utils/spawn.d.ts.map +1 -1
  38. package/dist/utils/spawn.js +6 -0
  39. package/dist/utils/spawn.js.map +1 -1
  40. package/package.json +1 -1
  41. package/dist/utils/retry.d.ts +0 -9
  42. package/dist/utils/retry.d.ts.map +0 -1
  43. package/dist/utils/retry.js +0 -29
  44. package/dist/utils/retry.js.map +0 -1
package/README.md CHANGED
@@ -1,18 +1,20 @@
1
1
  # claude-mcp-bridge
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/claude-mcp-bridge)](https://www.npmjs.com/package/claude-mcp-bridge)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
- [![Node.js](https://img.shields.io/badge/node-%3E%3D18-brightgreen)](https://nodejs.org/)
6
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.7-blue)](https://www.typescriptlang.org/)
7
- [![MCP SDK](https://img.shields.io/badge/MCP%20SDK-1.12-purple)](https://modelcontextprotocol.io/)
4
+ [![npm downloads](https://img.shields.io/npm/dm/claude-mcp-bridge)](https://www.npmjs.com/package/claude-mcp-bridge)
5
+ [![CI](https://github.com/hampsterx/claude-mcp-bridge/actions/workflows/ci.yml/badge.svg)](https://github.com/hampsterx/claude-mcp-bridge/actions/workflows/ci.yml)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7
+ [![Node.js](https://img.shields.io/node/v/claude-mcp-bridge)](https://nodejs.org/)
8
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
9
+ [![MCP](https://img.shields.io/badge/MCP-compatible-8A2BE2)](https://modelcontextprotocol.io/)
8
10
 
9
- MCP server that wraps [Claude Code CLI](https://github.com/anthropics/claude-code) as a subprocess, exposing code execution, agentic review, web search, and structured output as MCP tools.
11
+ MCP server that wraps [Claude Code CLI](https://github.com/anthropics/claude-code) as a subprocess, exposing its capabilities as [Model Context Protocol](https://modelcontextprotocol.io/) tools.
10
12
 
11
- Works with any MCP client: Codex CLI, Gemini CLI, Cursor, Windsurf, VS Code, or any tool that speaks [Model Context Protocol](https://modelcontextprotocol.io/).
13
+ Works with any MCP client: Codex CLI, Gemini CLI, Cursor, Windsurf, VS Code, or any tool that speaks MCP.
12
14
 
13
15
  ## Do you need this?
14
16
 
15
- If you're in a terminal agent (Codex CLI, Gemini CLI) with shell access, you can call Claude Code CLI directly:
17
+ If you're in a terminal agent (Codex CLI, Gemini CLI) with shell access, call Claude Code CLI directly:
16
18
 
17
19
  ```bash
18
20
  # Quick review of current diff
@@ -38,290 +40,203 @@ claude -p --bare --max-budget-usd 0.50 "Is this retry logic sound?"
38
40
  - You need concurrency management and security hardening
39
41
  - You want cost metadata surfaced in MCP responses
40
42
 
41
- ## Installation
43
+ ## Quick Start
44
+
45
+ ```bash
46
+ npx claude-mcp-bridge
47
+ ```
42
48
 
43
49
  ### Prerequisites
44
50
 
45
- - Node.js >= 18
46
51
  - [Claude Code CLI](https://github.com/anthropics/claude-code) installed and on PATH
47
52
  - Authentication (one of):
48
53
  - **Subscription**: `claude login` (uses your Pro/Max plan, no API credits needed)
49
54
  - **API key**: set `ANTHROPIC_API_KEY` (billed per use via console.anthropic.com)
50
55
 
51
- ### From source
52
-
53
- ```bash
54
- git clone https://github.com/hampsterx/claude-mcp-bridge.git
55
- cd claude-mcp-bridge
56
- npm install
57
- npm run build
58
- ```
59
-
60
- ### MCP client configuration
61
-
62
- Add to your MCP client config (e.g. `~/.claude/settings.json`, Cursor settings, etc.):
56
+ ### Codex CLI
63
57
 
58
+ Add to `~/.codex/config.json`:
64
59
  ```json
65
60
  {
66
61
  "mcpServers": {
67
- "claude-mcp-bridge": {
68
- "command": "node",
69
- "args": ["/path/to/claude-mcp-bridge/dist/index.js"],
70
- "env": {
71
- "ANTHROPIC_API_KEY": "sk-ant-..."
72
- }
62
+ "claude-bridge": {
63
+ "command": "npx",
64
+ "args": ["-y", "claude-mcp-bridge"]
73
65
  }
74
66
  }
75
67
  }
76
68
  ```
77
69
 
78
- Or if installed globally:
70
+ ### Gemini CLI
79
71
 
72
+ Add to `~/.gemini/settings.json`:
80
73
  ```json
81
74
  {
82
75
  "mcpServers": {
83
- "claude-mcp-bridge": {
84
- "command": "claude-mcp-bridge"
76
+ "claude-bridge": {
77
+ "command": "npx",
78
+ "args": ["-y", "claude-mcp-bridge"]
85
79
  }
86
80
  }
87
81
  }
88
82
  ```
89
83
 
90
- ## Tools
91
-
92
- ### `query`
93
-
94
- Execute a prompt via Claude Code CLI with optional file context and session resume.
84
+ ### Cursor / Windsurf / VS Code
95
85
 
86
+ Add to your MCP settings:
96
87
  ```json
97
88
  {
98
- "prompt": "Explain the error handling in this file",
99
- "files": ["src/utils/errors.ts"],
100
- "model": "sonnet",
101
- "workingDirectory": "/path/to/repo",
102
- "timeout": 60000,
103
- "maxBudgetUsd": 0.50
89
+ "claude-bridge": {
90
+ "command": "npx",
91
+ "args": ["-y", "claude-mcp-bridge"],
92
+ "env": {
93
+ "ANTHROPIC_API_KEY": "sk-ant-..."
94
+ }
95
+ }
104
96
  }
105
97
  ```
106
98
 
107
- | Parameter | Type | Default | Description |
108
- |-----------|------|---------|-------------|
109
- | `prompt` | string | (required) | The prompt to send to Claude |
110
- | `files` | string[] | | File paths relative to workingDirectory (text or images) |
111
- | `model` | string | `sonnet` | Model alias or full Claude model name |
112
- | `sessionId` | string | | Session ID to resume a multi-turn conversation |
113
- | `noSessionPersistence` | boolean | | Disable session persistence for one-off calls |
114
- | `workingDirectory` | string | `cwd` | Working directory for file resolution and CLI execution |
115
- | `timeout` | number | 60000 | Timeout in ms (120000 for image queries) |
116
- | `maxResponseLength` | number | | Soft limit on response length in words |
117
- | `maxBudgetUsd` | number | | Cost cap in USD |
118
- | `effort` | string | | `low`, `medium`, `high`, or `max` |
119
-
120
- Supports images (.png, .jpg, .jpeg, .gif, .webp, .bmp) up to 5MB each. Text files are inlined into the prompt; image paths are passed to Claude's Read tool.
121
-
122
- ### `structured`
123
-
124
- Generate JSON that conforms to a provided JSON Schema using Claude CLI's native `--json-schema` validation.
99
+ ## Tools
125
100
 
126
- ```json
127
- {
128
- "prompt": "Extract all function signatures from this file",
129
- "schema": "{\"type\":\"object\",\"properties\":{\"functions\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\"},\"params\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}},\"required\":[\"name\"]}}},\"required\":[\"functions\"]}",
130
- "files": ["src/index.ts"],
131
- "workingDirectory": "/path/to/repo"
132
- }
133
- ```
101
+ | Tool | Description |
102
+ |------|-------------|
103
+ | **query** | Execute prompts with file context, session resume, effort control, and budget caps. Supports text and images. |
104
+ | **review** | Agentic code review. Claude explores the repo with Read, Grep, Glob, and git commands. Quick diff-only mode available. |
105
+ | **search** | Web search via Claude CLI's WebSearch and WebFetch tools. Returns synthesized answers with sources. |
106
+ | **structured** | JSON Schema validated output via Claude CLI's native `--json-schema`. |
107
+ | **ping** | Health check with CLI version, auth method, capabilities, and model config. |
108
+ | **listSessions** | List active sessions with cumulative cost, turn count, and timestamps. |
134
109
 
135
- | Parameter | Type | Default | Description |
136
- |-----------|------|---------|-------------|
137
- | `prompt` | string | (required) | What to generate or extract |
138
- | `schema` | string | (required) | JSON Schema as a JSON string (max 20KB) |
139
- | `files` | string[] | | Text file paths to include as context (no images) |
140
- | `model` | string | `sonnet` | Model alias or full model name |
141
- | `sessionId` | string | | Session ID to resume |
142
- | `noSessionPersistence` | boolean | | Disable session persistence |
143
- | `workingDirectory` | string | `cwd` | Working directory for file resolution |
144
- | `timeout` | number | 60000 | Timeout in ms |
145
- | `maxBudgetUsd` | number | | Cost cap in USD |
110
+ ### query
146
111
 
147
- Returns clean JSON in the first content block. Metadata (model, session, cost) in a separate content block so JSON parsing isn't broken.
112
+ Execute a prompt with optional file context. Supports session resume via `sessionId`, effort control (`low`/`medium`/`high`/`max`), and budget caps (`maxBudgetUsd`). Images (.png, .jpg, .gif, .webp, .bmp) up to 5MB each are passed to Claude's Read tool.
148
113
 
149
- ### `review`
114
+ Key parameters: `prompt` (required), `files`, `model` (default `sonnet`), `sessionId`, `effort`, `maxBudgetUsd`, `workingDirectory`, `timeout` (default 60s).
150
115
 
151
- Repo-aware code review with two modes:
116
+ ### review
152
117
 
153
- **Agentic mode** (default): Claude explores the repo using Read, Grep, Glob, and git commands. It follows imports, checks tests, and reads surrounding context. Slower but thorough.
118
+ Two modes:
119
+ - **Agentic** (default): Claude runs inside the repo with Read, Grep, Glob, and git commands. It diffs, reads files, follows imports, and checks tests. Timeout auto-scales from diff size.
120
+ - **Quick** (`quick: true`): Diff-only review, no repo exploration. Faster and cheaper.
154
121
 
155
- **Quick mode** (`quick: true`): Reviews a pre-computed diff only. No tool calls, no file exploration. Faster, cheaper, good for small changes.
122
+ Key parameters: `uncommitted` (default true), `base`, `focus`, `quick`, `model` (default `opus`), `effort` (default `high`), `maxBudgetUsd`, `workingDirectory`, `timeout`.
156
123
 
157
- ```json
158
- {
159
- "base": "main",
160
- "focus": "security and error handling",
161
- "workingDirectory": "/path/to/repo",
162
- "maxBudgetUsd": 1.00
163
- }
164
- ```
124
+ ### search
165
125
 
166
- | Parameter | Type | Default | Description |
167
- |-----------|------|---------|-------------|
168
- | `uncommitted` | boolean | `true` | Review uncommitted changes (staged + unstaged) |
169
- | `base` | string | | Base branch/ref to diff against (overrides uncommitted) |
170
- | `focus` | string | | Review focus area (e.g. "security", "error handling") |
171
- | `quick` | boolean | `false` | Use quick (diff-only) mode instead of agentic |
172
- | `model` | string | `opus` | Model alias or full model name |
173
- | `sessionId` | string | | Session ID to resume |
174
- | `noSessionPersistence` | boolean | | Disable session persistence |
175
- | `workingDirectory` | string | `cwd` | Repository root |
176
- | `timeout` | number | 300000 / 120000 | 5min (agentic) or 2min (quick) |
177
- | `maxResponseLength` | number | | Soft limit on response length in words |
178
- | `maxBudgetUsd` | number | | Cost cap in USD |
179
- | `effort` | string | `high` | `low`, `medium`, `high`, or `max` |
126
+ Web search via Claude CLI's WebSearch and WebFetch tools. Returns synthesized answers with source URLs.
180
127
 
181
- Agentic mode allowed tools: `Read`, `Grep`, `Glob`, `Bash(git diff:*)`, `Bash(git log:*)`, `Bash(git show:*)`, `Bash(git status:*)`.
128
+ Key parameters: `query` (required), `model` (default `sonnet`), `maxResponseLength`, `maxBudgetUsd`, `timeout` (default 120s).
182
129
 
183
- ### `search`
130
+ ### structured
184
131
 
185
- Web search via Claude Code CLI using WebSearch and WebFetch tools.
132
+ Generate JSON conforming to a provided schema using Claude CLI's native `--json-schema` flag. Returns clean JSON in the first content block, metadata in a separate block so JSON parsing isn't broken.
186
133
 
187
- ```json
188
- {
189
- "query": "What changed in MCP SDK v1.12?",
190
- "maxResponseLength": 500
191
- }
192
- ```
134
+ Key parameters: `prompt` (required), `schema` (required, JSON string, max 20KB), `files`, `model` (default `sonnet`), `sessionId`, `maxBudgetUsd`, `timeout` (default 60s).
193
135
 
194
- | Parameter | Type | Default | Description |
195
- |-----------|------|---------|-------------|
196
- | `query` | string | (required) | Search query or question |
197
- | `model` | string | `sonnet` | Model alias or full model name |
198
- | `sessionId` | string | | Session ID to resume |
199
- | `noSessionPersistence` | boolean | | Disable session persistence |
200
- | `workingDirectory` | string | `cwd` | Working directory for the CLI |
201
- | `timeout` | number | 120000 | Timeout in ms |
202
- | `maxResponseLength` | number | | Soft limit on response length in words |
203
- | `maxBudgetUsd` | number | | Cost cap in USD |
204
- | `effort` | string | `medium` | `low`, `medium`, `high`, or `max` |
136
+ ### ping
205
137
 
206
- ### `ping`
138
+ No parameters. Returns CLI version, auth method (subscription/api-key/none), configured models, capabilities, and server version.
207
139
 
208
- Health check. No parameters. Returns CLI availability, auth status, configured models, server version, and capability flags.
140
+ ### listSessions
209
141
 
210
- ```
211
- cliFound: true
212
- version: 2.1.92 (Claude Code)
213
- authMethod: subscription
214
- subscriptionType: max
215
- defaultModel: sonnet
216
- fallbackModel: haiku
217
- serverVersion: 0.1.0
218
- nodeVersion: v22.22.0
219
- maxConcurrent: 3
220
- capabilities: bareMode=true, jsonOutput=true, jsonSchema=true, sessionResume=true
221
- ```
142
+ No parameters. Returns active sessions with metadata: `sessionId`, `model`, `createdAt`, `lastUsedAt`, `turnCount`, `totalCostUsd`.
222
143
 
223
- `authMethod` is one of: `api-key` (ANTHROPIC_API_KEY set), `subscription` (logged in via `claude login`), or `none`.
144
+ All tools attach execution metadata (`_meta`) with `durationMs`, `model`, `sessionId`, `totalCostUsd`, and token breakdowns. See [DESIGN.md](DESIGN.md) for details.
224
145
 
225
146
  ## Configuration
226
147
 
227
- All configuration is through environment variables. None are required if Claude CLI is on PATH and you're authenticated (via `claude login` or `ANTHROPIC_API_KEY`).
228
-
229
- ### Authentication
230
-
231
- The bridge supports two auth methods, matching Claude Code CLI:
232
-
233
- | Method | Setup | Billing |
234
- |--------|-------|---------|
235
- | **Subscription** | `claude login` (OAuth) | Pro/Max plan (included) |
236
- | **API key** | Set `ANTHROPIC_API_KEY` | Pay-per-use (console.anthropic.com) |
237
-
238
- If `ANTHROPIC_API_KEY` is set, it takes priority over subscription auth. To use your subscription instead, unset the API key.
239
-
240
148
  ### Models
241
149
 
242
150
  | Variable | Default | Description |
243
151
  |----------|---------|-------------|
244
152
  | `CLAUDE_DEFAULT_MODEL` | | Shared default for all tools |
245
- | `CLAUDE_QUERY_MODEL` | `sonnet` | Default model for query |
246
- | `CLAUDE_STRUCTURED_MODEL` | `sonnet` | Default model for structured |
247
- | `CLAUDE_SEARCH_MODEL` | `sonnet` | Default model for search |
248
- | `CLAUDE_REVIEW_MODEL` | `opus` | Default model for review |
249
- | `CLAUDE_FALLBACK_MODEL` | `haiku` | Fallback on quota exhaustion (set to `none` to disable) |
153
+ | `CLAUDE_QUERY_MODEL` | `sonnet` | Default for query |
154
+ | `CLAUDE_STRUCTURED_MODEL` | `sonnet` | Default for structured |
155
+ | `CLAUDE_SEARCH_MODEL` | `sonnet` | Default for search |
156
+ | `CLAUDE_REVIEW_MODEL` | `opus` | Default for review |
157
+ | `CLAUDE_FALLBACK_MODEL` | `haiku` | Fallback on quota exhaustion (`none` to disable) |
250
158
 
251
- Model resolution order: explicit parameter > tool-specific env var > `CLAUDE_DEFAULT_MODEL` > built-in default.
159
+ Model resolution: explicit parameter > tool-specific env var > `CLAUDE_DEFAULT_MODEL` > built-in default.
252
160
 
253
- ### Effort and budget
161
+ ### Runtime
254
162
 
255
163
  | Variable | Default | Description |
256
164
  |----------|---------|-------------|
257
- | `CLAUDE_REVIEW_EFFORT` | `high` | Default effort for review tool |
258
- | `CLAUDE_SEARCH_EFFORT` | `medium` | Default effort for search tool |
259
- | `CLAUDE_QUERY_EFFORT` | | Default effort for query tool |
165
+ | `CLAUDE_MAX_CONCURRENT` | `3` | Max concurrent subprocess spawns |
166
+ | `CLAUDE_CLI_PATH` | `claude` | Path to CLI binary |
260
167
  | `CLAUDE_MAX_BUDGET_USD` | | Global cost cap in USD (per call) |
168
+ | `ANTHROPIC_API_KEY` | | API key for bare mode auth |
261
169
 
262
- ### Runtime
170
+ ### Effort
263
171
 
264
172
  | Variable | Default | Description |
265
173
  |----------|---------|-------------|
266
- | `CLAUDE_MAX_CONCURRENT` | `3` | Max simultaneous Claude CLI processes |
267
- | `CLAUDE_CLI_PATH` | `claude` | Custom path to Claude CLI binary |
268
- | `ANTHROPIC_API_KEY` | | API key for bare mode auth |
269
-
270
- ## Security
271
-
272
- ### Subprocess environment isolation
273
-
274
- Only a strict allowlist of environment variables is passed to Claude CLI subprocesses: `ANTHROPIC_API_KEY`, `CLAUDE_CONFIG_DIR`, `CLAUDE_CODE_USE_BEDROCK`, `CLAUDE_CODE_USE_VERTEX`, `AWS_REGION`, `AWS_DEFAULT_REGION`, `HOME`, `PATH`, `USER`, `SHELL`, `LANG`, `TERM`, `XDG_CONFIG_HOME`. Everything else is stripped.
275
-
276
- ### Path sandboxing
277
-
278
- All file paths are resolved to absolute paths via `realpath()` and verified to stay within the working directory. Symlink traversal and `..` path components that escape the sandbox are rejected.
279
-
280
- ### Git argument injection prevention
281
-
282
- The `base` parameter in the review tool is validated against `/^[\w./-]+$/` before being passed to git commands, preventing argument injection (e.g. a malicious ref like `--output=/tmp/pwned`).
283
-
284
- ### Output redaction
285
-
286
- CLI output is scanned for sensitive patterns before being returned: Anthropic API keys (`sk-ant-*`), Bearer tokens, token assignments, and base64-encoded strings that look like secrets are replaced with `[REDACTED]`.
287
-
288
- ### Limits
289
-
290
- | Limit | Value |
291
- |-------|-------|
292
- | Max file size (text) | 1 MB |
293
- | Max file size (image) | 5 MB |
294
- | Max files per request | 20 |
295
- | Max JSON Schema size | 20 KB |
296
- | Hard timeout cap | 10 minutes |
297
- | Concurrency queue timeout | 30 seconds |
298
-
299
- ## Concurrency
300
-
301
- Requests are queued with a FIFO scheduler. Default: 3 concurrent Claude CLI processes. If all slots are busy, new requests wait up to 30 seconds before being rejected. Timed-out processes are killed with SIGTERM, then SIGKILL after 5 seconds. On Unix, the entire process group is killed to clean up child processes.
174
+ | `CLAUDE_REVIEW_EFFORT` | `high` | Default effort for review |
175
+ | `CLAUDE_SEARCH_EFFORT` | `medium` | Default effort for search |
176
+ | `CLAUDE_QUERY_EFFORT` | | Default effort for query |
177
+
178
+ ## Choosing a Claude Code MCP server
179
+
180
+ | You need... | Consider |
181
+ |-------------|----------|
182
+ | Structured output, effort/budget control, session resume, cost metadata | This bridge |
183
+ | Multi-tool orchestration (read, grep, edit, bash as separate MCP tools) | [mcp-claude-code](https://github.com/SDGLBL/mcp-claude-code) |
184
+ | Session continuity with async execution | [claude-mcp](https://github.com/zhendalf/claude-mcp) |
185
+ | Maintained lightweight wrapper | [@kunihiros/claude-code-mcp](https://github.com/KunihiroS/claude-code-mcp) |
186
+ | Native Claude Code MCP (built-in, no wrapper) | `claude mcp serve` ([docs](https://github.com/anthropics/claude-code)) |
187
+
188
+ ## Performance
189
+
190
+ Claude Code CLI has minimal startup overhead. Wall time is dominated by model inference and any agentic exploration.
191
+
192
+ | Scenario | Typical time |
193
+ |----------|-------------|
194
+ | Trivial prompt (sonnet) | 5-10s |
195
+ | Quick review, small diff | 15-30s |
196
+ | Agentic review (explores repo) | 30s to 10 min |
197
+ | Web search + synthesis | 15-30s |
198
+
199
+ Cost metadata (`totalCostUsd`, token breakdowns) is returned in `_meta` on every response.
200
+
201
+ ## Bridge family
202
+
203
+ Three MCP servers, same architecture, different underlying CLIs. Each wraps a terminal agent as a subprocess and exposes it as MCP tools. Pick the one that matches your model provider, or run multiple for cross-model workflows.
204
+
205
+ | | [claude-mcp-bridge](https://github.com/hampsterx/claude-mcp-bridge) | [gemini-mcp-bridge](https://github.com/hampsterx/gemini-mcp-bridge) | [codex-mcp-bridge](https://github.com/hampsterx/codex-mcp-bridge) |
206
+ |---|---|---|---|
207
+ | **CLI** | Claude Code | Gemini CLI | Codex CLI |
208
+ | **Provider** | Anthropic | Google | OpenAI |
209
+ | **Tools** | query, review, search, structured, ping, listSessions | query, review, search, structured, ping | codex, review, search, query, structured, ping, listSessions |
210
+ | **Agentic review** | Claude explores repo with Read/Grep/Glob/git | Gemini explores repo with file reads and git | Codex explores repo in full-auto mode |
211
+ | **Structured output** | Native `--json-schema` (no Ajv) | Ajv validation | Ajv validation |
212
+ | **Session resume** | Native `--resume` | Not supported | Session IDs with multi-turn |
213
+ | **Budget caps** | Native `--max-budget-usd` | Not supported | Not supported |
214
+ | **Effort control** | `--effort low/medium/high/max` | Not supported | Not supported |
215
+ | **Cold start** | ~1-2s | ~16s | <100ms (inference dominates) |
216
+ | **Auth** | `claude login` (subscription) or `ANTHROPIC_API_KEY` | `gemini auth login` | `OPENAI_API_KEY` |
217
+ | **Cost** | Subscription (included) or API credits | Free tier available | Pay-per-token |
218
+ | **Concurrency** | 3 (configurable) | 3 (configurable) | 3 (configurable) |
219
+ | **Model fallback** | Auto-retry with fallback model | Not supported | Auto-retry with fallback model |
220
+
221
+ All three share: subprocess env isolation, path sandboxing, output redaction, FIFO concurrency queue, MCP tool annotations, `_meta` response metadata, progress heartbeats.
302
222
 
303
223
  ## Development
304
224
 
305
225
  ```bash
306
- npm run build # Compile TypeScript
307
- npm run dev # Watch mode
308
- npm test # Run unit tests (vitest)
309
- npm run lint # ESLint
310
- npm run typecheck # Type check without emitting
311
- npm run smoke # Smoke test against live Claude CLI
226
+ npm install
227
+ npm run build # Compile TypeScript
228
+ npm run dev # Watch mode
229
+ npm test # Run tests (vitest)
230
+ npm run lint # ESLint
231
+ npm run typecheck # tsc --noEmit
232
+ npm run smoke # Smoke test against live CLI
312
233
  ```
313
234
 
314
- ### Smoke tests
315
-
316
- ```bash
317
- node scripts/smoke-test.mjs query ~/my-repo
318
- node scripts/smoke-test.mjs structured ~/my-repo
319
- node scripts/smoke-test.mjs review ~/my-repo
320
- node scripts/smoke-test.mjs search
321
- node scripts/smoke-test.mjs ping
322
- ```
235
+ ## Further reading
323
236
 
324
- Requires Claude CLI installed and `ANTHROPIC_API_KEY` set.
237
+ - [DESIGN.md](DESIGN.md) - Architecture, sessions, cost tracking, response metadata, progress notifications
238
+ - [SECURITY.md](SECURITY.md) - Environment isolation, path sandboxing, output redaction, tool sandboxing
239
+ - [CHANGELOG.md](CHANGELOG.md) - Release history
325
240
 
326
241
  ## License
327
242
 
@@ -0,0 +1,24 @@
1
+ import type { ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
2
+ /**
3
+ * MCP tool annotations for all claude-mcp-bridge tools.
4
+ *
5
+ * Annotations are hints that help MCP clients understand tool behavior
6
+ * for permission prompts, safety checks, and orchestration decisions.
7
+ *
8
+ * readOnly: query/review/search/structured are false because they can persist
9
+ * Claude CLI session state to disk (~/.claude/) when sessionId is used.
10
+ * ping is true (purely local, no side effects).
11
+ *
12
+ * review: destructive=false because the default --allowed-tools list is read-only
13
+ * (Read, Grep, Glob, git). Callers that pass custom tools including write access
14
+ * should treat it as potentially destructive.
15
+ *
16
+ * Titles are set on the registerTool config in index.ts, not here (avoid duplication).
17
+ */
18
+ export declare const queryAnnotations: ToolAnnotations;
19
+ export declare const reviewAnnotations: ToolAnnotations;
20
+ export declare const searchAnnotations: ToolAnnotations;
21
+ export declare const structuredAnnotations: ToolAnnotations;
22
+ export declare const listSessionsAnnotations: ToolAnnotations;
23
+ export declare const pingAnnotations: ToolAnnotations;
24
+ //# sourceMappingURL=annotations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../src/annotations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAE1E;;;;;;;;;;;;;;;GAeG;AAEH,eAAO,MAAM,gBAAgB,EAAE,eAK9B,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,eAK/B,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,eAK/B,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,eAKnC,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,eAKrC,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,eAK7B,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * MCP tool annotations for all claude-mcp-bridge tools.
3
+ *
4
+ * Annotations are hints that help MCP clients understand tool behavior
5
+ * for permission prompts, safety checks, and orchestration decisions.
6
+ *
7
+ * readOnly: query/review/search/structured are false because they can persist
8
+ * Claude CLI session state to disk (~/.claude/) when sessionId is used.
9
+ * ping is true (purely local, no side effects).
10
+ *
11
+ * review: destructive=false because the default --allowed-tools list is read-only
12
+ * (Read, Grep, Glob, git). Callers that pass custom tools including write access
13
+ * should treat it as potentially destructive.
14
+ *
15
+ * Titles are set on the registerTool config in index.ts, not here (avoid duplication).
16
+ */
17
+ export const queryAnnotations = {
18
+ readOnlyHint: false,
19
+ destructiveHint: false,
20
+ idempotentHint: false,
21
+ openWorldHint: true,
22
+ };
23
+ export const reviewAnnotations = {
24
+ readOnlyHint: false,
25
+ destructiveHint: false,
26
+ idempotentHint: false,
27
+ openWorldHint: true,
28
+ };
29
+ export const searchAnnotations = {
30
+ readOnlyHint: false,
31
+ destructiveHint: false,
32
+ idempotentHint: true,
33
+ openWorldHint: true,
34
+ };
35
+ export const structuredAnnotations = {
36
+ readOnlyHint: false,
37
+ destructiveHint: false,
38
+ idempotentHint: false,
39
+ openWorldHint: true,
40
+ };
41
+ export const listSessionsAnnotations = {
42
+ readOnlyHint: true,
43
+ destructiveHint: false,
44
+ idempotentHint: true,
45
+ openWorldHint: false,
46
+ };
47
+ export const pingAnnotations = {
48
+ readOnlyHint: true,
49
+ destructiveHint: false,
50
+ idempotentHint: true,
51
+ openWorldHint: false,
52
+ };
53
+ //# sourceMappingURL=annotations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"annotations.js","sourceRoot":"","sources":["../src/annotations.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAoB;IAC/C,YAAY,EAAE,KAAK;IACnB,eAAe,EAAE,KAAK;IACtB,cAAc,EAAE,KAAK;IACrB,aAAa,EAAE,IAAI;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAoB;IAChD,YAAY,EAAE,KAAK;IACnB,eAAe,EAAE,KAAK;IACtB,cAAc,EAAE,KAAK;IACrB,aAAa,EAAE,IAAI;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAoB;IAChD,YAAY,EAAE,KAAK;IACnB,eAAe,EAAE,KAAK;IACtB,cAAc,EAAE,IAAI;IACpB,aAAa,EAAE,IAAI;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAoB;IACpD,YAAY,EAAE,KAAK;IACnB,eAAe,EAAE,KAAK;IACtB,cAAc,EAAE,KAAK;IACrB,aAAa,EAAE,IAAI;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAoB;IACtD,YAAY,EAAE,IAAI;IAClB,eAAe,EAAE,KAAK;IACtB,cAAc,EAAE,IAAI;IACpB,aAAa,EAAE,KAAK;CACrB,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAoB;IAC9C,YAAY,EAAE,IAAI;IAClB,eAAe,EAAE,KAAK;IACtB,cAAc,EAAE,IAAI;IACpB,aAAa,EAAE,KAAK;CACrB,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Rich tool descriptions for MCP clients.
3
+ *
4
+ * Descriptions include capability summaries, cost guidance, and prompt tips
5
+ * so calling LLMs can make informed tool selection and parameterization decisions.
6
+ *
7
+ * Keep each description at or under 2048 bytes to avoid bloating tool listings.
8
+ */
9
+ export declare const queryDescription = "Execute a prompt via Claude Code CLI with optional file context and session resume. Claude is an AI coding agent that can generate, analyze, refactor, and explain code.\n\nCapabilities: code generation and refactoring, code analysis and explanation, file understanding (text and images), multi-turn conversations via sessionId.\n\nCost: Default model is Sonnet (~$0.01-0.10/call). Use effort=\"low\" for simple tasks, effort=\"high\" + model=\"opus\" for complex analysis. Set maxBudgetUsd to cap per-call cost (recommended for effort=\"max\" or model=\"opus\").\n\nTips:\n- Set workingDirectory to the target repo for project-aware responses.\n- Break complex tasks into focused prompts rather than one large request.\n- Resume multi-turn conversations with sessionId from a previous response's metadata.\n- Include relevant files via the files parameter for targeted context (text files inlined in prompt, images trigger allowed-tools mode).\n- Use noSessionPersistence=true for stateless one-shot calls.";
10
+ export declare const reviewDescription = "Repo-aware code review powered by Claude Code CLI. Returns structured feedback on code changes with two modes:\n\n- Agentic (default): Claude explores the repo with Read, Grep, Glob, and git tools. Reads changed files, follows imports, and examines related code before reviewing. Best for thorough reviews. Default timeout: auto-scaled from diff size (3-10 minutes).\n- Quick (quick: true): Receives only the diff text. Fast single-pass review without repo exploration. Default timeout: 2 minutes.\n\nCost: Both modes default to Opus (~$0.05-0.15 quick, ~$0.25-0.50 agentic). Override with model parameter. Use maxBudgetUsd to cap cost on large diffs.\n\nTips:\n- Use the focus parameter to direct attention: \"security\", \"performance\", \"error handling\", \"test coverage\".\n- Set workingDirectory to the repo being reviewed (auto-resolves to git root).\n- Default reviews uncommitted changes (staged + unstaged). Use base to review a branch diff (e.g. base: \"main\").\n- Prefer agentic mode for important reviews, quick mode for rapid feedback during development.";
11
+ export declare const searchDescription = "Web search via Claude Code CLI using WebSearch and WebFetch tools. Searches the web and synthesizes a comprehensive answer with source URLs.\n\nUse for: current information, documentation lookups, API references, comparing libraries, and research questions.\n\nCost: Typically ~$0.02-0.05/search with Sonnet.\n\nTips:\n- Ask specific, focused questions for best results.\n- Results include source URLs for verification.\n- Use maxResponseLength to control response verbosity.\n- Increase timeout for complex research queries that may require multiple web fetches.";
12
+ export declare const structuredDescription = "Generate JSON conforming to a provided JSON Schema. Uses Claude CLI's native --json-schema flag for validated output (not client-side validation).\n\nUse for: data extraction from text/files, classification, entity parsing, or any task needing machine-parseable output.\n\nCost: Similar to query (~$0.01-0.10/call). Schema complexity doesn't significantly affect cost.\n\nTips:\n- Pass the JSON Schema as a JSON string in the schema parameter.\n- Schema max size: 20KB. Keep schemas focused for reliable output.\n- For extraction tasks, include source text via the files parameter or inline in the prompt.";
13
+ export declare const listSessionsDescription = "List active Claude CLI sessions tracked by this server. Returns session metadata (IDs, models, timing, turn counts, cumulative cost) for orchestration. Use to check available sessions before resuming with sessionId. No cost (local lookup only).";
14
+ export declare const pingDescription = "Health check: verifies Claude CLI is installed and authenticated, reports versions, capabilities, and configuration. No cost (local check only).";
15
+ //# sourceMappingURL=descriptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptions.d.ts","sourceRoot":"","sources":["../src/descriptions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,gBAAgB,m/BAWiC,CAAC;AAE/D,eAAO,MAAM,iBAAiB,mjCAWiE,CAAC;AAEhG,eAAO,MAAM,iBAAiB,wjBAUyD,CAAC;AAExF,eAAO,MAAM,qBAAqB,kmBAS2D,CAAC;AAE9F,eAAO,MAAM,uBAAuB,yPAAyP,CAAC;AAE9R,eAAO,MAAM,eAAe,qJAAqJ,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Rich tool descriptions for MCP clients.
3
+ *
4
+ * Descriptions include capability summaries, cost guidance, and prompt tips
5
+ * so calling LLMs can make informed tool selection and parameterization decisions.
6
+ *
7
+ * Keep each description at or under 2048 bytes to avoid bloating tool listings.
8
+ */
9
+ export const queryDescription = `Execute a prompt via Claude Code CLI with optional file context and session resume. Claude is an AI coding agent that can generate, analyze, refactor, and explain code.
10
+
11
+ Capabilities: code generation and refactoring, code analysis and explanation, file understanding (text and images), multi-turn conversations via sessionId.
12
+
13
+ Cost: Default model is Sonnet (~$0.01-0.10/call). Use effort="low" for simple tasks, effort="high" + model="opus" for complex analysis. Set maxBudgetUsd to cap per-call cost (recommended for effort="max" or model="opus").
14
+
15
+ Tips:
16
+ - Set workingDirectory to the target repo for project-aware responses.
17
+ - Break complex tasks into focused prompts rather than one large request.
18
+ - Resume multi-turn conversations with sessionId from a previous response's metadata.
19
+ - Include relevant files via the files parameter for targeted context (text files inlined in prompt, images trigger allowed-tools mode).
20
+ - Use noSessionPersistence=true for stateless one-shot calls.`;
21
+ export const reviewDescription = `Repo-aware code review powered by Claude Code CLI. Returns structured feedback on code changes with two modes:
22
+
23
+ - Agentic (default): Claude explores the repo with Read, Grep, Glob, and git tools. Reads changed files, follows imports, and examines related code before reviewing. Best for thorough reviews. Default timeout: auto-scaled from diff size (3-10 minutes).
24
+ - Quick (quick: true): Receives only the diff text. Fast single-pass review without repo exploration. Default timeout: 2 minutes.
25
+
26
+ Cost: Both modes default to Opus (~$0.05-0.15 quick, ~$0.25-0.50 agentic). Override with model parameter. Use maxBudgetUsd to cap cost on large diffs.
27
+
28
+ Tips:
29
+ - Use the focus parameter to direct attention: "security", "performance", "error handling", "test coverage".
30
+ - Set workingDirectory to the repo being reviewed (auto-resolves to git root).
31
+ - Default reviews uncommitted changes (staged + unstaged). Use base to review a branch diff (e.g. base: "main").
32
+ - Prefer agentic mode for important reviews, quick mode for rapid feedback during development.`;
33
+ export const searchDescription = `Web search via Claude Code CLI using WebSearch and WebFetch tools. Searches the web and synthesizes a comprehensive answer with source URLs.
34
+
35
+ Use for: current information, documentation lookups, API references, comparing libraries, and research questions.
36
+
37
+ Cost: Typically ~$0.02-0.05/search with Sonnet.
38
+
39
+ Tips:
40
+ - Ask specific, focused questions for best results.
41
+ - Results include source URLs for verification.
42
+ - Use maxResponseLength to control response verbosity.
43
+ - Increase timeout for complex research queries that may require multiple web fetches.`;
44
+ export const structuredDescription = `Generate JSON conforming to a provided JSON Schema. Uses Claude CLI's native --json-schema flag for validated output (not client-side validation).
45
+
46
+ Use for: data extraction from text/files, classification, entity parsing, or any task needing machine-parseable output.
47
+
48
+ Cost: Similar to query (~$0.01-0.10/call). Schema complexity doesn't significantly affect cost.
49
+
50
+ Tips:
51
+ - Pass the JSON Schema as a JSON string in the schema parameter.
52
+ - Schema max size: 20KB. Keep schemas focused for reliable output.
53
+ - For extraction tasks, include source text via the files parameter or inline in the prompt.`;
54
+ export const listSessionsDescription = `List active Claude CLI sessions tracked by this server. Returns session metadata (IDs, models, timing, turn counts, cumulative cost) for orchestration. Use to check available sessions before resuming with sessionId. No cost (local lookup only).`;
55
+ export const pingDescription = `Health check: verifies Claude CLI is installed and authenticated, reports versions, capabilities, and configuration. No cost (local check only).`;
56
+ //# sourceMappingURL=descriptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptions.js","sourceRoot":"","sources":["../src/descriptions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;8DAW8B,CAAC;AAE/D,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;;;;;;;;+FAW8D,CAAC;AAEhG,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;;;;;;;uFAUsD,CAAC;AAExF,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;6FASwD,CAAC;AAE9F,MAAM,CAAC,MAAM,uBAAuB,GAAG,sPAAsP,CAAC;AAE9R,MAAM,CAAC,MAAM,eAAe,GAAG,kJAAkJ,CAAC"}