Skip to content

Support for OpenTelemetry Context Propagation for MCP via _meta field #14843

@punitmahes

Description

@punitmahes

Description

I am looking to implement end-to-end distributed tracing for an AI agent architecture using the Model Context Protocol (MCP).

Currently, the MCP Auto Instrumentation SDK propagates OpenTelemetry context via a reserved _meta field within the JSON-RPC message body, rather than standard HTTP headers. As the AI MCP Proxy plugin acts as a protocol bridge, I am proposing a feature to extract tracing context from this _meta field to ensure trace continuity through the Kong Gateway.

Background: Why _meta?

The Model Context Protocol (MCP) standardized the use of the _meta property bag for several reasons:

  • Transport Agnosticism: MCP is designed to work over stdio, WebSockets, and SSE. Since stdio lacks HTTP headers, transport-independent propagation is required.
  • Multiplexing: Over Streamable HTTP (SSE), multiple tool calls can occur within one long-lived HTTP request. Header-based tracing only captures the connection, whereas _meta allows each tool call to have its own unique trace/span parentage.
  • Specification: This convention is formalized in the MCP specification (referencing PR #414), reserving keys like traceparent, tracestate, and baggage within the _meta object.

Proposed Capability

Since the AI MCP Proxy plugin already parses the request body to perform protocol translation, it would be highly beneficial if the plugin could:

  1. Extract the traceparent (and tracestate/baggage) from $.params._meta.
  2. Map this to the gateway's internal OpenTelemetry span as a remote parent.
  3. Inject the updated context into the outgoing headers for the upstream service.

Example Payload

{
  "jsonrpc": "2.0",
  "id": "1",
  "method": "tools/call",
  "params": {
    "name": "get_weather",
    "arguments": { "location": "San Francisco" },
    "_meta": {
      "traceparent": "00-0af7651916cd43dd8448eb211c80319c-00f067aa0ba902b7-01",
      "tracestate": "...",
      "baggage": "..."
    }
  }
}

Questions / Discussion

  • Existing Hooks: Does the current AI MCP Proxy plugin (or the core OpenTelemetry plugin) have an existing hook or configuration option to extract OTel context from the request body rather than headers?
  • Roadmap: Is body-based context extraction on the formal roadmap for Kong’s AI Gateway observability features, especially given the rising adoption of the MCP standard?

References

Happy to implment a solution if needed.

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