deniz.in

Markets

Weather

Loading weather

· via dev.to (home feed)

An OpenCode agent spent 177,444 tokens on a 'hi' because of MCP tool definitions

A dev.to post by Bold.org's VP of Technology traces how MCP tool definitions made a one-word greeting cost 177,444 tokens, and how on-demand tool discovery cut it by 92%.

An OpenCode agent spent 177,444 tokens on a 'hi' because of MCP tool definitions

A six-figure token bill for one word

Bold.org, a scholarship platform, runs an internal agent on OpenCode that staff use to investigate production issues, look up information and assemble reports, with integrations into the systems where that data lives. According to a dev.to post by Orestis Ioannou, the company's VP of Technology, usage limits were being hit far sooner than expected over a stretch of days. Token consumption was growing faster than the number of sessions or automations could explain, which did not fit the expectation that the model in use, Astra, should need fewer tokens to complete tasks.

The investigation started with the hosted deployment's SQLite database (running OpenCode 1.18.31), which records session history and per-call usage. Queries covering September 14 and 15 surfaced one Astra conversation at 50.4 million tokens across 121 model calls, with 49.9 million of those in cache reads. That initially looked like evidence for long conversations being the cause: the agent kept re-reading a large context rather than producing enormous answers. Reasoning effort did not appear responsible either, since the inspected sessions used the model default and reasoning tokens made up a small share of the total.

Tracing sessions back to their opening calls complicated that explanation. One Astra session began with roughly 177K input tokens before it had gathered any results, and others started at a similar size. To find the floor, Ioannou opened a brand-new conversation and sent the single word "hi." The session recorded 177,444 input tokens — no prior messages, no tool calls, nothing to investigate.

The overhead was in the tool catalog

Running OpenCode TokenScope on that fresh session confirmed 177,431 input tokens for a 13-token response, while the visible conversation was tiny. The skill catalog was estimated at about 3,400 tokens and the inspectable tool definitions at about 5,800 — nowhere near enough to explain the request. The gap was in what the report could not see: its tool inventory in that setup omitted the full MCP definitions.

Inspecting those catalogs separately on the hosted machine found the dominant item: the Meta Ads integration, exposing 97 tools with roughly 595K characters of descriptions and parameter schemas, about 72% of the measured MCP definition text. This was not advertising data the agent had retrieved; it was the documentation needed to call the tools, attached to every request whether or not anyone was asking about advertising. Disabling Meta Ads and repeating the greeting dropped the count from 177,444 to 54,181 tokens, with the model, reasoning effort and skills unchanged. A single integration accounted for roughly 69% of the original request.

On-demand discovery as the fix

Removing the integration was not an acceptable answer, since people relied on it. It turned out the installed version already supported an alternative: experimental Code Mode. Setting OPENCODE_EXPERIMENTAL_CODE_MODE=true on the OpenCode service and restoring Meta Ads brought the greeting down to 13,274 tokens — a starting context roughly 92% smaller, with the full set of integrations intact.

Under Code Mode, the model writes code that calls tools, chains operations together and filters results, rather than pulling every intermediate response back into the conversation. It starts from a compact catalog, looks up the signatures it needs, and runs JavaScript through an execute step in a confined runtime, while MCP still handles the underlying calls. Ioannou cautions that the 92% figure describes the greeting's recorded usage, not the final bill: real investigations still load definitions and results as they work.

The post also notes that OpenCode 2 makes Code Mode the default for MCP servers, and that the pattern is not unique to OpenCode — Claude Code has MCP Tool Search, and Codex defaults to deferred MCP discovery on supported configurations.

Why it matters

The cost of agent integrations is not only what it costs to use a tool, but what it costs to make every tool available on every request. Large MCP catalogs inflate the baseline context, eat usage budgets, and — as observed at Bold.org — coincide with more frequent compactions, slower responses and worse answers. Deferred and on-demand tool discovery is becoming the default across major harnesses, so teams running older versions or statically loaded catalogs should measure what their very first request contains. A one-word greeting turns out to be an effective diagnostic.

  • #ai-agents
  • #mcp
  • #llm
  • #token-costs
  • #opencode

Related posts