Code Mode is quickly becoming a popular way to connect AI agents to tools. Instead of handing the model a list of MCP tools, it turns them into a TypeScript API and lets the model write code that calls them. Cloudflare ships it as @cloudflare/codemode, and Anthropic's programmatic tool calling follows the same idea. It saves context and handles large tool sets well. It also changes what security tooling can see.
We wanted to know what an MCP security scanner sees when every tool sits behind a single code tool. So we scanned the same deliberately vulnerable MCP server twice with VAAST, once directly and once behind Code Mode. Behind the wrapper, the scanner saw one tool instead of four and reported 2 results instead of 26. With state-changing probes enabled, it marked the wrapper as passing all seven of its checks. The poisoned instructions we planted were still there, still on their way to the model.
This post covers what we measured, two further problems we found along the way, and how we changed VAAST so that, with state-changing probes enabled, its results through Code Mode match direct scanning. We ran all experiments on November 22, 2026, against local fixtures we control, using Cloudflare's open-source SDK in wrangler dev. No production systems were tested.
How Code Mode changes what a scanner sees
A classic MCP client calls tools/list, shows the model each tool with its description, and lets the model call them one at a time. Most MCP security scanners work the same way: they read the tool list, check each description for hidden instructions, and send probe inputs to each tool to see how it responds.
Code Mode replaces that tool list with one tool, code, whose only input is a JavaScript function. Behind it, each upstream tool becomes a typed method on a codemode object, and each tool's description becomes a documentation comment in the generated TypeScript. The function runs in an isolated sandbox and can call several upstream tools in sequence.
So a scanner pointed at a Code Mode endpoint gets a tool list with exactly one entry. Nobody had measured what that does to scan results, so we did.
Our setup
We ran VAAST's MCP Scanner through the same code path the desktop app uses: v0.3.10 for the "before" results and v0.3.11 for the "after" results. On the Code Mode side we used @cloudflare/codemode 0.5.6 (codeMcpServer with DynamicWorkerExecutor, outbound network blocked) running under wrangler dev 4.166.0, with @modelcontextprotocol/sdk 1.32.2.
Our main target was mcp-vulnerable, a small server we built with four tools and known flaws:
get_user_info, whose description hides instructions telling the model to call a destructive tool without telling the user (tool poisoning);echo_back, which reflects its input back;parse_config, which leaks Python tracebacks on bad input;delete_all_records, marked destructive (in the fixture it only logs).
To check for false positives, we also scanned 44 benign MCP servers replayed from real-world tool definitions, 634 tools in total. Every server was scanned in two profiles: the default read-only profile, which never calls tools that may change state, and a full profile with "Also probe tools that may change state" enabled. We captured the Code Mode traffic in Burp Suite. The experiment made no model calls and cost nothing to run.
The scanner went blind
Scanned directly, VAAST found four tools and reported 26 results: the poisoning on get_user_info, reflection and schema-validation issues on get_user_info and echo_back, traceback leaks on parse_config, and delete_all_records skipped because the scan was read-only (figure 1).

Figure 1: Scanned directly, VAAST v0.3.10 discovers four tools and reports 26 results.
Behind Code Mode, the same server showed one tool (figure 2), and the scan returned two results: one poisoning finding, attributed to code, and one skipped check (figure 3).

Figure 2: The same server behind Code Mode exposes a single tool, code.

Figure 3: Behind Code Mode, VAAST v0.3.10 reports 2 results instead of 26.
Three things happened at once.
The poisoning finding survived, but lost its address. Code Mode copies each upstream tool's description into the code tool's documentation, so the same detection rules still fired. But they fired on code, so a reviewer could no longer tell which real tool was poisoned.
Every dynamic finding disappeared. The scanner sent its probe inputs to code, which only accepts a function. The wrapper rejected them before any upstream tool was ever called. Every reflection, schema and traceback finding was gone, in both profiles.
The wrapper looked clean. In the full profile, the scanner probed code seven times and every probe passed. Anyone reading that report would reasonably conclude that the tool had been tested and was fine.
The danger itself didn't go anywhere. Figure 4 shows the tools/list response from the wrapper: one tool, with the hidden instructions from get_user_info sitting inside its description, ready for whatever model receives it.

