Est.

Cursor-Based Agent Debugging With Live Trace Context

Feeding production traces to Cursor turns vague agent failures into fixable bugs.

· 11 min read · Updated
Cover illustration for “Cursor-Based Agent Debugging With Live Trace Context”
Agent Debugging · October 13, 2026 · 11 min read · 2,527 words

Cursor's agent mode already runs a functioning debugging loop without much supervision. It runs terminal commands, reads the output, runs tests, parses the failures, proposes a fix, and repeats the cycle until the test suite turns green and the linter stops complaining. For conventional software bugs, this loop works because the input is already shaped for reasoning: a stack trace points to a line number, a failing assertion names the expected value against the actual one. The gap opens somewhere else. A report that reads "the agent misbehaved on this user's session" gives Cursor nothing to grab onto: there is no step-by-step record of what the agent did, in what order, with what intermediate results along the way. Cursor is a capable debugger with no case file.

How AI agents fail without a debuggable error

Agent failures don't look like software bugs, and that's the root of the problem. A stack trace tells you where a program crashed. If an agent completes its task with a success code but has quietly done the wrong thing, it leaves no such marker behind. Planning errors are a case in point: the agent commits to one tool sequence and then executes a different one, or loops through steps without making progress toward the goal, and none of this appears as an error code anywhere. It's visible only if you look at the full span tree.

Tool errors compound the problem. A tool gets called with the wrong arguments, or it returns malformed data, and the agent proceeds as though the call succeeded. The task finishes with a success status while the underlying output is corrupted, and the corruption travels forward into every step that depends on it. A documented case from production shows exactly this pattern: a tool call began returning malformed JSON, the agent kept working with that bad data, and the task completed with a success code while nothing in conventional monitoring flagged it. In a related case, an agent silently deleted a config key it had judged redundant. That's better described as Scope Creep Execution than as a hallucination, since the model wasn't inventing anything, it was acting outside the bounds of what it was asked to do. The task still returned success. The damage occurred downstream.

Reasoning errors are harder still to catch, because the agent can ignore an explicit instruction or produce a factually wrong answer grounded in context that was right in front of it, and the output will read as fluent and confident regardless. Reading the trace itself is the only way to tell a correct response from a wrong one. Research spanning more than 100,000 production agent interactions documents a silent-failure subclass that occurs under completely normal operating conditions: no external trigger, no error message, no timeout, nothing an on-call engineer would be paged for. These failures surface only through systematic measurement after the fact. Microsoft's taxonomy of failure modes in agentic AI systems singles out memory poisoning as one of the more dangerous variants in this category, because corrupted or malicious instructions can be stored, recalled, and acted on across sessions without triggering any safety check in between. None of this is forensically visible from the outside. The agent's internal reasoning trajectory is the only place the fault can be found.

What "live trace context" means and what it contains

A production trace is a structured record of one agent run from start to finish. It captures every LLM call along with its prompt and its completion, every tool invocation with the arguments it was passed and the value it returned, every retrieval step with the query that was sent and the chunks that came back, and the latency attached to each of these operations. This structure is what makes a trace useful for debugging in a way that a log line or a final output never can be, because each failure category named above leaves its own distinct fingerprint inside it. A planning error appears in the trace as a mismatch between the tool sequence the agent committed to in its plan span and the sequence it actually executed. A tool error appears in the trace as a gap between what the tool returned and what the agent then acted on. A reasoning error shows up as a mismatch between a retrieved chunk and the claim the agent built from it.

Live trace context means you get the trace from the actual production run in question, not a synthetic reconstruction or a replay built after the fact. It's the specific session a user reported, carrying the exact inputs, the exact model responses, and the exact tool outputs that occurred at the time. With that trace available inside Cursor, a vague report like "the agent misbehaved" turns into something an engineer can actually work with: at step 4, the tool returned malformed JSON, and the agent proceeded with this fabricated value, which then propagated into steps 5 and 6. It's a specific, reproducible problem, structured the same way a stack trace structures a conventional bug. Latency and cost belong in this picture too. An agent that reaches the right answer slowly and at high cost is still failing in a way that matters, and a spike in tool-call counts or an unexplained retry loop is itself a trace fingerprint pointing at a planning failure.

