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:
- Tool calls can return large JSON responses or shell/MCP outputs.
- Truncating long outputs can discard important information.
- Long-running sessions need summarization, but summaries are lossy.
- MCP servers can expose many tool descriptions that may not be used.
- Terminal sessions can produce large outputs while still containing useful state.
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]
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.
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.
Models used: Cursor agent harness · frontier agentic models · MCP · Agent Skills
Scale
- Selective MCP tool loading reduced total agent tokens by 46.9% in MCP-using runs.“this strategy reduced total agent tokens by 46.9%”article, stated
- The pattern supports five concrete context surfaces in Cursor.“1. Turning long tool responses into files 2. Referencing chat history during summarization 3. Supporting the Agent Skills open standard”article, stated
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.
Truncate long shell or MCP results.
Rejected because: Truncation can lose important information that the agent may need later.
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.
Patterns
context-compaction (context)
Cursor summarizes long-running sessions while retaining chat history in files so the agent can recover details after lossy compression.
tool-use-orchestration (orchestration)
The agent dynamically reads files, tails long outputs, and looks up MCP tools or skills only when required.
tail to check the end, and then read more if it needs to.”article, statedagent-memory (context)
Chat histories, terminal sessions, tool outputs, and skills are kept as retrievable state outside the immediate prompt.
cost-aware-routing (model-operations)
Cursor reduces token usage by keeping MCP descriptions out of the context window unless the agent needs them.
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.
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.
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.
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.
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.
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.
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
Outcomes
- Reduced MCP-tool-run token usage by 46.9%.
- Reduced unnecessary summarization when reaching context limits.
- Improved agent ability to recover from MCP re-authentication status.
- Established five dynamic context surfaces in Cursor's harness.
The article reports a 46.9% token reduction in MCP-tool runs and lists five production context-discovery techniques.