@ruifung/codemode-bridge 1.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 (39) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +378 -0
  3. package/dist/cli/commands.d.ts +70 -0
  4. package/dist/cli/commands.js +436 -0
  5. package/dist/cli/config-manager.d.ts +53 -0
  6. package/dist/cli/config-manager.js +142 -0
  7. package/dist/cli/index.d.ts +19 -0
  8. package/dist/cli/index.js +165 -0
  9. package/dist/executor/container-executor.d.ts +81 -0
  10. package/dist/executor/container-executor.js +351 -0
  11. package/dist/executor/executor-test-suite.d.ts +22 -0
  12. package/dist/executor/executor-test-suite.js +395 -0
  13. package/dist/executor/isolated-vm-executor.d.ts +78 -0
  14. package/dist/executor/isolated-vm-executor.js +368 -0
  15. package/dist/executor/vm2-executor.d.ts +21 -0
  16. package/dist/executor/vm2-executor.js +109 -0
  17. package/dist/executor/wrap-code.d.ts +52 -0
  18. package/dist/executor/wrap-code.js +80 -0
  19. package/dist/index.d.ts +6 -0
  20. package/dist/index.js +6 -0
  21. package/dist/mcp/config.d.ts +44 -0
  22. package/dist/mcp/config.js +102 -0
  23. package/dist/mcp/e2e-bridge-test-suite.d.ts +28 -0
  24. package/dist/mcp/e2e-bridge-test-suite.js +429 -0
  25. package/dist/mcp/executor.d.ts +31 -0
  26. package/dist/mcp/executor.js +121 -0
  27. package/dist/mcp/mcp-adapter.d.ts +12 -0
  28. package/dist/mcp/mcp-adapter.js +49 -0
  29. package/dist/mcp/mcp-client.d.ts +85 -0
  30. package/dist/mcp/mcp-client.js +441 -0
  31. package/dist/mcp/oauth-handler.d.ts +33 -0
  32. package/dist/mcp/oauth-handler.js +138 -0
  33. package/dist/mcp/server.d.ts +25 -0
  34. package/dist/mcp/server.js +322 -0
  35. package/dist/mcp/token-persistence.d.ts +57 -0
  36. package/dist/mcp/token-persistence.js +131 -0
  37. package/dist/utils/logger.d.ts +44 -0
  38. package/dist/utils/logger.js +123 -0
  39. package/package.json +56 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,378 @@
