-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Description
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. Sincestdiolacks 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
_metaallows 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, andbaggagewithin the_metaobject.
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:
- Extract the
traceparent(andtracestate/baggage) from$.params._meta. - Map this to the gateway's internal OpenTelemetry span as a remote parent.
- 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.