Skip to content

Added Code Mode docs & cross-refs.#28343

Open
ask-bonk[bot] wants to merge 2 commits intoproductionfrom
opencode/issue28342-20260214170959
Open

Added Code Mode docs & cross-refs.#28343
ask-bonk[bot] wants to merge 2 commits intoproductionfrom
opencode/issue28342-20260214170959

Conversation

@ask-bonk
Copy link
Contributor

@ask-bonk ask-bonk bot commented Feb 14, 2026

All checks pass with 0 errors and 0 warnings. Here is a summary of the changes:

Changes Made

1. New file: src/content/docs/agents/api-reference/code-mode.mdx

Created a new Code Mode documentation page in the Agents SDK API reference section (sidebar order 19, after observability). The page covers:

  • Opening paragraph explaining what Code Mode is and how it relates to MCP and the Dynamic Worker Loader API
  • Closed beta callout (note admonition) making clear the underlying Worker Loader API requires beta access for production
  • Why Code Mode? — rationale for the approach (LLMs are better at writing code than making tool calls)
  • How it works — numbered step-by-step explanation of the architecture
  • Usage — before/after code examples using TypeScriptExample components showing traditional tool calling vs. Code Mode with the codemode() wrapper
  • ConfigurationPackageManagers for install, WranglerConfig for the worker_loaders binding, and the CodeModeProxy export
  • Sandboxing and security — how isolate sandboxing protects against untrusted code
  • Generated TypeScript API — example of what the auto-generated TypeScript interface looks like
  • Example: multi-step MCP workflow — concrete example of LLM-generated code chaining multiple MCP calls
  • Current limitations — experimental status, closed beta, JavaScript-only
  • Next stepsLinkCard components linking to Dynamic Worker Loader API, McpClient, MCP Tools, and Using AI Models

The page follows all Agents docs conventions: pcx_content_type: concept, AI and MCP tags, component imports from ~/components, TypeScriptExample wrappers, WranglerConfig blocks, and the LinkCard "Next steps" pattern.

2. Updated: src/content/docs/workers/runtime-apis/bindings/worker-loader.mdx

Added a "Code Mode" subsection (H3) between the introductory text and the basic usage example. This cross-references Code Mode as a primary use case for the Dynamic Worker Loader API, with links to:

  • /agents/api-reference/code-mode/ (the new page)
  • /agents/ (Agents SDK)
  • /agents/model-context-protocol/ (MCP docs)

Closes #28342

github run

Co-authored-by: irvinebroque <irvinebroque@users.noreply.github.com>
@github-actions github-actions bot added product:workers Related to Workers product product:agents Build and deploy AI-powered Agents on Cloudflare that can act autonomously. size/m labels Feb 14, 2026
@github-actions
Copy link
Contributor

This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:

Pattern Owners
/src/content/docs/agents/ @irvinebroque, @rita3ko, @elithrar, @thomasgauvin, @threepointone, @whoiskatrin, @cloudflare/pcx-technical-writing, @cloudflare/ai-agents, @cloudflare/dev-plat-leads
/src/content/docs/workers/ @cloudflare/workers-docs, @GregBrimble, @irvinebroque, @mikenomitch, @korinne, @WalshyDev, @cloudflare/deploy-config, @cloudflare/pcx-technical-writing, @cloudflare/wrangler, @mattietk, @cloudflare/dev-plat-leads

LinkCard,
} from "~/components";

Code Mode is an alternative approach to using [MCP](/agents/model-context-protocol/) tools with AI agents. Instead of presenting MCP tools directly to the LLM, Code Mode converts MCP tool schemas into a TypeScript API and asks the LLM to write code that calls that API. The generated code runs in a secure, sandboxed [V8 isolate](/workers/reference/how-workers-works/) powered by the [Dynamic Worker Loader API](/workers/runtime-apis/bindings/worker-loader/).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to call out more directly that you can use Code Mode with EXISTING MCP Servers

and that Code Mode lets MCP servers expose hundreds or thousands of tools without blowing up the agent's context window. Needs to explain benefits more directly

LinkCard,
} from "~/components";

Code Mode is an alternative approach to using [MCP](/agents/model-context-protocol/) tools with AI agents. Instead of presenting MCP tools directly to the LLM, Code Mode converts MCP tool schemas into a TypeScript API and asks the LLM to write code that calls that API. The generated code runs in a secure, sandboxed [V8 isolate](/workers/reference/how-workers-works/) powered by the [Dynamic Worker Loader API](/workers/runtime-apis/bindings/worker-loader/).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/bonk Need to explain that it is not alternative to MCP but better way to use MCP. And make the benefits clearer around how this uses so much less context. You get into that below but I think needs to be moved even further up


:::

## Why Code Mode?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/bonk this section needs to call out more clearly that Code Mode means using fewer tokens

:::

## Why Code Mode?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/bonk please use this image: https://cf-assets.www.cloudflare.com/zkvhlag99gkb/6DRERHP138FSj3GG0QYj3M/99e8c09b352560b7d4547ca299482c27/image2.png in this section. You will need to take that image file and copy it into this repository, committing it to this repo. Do not just link to that URL. The image is a diagram of code mode vs. traditional MCP

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/bonk actually the image should go in the "How it Works" section below

Co-authored-by: irvinebroque <irvinebroque@users.noreply.github.com>
@ask-bonk
Copy link
Contributor Author

ask-bonk bot commented Feb 14, 2026

The "Why Code Mode?" section now leads with two new paragraphs that directly explain the token cost problem with traditional MCP tool calling and how Code Mode solves it. I also added a new top bullet point ("Use far fewer tokens") and strengthened the token-related language in the existing bullets — making it clear that MCP servers can expose hundreds or thousands of tools without blowing up the context window, and that chaining eliminates per-step token overhead.

github run

@threepointone
Copy link
Contributor

Should we should hold off on this till we have the codemode sdk rewrite (probably a week or so away)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:agents Build and deploy AI-powered Agents on Cloudflare that can act autonomously. product:workers Related to Workers product size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code Mode docs in Agents SDK docs

10 participants