1
+ # Code Mode Bridge
2
+
3
+ [![npm](https://img.shields.io/npm/v/@ruifung/codemode-bridge)](https://www.npmjs.com/package/@ruifung/codemode-bridge)
4
+
5
+ An MCP (Model Context Protocol) server that connects to upstream MCP servers and exposes all their tools through a single `eval` tool for unified orchestration and execution.
6
+
7
+ ## Features
8
+
9
+ - **Multi-server bridging**: Connect to multiple upstream MCP servers simultaneously
10
+ - **Tool aggregation**: Exposes all upstream tools through a single `eval` tool
11
+ - **Dynamic discovery**: Auto-generated TypeScript type definitions show agents exactly what's available
12
+ - **Namespaced tools**: Tools are automatically namespaced by server (e.g., `kubernetes__pods_list`)
13
+ - **Multi-executor sandbox**: Three executor backends with automatic selection
14
+ - **isolated-vm** (preferred) -- V8 isolate with strict JS-level sandboxing
15
+ - **container** -- Docker/Podman with OS-level isolation (`--network=none`, `--read-only`, `--cap-drop=ALL`)
16
+ - **vm2** -- Lightweight VM2 sandbox
17
+ - **Status introspection**: Built-in `status` tool reports executor type, upstream servers, and available tools
18
+ - **CLI management**: Command-line interface for server configuration
19
+
20
+ ## Quick Start
21
+
22
+ ### Installation
23
+
24
+ ```bash
25
+ # Run without installing
26
+ npx @ruifung/codemode-bridge
27
+
28
+ # Or install globally
29
+ npm install -g @ruifung/codemode-bridge
30
+ codemode-bridge
31
+ ```
32
+
33
+ #### From Source
34
+
35
+ ```bash
36
+ git clone https://github.com/ruifung/mcp-cm-bridge.git
37
+ cd mcp-cm-bridge
38
+ npm install
39
+ npm run build
40
+ node dist/cli/index.js run
41
+
42
+ # Or run in dev mode (builds and runs in one step)
43
+ npm run dev
44
+ ```
45
+
46
+ ### Basic Usage
47
+
48
+ List configured servers:
49
+
50
+ ```bash
51
+ codemode-bridge config list
52
+ ```
53
+
54
+ Add a new server:
55
+
56
+ ```bash
57
+ codemode-bridge config add kubernetes --type stdio --command "npx" --args "-y,kubernetes-mcp-server@latest"
58
+ ```
59
+
60
+ Start the bridge (loads all configured servers):
61
+
62
+ ```bash
63
+ codemode-bridge run
64
+ ```
65
+
66
+ Load specific servers:
67
+
68
+ ```bash
69
+ codemode-bridge run --servers kubernetes,time
70
+ ```
71
+
72
+ ## Configuration
73
+
74
+ Servers are stored in `~/.config/codemode-bridge/mcp.json`:
75
+
76
+ ```json
77
+ {
78
+ "servers": {
79
+ "kubernetes": {
80
+ "type": "stdio",
81
+ "command": "npx",
82
+ "args": ["-y", "kubernetes-mcp-server@latest"]
83
+ },
84
+ "time": {
85
+ "type": "stdio",
86
+ "command": "uvx",
87
+ "args": ["mcp-server-time"]
88
+ },
89
+ "example-http": {
90
+ "type": "http",
91
+ "url": "https://example.com/mcp"
92
+ }
93
+ }
94
+ }
95
+ ```
96
+
97
+ ### Server Types
98
+
99
+ - **stdio**: Execute a command that runs an MCP server via stdin/stdout
100
+ - **http**: Connect to an HTTP-based MCP server (supports OAuth)
101
+
102
+ ## Executors
103
+
104
+ The bridge supports three executor backends. On startup, it automatically selects the best available one, or you can force a specific executor via the `EXECUTOR_TYPE` environment variable.
105
+
106
+ ### Selection Order (auto-detect)
107
+
108
+ | Priority | Executor | Selection Criteria |
109
+ |----------|------------|---------------------------------------------|
110
+ | 0 | `isolated-vm` | `isolated-vm` npm package is installed |
111
+ | 1 | `container` | Docker or Podman runtime is available |
112
+ | 2 | `vm2` | Always available (bundled dependency) |
113
+
114
+ ### Environment Variables
115
+
116
+ | Variable | Description |
117
+ |------|-------------|
118
+ | `EXECUTOR_TYPE` | Force a specific executor: `isolated-vm`, `container`, or `vm2`. Throws if unavailable. |
119
+ | `CONTAINER_RUNTIME` | Override container runtime detection (e.g., `podman`, `/usr/bin/docker`). |
120
+
121
+ ### Executor Comparison
122
+
123
+ | Feature | isolated-vm | container | vm2 |
124
+ |---------|-------------|-----------|-----|
125
+ | JS-level sandboxing | Yes (V8 isolate) | No (full Node.js inside) | Yes (VM2 sandbox) |
126
+ | Network isolation | No APIs exposed | OS-level (`--network=none`) | No APIs exposed |
127
+ | File system isolation | No APIs exposed | OS-level (`--read-only`) | No APIs exposed |
128
+ | `require`/`process` blocked | Yes | No (container boundary) | Yes |
129
+ | Concurrency | Parallel | Serialized (one-at-a-time) | Parallel |
130
+ | Startup overhead | Low | Higher (container + worker thread) | Low |
131
+ | Security model | V8 process isolation | Container boundary | JS context isolation |
132
+
133
+ ### Container Executor Security Flags
134
+
135
+ When using the container executor, each container runs with:
136
+
137
+ ```
138
+ --network=none --read-only --cap-drop=ALL --user=node
139
+ --tmpfs /tmp:rw,noexec,nosuid,size=64m
140
+ --pids-limit=64 --memory=256m --cpus=1.0
141
+ ```
142
+
143
+ ## How It Works
144
+
145
+ 1. **Connection**: Connects to all configured upstream MCP servers
146
+ 2. **Tool Collection**: Gathers tools from all servers via the MCP protocol
147
+ 3. **Tool Wrapping**: Uses `@cloudflare/codemode` SDK to wrap all tools with auto-generated TypeScript definitions
148
+ 4. **Exposure**: Exposes two MCP tools -- `eval` (code execution) and `status` (introspection)
149
+ 5. **Execution**: Runs agent-generated code in the selected executor sandbox with tool access via `codemode.*`
150
+
151
+ ## MCP Tools
152
+
153
+ ### `eval`
154
+
155
+ Executes agent-generated JavaScript/TypeScript code with access to all upstream tools via the `codemode` namespace.
156
+
157
+ ```typescript
158
+ // Example: cross-server orchestration
159
+ const time = await codemode.time__get_current_time({ timezone: "America/New_York" });
160
+ const pods = await codemode.kubernetes__pods_list_in_namespace({ namespace: "default" });
161
+ return { time, podCount: pods.length };
162
+ ```
163
+
164
+ ### `status`
165
+
166
+ Returns metadata about the running bridge: executor type, selection reason, timeout, and a list of all connected upstream servers with their tool counts.
167
+
168
+ ## CLI Commands
169
+
170
+ ```bash
171
+ # Start the bridge (default command)
172
+ codemode-bridge run [options]
173
+ --servers <names> Comma-separated list of servers to load
174
+ --config <path> Custom config file path
175
+
176
+ # Configuration management
177
+ codemode-bridge config list # Show all configured servers
178
+ codemode-bridge config show <name> # Show specific server config
179
+ codemode-bridge config add <name> # Add new server
180
+ codemode-bridge config remove <name> # Remove server
181
+ codemode-bridge config edit <name> # Edit server config
182
+ codemode-bridge config info # Show config file location
183
+ ```
184
+
185
+ ## Architecture
186
+
187
+ ```
188
+ +---------------------------------------------------------+
189
+ | MCP Clients (Claude, OpenCode, etc) |
190
+ +------------------------+--------------------------------+
191
+ | MCP Protocol
192
+ |
193
+ +------------------------v--------------------------------+
194
+ | Code Mode Bridge (MCP Server) |
195
+ | +--------------------------------------------------+ |
196
+ | | "eval" Tool "status" Tool | |
197
+ | | - Auto-generated type definitions | |
198
+ | | - Sandbox code execution | |
199
+ | | - Tool orchestration | |
200
+ | +--------------------------------------------------+ |
201
+ | +--------------------------------------------------+ |
202
+ | | Executor Registry | |
203
+ | | isolated-vm | container | vm2 | |
204
+ | +--------------------------------------------------+ |
205
+ +------------------------+--------------------------------+
206
+ | MCP Client (@ai-sdk/mcp)
207
+ +------------+------------+-----------+
208
+ | | | |
209
+ +----v-----+ +---v----+ +----v------+ +--v-------+
210
+ |Kubernetes | | Time | | GitLab | | Memory |
211
+ | Server | | Server | | Server | | Server |
212
+ +----------+ +--------+ +-----------+ +----------+
213
+ ```
214
+
215
+ ## Project Structure
216
+
217
+ ```
218
+ src/
219
+ +-- cli/
220
+ | +-- index.ts # CLI entry point
221
+ | +-- commands.ts # Command implementations
222
+ | +-- config-manager.ts # Configuration file management
223
+ +-- executor/
224
+ | +-- vm2-executor.ts # VM2 sandbox executor
225
+ | +-- isolated-vm-executor.ts # isolated-vm V8 isolate executor
226
+ | +-- container-executor.ts # Docker/Podman container executor
227
+ | +-- container-runner.mjs # Container main thread (stdin/stdout RPC)
228
+ | +-- container-worker.mjs # Container worker thread (eval + console capture)
229
+ | +-- wrap-code.ts # Shared code wrapping (acorn AST)
230
+ | +-- executor-test-suite.ts # Universal executor test suite
231
+ | +-- executor-runner.test.ts # Runs test suite against all executors
232
+ +-- mcp/
233
+ | +-- server.ts # MCP server + upstream connections
234
+ | +-- executor.ts # Executor factory, registry, and type exports
235
+ | +-- mcp-adapter.ts # Protocol adapter (AI SDK Tool -> MCP)
236
+ | +-- mcp-client.ts # Upstream MCP client management
237
+ | +-- config.ts # Configuration types
238
+ | +-- oauth-handler.ts # OAuth flow for HTTP MCP servers
239
+ | +-- token-persistence.ts # OAuth token storage
240
+ | +-- e2e-bridge-test-suite.ts # E2E bridge test suite
241
+ | +-- e2e-bridge-runner.test.ts # Runs E2E suite against all executors
242
+ +-- utils/
243
+ | +-- logger.ts # Winston logger
244
+ +-- index.ts # Package main entry point
245
+ ```
246
+
247
+ ## Development
248
+
249
+ ### Build
250
+
251
+ ```bash
252
+ npm run build
253
+ ```
254
+
255
+ ### Test
256
+
257
+ ```bash
258
+ # Run all tests (executor unit + E2E bridge, all 3 executors)
259
+ npm test
260
+
261
+ # Run E2E bridge tests only
262
+ npm run test:e2e
263
+
264
+ # Run tests with UI
265
+ npx vitest --ui
266
+ ```
267
+
268
+ ### Test CLI locally
269
+
270
+ ```bash
271
+ npm run dev -- run --servers time
272
+ npm run dev -- config list
273
+ ```
274
+
275
+ ## Security
276
+
277
+ - **Multi-layer isolation**: Three executor backends with different security tradeoffs
278
+ - **Timeout enforcement**: Configurable timeout (default 30s) prevents infinite loops
279
+ - **No network access**: All executors block network access (JS-level or OS-level)
280
+ - **No file system access**: Executors cannot read/write host files
281
+ - **Tool isolation**: Only tools from configured upstream servers are accessible
282
+ - **Container hardening**: Container executor runs non-root with dropped capabilities, read-only filesystem, PID/memory/CPU limits
283
+
284
+ ## Adding to Your MCP Client
285
+
286
+ ### VS Code / GitHub Copilot
287
+
288
+ Add to your `.vscode/mcp.json` (workspace) or user `settings.json`:
289
+
290
+ ```json
291
+ {
292
+ "servers": {
293
+ "codemode-bridge": {
294
+ "command": "npx",
295
+ "args": ["-y", "@ruifung/codemode-bridge"]
296
+ }
297
+ }
298
+ }
299
+ ```
300
+
301
+ To load only specific upstream servers:
302
+
303
+ ```json
304
+ {
305
+ "servers": {
306
+ "codemode-bridge": {
307
+ "command": "npx",
308
+ "args": ["-y", "@ruifung/codemode-bridge", "--servers", "kubernetes,time"]
309
+ }
310
+ }
311
+ }
312
+ ```
313
+
314
+ To force a specific executor:
315
+
316
+ ```json
317
+ {
318
+ "servers": {
319
+ "codemode-bridge": {
320
+ "command": "npx",
321
+ "args": ["-y", "@ruifung/codemode-bridge"],
322
+ "env": {
323
+ "EXECUTOR_TYPE": "container"
324
+ }
325
+ }
326
+ }
327
+ }
328
+ ```
329
+
330
+ ### Claude Desktop
331
+
332
+ Add to `claude_desktop_config.json` (`%APPDATA%\Claude\` on Windows, `~/Library/Application Support/Claude/` on macOS):
333
+
334
+ ```json
335
+ {
336
+ "mcpServers": {
337
+ "codemode-bridge": {
338
+ "command": "npx",
339
+ "args": ["-y", "@ruifung/codemode-bridge"]
340
+ }
341
+ }
342
+ }
343
+ ```
344
+
345
+ ### OpenCode
346
+
347
+ Add to `~/.config/opencode/opencode.json` (or project-level `opencode.json`):
348
+
349
+ ```json
350
+ {
351
+ "mcp": {
352
+ "codemode-bridge": {
353
+ "type": "stdio",
354
+ "command": "npx",
355
+ "args": ["-y", "@ruifung/codemode-bridge"]
356
+ }
357
+ }
358
+ }
359
+ ```
360
+
361
+ ### If installed globally
362
+
363
+ If you've installed the package globally (`npm install -g @ruifung/codemode-bridge`), replace the `npx` command with the direct binary:
364
+
365
+ ```json
366
+ {
367
+ "command": "codemode-bridge",
368
+ "args": []
369
+ }
370
+ ```
371
+
372
+ ## Acknowledgements
373
+
374
+ This project is built on [`@cloudflare/codemode`](https://www.npmjs.com/package/@cloudflare/codemode), Cloudflare's Code Mode SDK. The SDK provides the core tool-wrapping and type-generation engine that enables agents to call multiple MCP tools through a single `eval` interface. This project adapts that capability to run locally outside of Cloudflare Workers, using sandboxed executors (isolated-vm, Docker/Podman containers, or vm2) instead.
375
+
376
+ ## AI Generated Code Disclosure
377
+
378
+ This project is largely AI-generated. It serves as an experiment to get Cloudflare's Code Mode SDK working locally without paying for Workers, by bridging upstream MCP servers through a sandboxed executor.
@@ -0,0 +1,70 @@
1
+ /**
2
+ * CLI Commands for Code Mode Bridge
3
+ *
4
+ * Implements subcommands for managing and running the bridge
5
+ */
6
+ /**
7
+ * Run the bridge server
8
+ */
9
+ export declare function runServer(configPath?: string, servers?: string[], debug?: boolean): Promise<void>;
10
+ /**
11
+ * List all configured servers
12
+ */
13
+ export declare function listServersCommand(configPath?: string): void;
14
+ /**
15
+ * Show a specific server configuration
16
+ */
17
+ export declare function showServerCommand(name: string, configPath?: string): void;
18
+ /**
19
+ * Add a new server configuration
20
+ */
21
+ export declare function addServerCommand(name: string, options: {
22
+ type: string;
23
+ command?: string;
24
+ args?: string[];
25
+ url?: string;
26
+ env?: Record<string, string>;
27
+ }, configPath?: string): void;
28
+ /**
29
+ * Remove a server configuration
30
+ */
31
+ export declare function removeServerCommand(name: string, configPath?: string): void;
32
+ /**
33
+ * Edit a server configuration
34
+ */
35
+ export declare function editServerCommand(name: string, options: Partial<{
36
+ type?: string;
37
+ command?: string;
38
+ args?: string[];
39
+ url?: string;
40
+ env?: Record<string, string>;
41
+ }>, configPath?: string): void;
42
+ /**
43
+ * Show config file information
44
+ */
45
+ export declare function configInfoCommand(configPath?: string): void;
46
+ /**
47
+ * Login command for OAuth servers
48
+ *
49
+ * Usage: codemode-bridge auth login <server-name>
50
+ *
51
+ * Starts the bridge connected only to the specified OAuth server.
52
+ * This allows the OAuth flow to complete naturally during connection.
53
+ */
54
+ export declare function authLoginCommand(serverName: string, configPath?: string): Promise<void>;
55
+ /**
56
+ * Logout command for OAuth servers
57
+ *
58
+ * Usage: codemode-bridge auth logout <server-name>
59
+ *
60
+ * Clears all stored authentication data (tokens and client info) for the server.
61
+ */
62
+ export declare function authLogoutCommand(serverName: string, configPath?: string): void;
63
+ /**
64
+ * List command for OAuth servers
65
+ *
66
+ * Usage: codemode-bridge auth list
67
+ *
68
+ * Shows all OAuth-enabled servers and their authentication status.
69
+ */
70
+ export declare function authListCommand(configPath?: string): void;