Dynamic Context Discovery for Production Coding Agents

cursor · Tech · 2026 · source Agentic: yes · promotional bias: low · source-backed · extracted with prompt 0.5.6 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Coding-agent context engineering

Cursor needed coding agents to use long-running task context efficiently without bloating the LLM context window with huge tool outputs, chat histories, MCP tool descriptions, terminal output, and static instructions that might never be needed.

Constraints:

Architecture

Cursor's dynamic context discovery pattern moves large or rarely needed context into files and gives the agent tools to inspect them when needed. Long tool outputs are written to files; chat history is referenced during summarization; Agent Skills provide discoverable task instructions; MCP tool descriptions are synced to folders so only tool names are in static context; and terminal sessions are treated as files. The agent starts with less static context and pulls relevant data dynamically through file reads, tailing, and tool lookups.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  agent-harness[Agent harness] --> file-backed-context-store[File-backed context store]
  file-backed-context-store --> tool-output-files[Tool output files]
  file-backed-context-store --> chat-history-files[Chat history files]
  file-backed-context-store --> skill-folders[Skill folders]
  file-backed-context-store --> mcp-tool-folders[MCP tool folders]
  file-backed-context-store --> terminal-session-files[Terminal session files]
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Agent harness Model instructions and tools optimized for each frontier coding model. File-backed context store
File-backed context store Stores long tool outputs, terminal logs, skills, MCP tool descriptions, and chat histories. Tool output files, Chat history files, Skill folders, MCP tool folders, Terminal session files
Tool output files Large shell or MCP responses written to files for selective reading. Agent harness
Chat history files Detailed prior conversation state available to summarization and later agent reads. Agent harness
Skill folders Agent Skills open-standard instructions discoverable by the agent when relevant. Agent harness
MCP tool folders Synced MCP tool descriptions loaded only when the task calls for them. Agent harness
Terminal session files Integrated terminal output exposed as file-like state rather than static prompt text. Agent harness

Data flow

Instead of injecting all possible context into the prompt, Cursor writes bulky tool outputs, histories, skills, MCP descriptions, and terminals to file-like locations. The agent receives lightweight static pointers, checks tails or descriptions as needed, and reads more only when the task calls for it. Summarization can recover detail by referencing chat-history files rather than relying only on lossy summary text.

“As models have become better as agents, we've found success by providing fewer details up front, making it easier for the agent to pull relevant context on its own.”article, stated
“In Cursor, we instead write the output to a file and give the agent the ability to read it.”article, stated

Why this architecture

Cursor found that stronger agents do better with less static context and more ability to discover relevant context dynamically. File-backed context avoids both truncation data loss and prompt bloat, while selective MCP loading sharply reduces token use in runs that actually call MCP tools.

“Dynamic context discovery is far more token-efficient, as only the necessary data is pulled into the context window.”article, stated
“It can also improve the agent's response quality by reducing the amount of potentially confusing or contradictory information in the context window.”article, stated

Models used: Cursor agent harness · frontier agentic models · MCP · Agent Skills

Scale

Alternatives considered (roads not taken)

Include static context up front.

Rejected because: Static context wastes tokens and can confuse the model with irrelevant or contradictory information.

“We're calling this pattern dynamic context discovery, in contrast to static context which is always included.”article, stated

Truncate long shell or MCP results.

Rejected because: Truncation can lose important information that the agent may need later.

“The common approach coding agents take is to truncate long shell commands or MCP results. This can lead to data loss”article, stated

Load every MCP tool description into the prompt.

Rejected because: Cursor instead syncs tool descriptions to a folder and gives the agent only small static context plus tool names.

“The agent now only receives a small bit of static context, including names of the tools, prompting it to look up tools when the task calls for it.”article, stated

Patterns

context-compaction (context)

Cursor summarizes long-running sessions while retaining chat history in files so the agent can recover details after lossy compression.

“When the model's context window fills up, Cursor triggers a summarization step to give the agent a fresh context window with a summary of its work so far.”article, stated

tool-use-orchestration (orchestration)

The agent dynamically reads files, tails long outputs, and looks up MCP tools or skills only when required.

“The agent calls tail to check the end, and then read more if it needs to.”article, stated

agent-memory (context)

Chat histories, terminal sessions, tool outputs, and skills are kept as retrievable state outside the immediate prompt.

“5. Treating all integrated terminal sessions as files”article, stated

cost-aware-routing (model-operations)

Cursor reduces token usage by keeping MCP descriptions out of the context window unless the agent needs them.

“In an A/B test, we found that in runs that called an MCP tool, this strategy reduced total agent tokens by 46.9%”article, stated

Tradeoffs

Context loading strategy

Chose Dynamic discovery through files and tool lookups. over Static upfront context injection..

Rationale: Dynamic discovery reduces token waste and confusion while preserving access to details.

“only the necessary data is pulled into the context window”article, stated

Long output handling

Chose Write outputs to files and let the agent tail/read them. over Truncating long outputs directly into context..

Rationale: Files preserve the full output without forcing all of it into the context window.

“In Cursor, we instead write the output to a file and give the agent the ability to read it.”article, stated

MCP tool exposure

Chose Small static context plus file-backed tool descriptions. over Full MCP tool descriptions in the prompt..

Rationale: This produced a measured token reduction while preserving tool discoverability.

“The agent now only receives a small bit of static context, including names of the tools”article, stated

Gotchas (what bit them)

Truncating long tool outputs can silently remove crucial information.

Root cause: Shell commands and MCP calls can return large responses that exceed comfortable context limits.

Resolution: Cursor writes long outputs to files and lets the agent inspect them selectively.

“This can lead to data loss, which could include important information you wanted in the context.”article, stated

Summarization can degrade the agent's knowledge.

Root cause: Summaries are lossy compression of prior context.

Resolution: Cursor uses chat-history files so the agent can refer back to detailed history during or after summarization.

“But the agent's knowledge can degrade after summarization since it's a lossy compression of the context.”article, stated

MCP re-authentication could hide tools from the agent.

Root cause: Without file-backed status, the agent forgot unavailable tools entirely.

Resolution: MCP tool status is communicated through files so the agent can tell users to re-authenticate.

“previously if an MCP server needed re-authentication, the agent would forget about those tools entirely, leaving the user confused.”article, stated

Evaluation

Cursor evaluated the MCP context-loading change with an A/B test over runs that called MCP tools and reports token reduction as the primary measured outcome.

Metrics: 46.9% reduction in total agent tokens for MCP-tool runs · Statistical significance with high variance based on installed MCP count

“this strategy reduced total agent tokens by 46.9% (statistically significant, with high variance based on the number of MCPs installed).”article, stated

Outcomes

The article reports a 46.9% token reduction in MCP-tool runs and lists five production context-discovery techniques.

“This has resulted in fewer unnecessary summarizations when reaching context limits.”article, stated
“This file approach also unlocks the ability to communicate the status of MCP tools to the agent.”article, stated