← Back
Cloudflare
Cloudflare releases @cloudflare/codemode v0.2.1 with MCP integration and zero-dependency core
Cloudflare Workers · releasesdkapibreaking-changefeature · developers.cloudflare.com ↗

New MCP Integration

The v0.2.1 release introduces a new @cloudflare/codemode/mcp export that provides two functions for integrating MCP (Model Context Protocol) servers with Code Mode:

  • codeMcpServer() — wraps existing MCP servers, exposing all upstream tools as typed codemode.* methods that LLMs can call from generated code
  • openApiMcpServer() — creates searchable MCP tools from OpenAPI specifications, with automatic $ref resolution and host-side request proxying

Breaking Change: Restructured Exports

Version 0.2.0 moved the following to @cloudflare/codemode/ai:

  • generateTypes
  • ToolDescriptor / ToolDescriptors types

The main entry point (@cloudflare/codemode) is now zero-dependency, exporting only core utilities: sanitizeToolName, normalizeCode, generateTypesFromJsonSchema, jsonSchemaToType, DynamicWorkerExecutor, and ToolDispatcher. The ai and zod peer dependencies are now optional.

Sandbox Enhancements

DynamicWorkerExecutor now accepts an optional modules configuration to inject custom ES modules directly into the sandbox. This allows generated code to import utility functions without network calls or external dependencies.

Additionally, DynamicWorkerExecutor now handles code normalization and tool name sanitization internally, eliminating the need for developers to manually call these functions before execution.

Action Items

  • Update imports: move generateTypes and type definitions from @cloudflare/codemode to @cloudflare/codemode/ai
  • Remove any manual calls to normalizeCode() and sanitizeToolName() — these are now handled automatically
  • Upgrade via npm i @cloudflare/codemode@latest