Your Agent Trace Ends at the MCP Boundary and You Never See Why the Tool Was Slow

An agent calls an MCP tool, the tool takes nine seconds, and your distributed trace shows a single flat span with no idea what happened inside. The server did real work and emitted its own spans, but they landed in a separate trace you will never find.

Viral RuparelNo. 97 of 9711 min read

A team I was helping had an agent that called an MCP tool to pull records from an internal service, and once or twice an hour that call took nine seconds instead of the usual two hundred milliseconds. Their trace showed the problem and told them nothing about it. There was a span named execute_tool search_records, it was nine seconds wide, and underneath it there was nothing. A flat bar. The agent had done its job and recorded the call faithfully. Everything that made the call slow had happened on the other side of a boundary the trace could not cross.

The server was not silent. It was well instrumented, with spans for the database query, the upstream API fan-out, and a retry loop that fired on a flaky dependency. All of that existed. It was just sitting in a different trace, with a different trace ID, created the moment the request arrived with no parent to attach to. To find the nine-second tail you would have to know the server's trace ID, which your side never saw, or go spelunking by timestamp through a service you may not even own. In practice nobody does that, so the tool call stays a mystery and the agent gets blamed for latency it only passed through.

On the left, an agent span for an MCP tool call sits flat and empty while the server's database and retry spans live in a separate disconnected trace; on the right, traceparent carried through MCP _meta makes those same server spans children of the agent's tool-call span in one trace.
Figure. A broken two-trace span tree beside one joined trace stitched through MCP _meta

The boundary that eats your trace

Distributed tracing works because every span carries the identity of its parent. A trace is a tree of spans joined by IDs, and the join only happens if the parent's identity travels with the request to wherever the child is created. Inside one process the tracer threads that context for you. The moment a call leaves the process, something has to carry the context across, and that something is a convention both sides agree on.

For HTTP services the convention is settled. The W3C Trace Context specification defines a traceparent header that holds the trace ID, the parent span ID, and the sampling decision, plus a tracestate header for vendor data. Every mainstream tracer injects these headers on outbound requests and extracts them on inbound ones, so a REST call from service A lands as a child span under A's trace in service B without anyone thinking about it.

MCP is where this quietly stopped working. An MCP tool call is a JSON-RPC message, and until recently the spec said nothing about where trace context should live inside it. So instrumentation authors had nowhere agreed to put the traceparent. Some put it in HTTP headers, which breaks the instant the transport is STDIO instead of Streamable HTTP, since STDIO has no headers. Some put it in the tool arguments, which pollutes the tool's schema and confuses the model. Most put it nowhere, which is why the span tree ends at the boundary. The same way a tool's circuit breaker has to live at the MCP layer to be transport-agnostic, trace context has to ride inside the protocol message itself, not in whatever is wrapping it today.

What the 2026-07-28 spec actually changed

The MCP revision dated 2026-07-28 closed this gap. Among a set of larger changes, including making the protocol stateless and reworking tasks, the changelog has one line that matters here: it documents OpenTelemetry trace context propagation conventions for _meta keys, naming traceparent, tracestate, and baggage, under SEP-414. That is the whole fix, and it is worth understanding why _meta is the right home for it.

Every MCP request can carry a _meta object. It is the protocol's designated slot for metadata that is not part of a method's semantic arguments: things the transport layer and middleware care about, not things the tool's logic reads. Trace context is exactly that. It is about the call, not about what the call does. Putting the traceparent in _meta keeps it out of the tool's input schema, so the model never sees it and the tool never has to declare it, and it travels inside the JSON-RPC envelope, so it works identically over Streamable HTTP and STDIO. One place, both transports, no schema pollution.

The keys are the standard W3C names, which is the second half of why this matters. Because _meta now carries a plain traceparent, any OpenTelemetry SDK's existing propagator can inject and extract it with no MCP-specific code. You are not inventing a new format. You are moving the format everyone already implements into the one field MCP reserved for it. This lands in the same season as the protocol version negotiation changes that also moved identity into _meta, and it is the same instinct: metadata about the call belongs in the envelope, carried on every request, not in a handshake you might skip.

Injecting context on the client

The client side is the half that gets forgotten, because the client usually thinks of itself as the top of the trace rather than a link in a chain. But the agent is the parent here. When it calls a tool, it must stamp the request with its current span so the server can attach to it.

