New MCP Integration Features
The v0.2.1 release adds comprehensive MCP (Model Context Protocol) support through a new @cloudflare/codemode/mcp export. Two key functions enable seamless integration:
codeMcpServer()wraps existing MCP servers with acodetool that automatically converts upstream tools into typedcodemode.*methods accessible to LLMsopenApiMcpServer()createssearchandexecuteMCP tools directly from OpenAPI specifications, with built-in request proxying and$refresolution
This allows LLMs to call external tools and APIs through generated code with full type safety.
Zero-Dependency Main Entry Point
A significant breaking change restructures the SDK's export organization. The main entry point (@cloudflare/codemode) no longer requires ai and zod as peer dependencies. Functions related to LLM integration have moved to @cloudflare/codemode/ai, while the core entry point now focuses on:
- Code transformation utilities (
sanitizeToolName,normalizeCode) - JSON Schema processing (
generateTypesFromJsonSchema,jsonSchemaToType) - Sandbox execution (
DynamicWorkerExecutor,ToolDispatcher)
This change reduces dependencies for users who only need sandboxed code execution without LLM-specific features.
Enhanced Sandbox Customization
DynamicWorkerExecutor now accepts an optional modules configuration to inject custom ES modules into the sandbox environment. Developers can pass a modules object with JavaScript source code, making those utilities available via standard import statements within generated code. This simplifies common patterns for sandboxed execution.
Additional Improvements
The executor now handles code normalization and tool name sanitization automatically, eliminating the need for manual preprocessing. Upgrade with npm i @cloudflare/codemode@latest to access these features.