Skip to content

Is MCP Dead? | Cloudflare Code Mode Explained | AI Agents & Tool Calling

Read the Portuguese translation →

Author: At A Glance! · Watch on YouTube

Video authored by the channel shown, not by IANIA; all rights belong to the creator. Transcript and summary generated automatically; the original-language content is preserved.

Original language: English

Original video: Is MCP Dead? | Cloudflare Code Mode Explained | AI Agents & Tool Calling · Channel: At A Glance! · 10:37 · Watch on YouTube

Topics: AI agents, AI safety

The video explains Cloudflare’s Code Mode as an alternative way for AI agents to use many tools, without changing the MCP protocol itself. Rather than loading a large catalog of individual tool definitions into the model’s context, the agent can discover capabilities and write JavaScript to combine operations in a controlled execution environment. Code Mode can help with large catalogs and workflows involving dependent steps, but traditional tool calling may be better for simple actions. The video emphasizes that sandboxing is not a substitute for authorization and recommends testing Code Mode against a conventional baseline before adopting it.

  • Code Mode changes how agents use tools, not the MCP protocol.
  • A large catalog of individual tool definitions can consume model context before the task begins.
  • Cloudflare’s approach uses search to discover capabilities and execute to run generated JavaScript.
  • Code can combine dependent operations and handle control flow, potentially reducing repeated model turns.
  • The video reports an example comparison of approximately 1.17 million tokens for native tool definitions versus roughly 2,000 tokens for the Code Mode interface; this concerns the tool definition footprint, not all workflow tokens.
  • Two patterns are described: wrapping an existing MCP server with a code-oriented interface, or searching and executing operations from a large API specification.
  • Traditional tool calling may be cleaner for a small number of tools and a simple action.
  • Production safeguards include least-privilege permissions, isolated execution, network controls, validation, approvals for sensitive actions, and audit logs.
  • The video recommends measuring tokens, model turns, latency, failures, task completion, accuracy, and security violations against a conventional baseline.
Start Chapter Summary
00:07 The tool-calling problem and Code Mode The video introduces the challenge of exposing large tool catalogs to models and explains how Code Mode uses discovery and generated code instead.
02:44 Execution, example, and token comparison It describes the isolated execution path, walks through a conditional DNS update, and qualifies the reported token-footprint comparison.
05:22 Code Mode patterns, trade-offs, and security The video compares two Code Mode patterns, explains when traditional tool calling may be preferable, and outlines production security safeguards.
08:30 How to evaluate Code Mode and the takeaway It recommends testing Code Mode against a conventional baseline and concludes that MCP connects capabilities, Code Mode orchestrates them, and security controls what is allowed.

Code Mode changes how agents use tools, not the MCP protocol itself. — 00:38

The key difference is that we are moving some of the orchestration from repeated model decisions into code. — 02:12

A sandbox constrains execution; permissions determine what an agent is allowed to do. — 07:58

MCP connects; code mode orchestrates. Security controls what is allowed. — 10:37

MCP, Code Mode, Cloudflare, tool calling, JavaScript, sandbox

00:07 Hello everyone, welcome back to my YouTube channel. Have you ever wondered what happens when an AI agent needs to work with hundreds or even thousands of tools? The problem isn’t necessarily that MCP can’t handle these tools. The challenge is how we expose them to the model and how the model uses them efficiently. That’s where Code Mode comes in. Instead of asking the model to select and call individual tools repeatedly, we let it write a program that combines multiple operations. And

00:38 the important point is this. Code Mode changes how agents use tools, not the MCP protocol itself. Let’s understand the problem first. Every tool can have a name, description, input schema, parameters, and constraints. When we have just a few tools, this is manageable. Let’s imagine an agent working with thousands of API operations; providing all those definitions to the model can consume a significant amount of its context before it even starts solving the actual problem. But imagine that

01:09 context could otherwise be used for the user’s request. Useful information and reasoning. So, the challenge is simple. How can we give an agent access to many capabilities without loading every tool definition into its context up front? This is where Cloudflare’s Code Mode approach becomes interesting. Instead of exposing a massive API catalog as individual model-facing tools. This approach provides two primary operations: search and execute. Think of search as a discovery mechanism. The model uses it to find the API capabilities it needs. Then, execute

01:41 runs JavaScript code that calls those capabilities and processes the results. For example, if an agent needs to find a DNS record and update it, it can discover the relevant operations and write a small program to perform the workflow. The model doesn’t need every API endpoint’s full schema in its context from the beginning. Now let’s compare the two approaches. With traditional tool calling, the model typically selects a tool, receives its result, and then decides what to do next. If several operations depend on

02:12 one another, this can require multiple model turns. With Code Mode, the model can write a program containing the entire sequence of operations. For example, it can retrieve a record, check its current value, and update it only if a condition is satisfied. The program handles that control flow, so intermediate results can remain within the execution environment instead of being returned to the model after every operation. The key difference is that we are moving some of the orchestration from repeated model decisions into code . But here is an important question. If

02:44 the model generates code, where does that code actually execute? In Cloudflare’s server-side Code Mode architecture, the model connects through an MCP client. It discovers the capabilities and submits the generated JavaScript for execution. That code runs in an isolated worker environment and accesses the API through the host-controlled execution path. The resulting information is then returned to the model. Notice that the generated code isn’t simply given unrestricted access to the user’s machine. However,

