Repository navigation
codemode: programmable MCP tool use with deferred exposure #66626
G36maid
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
What are you proposing?
A
codemodetool for the agent: the model writes a script that calls session tools (MCP tools as namespaced functions) in one execution, and only the script's output reaches the context. MCP tools are deferred inside the script environment by default, with BM25 tool search for discovery. Plus per-server exposure settings so each MCP server can choosecodemode/deferred/direct, like pi's toolexposurefield.Why does this matter?
Zed currently puts every MCP tool into the model's tool list on every turn. This works fine with small servers, but with big ones it's a problem.
Example: ghidra-mcp exposes 200+ tools. All of them would sit in every thread's tool list, even in threads that never touch reverse engineering. The server author had to implement his own lazy loading (
search_tools/load_tool_group) because hosts don't do it.Anthropic measured ~77K tokens consumed before the first user message with 50+ MCP tools loaded upfront, dropping to ~8.7K with deferred loading (Advanced tool use).
Second problem: tool results can't be piped. My zed-mcp-server-markitdown has a single
convert_to_markdown(uri)tool — converting a PDF dumps the whole document into context, and anything the model does with it next means the full text round-trips through the model again. Anthropic measured 150K → 2K tokens for exactly this pattern with code execution (Code execution with MCP).Code mode solves both problems in one mechanism: tool schemas stay out of the context (tools are functions, deferred by default), and intermediate results never round-trip through the model.
Are there any examples or context?
Each exposure option has a real precedent. Two agents ship code mode today (
codemode):codemodetool where the model writes JavaScript to call tools, MCP tools deferred inside it by default (docs/codemode.md)codemode: falseescape hatch (release notes,packages/codemode)The approach itself comes from Cloudflare's Code Mode: the better way to use MCP.
The intermediate step — keep native tool calls but defer the schemas — is what the others do (
deferred), and was already proposed in #64004tool_search(ToolExposure)Zed right now is
directonly — every MCP tool on the native tool list, no other exposure option.Possible approach
codemodetool itself — a script interpreter (pi uses QuickJS; embeddable, small) exposing session tools, MCP tools as namespaced functions deferred by default.exposurefield:codemode(tools only callable from scripts),deferred(discoverable via tool search), ordirect(on the native tool list, today's behavior). This generalizes OpenCode'scodemode: true/false.My plan is to start with the codemode tool itself, since it solves both problems in one mechanism. If anyone sees a reason not to do this, better to hear it now.
All reactions