← Back
Cloudflare
Cloudflare releases Codemode v0.2.1 with MCP support and simplified dependencies
Cloudflare Workers · releasefeaturesdkapibreaking-change · developers.cloudflare.com ↗

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 a code tool that automatically converts upstream tools into typed codemode.* methods accessible to LLMs
  • openApiMcpServer() creates search and execute MCP tools directly from OpenAPI specifications, with built-in request proxying and $ref resolution

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.