Repository navigation
feat(mcp): trace client operations and propagate context - #1025
Open
Abhijeet Prasad (AbhiPrasad) wants to merge 6 commits into
Open
Abhijeet Prasad (AbhiPrasad) wants to merge 6 commits into
Abhijeet Prasad (AbhiPrasad) wants to merge 6 commits into
Conversation
Abhijeet Prasad (AbhiPrasad)
force-pushed
the
abhi/mcp-client-tracing-ae460b73
branch
from
October 29, 2026 19:14
08f5717 to
12477ab
Compare
Abhijeet Prasad (AbhiPrasad)
force-pushed
the
abhi/mcp-client-tracing-ae460b73
branch
2 times, most recently
from
October 29, 2026 20:44
21b913d to
3c53e63
Compare
Abhijeet Prasad (AbhiPrasad)
marked this pull request as ready for review
October 29, 2026 20:48
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
> 🤖 **This text was AI-generated.** The server integration no longer provides ask_llm or cassette setup. Client coverage still depended on both and stored version-specific protocol snapshots. Use the real add tool for connected HTTP and subprocess tests: ```text agent -> MCP client -> MCP server -> nested-work ``` Remove client cassettes and stdio recording hooks. Assert propagated trace metadata on the actual server context, preserving baggage, content opt-out, client-only operation, and connected parentage checks without external LLM calls. Refs #1023
Abhijeet Prasad (AbhiPrasad)
force-pushed
the
abhi/mcp-client-tracing-ae460b73
branch
from
October 29, 2026 21:13
3c53e63 to
dd14cdc
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1024, which adds MCP server instrumentation. This is PR 2 of the MCP instrumentation work.
Problem
Server instrumentation records MCP execution, but the caller has no span for the round trip. Without automatic context propagation, the agent and server appear in separate traces:
Solution
Add
wrap_mcp_client(client_or_session, capture_content=True)to trace outgoing requests and propagate W3C trace context and Braintrust baggage throughparams._meta.Each side works independently. With both client and server wrapped, nested work joins the caller's trace:
Supports official
mcp>=1.28.1,<3clients and sessions, standalonefastmcp>=2.14.7,<5clients, and corresponding fastmcp-slim releases. MCP dependencies remain optional.metadata["mcp.span.kind"] = "client"identifies the round trip.capture_content=Falseto omit arguments and results; discovery inventories are always omitted.Wrap before connecting to include negotiation, or wrap an active client/session. Repeated wrapping updates settings without adding spans, and FastMCP reconnects inherit those settings.
Framework tool spans can parent the MCP round trip. When
opentelemetry-instrumentation-mcpis enabled, its instrumentor owns client spans, propagation, and capture settings; Braintrust adds no duplicate client span.Integration tests use real clients and servers in memory, over localhost HTTP, and over stdio subprocesses. They assert span payloads, parentage, and received trace metadata directly, without cassettes or external LLM calls.
Scope and next steps
One-way notifications, session lifetimes, and detached task APIs do not create client operation spans. Automatic client setup and documentation follow in PR 3.
MCPIntegration.setup()continues to enable server tracing independently.Refs #1023