MCP Tracing
Model Context Protocol (MCP) enables AI agents to interact with external tools and data sources. When tracing MCP applications, client and server operations produce separate traces by default, which can be useful for establishing service boundaries.
However, you can link these traces together by propagating trace metadata from client to server, creating a unified view of the entire request flow.
Separate vs. Linked Traces
Separate traces: MCP client and server generate independent traces. Useful when you need clear service boundaries or when client and server are managed by different teams.
Linked traces: Propagate trace context from client to server using MCP’s _meta
field. This creates a single, connected trace showing the complete request flow from client through server to external APIs.
Propagating Trace Context
MCP supports context propagation through its _meta
field convention. By injecting OpenTelemetry context (W3C Trace Context format) into tool calls, you can link client and server traces:
- Extract the current trace context on the client side
- Inject it into the MCP tool call’s
_meta
field - Extract and restore the context on the server side
- All server operations inherit the client’s trace context
Link to example trace in Langfuse
Implementation
See a complete implementation in the langfuse-examples repository demonstrating end-to-end MCP tracing with OpenAI, Exa API, and Langfuse.