# Did You Know @cloudflare/codemode v0.2.1 Turns a Whole MCP Server Into One Tool?

Hey there, I'm Shiichan! I found an update to one of Cloudflare's agent SDKs today, and it made me grin. It looks like a small patch release at first glance, but there's some clever engineering packed in, so let me walk you through it.

## What was announced?

According to the Cloudflare Changelog, the AI agent SDK `@cloudflare/codemode` has been updated to v0.2.1. Code Mode is Cloudflare's approach that lets an AI agent write and run a single block of code in a sandbox instead of making tool calls one by one. This release adds a new `@cloudflare/codemode/mcp` entry point that significantly improves how you work with MCP (Model Context Protocol, an open protocol for connecting AI models to external tools and data sources).

## The story so far

In the previous v0.2.0 release, there was a breaking change: `generateTypes` and the `ToolDescriptor` / `ToolDescriptors` types moved to a new `@cloudflare/codemode/ai` subpath. On top of that, the main entry point used to require `ai` and `zod` as peer dependencies, which was a somewhat heavy ask for anyone who just wanted the Code Mode execution runtime.

## What changes

In v0.2.1, the main entry point drops the required `ai` and `zod` peer dependencies, leaving a zero-dependency core built around these utilities:

- `sanitizeToolName`
- `normalizeCode`
- `generateTypesFromJsonSchema`
- `jsonSchemaToType`
- `DynamicWorkerExecutor`
- `ToolDispatcher`

That means projects that don't use the AI SDK can now pull in just the Code Mode execution runtime, without the extra weight. And thanks to the new `@cloudflare/codemode/mcp`, plugging an existing MCP server into an agent just got a lot easier too.

## Dive Deep

The new `mcp` entry point ships two functions.

- `codeMcpServer({ server, executor })` — wraps an existing MCP server with a single `code` tool. Once wrapped, every tool the upstream MCP server exposes becomes a typed `codemode.*` method
- `openApiMcpServer({ spec, executor, request })` — generates `search` and `execute` MCP tools straight from an OpenAPI spec, proxying requests on the host side and resolving `$ref` references automatically

In short, instead of handing the LLM a long list of individual tools, you can now hand it a single bundled "code tool". Here's roughly how it looks:

```ts
import { codeMcpServer } from "@cloudflare/codemode/mcp";

const tool = codeMcpServer({
  server: existingMcpServer,
  executor,
});
```

On the agent side, you just write one block of code with calls like `codemode.xxx()`, and multiple upstream tool calls get resolved in a single pass.

There's another quieter but handy change: `DynamicWorkerExecutor` now accepts a `modules` option, letting you inject your own custom ES modules into the sandbox runtime. That should come in handy if you want to tailor what's available inside the sandbox on a per-project basis.

## Wrap-up

Here's a recap of this release.

- `@cloudflare/codemode/mcp` is new: `codeMcpServer()` wraps an existing MCP server into a single code tool, and `openApiMcpServer()` auto-generates MCP tools from an OpenAPI spec
- The main entry point no longer requires `ai` and `zod` as peer dependencies, making it lighter and dependency-free
- `DynamicWorkerExecutor` gained a `modules` option for injecting custom modules into the sandbox
- As a reminder from v0.2.0, `generateTypes` and the `ToolDescriptor` / `ToolDescriptors` types have moved to `@cloudflare/codemode/ai` (worth checking if you have existing code using them)

If you're wiring MCP servers or OpenAPI-based APIs into Cloudflare's agent platform, this release looks well worth a closer look.
