6 ms·
Show HN: I built an MCP server using Cloudflare's code mode pattern
Read this article by Cloudflare this morning https://blog.cloudflare.com/code-mode/ https://blog.cloudflare.com/code-mode/ the main argument being that LLMs are much better at writing typescript code than tool calls because they've seen typescript code many more times.
HN Discussion: https://news.ycombinator.com/item?id=45399204 https://news.ycombinator.com/item?id=45399204
https://news.ycombinator.com/item?id=45386248 https://news.ycombinator.com/item?id=45386248
Deno provides a great sandbox environment for Typescript code execution because of its permissions system which made it easy to spin up code that only has access to fetch and network calls.
Stick an MCP proxy on top of that and you've got "CodeMode" (code intermixed with MCP tool calls) for more advanced workflow orchestration.
https://github.com/jx-codes/codemode-mcp https://github.com/jx-codes/codemode-mcp
There's a lot of things that can be improved here. Like a virtual file system for the agent to actually build up its solution instead of being forced to one shot the solution but the bones are there.
- fabmilo 1y agoI was just reflecting on this blog post after reading it this morning. What do you think on code mode after implementing it? At this point would not be better to just have a sandboxed api environment with customizable api/tools endpoints? basically an RL environment :)
- jmcodes 1y agoYeah the main value is definitely the code execution layer. You could easily generate a type-safe client from your REST, GraphQL, TRPC layer, expose it to the Deno layer and list the types as a resource or something. No need to involve MCP at all. You're basically just defining a stdlib for the LLM. If you run `deno check` before executing the code you'd get the type-safety loop (working on this now) Later I want to see what'd happen if you give the LLM a repo of sorts to store useful snippets and functions with comments for later use. So the LLM itself would save workflows, be able to import them into the Deno environment and chain those together. It definitely needs a prompt that tells it to use the MCP server but I can see it being pretty powerful. I only did simple tests like get Reddit posts, their comments, find the weather on those days, stick them in duckdb, and run some social media metric queries. I could see that same test being: "find me leads, filter by keywords, run against some parquet file stored somewhere using duckdb, craft an email for my boss." I'm kind of ranting but I think this a pretty exciting approach. Edit: GraphQL style codegen layer but for all your APIs seems like a pretty obvious middle layer for this, maybe next weekend.
- danielser 1y agoI came here looking for partial solutions to fill gaps in our own attempts at CodeMode service. However I'll give you some hope ;) > Later I want to see what'd happen if you give the LLM a repo of sorts to store useful snippets and functions with comments for later use. So the LLM itself would save workflows, be able to import them into the Deno environment and chain those together. OMG this is the first thing you should do. We have similar now and its freaking amazing. Just discussing yesterday how I can't remember it going off the rails since implementing automem last week even. Best thing it does, fully recaps all your daily accomplishments, across all platforms (Claude Code, Claude Desktop, ChatGPT, Cursor). https://i.postimg.cc/Z0tYGKvf/Screenshot-2025-09-28-at-3-15-38-PM.png https://i.postimg.cc/Z0tYGKvf/Screenshot-2025-09-28-at-3-15-... https://i.postimg.cc/SQX6bTzV/Screenshot-2025-09-28-at-3-16-23-PM.png https://i.postimg.cc/SQX6bTzV/Screenshot-2025-09-28-at-3-16-... Called Automem by a friend of my (Jack Arturo), currently closed-source, though I'm sure you could reverse engineer it enough. - its a hosted stack of FalkorDB + QDrant - has endpoints for creating/retrieving memories - embeds stuff using ChatGPT models - Uses Graph nodes for relating memories together - Has a dream/sleeping phase which degrades long term memory relevant, finds and tracks patterns and more. - Has an MCP which connects any AI directly to memory - Automated hooks which record memory queues on commit, deploy, learning moments - Automated storing of all queued memories on chat end. - A lot more magic under the hood too. So in reality you get a near biological memory, useful by any MCP agent. To be fair Jack has about a 2 month head start on the rest of us with this idea haha. -- The setup were building will be an always running setup, so it also has a scheduling runtime in Node that uses MD files to create automatable workflows, some uses agents, some just run bash. They can call mcps, tools, run commands, log output, use automem etc, all in human readable text. https://i.postimg.cc/Y246Bnmx/Screenshot-2025-09-28-at-3-11-14-PM.png https://i.postimg.cc/Y246Bnmx/Screenshot-2025-09-28-at-3-11-... https://i.postimg.cc/ThM2zY5Z/Screenshot-2025-09-28-at-3-17-16-PM.png https://i.postimg.cc/ThM2zY5Z/Screenshot-2025-09-28-at-3-17-... https://i.postimg.cc/vT6H26T7/Screenshot-2025-09-28-at-3-17-37-PM.png https://i.postimg.cc/vT6H26T7/Screenshot-2025-09-28-at-3-17-... PS Keep up the great work on your codemode service, got some great ideas from yours to incorporate to ours that should resolve the one or 2 issues we had outstanding. Will share if I get it working, https://github.com/danieliser/code-mode https://github.com/danieliser/code-mode if it gets any where
- nivertech 1y agoCan you expand on the RL thing? Just because an agent “lives” in the environment, doesn’t make it RL. It needs a reward function, or even better something like Gym.
- danielser 1y agoor did he mean Real Life environment which is how i read it, with access to real APIs and tools etc.
- manojlds 1y agoI read it as this leading towards an alternative to MCP, what many people have been thinking about as well. Just that to not completely pull the rug on the most hyped thing right now, they are like this is a better way to do MCP.
- jmcodes 1y agoHaha yes, yes it is. I wrote out and implemented that approach in the links below. I've been playing with it for a few hours and I have to say I actually really really like it. One thing I ran into is that since the RPC calls are independent Deno processes, you can't keep say DuckDB or SQLite open. But since it's just typescript on Deno. I can just use a regular server process instead of MCP, expose it through the TS RPC files I define, and the LLM will have access to it. https://github.com/jx-codes/mcp-rpc https://github.com/jx-codes/mcp-rpc https://news.ycombinator.com/item?id=45420133 https://news.ycombinator.com/item?id=45420133
- kordlessagain 1y agoThis is a terrible idea masquerading as innovation. Cloudflare wants you to believe LLMs write TypeScript better than they make tool calls, but they're really just creating another dependency on their infrastructure. 1. Tool calls are intentionally simple; adding a code generation layer introduces needless complexity and failure points. 2. Cloudflare already acts as a man-in-the-middle for ~20% of the Internet with limited transparency about government data requests 3. This is clearly designed to drive adoption of their Worker platform and create lock-in for AI agent developers Similar to their x402 payment scheme that reinvents HTTP 402 under their control, the community has already built alternatives (see the Aperture implementation from Lightning) that don't require surrendering more of your stack to Cloudflare. Remember what's happening here: a company with unprecedented visibility into web traffic wants even more control over how AI agents interact with the internet. Even if you don't believe that AI will eventually self govern itself, this is a horrible idea to limit individual's ability to automate portions of their access to the web. No thanks.
- dennisy 1y agoWhilst I agree that Cloudflare have a vested interest here, there have been other proposers of this concept such as huggingface. https://huggingface.co/blog/smolagents https://huggingface.co/blog/smolagents
- danielser 1y agoIs this not just GraphQL for MCP/Tools? In which case your likely wrong, people do want it, and AI will be very good at orchestrating simple patterns. CF definitely has a vested interest.. The problem for them now that I see is that THEY DIDN"T ACTUALLY LAUNCH IT... but did describe what it is/does in complete detail. Now there are gonna be dozens of non CF locked clones, just like the one OP linked.
- gavmor 1y ago> LLMs are much better at writing code than at tool calling. Wait, really? This is harder to get right: ``` { "jsonrpc": "2.0", "id": 102, "method": "tools/call", "params": { "name": "book_flight", "arguments": { "origin": "SFO", "destination": "JFK", "departureDate": "2025-10-15", "returnDate": "2025-10-18", "passengers": 2, "cabinClass": "business" } } } ``` Than the equivalent... but with `method: "POST"` boilerplate, etc? Or is it literally the chaining of tools that's missing from—and fundamentally faulty in—MCP client implementations?
- jmcodes 1y agoSo this is a first pass to capture the workflow part (mix code and MCP calls). The fetch code isn't any better than the tool code I agree, but typescript code is more common so I'd guess this would be too? But anyway I think the real power comes with the type-safety part that I left out this morning (working on it now). From what I understand Cloudflare is essentially generating an SDK for the LLM to write code against. Instead of writing that fetch call. The LLM would generate ``` const redditResults = await redditMCP_getTopPosts(subreddit); const insertMutation = await duckdb_Insert("SQL STUFF", redditResults.map(...)); const results = await duckDb_Query(args: duckDb_QueryArgs); return resultsInSomeNiceFormat; ``` Where the method names come from the MCP server tools, and the argument types are autogenerated from the MCP schemas themselves. No idea if this is a valuable workflow or not personally. I just thought it was cool and wanted to tinker with it.
- danielser 1y agoCorrect, this is like giving the LLM full specs on your GraphQL endpoint, and telling it have fun, get only what you need. Except it can use Typescript to manipulate the data mid stream. So in reality this is MCP Middleware + MCP Orchestration + Tool Call Efficiency. It will save tokens as well due to only returning what it needs, but more so just think of going from 10 consecutive tool calls, to 1 call that gives you everything you need and nothing you don't, with 1/10th the time taken to accomplish.
- WilcoKruijer 1y agoI find it interesting how this project uses all three major JavaScript runtimes in a single project. Bun for the code itself, Deno for sandboxing and Node for running the MCP server. Says something about the ecosystem.
- jmcodes 1y agoSays something about my coding haha. Yeah since it's using Deno it'd be cool just use Deno throughout. Definitely gotta clean up the code quite a bit.
- malnourish 1y agoWhy Deno over Bun? Forgive my naivety, I was a backend dev for years and am only now familiarizing myself with the JS/TS ecosystem
- davidghowell 1y agoThe point seems to be to just use 1 instead of all 3 runtimes. OP needs the Deno sandbox and security features so that is the deciding factor.
- jmcodes 1y agoLike the the other commenter said, just for the permissions. If Bun had a sandbox I'd use it. Deno isn't my cup of tea (although I appreciate it more after building with it the past two days). My impression is that it is lightweight, you can deploy it easily to edge workers and it's built on rust so you can actually use it to build your own runtime with only the parts you want. (I was working on this for a game when I ran into the CF blog article). Node/npm is the grandpa, can't go wrong but it doesn't run typescript by default and you'll lose cool points. pnpm is cool don't really know what makes it different these days except it has a nice cache by default so you get faster installs, and you can do monorepos semi-easily. It's my default if I can't use Bun. Bun is newer and my current favorite. You can compile to single executable, have access to most of the npm ecosystem (some packages still have minor issues), you have a built in sqlite db so it's great for prototyping, and some other niceties. There's a lot more to it but that's the important differences I run into in my day to day.
- luckydata 1y agodoes this approach actually work? is it more reliable than plain mcp calls?
- danielser 1y agoThink of GraphQL, this gives the AI all the structure via Typescript of the MCP / API / Tools, lets it orchestrate its own response. So once it has the API shape in memory, it could make dozens of tool calls in a single call. It isn't about token saving, its about time/efficiency of tool usage/response time accumulation. Instead of 20 separate tool calls one after the other, you get one larger, orchestrated one that only returns exactly what it needed.
- cpard 1y agoThe valuable lesson from what Cloudflare claims is that if you want to make an LLM perform as you expect you have to build considering their strengths and weaknesses. You can see the same behavior if you try to ask an LLM to code in an API that is not commonly used. When it comes to MCP tooling I followed a different path but with similar assumptions. There are tools that LLMs have been Rled to death to use. So I’m modeling my tools after them. Specifically, I try to have a “glob” tool, used to let the LLM figure out structure. A search and a read tool and use regexp as much as possible for passing parameters. You can see an early version of this pattern here: https://github.com/typedef-ai/fenic/blob/main/examples/mcp/docs-server/README.md https://github.com/typedef-ai/fenic/blob/main/examples/mcp/d... It has been working well, at least in terms of the model knowing how to invoke and use the tools. I have to say though that each model is different. I see differences between Claude code and Codex when I use the MCP for development, at least on how good they are in retrieving the information they need. Maybe I should try to run some benchmarking and compare more formally
- evertedsphere 1y agoalso seen in https://lucumr.pocoo.org/2025/8/18/code-mcps/ https://lucumr.pocoo.org/2025/8/18/code-mcps/
- lucis 1y agoMCP is the best SDK
- jmcodes 1y agohttps://github.com/jx-codes/mcp-rpc https://github.com/jx-codes/mcp-rpc For those of you interested, I wrote out and built an more RPC typescript centric approach to avoid using other MCP servers at all. Would appreciate some thoughts! https://news.ycombinator.com/item?id=45420133 https://news.ycombinator.com/item?id=45420133
- Palmik 1y agoMany [1] models expect (MCP) tool calls to be formatted as a JSON. So if you expose code execition as an MCP tool to such model, it will have to generate the code escaped as a JSON string. I would exepct this to tank code generation quality. [1] Not all, some use different formats, e.g. GLM uses plain text with special tokens to denote param names and values.