# MCP client: inject the active trace context into _meta before the call.
from opentelemetry import trace, propagate

def call_tool(session, name, arguments):
    carrier = {}
    # The standard propagator writes traceparent/tracestate (and baggage)
    # into any dict. We hand it _meta instead of HTTP headers.
    propagate.inject(carrier)

    tracer = trace.get_tracer("agent")
    with tracer.start_as_current_span(f"execute_tool {name}") as span:
        span.set_attribute("gen_ai.tool.name", name)
        # Re-inject inside the span so carrier reflects THIS span as parent.
        propagate.inject(carrier)
        return session.call_tool(
            name=name,
            arguments=arguments,
            _meta=carrier,  # traceparent now rides in the envelope
        )

The one subtlety is ordering. You want the traceparent to name the tool-call span as the parent, not whatever span was active before it, so inject after you open the span, not before. Get that wrong and the server's work attaches one level too high, which is less broken than a severed trace but still misleading. Note that the attributes follow the OpenTelemetry GenAI span conventions, so the tool-call span reads consistently with the rest of your agent telemetry rather than in a dialect of its own.

Extracting context on the server

The server is the half that actually joins the trees. It reads the incoming _meta, extracts whatever context the client put there, and starts its handler span as a child of that context. If _meta is empty, because the caller did not instrument, it starts a fresh root, which is the current default behavior and the thing we are fixing.

# MCP server: extract context from _meta and parent the handler span to it.
from opentelemetry import trace, context, propagate

def handle_tool_call(request):
    meta = request.params.get("_meta", {})
    # Extract returns a Context carrying the remote parent, or an empty one.
    ctx = propagate.extract(meta)

    tracer = trace.get_tracer("records-server")
    # Starting the span inside this context makes it a child of the agent span.
    with tracer.start_as_current_span("search_records", context=ctx) as span:
        span.set_attribute("db.system", "postgresql")
        rows = run_query(request.params["arguments"])   # its own child spans
        return to_result(rows)

That is the entire mechanism. Nine lines on each side and the flat bar grows a subtree: the database query, the upstream fan-out, the retry loop, all of it now hanging under the agent's execute_tool span in one trace with one ID. When the nine-second tail happens again, you open the trace and the slow retry loop is right there, timestamped, instead of hidden in a service you would have had to go excavate by hand.

Why this is worth the wiring

The payoff is not prettier diagrams. It is that three things you probably already rely on stop lying to you once the trace is whole.

Latency attribution is the obvious one. A flat tool span tells you a call was slow; a joined trace tells you which hop inside it was slow, which is the difference between filing a vague ticket and fixing the retry loop. The same principle that makes a span tree show where the tokens went makes it show where the milliseconds went, but only if the tree does not get amputated at every tool boundary.

Cost attribution is the quieter one. If an MCP tool itself calls a model, that model's token usage lands on the server's spans. With a severed trace you cannot roll those tokens up to the agent run, or the tenant, that caused them, so your per-tenant budget caps are blind to spend that happens one hop away. Propagating context lets the usage flow back to the right owner. The caveat is that the server's attribute names are subject to the GenAI convention drift that can blank a dashboard on a quiet upgrade, so a joined trace is necessary but not sufficient; you still have to pin the vocabulary on both sides.

And error attribution. A tool that fails deep inside the server, in a dependency three calls down, surfaces to the agent as a generic tool error. A joined trace carries the real failure span up to where you can see it, which is what makes the difference between an SLO you can actually compute and one that reports on a surface so shallow it misses the real incidents.

The parts that bite

Propagation is only end to end if every hop plays along, and MCP servers are frequently code you do not own. If a third-party server does not extract from _meta, your context dies at that server and so does every span beyond it. You get a correct parent span for the call and a flat interior, which is the honest limit of what you can know, and better than a severed trace because at least the call sits in the right place. Treat uninstrumented servers as a black box you can time but not see into, and lean on them less for anything latency-sensitive.

