March 3, 2026 | Jeremiah Lowin

Stop Calling Tools, Start Writing Code (Mode)

Code to Joy

172 38

Comments

Join the conversation by posting on social media.

I guess I know what I'm going to fiddle around this next weekend 😅

wind_dude Reddit

It’s interesting… do the clients need to support “code mode” I’m noticing that’s the draw back clients aren’t supporting much of the mcp specs other than tools.

Dipseth Reddit

Nope its just text, any client should be able to support it.

wind_dude Reddit

So if I’m understanding correctly the client llm writes the code in a sandbox on the mcp server, and the biggest advantage is when it needs to chain tools from the same mcp server together

jlowin123 Author Reddit

Good question - no, clients don't need to support anything more than "normal" MCP tools to use this. Though I should note that in my tests, a Sonnet 4.6 class model was able to use code mode with a complex server, but a Haiku 4.5 class model made a few errors before finally using it correctly.

This is awesome, we had this on our backlog for our agent platform.

I do wonder now, are you also looking into a Client-Side Codemode? That would be interesting for scenarios where you control the client but not the MCP server.

jlowin123 Author Reddit

We could add it to the FastMCP client but FastMCP is more popular as a server framework than a client framework, as most people will use the clients bundled into their agents!

Out of curiosity, would this even be so difficult to implement? To me it sounds like the hard part is over if you have the transformation and the sandboxed environment, the client would receive the tool listing anyway no? :D Or maybe it's just me looking at it in a too simple way hehe

krychu Reddit

Looks great thanks. Do you have any plans / thoughts on exposing functions of multiple MCP servers through a single execute tool? In other words, enable LLM to write a single snippet of code that mixes functions from different MCP servers?

jlowin123 Author Reddit

Sure, first compose the servers in FastMCP, then add CodeMode to the outer one. https://gofastmcp.com/servers/composition

This is the direction I keep ending up in too: let the model write one coherent program against a small, stable surface instead of juggling 200 tools and partial state.

The big win with your CodeMode() thing, at least in my experience, is not just token savings but fewer “half-plans” where the model commits to a tool too early. Having a discovery phase plus a single code-run lets it reason, comment its own plan, and then hit the minimal set of calls.

If you haven’t already, I’d stress-test it against messy, legacy backends. Stuff like: one REST API, one SOAP-ish thing, one DB behind a gateway, all with slightly different auth. I’ve used Kong and Tyk as the outer gateway, and DreamFactory as the data gateway so the code only ever sees clean REST instead of weird SQL or vendor APIs; works well when you want MCP to feel “flat” even though the backend is chaos.

Yes..it is awesome. My token count decreased from 50k to 2-3k max... I have posted here details https://www.reddit.com/r/mcpweb/s/LY88juamR0

jlowin123 Author Reddit

That's so great to see!

u/jlowin123 Used code mode on the Amazon Ads MCP:
https://github.com/KuudoAI/amazon_ads_mcp

The just a few packages, like campaign manager is a beast. Just two tools blow the budget:

* cm_CreateAd — 9,475 tokens (giant ad creative schema)

* cm_UpdateAd — 9,310 tokens

The other top 5 alone eat 22,938 tokens

Code mode economics are fantastic. Initial context: 315 tokens (3 meta-tools). Then per-workflow:

* search_tools("create campaign") — ~100 tokens round-trip

* get_schemas(["cm_CreateCampaign"]) — ~300 tokens (only the tools you need)

* execute(code) — ~200 tokens

Total per workflow: ~600 tokens vs 34K upfront.

jlowin123 Author Reddit

Awesome! Thanks for sharing the token stats too

mycall Reddit

Should we do both? I do prefer code approach in trust/sandbox environments though.

Given that code mode executes arbitrary Python, how do you prevent malicious MCP servers from escaping the sandbox or accessing sensitive system resources? What security boundaries are in place?

Ideally, this should be on client side.

Don’t need an mcp for coding.