Added Code Mode docs & cross-refs.#28343
Conversation
Co-authored-by: irvinebroque <irvinebroque@users.noreply.github.com>
|
This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:
|
| 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/). |
There was a problem hiding this comment.
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/). |
There was a problem hiding this comment.
/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? |
There was a problem hiding this comment.
/bonk this section needs to call out more clearly that Code Mode means using fewer tokens
| ::: | ||
|
|
||
| ## Why Code Mode? | ||
|
|
There was a problem hiding this comment.
/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
There was a problem hiding this comment.
/bonk actually the image should go in the "How it Works" section below
Co-authored-by: irvinebroque <irvinebroque@users.noreply.github.com>
|
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. |
|
Should we should hold off on this till we have the codemode sdk rewrite (probably a week or so away)? |
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.mdxCreated a new Code Mode documentation page in the Agents SDK API reference section (sidebar order 19, after observability). The page covers:
TypeScriptExamplecomponents showing traditional tool calling vs. Code Mode with thecodemode()wrapperPackageManagersfor install,WranglerConfigfor theworker_loadersbinding, and theCodeModeProxyexportLinkCardcomponents linking to Dynamic Worker Loader API, McpClient, MCP Tools, and Using AI ModelsThe page follows all Agents docs conventions:
pcx_content_type: concept,AIandMCPtags, component imports from~/components,TypeScriptExamplewrappers,WranglerConfigblocks, and theLinkCard"Next steps" pattern.2. Updated:
src/content/docs/workers/runtime-apis/bindings/worker-loader.mdxAdded 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