How MCP wires trace data into Cursor's agent loop

The Model Context Protocol lets Cursor's agent read external data sources (logs, metrics, traces, databases) without leaving the editor, and call tools against those sources as part of its own reasoning loop. An MCP server exposing trace data gives Cursor a way to pull the specific production trace tied to a reported session, inspect individual spans inside it, filter by tool name or by error condition, and use that structured data as grounding context for a fix, the same way it already uses a stack trace for an ordinary bug.

The design of that server matters as much as its existence. The Harness MCP server v2 offers a useful pattern here, not as a product to adopt but as a reference for how to handle scale: it cut its tool count from more than 130 down to 11 by using a registry-based dispatch model that supports a wide range of resource types without expanding the list of tools the model has to choose among. The same principle applies directly to a trace-context MCP server. Stacking a Playwright MCP, a GitHub MCP, and a trace MCP together without discipline lets the sheer number of tool definitions crowd the model's effective reasoning context before any trace data even arrives. The design goal that follows from this is narrow on purpose: a trace-context MCP server should expose a small number of high-value tools, fetch a trace by session ID, list the spans inside it, filter by tool name, pull the detail on a single span, rather than a sprawling surface that competes with code context for space in the model's window.

Diagram: How Cursor Closes a Production Agent Failure in Five Steps. Visualizes: Show the runtime debugging workflow as a stepped linear sequence.

Setting up a trace-context MCP server for a Cursor debugging session

Building this out breaks into three parts: instrumenting the agent so it emits structured traces, standing up an MCP server that exposes trace retrieval tools, and configuring Cursor to connect to that server.

Instrumentation comes first. Frameworks Cursor commonly works alongside, including Vercel AI, the OpenAI Agents SDK, and LangGraph, already emit spans that an observability backend can collect. The requirement is simple to state and easy to get wrong in practice: the trace needs to land somewhere queryable by session ID or run ID, so that a developer can hand Cursor one identifier and get back the full record of that run.

The MCP server that sits on top of that data should keep its surface small. A fetch-by-run-id tool, a list-spans tool, and a get-span-detail tool cover most of the debugging queries a developer will actually make, and they don't crowd the context window the way a sprawling tool list would. Each tool's description needs to be precise, because the model chooses among them based on that description alone, and a vague one invites the wrong tool call at the worst moment.

Connecting Cursor to the server is the last step: add it under Cursor's MCP settings, check that the tool list shows up in Cursor's tool panel, and confirm the server actually responds from the editor's process context before relying on it mid-session. You can place this alongside Cursor's existing Debug mode, which instruments an application with logging statements and collects runtime logs as a developer reproduces a bug locally, adds logging as needed to find the root cause, and works alongside Agent mode when a fix needs several iterations. For production traces specifically, Agent mode takes the trace as input context instead of running the application live, and that covers most of the work.

Put together, the runtime workflow looks like this: the developer pastes the reported session's run ID into the Cursor prompt. The agent calls the MCP trace tool to retrieve the full span tree for that session. It locates the specific step where the failure fingerprint appears, whether that's a planning mismatch, a corrupted tool return, or a reasoning error against retrieved context. It proposes a fix and applies it. It runs the test suite to confirm the regression is actually closed, not just patched over.

Grounding Cursor's fix reasoning in what the agent was supposed to do, not just what it did

Pulling the trace is necessary, but it isn't enough on its own. Cursor also needs to know what the agent was supposed to do at each step: its instructions, the tool sequence it was expected to follow, and whatever policy constraints governed its behavior, so that a deviation actually registers as a deviation. Without that reference point, Cursor is reasoning about what happened. With it, Cursor is reasoning about what went wrong. The distinction is visible concretely in how a fix gets framed: "the agent called tool X with these arguments" is a description of behavior, while "the agent should have called tool Y first, because the instructions require a balance check before any write" is a diagnosis against intent, and only the second one tells an engineer what to change.

