feat(core): reserved trace context _meta keys and propagation docs (SEP-414)#2270
Open
mattzcarey wants to merge 1 commit into
Open
feat(core): reserved trace context _meta keys and propagation docs (SEP-414)#2270mattzcarey wants to merge 1 commit into
mattzcarey wants to merge 1 commit into
Conversation
…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.
🦋 Changeset detectedLatest commit: 1659b6e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
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.
Implements the SDK side of SEP-414: OpenTelemetry Trace Context Propagation Conventions.
The draft MCP specification (
basic/index.mdx, "Distributed Tracing Conventions") reserves the keystraceparent,tracestate, andbaggagein_metaas an explicit exception to the_metakey 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
_metabeyond 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_KEYwith JSDoc citing SEP-414 and the W3C formats, placed alongside the other reserved_metakey constants and exported viacore/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; readingctx.mcpReq._metain a handler on the server), synced viapnpm sync:snippets.packages/core/test/shared/traceContextMeta.test.ts: regression test asserting_meta.traceparent/tracestate/baggagesurvive the round trip to the server-side handler, back on the response_meta, and through notifications.@modelcontextprotocol/core.Validation
pnpm build:all— passpnpm check:all(typecheck + lint, all packages) — passpnpm --filter @modelcontextprotocol/core test— 467/467 pass (incl. 4 new)pnpm --filter @modelcontextprotocol/client test— 367/367 passpnpm --filter @modelcontextprotocol/server test— 72/72 passpnpm test:all— all tests pass; the only flagged item is the pre-existing e2e fake-timer/SSE unhandled-rejection flake inscenarios/protocol.test.ts(protocol:timeout:max-total [sse]), which reproduces identically on cleanmain.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