Composite scenario, not a real company. Assembled from common industry patterns; every number is illustrative and its assumptions are listed at the end.
This case belongs to Agents, Tools and MCP.
Context
- A software company with 300 engineers builds an internal assistant for questions such as "why did the checkout build fail after PR 4812, and is there a ticket for it?".
- It reaches the company's systems through two MCP servers (Model Context Protocol, a standard for exposing tools to model applications), each owned by a different team.
- The redesign replaces whole-object tools such as
get_diffwith scoped ones such aslist_changed_files.
| MCP server | Tools |
|---|---|
| Repo | search_code, read_file, get_diff, list_commits |
| Tickets | search_tickets, get_ticket |
Problem statement
Pilot traces showed that a typical question needed about 6 tool calls (7 model calls, the last one writing the answer). The tools returned whole objects: a large diff, a ticket with its entire comment thread.
| Pilot measure | Value |
|---|---|
| Average tool result | 18,000 tokens |
| Base (instructions plus tool definitions) | 6,000 tokens |
| Context window (assumed) | 128,000 tokens |
| Final call of a typical session | 114,000 tokens |
| A seventh tool call | 132,000 tokens: over the window, so it fails |
| Input tokens across the seven model calls | 420,000 |
Goals: median session under 75,000 input tokens, no context-length failures, and every answer citing its file or ticket.
Constraints
- Fixed: the assistant is read-only, and repo access must follow the asking engineer's own permissions.
- Fixed: tickets can contain customer data; only approved model providers may see them.
- Fixed: the MCP servers belong to other teams.
- Limit: a 30-second answer target for typical questions.
Why the traditional approach fell short
| Approach | Where it breaks |
|---|---|
| Code search | Finds strings but cannot connect a failing build, the diff that caused it and the ticket that describes it, so engineers hop between three tools |
| Wikis, runbooks, a scripted bot | Cover the questions someone expected |
| A model with tools | Can connect the evidence, but only if it fits in its context |
Options considered
| Option | Verdict |
|---|---|
| A. A dashboard linking build, PR and ticket (non-AI): one page per failing build with the diff summary and the matching tickets | Kept as the baseline and as a link target in answers |
| B. Assistant with scoped, paginated, truncating tools and a session budget: smaller tools, capped results, cursors, a token budget per session with a defined behaviour at the limit | Accepted |
| C. Keep the broad tools and buy a bigger context window | Rejected: the same session still processes about 5.7 times the tokens (see Results) and the window only delays the failure |
Solution architecture
Figure 1. Assistant components with two MCP tool servers
How to read this: tool results pass through the Orchestrator before the model sees them, so that is where the size limit and the budget are enforced.
Figure 2. One question, with the budget-exhausted path
How to read this: steps 5 to 14 repeat for each tool call, and the alt block is the decision the Orchestrator makes after every result.
How AI solved it, step by step
Step through one question, then switch to "Without the fix".
Under the hood
MCP messages are JSON-RPC 2.0, sent over stdio or Streamable HTTP. In the specification revision 2025-11-25:
| Step | Message |
|---|---|
| 1 | The client sends initialize with its protocol version, capabilities and clientInfo |
| 2 | The server answers with its capabilities (for example tools with listChanged) |
| 3 | The client sends notifications/initialized |
| 4 | tools/list returns the tool definitions; tools/call runs one |
The latest revision on the specification site as of 2026-10-21, 2026-07-28, drops the handshake: every request carries the protocol version, and its compatibility page says a modern client fails against a legacy server. Pin the revision.
What matters for context:
- The tool definitions go into every model request, and Anthropic's documentation counts the
toolsparameter,tool_useblocks andtool_resultblocks as input tokens. - The MCP tools page (revision 2026-07-28) defines no maximum result size, so limiting is your job. It also says servers SHOULD return tools in a deterministic order, which helps prompt-cache hit rates.
- Anthropic's "Writing effective tools for agents" says Claude Code restricts tool responses to 25,000 tokens by default, recommends pagination, filtering, range selection and truncation with sensible defaults, and shows a concise response of 72 tokens against 206 for the detailed one.
What went wrong / failure modes
| Failure | Mitigation |
|---|---|
| A diff or thread floods the context | A default cap of 2,000 tokens per result, cursors, and a concise format by default |
| Truncation hides the key line | The result says what was cut and how to ask for it; Anthropic's post suggests steering agents to "many small and targeted searches" |
| Redundant calls | The Orchestrator returns the earlier result and counts the call against a limit of 12 |
| Tool list growth: every added server adds definitions to every request | A cap on tool count |
| Permission leak: a shared service token exposes private repos | The server uses the asking user's identity and the Policy engine checks the repo argument |
| Protocol drift: a library upgrade changes the MCP revision | A contract test (tools/list and one tools/call) in CI |
| Customer data and injected text in tickets | Read-only tools, approved providers only, ticket text treated as untrusted |
Results
These are illustrative targets, not measurements. For a typical session of seven model calls, the input tokens processed are the sum of 6,000 + (k - 1) x r over k = 1 to 7.
| Measure | First design (r = 18,000) | Redesign (r = 1,500) |
|---|---|---|
| Input tokens across 7 calls | 7 x 6,000 + 18,000 x 21 = 420,000 | 42,000 + 31,500 = 73,500 |
| Ratio | 420,000 / 73,500 = 5.7 | |
| Tokens carried into a seventh tool call | 6,000 + 7 x 18,000 = 132,000, over the 128,000 window | 6,000 + 7 x 1,500 = 16,500 |
| Goal of under 75,000 | Missed | Met |
Tradeoffs and when NOT to use this approach
- Smaller tools need more calls for broad questions, so latency rises while tokens fall.
- Skip MCP for a single in-house tool; a direct function call is simpler (MCP vs function calling).
- Do not launch if repo permissions cannot be enforced per user.
Design rules extracted
- Size every tool result: a default cap, a cursor, a concise default format.
- Set a per-session token budget and decide in advance what the user sees at the limit.
- Say what was omitted inside the result so the model can narrow its next call.
- Run tools as the asking user, not as a shared service account.
- Pin the protocol revision and contract-test every server.
Assumptions
- All numbers are chosen for illustration: a 128,000-token window, a 6,000-token base, 7 model calls (6 tool results and the answer), an average of 18,000 tokens per result in the first design and 1,500 in the second.
- Input tokens for call k are 6,000 + (k - 1) x r; the model's own output tokens are ignored. 18,000 x (0 + 1 + ... + 6) = 378,000, plus 42,000, gives 420,000.
- The 2,000-token cap, the 25-of-40 file page, the limit of 12 calls and the 75,000-token goal are illustrative choices.
- The company, its repo and ticket systems, and PR 4812 are invented.
Last verified: 2026-10-22