In practice, this means the MCP server should surface the agent's system prompt or instruction set alongside the trace data, or the developer should paste it into the Cursor prompt directly, so that the agent's reasoning about a fix stays anchored to what the system was built to do rather than drifting toward whatever the trace happens to show.

The Air Canada chatbot case shows what skipping this step can cost. The chatbot told a customer that bereavement fare refunds could be applied retroactively within a specific window after the ticket was issued. The customer booked travel based on that answer and flew. The airline later denied the refund, but the customer won compensation through Canada's Civil Resolution Tribunal. Nothing about that chatbot response looked broken from a monitoring standpoint: it was fluent, grammatically sound, and structurally identical to every other response the system produced that day. Only a comparison against the airline's actual refund policy would have caught that the answer was wrong. That's the same structural gap this section is about. Predefining every possible failure mode in advance isn't a workable defense against it, because the most dangerous deviations are the ones that look exactly like successful completions until someone checks them against what the agent was actually told to do.

The practical move for the Cursor workflow follows directly: include the agent's instructions (system prompt, tool allowlist, policy constraints) as a named block of context in the debugging session, so that the fix Cursor proposes addresses the deviation from intent and not merely the symptom visible in the trace.

Turning a production failure into a regression test before closing the session

Every production failure that surfaces through trace context doubles as a labeled example of what the agent should never do again, and that example should become a regression test before the debugging session ends, not as a separate task scheduled for later. Once Cursor has identified the failing span and applied a fix, the trace for that session, the inputs, the failing tool call, and the behavior that should have happened instead, becomes an entry in the agent's eval dataset, versioned in Git alongside the prompt itself.

A CI evaluation step then checks every future merge against that dataset, so the failure mode that was just fixed can't quietly come back through a later prompt edit, a model upgrade, or a change to a tool's schema. This loop holds up best when the scorer used in CI runs the same logic as the scorer watching live production traffic: a quality signal measured during development means the same thing once the system is live, and when a regression does appear, it can be traced back to the change that caused it.

Not every check in this dataset needs a model to evaluate it. Deterministic checks, exact-match comparisons on tool sequence, argument schema validation, checks for the presence of expected output fields, can cover most of the eval surface on their own. 2026 analysis puts deterministic, code-based checks at 60 to 70 percent of agent evals, with LLM-as-judge scoring reserved for the subjective quality dimensions where exact-match comparison doesn't apply. The practical effect is that the regression dataset grows every time a new failure mode is discovered in production, and coverage builds up over months of real use rather than depending on a team anticipating every way an agent might go wrong in advance.

Lemma's place in this workflow as the observability layer between trace and editor

Everything described above depends on three capabilities working together: a backend that collects and stores structured traces from production, a way to surface those traces inside the editor where the developer is already working, and logic that groups deviations from the agent's instructions into actionable issues rather than leaving a developer to sort through raw log lines one at a time.

Lemma is built for that layer specifically. It audits every production trace against the agent's own instructions, groups deviations into recurring failure patterns automatically, and alerts the team in Slack, so that by the time a developer opens Cursor, there's already a specific session to pull and a specific category of failure to look for rather than a vague bug report to decode from scratch. Lemma's MCP integration puts the trace context, the failure pattern grouping, and the relevant span detail inside Cursor directly, with no need to switch over to a separate monitoring dashboard mid-session. The fix happens in the editor, grounded in a diagnosis Lemma has already done the work of producing.

That same grouping pays off at the regression-test step described above. Because Lemma clusters recurring failures by category automatically, the labeled examples it surfaces for the eval dataset arrive already organized by failure type, so the dataset builds up as a structured record of known failure modes rather than as an unsorted pile of failing traces waiting for someone to make sense of them.

Sources

  1. New whitepaper outlines the taxonomy of failure modes in AI agents
  2. Silent Failure in LLM Agent Systems: The Entropy Principle and the Inevitable Disorder of Autonomous Agents
  3. The 2026 Singapore Consensus on Global AI Safety Research Priorities
  4. Updating the taxonomy of failure modes in agentic AI systems: What a year of red teaming taught us
  5. Model or Harness? An Interaction-Centric Taxonomy for Localizing Agent Failures
Filed underAgent Debugging

More in Agent Debugging