r/opencodeCLI • • 3d ago

Does MCP code mode introduce a trade-off between token efficiency, context retention, and error recovery?

/r/mcp/comments/1yb94is/does_mcp_code_mode_introduce_a_tradeoff_between/

A doubt regarding trade-offs associated with code mode in mcp. Please refer to the original post.

2 Upvotes

2 comments sorted by

1

u/SirRobinBlibs 2d ago

Yeah, it's a real trade-off. Anthropic's post on code execution with MCP mostly frames the downside as sandbox and infra overhead, but what you're describing is the other half: the model only sees what the script returns, so anything you don't return is gone next turn. For the order example, have the script return the handles you'll need later (order IDs, customer ID, the status you filtered on) instead of just a summary, so turn 2 can refetch cheaply without redoing the whole chain. One OpenCode specific thing: the execute runtime has no filesystem access, imports or timers, just fetch plus the tool catalog, so the "write intermediate results to a file" trick from the Anthropic post doesn't apply, state has to come back through the output or a tool. For error recovery, wrap each tool call in try/catch inside the script and return which step failed plus whatever already succeeded, otherwise one exception throws away the partial work. And if one server is where you want every step visible to the model, set codemode: false on just that server and keep the rest in code mode.

1

u/Bleschart-Chrysten 1d ago

the link or text from your original post didnt come through btw. Generally though, pruning context to save tokens almost always hurts recovery unless you have a separate state tracker handling the retries.