03:15 isolation alone isn’t enough. We still need proper authorization, permission checks, and controls over which operations the code can perform. Let’s make this practical with a simple example. Suppose you ask an AI agent. Find the DNS record for app.example.com ; if it points to the old IP address, update it to the new one. The agent first discovers the relevant DNS operations. It then queries the matching host name and checks the current IP address. Here you can see the current IP address is 192.0.2.10.

03:49 And the target IP address is 192.0.2.25 . The generated program checks whether the current value matches the expected old address. Only if that condition is satisfied does it attempt the update. Finally, it returns the result. Instead of orchestrating every step through a separate model decision, the agent can express the dependent operations in one program. One important detail: a real implementation must enforce authorization and any required approval before performing a write operation.

04:20 The code which is shown here is illustrative, not a ready-to-run Cloudflare script. Now let’s look at the numbers presented in the comparison . For the API catalog shown here, Cloudflare reports approximately 1.17 million tokens for the native tool definition footprint, compared with roughly 2,000 tokens for the code mode interface. That’s a reduction of approximately 99.9%in the reported tool definition footprint. But there is an important distinction: this is not a

04:51 99.9%reduction in every token used by the entire agent workflow. The comparison concerns the tool definition and interface footprint. Actual token usage will depend on the task, the generated code, the returned result, and the model interactions involved. Still, when a model needs access to a very large API catalog, reducing the definitions it must process upfront can make a substantial difference. This concerns the tool definition and interface footprint. Actual token usage

05:22 will depend on the task, the generated code, the returned result, and the model interactions involved. Code mode isn’t a single architecture that works identically everywhere. The presentation highlights two major patterns. The first is the single code-oriented interface wrapped around an existing MCP server; instead of exposing every upstream tool separately to the model, the interface lets generated code work with the available typed methods. This can be useful when you already have an MCP server and want

05:53 to simplify how the model interacts with it. The second pattern uses search functions and execute functions against a large API specification. Here the model discovers the operations it needs and executes them through the generated code. This approach is particularly useful when an API catalog contains thousands of endpoints. So the distinction is that one pattern wraps existing tools while the other discovers and executes operations from a large API surface. At this point you might think we should replace every traditional tool with Code Mode, but

06:25 that’s not necessarily the right decision. If an agent has only a few tools and needs to perform one simple action, traditional tool calling may be a cleaner solution. Code Mode becomes more attractive when a workflow involves multiple dependent operations, conditional logic, loops, filtering, or processing large results. However, we also need to consider security and complexity. Can we safely constrain the generated code? Can we inspect and audit its actions? Does the code actually reduce context usage or improve the workflow? If the answer is

06:57 no, introducing Code Mode might create more complexity than value. Choose the interaction pattern based on the problem. If the answer is no, introducing Code Mode might create more complexity than value. Choose the interaction pattern based on the problem, not simply because the newer approach looks more advanced. Now let’s discuss one of the most important production considerations, which is security. Running generated code in a sandbox helps isolate execution, but it doesn’t automatically make every action

07:27 safe. Imagine an agent that has permission to read DNS records but should not be allowed. To delete them. Even if the model generates code that attempts to delete a record, the permission layer should reject that operation. That’s why production systems need multiple safeguards. Use least-privilege permissions, isolate code execution, control network access, validate inputs and outputs, require approvals for sensitive actions, and maintain audit logs. Remember that sandboxing and authorization solve

07:58 different problems. That’s why production systems need multiple safeguards. Use least-privilege permissions, isolate code execution, control network access, validate inputs and outputs, require approval for sensitive actions, and maintain audit logs. Remember that sandboxing and authorization solve different problems. A sandbox constrains execution; permissions determine what an agent is allowed to do. Both are essential when generated code can interact with real systems. Hope you have understood this

08:30 security aspect. So if you are building production-grade AI agents, how should you start using Code Mode? Don’t replace your current existing tool-calling architecture immediately. First, identify a workflow that requires several dependent tool calls. Establish a baseline using conventional tool calling. Then implement the same workflow using Code Mode. Now compare both approaches across the same task. Measure the input and output tokens. The number of model turns, end-to-end latency, API failures, task completion, accuracy, and security violations. Also

09:03 test what happens when an API call fails. The generated code behaves unexpectedly, or an operation is unauthorized. Finally, compare the results; if code mode reduces overhead and improves the workflow without compromising correctness or security, it may be worth adopting. The goal is not to use code mode everywhere. The goal is to prove that it actually delivers measurable value for your particular workload. Let’s bring everything together. Think of MCP as a standard that allows AI applications to

09:35 connect with external capabilities. Code mode changes how the model uses those capabilities. Instead of manually orchestrating every individual tool call, the model can write a program that discovers, combines, and executes multiple operations. The program runs within a controlled execution environment. While authorization and other security policies govern what it actually does, the result is a different way of orchestrating tools, particularly when workflows involve many operations or large API catalogs. And remember, code mode isn’t

10:05 automatically better in every situation ; traditional tool calling remains useful for simple and direct actions. So, to conclude, is MCP dead? No. What’s changing is how we expose and orchestrate tools for AI agents. Code mode demonstrates an alternative to providing large numbers of individual tools. If you are building AI agents, don’t focus only on what tools you expose. Also consider how the model discovers, combines, and executes them. MCP connects; code mode orchestrates.

10:37 Security controls what is allowed. That’s the mental model to remember. I hope you have understood every single concept involved in this particular video. If you have any single doubt, you can straight away put it in the comment section; I will be happy to solve it. For more such videos, do like , share, and subscribe to my channel. Also, hit the bell icon and don’t forget to follow me on Instagram. Please join me on Telegram. Thanks for watching, have a good day ahead.