Skip to content

feat(core): reserved trace context _meta keys and propagation docs (SEP-414)#2270

Open
mattzcarey wants to merge 1 commit into
mainfrom
feat/sep-414-trace-context-meta-keys
Open

feat(core): reserved trace context _meta keys and propagation docs (SEP-414)#2270
mattzcarey wants to merge 1 commit into
mainfrom
feat/sep-414-trace-context-meta-keys

Conversation

@mattzcarey

Copy link
Copy Markdown
Contributor

Implements the SDK side of SEP-414: OpenTelemetry Trace Context Propagation Conventions.

The draft MCP specification (basic/index.mdx, "Distributed Tracing Conventions") reserves the keys traceparent, tracestate, and baggage in _meta as an explicit exception to the _meta key prefix rule. When present, the values MUST follow the W3C Trace Context (traceparent, tracestate) and W3C Baggage formats. Spec PR: modelcontextprotocol/modelcontextprotocol#414.

Note: passthrough already worked — the SDK never touches user-supplied _meta beyond the envelope keys it owns, so trace context already propagated end to end. This PR adds the named constants, documentation, and a regression test to lock the behavior in:

  • packages/core/src/types/constants.ts: TRACEPARENT_META_KEY, TRACESTATE_META_KEY, BAGGAGE_META_KEY with JSDoc citing SEP-414 and the W3C formats, placed alongside the other reserved _meta key constants and exported via core/public (and therefore re-exported by @modelcontextprotocol/client / @modelcontextprotocol/server).
  • docs/client.md / docs/server.md: new "Trace context propagation" sections with type-checked examples (per-request _meta, fetch-middleware injection on the client; reading ctx.mcpReq._meta in a handler on the server), synced via pnpm sync:snippets.
  • packages/core/test/shared/traceContextMeta.test.ts: regression test asserting _meta.traceparent/tracestate/baggage survive the round trip to the server-side handler, back on the response _meta, and through notifications.
  • Changeset: patch for @modelcontextprotocol/core.

Validation

  • pnpm build:all — pass
  • pnpm check:all (typecheck + lint, all packages) — pass
  • pnpm --filter @modelcontextprotocol/core test — 467/467 pass (incl. 4 new)
  • pnpm --filter @modelcontextprotocol/client test — 367/367 pass
  • pnpm --filter @modelcontextprotocol/server test — 72/72 pass
  • pnpm test:all — all tests pass; the only flagged item is the pre-existing e2e fake-timer/SSE unhandled-rejection flake in scenarios/protocol.test.ts (protocol:timeout:max-total [sse]), which reproduces identically on clean main.

Downstream impact: none for cloudflare/agents; enables Workers trace propagation later.

Note for maintainers: if the constants are considered clutter, happy to reduce this to docs-only.

Closes #2196

…EP-414)

Add TRACEPARENT_META_KEY, TRACESTATE_META_KEY, and BAGGAGE_META_KEY
constants for the unprefixed _meta keys reserved by SEP-414, export them
from core/public, document trace context propagation in the client and
server guides (with type-checked examples), and add a passthrough
regression test covering request, response, and notification _meta.
@mattzcarey mattzcarey requested a review from a team as a code owner June 9, 2026 20:39
@changeset-bot

changeset-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1659b6e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modelcontextprotocol/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@2270

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/codemod@2270

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@2270

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server-legacy@2270

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@2270

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/fastify@2270

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@2270

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@2270

commit: 1659b6e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement SEP-414: Document OpenTelemetry Trace Context Propagation Conventions

1 participant