Figure 4: The poisoned instructions travel inside the single code tool's description.
On the 44 benign servers, Code Mode added no false positives. One server failed outright behind the wrapper, which led to our third finding.
Code Mode drops the hints that say what's safe to call
MCP tools can carry annotations like readOnlyHint and destructiveHint. Clients, approval prompts and scanners use them to decide whether a tool can be called without asking. codeMcpServer doesn't carry them into the generated API, so behind the wrapper every method looks the same.
We saw why this matters while building our fix. Our first version guessed safety from method names whenever annotations were missing. Across the benign servers, that version would have called two methods in read-only mode that their servers explicitly declare as state-changing, including d1_database_query, which is annotated readOnlyHint: false. The name looked harmless; the annotation said otherwise. Guessing from names is not a safe substitute.
This isn't only a scanner problem. Any approval or policy layer that relies on annotations loses its signal behind Code Mode. Wrappers could close the gap by preserving annotations in their generated documentation or discovery APIs.
One bad schema takes down every connector
The benign server that failed behind the wrapper was github-mcp-server, which scanned fine directly. Of its tools that declare an outputSchema, 74 of 123 use a root type other than "object", mostly ["null","object"].
Under protocol revisions before 2026-07-28, the MCP spec requires outputSchema to have type: "object" at its root, and the MCP TypeScript SDK enforces that when listing tools. The rule was lifted for revision 2026-07-28 (typescript-sdk #1149). So rejecting these schemas is correct for older revisions. The problem is what happens next: Code Mode treats one invalid tool as fatal for the entire runtime.
We confirmed this in a multi-server Code Mode runtime. Two healthy servers worked together. Adding github-mcp-server, in either order, made every connector unavailable. A minimal fixture with just two tools, only one of which used ["object","null"], did the same.
So one outdated or untrusted upstream server can take down every other connected server, including any safety or approval tooling running alongside it. It doesn't leak data or run code, and it only affects the deployment that connected the bad server. But it's a real robustness gap, and widely used servers trigger it today. We're not the only ones to hit it: OpenAI's hosted apps endpoint fails the same way in another MCP client, where four invalid tools out of 149 make Gmail, Calendar and Slack unusable (pi-mcp-adapter #881).
We reported the all-or-nothing behavior to Cloudflare as cloudflare/agents#3017, suggesting that the runtime skip or flag the one non-conforming tool (or connector) and keep the rest working.
How VAAST sees through Code Mode
Starting with v0.3.11, VAAST's MCP Scanner understands code-execution wrappers. It:
- Detects the wrapper and recovers each upstream method from the generated TypeScript documentation.
- Reports findings per method, as
code::codemode.<method>, so the poisoned tool is named again. - Probes each method on its own, through generated code that calls only that one method.
- Refuses to guess what's safe. Because annotations aren't visible through the wrapper, read-only scans never call wrapped methods. Each one is listed as skipped, with the reason. Full coverage requires explicitly enabling state-changing probes against a disposable server, or scanning the unwrapped server directly.
In a read-only scan through Code Mode, v0.3.11 now pins the poisoning to get_user_info and lists all four methods as skipped, with the reason (figure 5).

Figure 5: VAAST v0.3.11 attributes the poisoning to get_user_info and explains why each wrapped method was skipped.
With state-changing probes enabled, the scan through Code Mode returns 33 results (figure 6), and the direct scan returns 31 (figure 7). The difference is two rows describing the wrapper itself. Every finding on every upstream tool is identical.

Figure 6: Full scan through Code Mode with VAAST v0.3.11: 33 results.

Figure 7: The same server scanned directly: 31 results, with the same findings on every tool.
Burp confirms that the probes now reach the real tools. In figure 8, the generated code calls only parse_config, and the real traceback comes back through the wrapper.

Figure 8: A v0.3.11 probe calls one upstream method through Code Mode, and the real finding comes back.
For mcp-vulnerable, before and after:
- Read-only, through Code Mode: v0.3.10 reported 2 results, with the poisoning attributed to
code. v0.3.11 reports 10, with the poisoning attributed toget_user_infoand all 4 methods skipped with a reason. - Full, through Code Mode: v0.3.10 reported 8 results, with 7 probes falsely passing on
code. v0.3.11 reports 33, and every finding matches the direct scan. - Full, direct (baseline): 31 results in both versions.
We then reran the comparison across all 45 servers. Direct scanning was unchanged between versions, with 0 differences across 7,454 probe results. In the full profile, all 507 wrapped methods' worst verdicts through Code Mode matched their direct-scan verdicts, and 3,499 of 3,548 individual probe results were identical. The remaining differences come from Code Mode renaming reserved words and from extra schema probes made possible by the more specific generated types, all of which passed. In the read-only profile, all 507 wrapped methods were skipped with a reason, and no call reached an upstream tool.
Limitations
This experiment measured the scanner, not the model. Whether a model given the code tool actually follows poisoned instructions, and how often compared with direct tool calling, is the subject of our next experiment. We also tested only one wrapper implementation, @cloudflare/codemode 0.5.6, which Cloudflare labels experimental, and only in local wrangler dev. We did not test Cloudflare's hosted MCP portals or Anthropic's hosted code execution. Finally, our Code Mode traffic passed through two small forwarding processes in the lab. We checked that the process lifecycle they introduce doesn't affect results, with 0 differences across 7,454 direct probe results.
What we recommend
If you scan MCP servers before approving them for your agents, scan the upstream servers directly, not only the Code Mode endpoint your agents connect to. Treat a clean result for a server that exposes a single code or execute tool as unverified, unless your scanner explicitly understands the wrapper.
If you build or deploy code-mode wrappers, preserve tool annotations in what the model and its tooling can see, and isolate tool-list failures so one bad schema can't take down every connector.
If you rely on annotations for approvals or policy, check that they survive every layer between the server and the model.
Try it
If your agents connect to MCP servers through Code Mode, or anything like it, VAAST can now tell you what's actually behind the wrapper. Code Mode-aware scanning is available in VAAST v0.3.11 and later. The raw scan exports behind this post are available for download: direct, read-only, direct, full, Code Mode, read-only and Code Mode, full. Questions or corrections are welcome at [email protected].
Update, November 23, 2026: corrected the probe-level comparison to the figures for the released v0.3.11 (an earlier version of this post quoted numbers from a pre-release build), and clarified that results match direct scanning when state-changing probes are enabled.
Ready to map your own surface?
Start with the VAAST free tier.
The free tier includes the baseline payload library across the full category catalog. Enough to do a meaningful first pass on a real target.