@cloudflare/codemode v0.2.1 — MCP export, zero-dep main entry, and sandbox modules
Key Points
- New @cloudflare/codemode/mcp export
- Main entry point no longer requires ai or zod
- DynamicWorkerExecutor supports custom sandbox modules
Summary
@cloudflare/codemode v0.2.1 introduces a dedicated MCP barrel export, removes ai/zod as required peer dependencies from the main package, and adds finer control over sandboxed execution via DynamicWorkerExecutor.
Key Points
-
New @cloudflare/codemode/mcp export
- codeMcpServer({ server, executor }) — wraps an existing MCP server so each upstream tool is exposed as a typed codemode.* method.
- openApiMcpServer({ spec, executor, request }) — generates search/execute MCP tools from an OpenAPI spec with host-side request proxying and automatic $ref resolution.
-
Zero-dependency main entry point
- The main package (@cloudflare/codemode) no longer requires ai or zod as peer dependencies; those are only required when importing @cloudflare/codemode/ai.
- Breaking change (since v0.2.0): generateTypes and related ToolDescriptor types were moved to @cloudflare/codemode/ai. Update imports accordingly.
-
Sandbox and execution improvements
- DynamicWorkerExecutor accepts a modules option to inject arbitrary ES modules into the sandbox:
const executor = new DynamicWorkerExecutor({
loader: env.LOADER,
modules: { "utils.js": `export function add(a, b) { return a + b; }` },
});
// Inside the sandbox: import { add } from "utils.js"
- The executor now normalizes code and sanitizes tool names internally; you no longer need to call normalizeCode() or sanitizeToolName() before execute().
Migration notes
-
Move generateTypes imports:
- Before: import { generateTypes } from "@cloudflare/codemode"
- After: import { generateTypes } from "@cloudflare/codemode/ai"
-
Upgrade command: npm i @cloudflare/codemode@latest
See the Code Mode documentation for full API details and examples.