You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 value
tracestate — W3C Trace Context v1 trace state header value
baggage — 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 to get_progress_token/set_progress_token
No extractor/injector helpers for integration with the opentelemetry or tracing-opentelemetry ecosystems
Without these, every caller must hardcode string literals, making the feature invisible to SDK users
and impossible to test in isolation.
Add a feature-gated (e.g. feature = "opentelemetry") helper module that implements
the OpenTelemetry TextMapPropagator interface using these three fields, enabling:
Injection: write span context from an active opentelemetryContext into Meta
Extraction: restore a Context from a Meta received on an incoming request
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 opentelemetry feature 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 (traceparent etc.) and the _meta fields 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-Name headers; trace
context flows through both HTTP headers and _meta in the same request path
SEP-414: W3C Trace Context propagation in
_meta— rust-sdk implementationSpec 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
_metakeys, enabling distributedtracing 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 valueServers and clients that emit or consume OpenTelemetry spans use these keys to propagate span context
through the
_metafield of any MCP request.Why this needs code changes in rust-sdk
Metaincrates/rmcp/src/model/meta.rsis a transparentJsonObject(line 199), so the valuescan be stored today via raw map operations. But the SDK currently provides no typed support:
PROGRESS_TOKEN_FIELDget_traceparent,set_traceparent, etc.) analogous toget_progress_token/set_progress_tokenopentelemetryortracing-opentelemetryecosystemsWithout these, every caller must hardcode string literals, making the feature invisible to SDK users
and impossible to test in isolation.
Proposed work
meta.rs: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_baggagefeature = "opentelemetry") helper module that implementsthe OpenTelemetry
TextMapPropagatorinterface using these three fields, enabling:opentelemetryContextintoMetaContextfrom aMetareceived on an incoming requestfeature flag is enabled.
Affected areas
crates/rmcp/src/model/meta.rs(constants + typed accessors); optional newcrates/rmcp/src/telemetry.rsormodel/trace_context.rsfor the propagator impl.Cargo.tomlfor the optionalopentelemetrydependency.Notes / risks
opentelemetryfeature gate keeps the dependency optional so users who don't needdistributed tracing don't pay the compile cost.
traceparentetc.) and the_metafields carry the same logical data; the propagator helper bridges both.Related existing issues
Mcp-Method/Mcp-Nameheaders; tracecontext flows through both HTTP headers and
_metain the same request path