README
¶
mcp-exporter
OpenTelemetry traces, metrics and logs for any MCP server, with no code changes.
mcp-exporter is a transparent proxy that sits between an MCP client and server,
understands the JSON-RPC traffic, and emits telemetry that follows the
OpenTelemetry MCP semantic conventions.
Any OTLP backend works (Grafana, Datadog, Honeycomb, SigNoz, Jaeger, ...), and so does Prometheus scraping.
client ──► mcp-exporter ──► MCP server
├─ OTLP ──► OTel Collector / backend
└─ /metrics (Prometheus pull, optional)

Try it in one command: deploy/compose/demo.sh starts an MCP server, the exporter, Grafana/Prometheus/Tempo/Loki
and a simulated agent, then opens on the dashboard above at http://localhost:3000/d/mcp-exporter.
The simulated agent calls tools (some fail on purpose), reads prompts and resources, runs a slow operation, and runs an MCP Task end to end.
See Demo.
| Transport | Command |
|---|---|
| stdio (local servers) | mcp-exporter stdio -- <server command> [args...] |
| Streamable HTTP | mcp-exporter http -listen :8080 -upstream http://server:3001 |
| legacy HTTP+SSE (2024-11-05) | the same command; clients connect to /sse as before |
Supported protocol versions: 2024-11-05 through 2026-07-28. For 2026-07-28 that includes stateless requests, server/discover,
subscriptions/listen and the Tasks extension.
📖 Full documentation: the wiki: getting started, Kubernetes, client mode, telemetry reference, architecture, profiles, security, troubleshooting.
Install
# Binary (linux/darwin/windows, amd64/arm64): https://github.com/firasmosbehi/mcp-exporter/releases
go install github.com/firasmosbehi/mcp-exporter/cmd/mcp-exporter@latest
# Container image (multi-arch, distroless, non-root)
docker pull ghcr.io/firasmosbehi/mcp-exporter:0.7.0
# Helm chart (OCI)
helm pull oci://ghcr.io/firasmosbehi/charts/mcp-exporter --version 0.7.0
Every artifact is signed with keyless cosign from the release workflow:
ID='https://github.com/firasmosbehi/mcp-exporter/.github/workflows/release.yml@refs/tags/v0.7.0'
ISSUER=https://token.actions.githubusercontent.com
cosign verify ghcr.io/firasmosbehi/mcp-exporter:0.7.0 --certificate-identity "$ID" --certificate-oidc-issuer $ISSUER
cosign verify ghcr.io/firasmosbehi/charts/mcp-exporter:0.7.0 --certificate-identity "$ID" --certificate-oidc-issuer $ISSUER
# binaries: verify checksums.txt, then sha256sum -c
cosign verify-blob checksums.txt --signature checksums.txt.sig --certificate checksums.txt.pem \
--certificate-identity "$ID" --certificate-oidc-issuer $ISSUER
Releases also carry SLSA build provenance (GitHub artifact attestations) for every archive, the image and the chart:
gh attestation verify mcp-exporter_<version>_linux_amd64.tar.gz -R firasmosbehi/mcp-exporter
gh attestation verify oci://ghcr.io/firasmosbehi/mcp-exporter:<version> -R firasmosbehi/mcp-exporter
gh attestation verify oci://ghcr.io/firasmosbehi/charts/mcp-exporter:<version> -R firasmosbehi/mcp-exporter
Quick start
Laptop (Claude Desktop, Cursor, Claude Code): prefix the server command.
// claude_desktop_config.json
"mcpServers": {
"github": {
"command": "mcp-exporter",
"args": ["stdio", "--", "npx", "-y", "@modelcontextprotocol/server-github"],
"env": { "OTEL_SERVICE_NAME": "github-mcp", "OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:4318" }
}
}
claude mcp add github -- mcp-exporter stdio -- npx -y @modelcontextprotocol/server-github
Docker: a full stack with an example server, the exporter, and Grafana + Prometheus + Tempo + Loki, plus a ready-made dashboard:
docker compose -f deploy/compose/docker-compose.yaml up --build
# MCP endpoint http://localhost:8080/mcp · Grafana http://localhost:3000 (dashboard "MCP Servers")
Kubernetes: the Helm chart runs your server with the exporter as a sidecar:
helm install weather oci://ghcr.io/firasmosbehi/charts/mcp-exporter --version 0.7.0 \
--set server.image=ghcr.io/acme/weather-mcp:1.2.0 --set server.port=3000 \
--set exporter.env.OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector.observability:4318
# Prometheus Operator instead of OTLP metrics:
# --set exporter.prometheus.enabled=true --set serviceMonitor.enabled=true
Gateway mode: one exporter for many servers
mcp-exporter http -listen :8080 \
-route github=http://github-mcp:3000 \
-route jira=http://jira-mcp:3000
# agents connect to http://gateway:8080/github/mcp and /jira/mcp
Each route serves /NAME/... with the /NAME prefix stripped. Its telemetry carries service.name=NAME, so every server still shows up as its own service.
Sessions and request ids are tracked per route. /readyz is ready when every upstream is, and /NAME/readyz checks a single route.
In Helm, set gateway.routes ([{name: github, url: http://github-mcp.tools:3000}]). The chart then deploys only the exporter.
Gateway mode is observability only: it adds no auth or policy.
Client mode: remote MCP servers you don't run
-role client observes from the agent's side, for SaaS or third-party MCP endpoints:
- Requests the agent sends become
CLIENTspans withserver.address/server.port, recorded inmcp.client.operation.duration, where every JSON-RPC error code counts as an error. - Session metrics become
mcp.client.session.durationandmcp.client.sessions.active. - Requests the server sends the agent (sampling, elicitation) are
SERVERspans.
// Recommended: wrap mcp-remote, so OAuth runs against the real server URL
"deepwiki": {
"command": "mcp-exporter",
"args": ["stdio", "-role", "client", "--", "npx", "-y", "mcp-remote", "https://mcp.deepwiki.com/mcp"]
}
# Or as an HTTP proxy for the agent (the agent connects to http://localhost:8080/mcp)
mcp-exporter http -role client -listen 127.0.0.1:8080 -upstream https://mcp.example.com
The Authorization header and other headers are forwarded but never recorded. In HTTP client mode, the agent sees the proxy's URL.
Servers that enforce the OAuth resource indicator / token audience (RFC 8707, required by the MCP authorization spec)
will reject tokens minted for that URL. For those, use the mcp-remote form above. The wiki's Client Mode page explains why the
proxy can't fix this, and gives a workaround for agents built on the TypeScript SDK.
Demo
deploy/compose/demo.sh # start: http://localhost:3000/d/mcp-exporter
deploy/compose/demo.sh down # stop and clean up
PROFILES=1 deploy/compose/demo.sh # also CPU profiles (Linux Docker): Grafana → Explore → Profiles
The demo-agent service (deploy/compose/demo.yaml) is a plain shell script speaking Streamable HTTP.
It keeps a session open with its own GET stream, so server log messages flow. It cycles through a weighted mix:
echo, get-sum, structured content, images, a 2–5 s long-running operation, a call to a tool that doesn't exist,
a call with invalid arguments, prompts, resources, and the task-required simulate-research-query
(create → poll tasks/get → tasks/result). Every ~40 rounds it ends the session and starts a new one.
Point your own MCP client at http://localhost:8080/mcp to add your traffic alongside it.
A second agent, traced-agent (cmd/demo-agent, agent.yaml), is instrumented with OTel.
Each step is an invoke_agent span with fake chat model calls (gen_ai.* attributes). Its tool calls carry the step's
trace context in params._meta, so the exporter's MCP spans nest under the step. Task polls link back to the call that created the task:

The shell agent sends no trace context, so each of its requests is its own trace, as with any uninstrumented client.
Configuration
Export is configured only through the standard OTel environment variables. For copy-paste recipes for Grafana Cloud, Honeycomb, Datadog and SigNoz, see docs/backends.md.
| Variable | Common values |
|---|---|
OTEL_EXPORTER_OTLP_ENDPOINT |
http://collector:4318 (OTEL_EXPORTER_OTLP_PROTOCOL=grpc for :4317) |
OTEL_TRACES_EXPORTER / OTEL_LOGS_EXPORTER |
otlp (default), console, none |
OTEL_METRICS_EXPORTER |
otlp (default), prometheus (serves localhost:9464/metrics with a service_name label; in containers set OTEL_EXPORTER_PROMETHEUS_HOST=0.0.0.0), console, none |
OTEL_TRACES_SAMPLER (+ _ARG) |
parentbased_traceidratio + 0.1 |
OTEL_SERVICE_NAME, OTEL_RESOURCE_ATTRIBUTES |
identify the server (deployment.environment.name=prod,...) |
OTEL_EXPORTER_OTLP_HEADERS, _CERTIFICATE, _CLIENT_CERTIFICATE, _CLIENT_KEY |
backend auth and mTLS |
Flags (mcp-exporter <mode> -h):
| Flag | Default | |
|---|---|---|
-service-name |
mcp-server |
used when OTEL_SERVICE_NAME is unset |
-role |
server |
client to observe from the agent's side (see Client mode) |
-inject-context |
true |
adds traceparent to params._meta of client requests that lack it, so instrumented servers join the trace |
-capture-payloads |
false |
records tool arguments and results on spans, redacted and truncated |
-max-payload |
4096 |
truncation limit for captured payloads |
-capture-tools |
all | comma-separated allowlist of tools whose payloads are captured |
-redact-keys |
see Security | regexp of object keys whose values are redacted (replaces the default) |
-listen, -upstream |
:8080, — |
http mode; request paths pass through to the upstream base URL |
-route NAME=URL |
— | http mode, repeatable, instead of -upstream: gateway mode (see above) |
| — | — | http mode: GET /healthz is liveness, and GET /readyz returns 503 while the upstream refuses TCP connections (cached 2s) |
-session-idle |
30m |
http mode; ends abandoned sessions and requests that never got a response |
-pprof |
off | serve the exporter's Go pprof on this address (see Profiles) |
-tls-cert, -tls-key, -tls-client-ca |
— | http mode; TLS, and mTLS when a client CA is given |
Telemetry
Spans: one per JSON-RPC request, named {mcp.method.name} {tool|prompt} (e.g. tools/call get_weather).
Requests from the client are SERVER spans. Server-initiated requests (sampling, elicitation, roots) are CLIENT spans.
Attributes: mcp.method.name, jsonrpc.request.id, gen_ai.tool.name, gen_ai.operation.name,
gen_ai.prompt.name, mcp.resource.uri, mcp.session.id (hashed), mcp.protocol.version,
mcp.server.name, mcp.client.name, network.transport, rpc.response.status_code, error.type.
Parent context comes from params._meta (traceparent/tracestate/baggage), and an HTTP traceparent header becomes a span link.
Tasks (MCP 2025-11-25, experimental): the request that creates a task, and every later
tasks/get, tasks/result and tasks/cancel (plus any message carrying the
io.modelcontextprotocol/related-task meta), get mcp.task.id and, where known, mcp.task.status.
Later spans link back to the creating span, so a long-running tool call shows up as one connected story.
The mcp.task.* names are this project's: the semantic conventions don't define task attributes yet.
Errors: error.type is the JSON-RPC error code, tool_error for results with isError: true,
cancelled (notifications/cancelled), or timeout (no response within -session-idle).
Per the conventions, the caller-side codes -32700 -32600 -32601 -32602 -32002 are recorded
in rpc.response.status_code but are not counted as server errors.
Metrics:
| Metric | Type | Key attributes |
|---|---|---|
mcp.server.operation.duration (s) |
histogram | method, tool, prompt, error.type, rpc.response.status_code, protocol version |
mcp.client.operation.duration (s) |
histogram | server-initiated requests |
mcp.server.session.duration (s) |
histogram | protocol version |
mcp.server.sessions.active |
up-down counter | |
mcp.server.requests.inflight |
up-down counter | method, tool |
mcp.message.size (By) |
histogram | mcp.direction, transport |
mcp.task.duration (s) |
histogram | creation to first terminal status of an MCP task; origin method and tool, mcp.task.status |
mcp_exporter.parse.errors |
counter | frames that were not JSON-RPC, forwarded untouched |
mcp_exporter.export.errors |
counter | signal: SDK errors, mostly failed exports to the backend |
otel.sdk.* |
various | the Go SDK's own metrics (processed and dropped spans and logs, exporter outcomes, queue sizes); experimental, turn off with OTEL_GO_X_OBSERVABILITY=false |
Session and request ids never become metric labels. Tool and prompt names are capped at 500 distinct values, and the rest fold into _other.
Logs: one access record per request (carrying trace_id/span_id), server notifications/message
with MCP levels mapped to OTel severities, and the server's stderr in stdio mode.
Dashboards and alerts: see deploy/grafana/dashboard.json and deploy/grafana/alerts.yaml (error rate, failing tools, slow tools, failing tasks, parse errors, failing exports, SDK queue saturation). The dashboard has rows for the server, MCP Tasks, client mode and exporter health.
Profiles
OTLP Profiles are in public Alpha. Two complementary sources, both in the compose overlay
(docker compose -f deploy/compose/docker-compose.yaml -f deploy/compose/profiling.yaml up --build,
then Grafana → Explore → Profiles):
- The exporter itself:
-pprof 127.0.0.1:6060(Helm:exporter.pprof.enabled) serves Go pprof on its own listener, never the proxy port. A Collector with the pprof receiver scrapes/debug/pprof/profile?seconds=10and ships OTLP profiles. - The MCP server, any language: the OpenTelemetry eBPF profiler
profiles every process on a Linux host (privileged, host PID). It labels each process with its
OTEL_SERVICE_NAME, so set that on the server to file its CPU profiles under the same service as its traces. For Kubernetes, see deploy/kubernetes/ebpf-profiler.yaml (DaemonSet).
Both need a backend that accepts OTLP profiles, such as Pyroscope or a Collector started with --feature-gates=service.profilesSupport.
The Alpha wire format changes between Collector releases, so keep your profilers and backend Collector on the same version
(this repo pins 0.162.0 to match grafana/otel-lgtm:0.36.0).
Profiles correlate with traces by service, instance and time window. Individual samples aren't tagged with span ids.
Security
- Payload capture is off by default, and can be limited to specific tools with
-capture-tools. - Captured payloads and server log data are redacted twice:
- by key: values under keys matching
-redact-keys(default(?i)pass|token|secret|key|auth|credential|cookie|session) - by value: JWTs,
Bearertokens,sk-…,gh[pousr]_…, Slackxox…tokens and AWS access key ids, wherever they appear
- by key: values under keys matching
Authorization, cookies and other headers are never recorded.Mcp-Session-Idis exported only as a truncated SHA-256.- In stdio mode, stdout carries only protocol frames: console exporters always write to stderr. On Linux and macOS, stdout is also reserved at the file-descriptor level, so even a stray print from a library can't corrupt the stream.
- Release images are distroless, run as a non-root user, and are cosign-signed, with SBOMs (.goreleaser.yaml).
Overhead
About 8 µs of CPU per request/response pair, including trace-context injection (go test ./internal/observe -bench .).
SSE streams are observed as they pass through and are never buffered or modified.
In HTTP mode the exporter asks the upstream for uncompressed responses (Accept-Encoding: identity), and gzip request bodies are forwarded decompressed. Both are needed to observe the traffic, and the sidecar hop is local.
Contributing
Issues and PRs are welcome. See CONTRIBUTING.md, the milestones, and the code of conduct. Report vulnerabilities privately as described in SECURITY.md.
License
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
demo-agent
command
Command demo-agent is a pretend AI agent for the demo stack.
|
Command demo-agent is a pretend AI agent for the demo stack. |
|
mcp-exporter
command
Command mcp-exporter is a transparent proxy that exports OpenTelemetry traces, metrics and logs for any MCP server.
|
Command mcp-exporter is a transparent proxy that exports OpenTelemetry traces, metrics and logs for any MCP server. |
|
internal
|
|
|
jsonrpc
Package jsonrpc parses the JSON-RPC 2.0 messages MCP is built on.
|
Package jsonrpc parses the JSON-RPC 2.0 messages MCP is built on. |
|
observe
Package observe wires OpenTelemetry and turns MCP traffic into telemetry.
|
Package observe wires OpenTelemetry and turns MCP traffic into telemetry. |
|
proxy
Package proxy carries MCP traffic between client and server and feeds every frame to an observe.Tracker.
|
Package proxy carries MCP traffic between client and server and feeds every frame to an observe.Tracker. |