Baggage is the sharp edge. The traceparent and tracestate carry only opaque IDs, so they are safe to pass anywhere. Baggage is arbitrary key-value data that rides along every downstream call, and _meta will happily carry whatever you inject. The moment you cross into an MCP server you do not control, every baggage entry crosses a trust boundary with it, out to that server and to whatever it calls next. Putting a user ID, a tenant name, or anything credential-shaped in baggage is a leak you built on purpose. Strip baggage you do not need before an external call, and strip inbound baggage from servers you do not trust, the same discipline you would apply to any header crossing a perimeter.

Sampling is the third trap. The sampling decision travels in the traceparent, so if the client decided not to sample a trace, the server honors that and emits nothing, which is usually what you want. But if client and server run independent samplers with different rates, you get partial trees: a parent span with children that were sampled out, or server spans with no parent because the client dropped the trace. Agree on head-based sampling, where the first service decides and everyone downstream obeys the flag in the traceparent, so a trace is either whole or absent rather than full of holes.

Last, the context is only as good as the propagator configuration on both ends. If one side uses the W3C propagator and the other defaults to a vendor format, the inject and extract do not line up and you are back to severed traces with extra steps. Standardize on the W3C Trace Context propagator across every service and every MCP participant, since that is the format the spec named and the one with no ambiguity.

The takeaway

An agent is a distributed system wearing a chat interface, and the oldest rule of distributed systems applies unchanged: a trace is only as complete as its least cooperative hop. MCP spent its first stretch as exactly that hop, the place where every trace went to die, not because anyone decided observability did not matter but because the spec had never said where the context should live. The 2026-07-28 revision said it. The context goes in _meta, under the standard W3C keys, carried on every request.

The work to adopt it is genuinely small, a propagator inject on the client and an extract on the server, and the payoff is that the slow tool call, the cost that happened one hop away, and the error buried three services deep all become things you can see instead of things you guess at. If your agent leans on MCP tools and your traces go flat the moment a call leaves the process, that boundary is almost certainly where your hardest incidents are hiding. If you want a second set of eyes on where your agent telemetry quietly goes dark, let us talk.

ShareXLinkedInviralruparel.com/blog/mcp-trace-context-propagation-broken-span-tree

Questions this essay answers

01What is MCP trace context propagation?

It is the practice of carrying W3C trace context, the traceparent and tracestate headers plus optional baggage, from an MCP client across a tool call into the MCP server, so the server's spans attach to the same distributed trace as the agent that called it. The 2026-07-28 MCP spec documents conventions for placing these values in the request `_meta` object. Without it, the server starts a fresh root trace and its work shows up in a separate trace your agent's trace never links to, leaving a flat, opaque span where a slow or failing tool call actually happened.

02Why does my agent trace show a flat span for an MCP tool call?

Because the context that ties spans together stops at the process boundary. Your agent creates a span for the tool call and sends the request, but if the traceparent is not placed somewhere the server reads, the server cannot know it is a child of your span. It either creates a new root trace or emits nothing you can correlate. Your side sees only the wall-clock duration of the call, with no visibility into the database query, the upstream API, or the retry loop inside the server that made it slow. The span is flat because the causal link was dropped in transit.

03Where does the traceparent go in an MCP request?

In the request's `_meta` object, under the reserved OpenTelemetry keys the 2026-07-28 spec names: `traceparent`, `tracestate`, and `baggage`. `_meta` is the standard MCP field for out-of-band metadata that is not part of a method's semantic arguments, which is exactly what trace context is. The client injects the current context into `_meta` before sending, and the server extracts it from `_meta` before starting its handler span. This works across both the Streamable HTTP and STDIO transports, since `_meta` travels inside the JSON-RPC message rather than in transport headers.

04Does propagating trace context across MCP leak sensitive data?

It can if you are careless with baggage. The traceparent and tracestate carry only trace and span identifiers, which are opaque and safe to pass. Baggage is different: it is arbitrary key-value data that rides along every downstream call, and anything you put there crosses the trust boundary into the MCP server and whatever it calls next. Never put user identifiers, API keys, or tenant secrets in baggage that leaves your trust zone. Treat an external MCP server as untrusted for both directions, and strip inbound baggage from servers you do not control.

Working on this in production?I help teams make agents like this reliable. Thirty minutes, no pitch.
Viral Ruparel

Generative AI consultant and full-stack architect. Ex-IBM, former Director of Engineering at a YC W20 startup. Writes about what breaks when agents meet reality.