Repository navigation
Architecture
┌──────────────────────── mcp-exporter ────────────────────────┐
client ───► │ transport (stdio pipes | HTTP reverse proxy + SSE observer) │ ───► MCP server
│ │ every frame (both directions) │
│ ▼ │
│ jsonrpc.Parse ─► Tracker.Frame ─► spans · metrics · logs ─┼──► OTLP / Prometheus
└──────────────────────────────────────────────────────────────┘
- Framing: stdio frames are newline-delimited, and lines of any length are supported. HTTP request bodies are read in full, up to 16 MiB. JSON responses are buffered as they stream to the client. SSE responses are parsed event by event as the bytes pass.
- Parsing: each frame is parsed as a single message or a batch. A frame that isn't valid JSON-RPC is forwarded unchanged and counted.
-
Correlation key: a request opens a pending entry keyed by (scope, direction, id), and the response travelling the other way closes it.
- The scope is the id space: the stdio pipe, the HTTP session (
Mcp-Session-Id), or, before a session exists (initialize), the single HTTP exchange. -
2026-07-28 is stateless: there's no session, and each request is answered on its own response stream. Each
exchange is therefore its own scope. When an exchange's response ends with a request still open, that request ends at
once:
cancelledif the stream closed, or the HTTP status if the upstream failed (502if unreachable). With a session (up to 2025-11-25), a response may come on another stream, so those requests wait for it or for the idle sweep. -
Legacy HTTP+SSE (2024-11-05) has no session header, and responses arrive on the
GET /ssestream, not on the POST. The stream'sendpointevent names the POST URL. Its query (sessionId, orsession_idin the Python SDK) becomes the session and scope for that stream and for POSTs to exactly that URL, and the session ends when the stream closes. Query strings the exporter hasn't learned this way are ignored. Gateway mode doesn't support legacy servers: theirendpointpath has no route prefix, and the exporter never rewrites forwarded bytes. Give each legacy server its own exporter. - This scoping is what lets responses arrive on a different stream than the request: a resumed GET stream, or server-initiated requests answered by a later POST.
- The scope is the id space: the stdio pipe, the HTTP session (
-
Other endings:
notifications/cancelledcloses the entry ascancelled. Entries left open longer than-session-idleare closed astimeout, and idle sessions and tasks are dropped. That bounds memory when clients vanish.
The proxy observes and doesn't rewrite, with these documented exceptions:
| Change | Why | Opt out |
|---|---|---|
traceparent (+ tracestate/baggage) added to params._meta of client requests that have none |
so instrumented servers continue the trace | -inject-context=false |
upstream requests get Accept-Encoding: identity (http mode) |
compressed responses can't be observed; the sidecar hop is local | |
| gzip request bodies are forwarded decompressed (http mode) | so they can be observed and injected; capped at 16 MiB |
-
Re-encoding: when injection re-encodes a request, ids and arguments are preserved byte for byte in meaning,
with no HTML escaping.
paramsthat aren't an object (array ornull) are never touched. - SSE: responses are forwarded byte for byte. That property is fuzz-tested under arbitrary read chunking.
In stdio mode, stdout is the protocol channel. Two layers keep it clean:
-
All platforms: console exporters (
OTEL_*_EXPORTER=console) are built with an explicit stderr writer. -
Linux and macOS: the exporter also duplicates the real stdout for protocol frames, then points file descriptor 1 at stderr (
dup2), so even a stray print from a library lands on stderr. Windows has no equivalent for already-open files.
The server's stderr is passed through and also exported as log records.
Each combination below was run end to end through the exporter, checking spans for correct correlation, error classification, session, protocol version and server name. The table is updated when a combination is added.
| Client | Server | Transports |
|---|---|---|
| TypeScript SDK (server-everything) / curl | TypeScript SDK server-everything
|
Streamable HTTP (CI smoke test), legacy HTTP+SSE |
Python SDK 1.30 ClientSession
|
Python SDK 1.30 FastMCP | Streamable HTTP, legacy HTTP+SSE (session_id), stdio |
| curl, raw 2026-07-28 | Python SDK 2.3 MCPServer (protocol 2026-07-28) |
Streamable HTTP (CI smoke test), stdio; includes server/discover and subscriptions/listen
|
Go cmd/demo-agent
|
TypeScript SDK server-everything
|
Streamable HTTP, with MCP Tasks (CI smoke test) |
Claude Desktop config via mcp-remote
|
mcp.deepwiki.com |
stdio client mode |
| Package | Responsibility |
|---|---|
internal/jsonrpc |
parsing and encoding; params._meta and related-task extraction; SetMeta
|
internal/observe |
OTel provider setup (autoexport), the error handler, and Tracker: correlation, spans, metrics, logs, redaction, tasks, sweeping |
internal/proxy |
stdio relay; HTTP reverse proxy with JSON/SSE observers, gzip handling, /healthz, /readyz
|
cmd/mcp-exporter |
CLI, stdout reservation, pprof listener, TLS |
Robustness: the parser, the SSE observer, bounded gunzip and Tracker.Frame all have Go fuzz targets that CI runs on every PR.
Fuzzing found and fixed a crash on "_meta": null in v0.3.1.
This wiki is generated from docs/wiki/ in the repository. Edit it there with a pull request; changes made here are overwritten.
Use it
Reference
Operate