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)? |
|
I just landed the codemode doc, so we just need to cross reference it now https://developers.cloudflare.com/agents/api-reference/codemode/ |
|
/bonk review the comments from @irvinebroque and the last comment from @threepointone re: codemode doc landing. Ensure this feedback is incorporated into the changes here. Then pull in the changes from #28480 so they are in this PR (as a single PR) and close as "addressing in #28480". Review against our styleguide and docs best practices. |
Remove the draft Code Mode page (code-mode.mdx) which is superseded by the codemode doc that @threepointone landed on production. Restore codemode.mdx from production and update worker-loader.mdx cross-refs to point to /agents/api-reference/codemode/. Addressing feedback from #28480.
|
Addressing in #28480. @threepointone landed the codemode doc on production, so this PR now:
The original feedback from @irvinebroque (token cost framing, MCP compatibility, benefits clarity) is all addressed in the production codemode doc that @threepointone rewrote. |
|
Here is a summary of what was done: SummaryFeedback incorporated
Changes made
Validation
|
|
/bonk I don't see the MCP server docs changes from #28480 here. Please address that. Check your work. |
Co-authored-by: elithrar <elithrar@users.noreply.github.com>
|
All changes applied and validated. Here is a summary of what was done: Changes madeApplied the MCP server docs changes from PR #28480 to Content from PR #28480 (applied)
Style guide fixes applied on top of PR #28480
Validation
|
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