Skip to content

[Feature]: native MCP trace-context propagation (SEP-414) — stdio support, transport-agnostic #62

Open

Description

@Savid

Is your feature request related to a problem?

To get a single end-to-end distributed trace across opencode → MCP server, W3C trace context has to be propagated into outbound MCP tools/call requests so the server's spans nest under the opencode tool span. Today this is only achievable for HTTP MCP servers, by intercepting outbound requests and injecting the context into the JSON-RPC _meta + headers. Two gaps:

  • stdio MCP servers get no trace context — there is no HTTP request to intercept, so their spans never connect to the parent trace.
  • Request-interception is a process-wide workaround that carries transport concerns (URL matching, content-length handling, body re-serialization) that belong in the MCP SDK, not a telemetry layer.

Describe the solution you'd like

Adopt SEP-414 ("OpenTelemetry Trace Context Propagation Conventions for _meta", merged into the MCP spec) once the MCP TypeScript SDK ships it. Injecting traceparent / tracestate into _meta at the client session layer is transport-agnostic — it covers stdio and HTTP uniformly and removes the need for any request-interception workaround. The SEP-414 wire format (bare traceparent / tracestate keys directly under params._meta) is straightforward to emit and read.

Describe alternatives you've considered

  • Patching child-process stdin for stdio — rejected: that stream is shared with other spawned subprocesses (shells, LSP servers, formatters); mutating it is fragile and risks corrupting non-MCP I/O.
  • Spawn-time TRACEPARENT env var — rejected: stdio MCP servers are long-lived and serve many calls, so a spawn-time value would be static rather than per-call.
  • Global fetch interception — works for HTTP transports only, and is a workaround rather than a protocol-level fix.

Telemetry type

  • Traces (Other), Configuration

Additional context

This depends on upstream work (all three required before it can be wired up end-to-end):

  1. MCP TypeScript SDK implements SEP-414 — tracking: Implement SEP-414: Document OpenTelemetry Trace Context Propagation Conventions modelcontextprotocol/typescript-sdk#2196 (related: OpenTelemetry integration out of the box modelcontextprotocol/typescript-sdk#1264, "OpenTelemetry out of the box").
  2. opencode upgrades @modelcontextprotocol/sdk to that version.
  3. opencode enables the (opt-in) propagation middleware on its MCP client.

References:

Checklist

  • I have searched existing issues and discussions for similar feature requests
  • I have checked the changelog to see if this already exists

Activity

  1. dialupdisaster commented on Jul 23, 2026

    @dialupdisaster
    Contributor

    Upstream OpenCode already had an exact implementation proposal: anomalyco/opencode#21539, feat(mcp): forward plugin-set _meta to downstream MCP tool calls.

    It added optional _meta output to tool.execute.before and forwarded that value into client.callTool(), which is the transport-independent insertion point needed for SEP-414 over both stdio and HTTP. The PR was closed by automated inactivity cleanup, not because of a technical rejection; it received no maintainer review.

    The remaining order of work is now:

    1. Revive or replace OpenCode #21539 against current dev, preserving sessionID and callID in the hook so a telemetry plugin can select the correct live tool span.
    2. Merge the hook and _meta forwarding into OpenCode.
    3. Add plugin-side injection of that tool span's W3C traceparent and optional tracestate under params._meta, following final SEP-414.

    The MCP TypeScript SDK side is ready: modelcontextprotocol/typescript-sdk#2270 merged the reserved keys and confirms _meta passthrough across transports. It does not inject context automatically. Baggage is also reserved by SEP-414, but should remain separately opt-in rather than being propagated by default.

  2. dialupdisaster commented on Jul 23, 2026

    @dialupdisaster
    Contributor

    A current OpenCode implementation is now open as anomalyco/opencode#38579.

    It updates the earlier proposals for OpenCode's current MCP catalog and SDK 1.29, forwards plugin-set params._meta through both normal and code-mode MCP calls, preserves SDK-owned progress metadata, and includes transport-level tests. Once merged, this plugin can inject the active tool span's SEP-414 traceparent and optional tracestate through tool.execute.before.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions