Skip to content

[Server][Client] Bridge W3C trace context between HTTP headers and _meta (SEP-414) - #473

Open
chr-hertel wants to merge 1 commit into
modelcontextprotocol:mainfrom
chr-hertel:feat/issue-355-trace-context-http-bridge
Open

[Server][Client] Bridge W3C trace context between HTTP headers and _meta (SEP-414)#473
chr-hertel wants to merge 1 commit into
modelcontextprotocol:mainfrom
chr-hertel:feat/issue-355-trace-context-http-bridge

Conversation

@chr-hertel

Copy link
Copy Markdown
Member

Summary

_meta-based trace context propagation already existed (RequestMeta parses traceparent/tracestate/baggage from JSON-RPC _meta), but nothing bridged it to/from native HTTP headers — so a caller propagating trace context via HTTP headers only, with no _meta, got no trace context at all, and vice versa.

  • src/Server/Stateless/RequestMeta.php: parseTraceContext() now falls back to the matching HTTP header when _meta doesn't set a trace key. _meta wins on conflict, since it's more specific to the call.
  • src/Server/Stateless/StatelessProtocol.php: threads the request's headers through to RequestMeta::fromParams().
  • src/Client/Stateless/HeaderFactory.php: mirrors any _meta trace context onto outbound traceparent/tracestate/baggage HTTP headers.

Closes #355.

Test plan

  • New unit tests covering: HTTP header present + no _meta_meta populated; both present (_meta wins); stdio transport (no HTTP headers) still works via _meta alone
  • Full phpunit suite passes (1708 tests)
  • phpstan analyse — no errors

…eta (SEP-414)

RequestMeta::parseTraceContext() now falls back to the native traceparent/
tracestate/baggage HTTP headers when _meta carries none, and HeaderFactory
mirrors an application-set _meta trace context onto those same headers on
outbound requests. _meta wins when both are present.
@chr-hertel chr-hertel added Server Issues & PRs related to the Server component Client Issues & PRs related to the Client component 2026-07-28 All issues and PRs related to the spec release 2026-07-28 labels Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2026-07-28 All issues and PRs related to the spec release 2026-07-28 Client Issues & PRs related to the Client component Server Issues & PRs related to the Server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Server][Client][Protocol] SEP-414: W3C Trace Context propagation via _meta

1 participant