Mhonn YbañezSRE, DevOps, AI Engineer
 Today I Learned
Read the full page

Does code mode replace MCP?

Posted
Tags
ai, agents, mcp

Code mode does not replace MCP. It turns an MCP server's tools into functions and has the model write one short program that runs in a sandbox, instead of making one tool call per step. It saves tokens on repetitive work and helps less when each step needs the model's judgment.

I watched a KodeKloud short about code mode. The video opens with people saying MCP is dead because of it, and I wanted to know if that is true. Everything below comes from the short plus what I already knew about MCP. I did not check the numbers it quotes.

The question I had

Does code mode replace MCP, or is it something different?

What I found

MCP in a paragraph

MCP is the standard way an AI agent connects to outside apps like a calendar, Slack or GitHub. An MCP server gives the agent a list of tools, and each tool is one action in that app. A calendar might have create event, list events and delete event. Every tool comes with a short description that tells the model what it does and what inputs it needs. I wrote about how MCP compares with UTCP before.

The traditional way

The video's example is asking an agent to schedule a different meeting for every day in January: 31 events, each with its own title and agenda.

  1. The model first receives the descriptions of all the tools it can use, for the calendar, Slack, GitHub and more. That can be thousands of tokens before any work happens.
  2. It calls create event for January 1st and gets a result back.
  3. For the second event, the model runs again and receives the whole conversation again: the tool descriptions, my request, and the first result.
  4. That repeats, and the conversation gets longer every round.

Caching can make this cheaper. Many models can also make several tool calls in one turn. Still, each call and each result goes through the model's context, so a long repetitive job gets expensive. This is the same cost I wrote about in what a context window is.

Code mode

Code mode (Cloudflare's name for it, according to the video) changes who makes the calls.

  1. Every tool on the MCP server is turned into a function automatically. The create event tool becomes a function called create event. Nobody writes these by hand.
  2. Instead of 31 tool calls, the model writes one short program: a list of the 31 meetings and a loop that calls create event for each.
  3. The program does not run inside the model. It runs in a sandbox, an isolated box with no general internet access that can only reach the functions it was given.
  4. The program makes all 31 calls. The model gets back only a short summary, like "31 events created".

Models are good at this because they have seen far more real code than tool calls. The video says Cloudflare's demo of this exact task used 81% fewer tokens. I could not check that number, so I take it as an example, not a promise.

What did not change

The calls still go through MCP, to the same MCP server, with the same permissions the agent already had. Code mode changes who makes the calls: a program instead of the model. So it is a better way to use MCP, not a replacement for it. The sandbox matters because the program is code the model just wrote, and I should not trust it any more than I would trust any generated code.

Traditional tool callsCode mode
Who makes the callsThe model, one at a timeA program the model wrote
Round trips through the modelManyOne to write the program, one for the summary
TokensGrow with each stepThe tool list plus a short program and a short result
Still uses MCPYesYes
Weak spotLong repetitive jobsSteps where the model needs to think about each result

Fewer tools in context

The video also says Cloudflare took the idea further. Its platform has thousands of actions, and giving each one its own tool would cost over a million tokens of descriptions. Its newer server gives the model just two tools, one to search for the right action and one to run code, which takes roughly a thousand tokens. I like that part, because the model looks things up when it needs them instead of carrying everything around. It lines up with what I found in whether a smaller context makes agents better.

How code mode is like an ordinary API call

The more I read, the more code mode felt like something I already know. It is what happens when you stop calling an API by hand and write a script against it.

A familiar API ideaThe code mode version
Calling an endpoint 31 times by handTraditional tool calls, with the model doing every call itself
A script with a loop that uses an SDKThe one short program the model writes
An SDK generated from an API descriptionMCP tools turned into functions automatically
A bulk endpoint, or GraphQL, that saves round tripsThe loop runs next to the tools instead of next to the model
Sending one request to a runner, like SQL or a stored procedureThe single "run code" tool, whose payload is a program

Seen this way, the model is a developer writing a small client script, and it only makes one real call: "run this".

Where the likeness breaks

  • The payload is code, not data. A normal API call has a shape the server designed. Here the model makes up the shape, so the sandbox has to limit what that code can reach.
  • The caller finds the functions as it goes. A developer reads the docs first. The model has to search for the right function, which is why the search tool matters.
  • Nobody had to build the bulk endpoint. With a normal API, the owner has to anticipate a bulk operation and build it. With code mode, the client can compose any batch out of the single actions that already exist.

Why not skip MCP and call the REST API?

If code mode is just a client script, a fair question is why the model does not write code against the plain REST API and leave MCP out. This part is my own reasoning, not from the video.

In principle it could. What MCP gives it is the part around the call:

  • A standard way to discover what is available, with descriptions written for a model.
  • A standard way to handle sign in and permissions, so the agent has no more access than it was given.
  • One protocol for many apps, instead of each REST API having its own shape and quirks.

The generated functions in code mode come from those tool descriptions. Without MCP, something else would have to supply the same descriptions and auth, and a large REST API would have the same too-many-tokens problem. So code mode builds on MCP and does not make it unnecessary.

Where my epiphany came in

My first thought was that code mode is batching: bundling a lot of requests into one go. Then I realised that is the same thing as the API comparison above. A bulk request and a client script with a loop are the same idea, and code mode lets the model write that script itself. That fits. The next thing I saw is the limit. If the model needs to see the result of one step to decide the next one, bundling does not help much.

I need to be careful here, though. A program can still branch on results with plain if and else, so some decisions are fine inside it. The limit is when the next step needs the model's judgment about what came back, like reading a message and deciding what to do about it. Then the program has to stop and hand control back to the model.

The second thing I noticed is that this starts to look like a deterministic workflow again. Once the code exists, it runs the same way every time, and I can read it before it runs. But the program is written fresh by the model for each task, so the plan is still the model's, not one I designed in advance.

Takeaway

Code mode does not kill MCP. It keeps MCP as the way to reach the apps, and changes the model from making every call to writing a short program that makes them. That saves tokens when the work is repetitive and the steps are predictable, and it helps less when each step needs the model to think.

I will be honest that I still do not fully understand code mode. I have not built anything with it, and I am working from a short video and my own comparisons. But if it can cut how much context an agent uses, I would take that as a win, and it is worth trying on a repetitive job to see how much it really saves.