Repository navigation
Implement SEP-414: W3C Trace Context propagation in _meta #886
Description
SEP-414: W3C Trace Context propagation in _meta — rust-sdk implementation
Spec PR: modelcontextprotocol/modelcontextprotocol#414
Track: Specification · Stage: final · Priority: P2 · Theme: Transport Evolution and Scalability
Needs code changes: Yes (Small) — additive (typed accessors + constants)
Summary
Formalizes three W3C Trace Context fields as standardized _meta keys, enabling distributed
tracing across MCP hops without inventing a parallel mechanism:
traceparent— W3C Trace Context v1 trace parent header valuetracestate— W3C Trace Context v1 trace state header valuebaggage— W3C Baggage header value
Servers and clients that emit or consume OpenTelemetry spans use these keys to propagate span context
through the _meta field of any MCP request.
Why this needs code changes in rust-sdk
Meta in crates/rmcp/src/model/meta.rs is a transparent JsonObject (line 199), so the values
can be stored today via raw map operations. But the SDK currently provides no typed support:
- No key-name constants analogous to
PROGRESS_TOKEN_FIELD - No typed accessors (
get_traceparent,set_traceparent, etc.) analogous toget_progress_token/set_progress_token - No extractor/injector helpers for integration with the
opentelemetryortracing-opentelemetryecosystems
Without these, every caller must hardcode string literals, making the feature invisible to SDK users
and impossible to test in isolation.
Proposed work
- Add string constants in
meta.rs:const TRACEPARENT_FIELD: &str = "traceparent"; const TRACESTATE_FIELD: &str = "tracestate"; const BAGGAGE_FIELD: &str = "baggage";
- Add typed read/write accessors on
Metafollowing theprogressTokenpattern:get_traceparent(&self) -> Option<&str>set_traceparent(&mut self, value: impl Into<String>)get_tracestate(&self) -> Option<&str>/set_tracestateget_baggage(&self) -> Option<&str>/set_baggage
- Add a feature-gated (e.g.
feature = "opentelemetry") helper module that implements
the OpenTelemetryTextMapPropagatorinterface using these three fields, enabling:- Injection: write span context from an active
opentelemetryContextintoMeta - Extraction: restore a
Contextfrom aMetareceived on an incoming request
- Injection: write span context from an active
- Add unit tests for round-trip set/get on all three fields, and for inject/extract when the
feature flag is enabled.
Affected areas
crates/rmcp/src/model/meta.rs (constants + typed accessors); optional new
crates/rmcp/src/telemetry.rs or model/trace_context.rs for the propagator impl.
Cargo.toml for the optional opentelemetry dependency.
Notes / risks
- The typed accessors are purely additive and carry no risk.
- The
opentelemetryfeature gate keeps the dependency optional so users who don't need
distributed tracing don't pay the compile cost. - Coordinate with SEP-2243 (Implement SEP-2243: HTTP Standardization #872) — the HTTP transport headers (
traceparentetc.) and the
_metafields carry the same logical data; the propagator helper bridges both.
Related existing issues
- Implement SEP-2243: HTTP Standardization #872 — Implement SEP-2243: HTTP Standardization —
Mcp-Method/Mcp-Nameheaders; trace
context flows through both HTTP headers and_metain the same request path
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
DaleSeo commentedon Jun 4, 2026
I'm tackling this since it's blocking Apollo MCP Server!
Necmttn commentedon Jun 21, 2026
Typed accessors are useful, but conformance tests matter more. Add fixtures that inject
traceparent,tracestate, andbaggageon client request meta, read them on the server, start a child span, then propagate through a nested tool or resource request.Also test invalid
traceparenthandling: ignore it or surface a parse error without corrupting the meta map. That makes SEP-414 more than constants.Generated with ax.