MCP server observability: execution logs and trace context
How to see what your MCP server is doing in production: structured execution logs for every tool call, W3C trace context from request _meta, and what replaces the deprecated MCP logging capability.
To observe an MCP server, log one structured event when each tool call, prompt, or resource read starts and another when it ends, and attach the caller's trace ID to both. In xmcp that is one config line: observability: { enabled: true }. Events go to stderr as JSON, never include arguments or results, and carry the W3C trace context the client sent.
This guide follows the repository's execution observability example.
What changed for observability in MCP 2026-07-28?
Two things in the 2026-07-28 revision affect how servers are observed:
- MCP logging is deprecated. The protocol's Logging feature, where servers send
notifications/messageto the client, is deprecated together with Roots and Sampling. The changelog's suggested migration is to log to stderr or use OpenTelemetry. - Trace context has a documented home. The revision documents conventions for carrying
traceparent,tracestate, andbaggagein a request's_meta, so a trace can cross an MCP call on any transport, not only HTTP.
The practical result: logs belong to the server operator, and correlation travels with the request.
How do I turn on execution logs?
Set observability.enabled in xmcp.config.ts:
Every tool call, prompt retrieval, and resource read now emits an execution.start event and an execution.end event. There is no handler wrapper to add: the logger runs before your MCP middleware, so it also records middleware failures and short-circuited results.
Events are JSON lines written with console.error. That is stderr on Node.js, which keeps STDIO's stdout free for MCP messages, and the platform's error console on Cloudflare Workers. Nothing is sent to an external service.
What does an execution event contain?
Events use Elastic Common Schema field names, with xmcp details under xmcp:
| Field | Meaning |
|---|---|
event.action | execution.start or execution.end |
event.duration | Elapsed time in nanoseconds, on the end event |
event.outcome | success, failure, or unknown, on the end event |
transaction.id | Correlation ID shared by one execution's start and end events |
xmcp.method | tools/call, prompts/get, or resources/read |
xmcp.component | The tool, prompt, or registered resource name |
xmcp.status | success, failure, cancelled, input_required, or unknown |
error.message | A safe summary for error results and thrown exceptions |
trace.id, parent.id | The incoming W3C trace and parent IDs, when a valid traceparent came |
A successful tool call ends with an event like this:
What is deliberately not logged?
Arguments, results, raw resource URIs, error stacks, original exception messages, credentials, and raw request headers are all excluded. Resource names come from registration, so dynamic URI parameters never reach the log. An error summary tells you whether a handler threw or returned an error result without copying its contents.
Tool inputs often contain user data. Logging the shape of an execution and not its payload keeps the logs safe to ship to a shared platform.
How does trace context reach the logs?
xmcp reads traceparent from the request's MCP params._meta, which works on HTTP and STDIO. When _meta has no valid value, it falls back to the HTTP traceparent header.
Both events for that call include "trace": { "id": "0af7651916cd43dd8448eb211c80319c" } and "parent": { "id": "b7ad6b7169203331" }. Search your log platform for the trace ID and the MCP call lines up with the rest of the request that caused it.
These IDs are caller-supplied correlation data, not authentication. Only the trace and parent IDs are logged; tracestate and baggage are not.
How do I forward the trace to downstream services?
getRequestContext() exposes a read-only copy of the current request's _meta. Read traceparent from it and send it on the calls your tool makes:
Pass the returned headers to fetch and the downstream service joins the same trace. getRequestContext() works inside async helpers, so the function that makes the HTTP call can read the context itself.
Run the example
Use Node.js 22.12 or later and pnpm. From a checkout of the xmcp repository:
Send the request above from another terminal, then open execution.log. Call the fail tool to see a failure event with a safe summary in place of the original error message.
Common questions
Does xmcp create OpenTelemetry spans?
No. Execution logs carry the incoming trace and parent IDs so they correlate with your traces, but xmcp does not create spans or configure an exporter. Use your own OpenTelemetry setup for spans.
Do execution logs work over STDIO?
Yes. Events go to stderr, so stdout carries only MCP messages. Over STDIO, trace IDs come from _meta.traceparent.
Are listings logged?
No. Tool calls, prompt retrievals, and resource reads are logged. Listings and completion requests are excluded, and so are tool arguments rejected by validation before the handler runs.
How are multi round-trip tools logged?
A tool that returns input_required produces a separate event pair for each round. Intermediate rounds have status input_required; the final round has the real outcome. See Human-in-the-loop MCP tools.
Should I still use MCP log notifications?
For new servers, prefer stderr logs or OpenTelemetry. getRequestContext().log() still exists in xmcp, but the default server does not enable the MCP logging capability, and the protocol feature is deprecated as of 2026-07-28.
Next steps
- Execution logs reference for every field and the privacy rules.
- Request context for
_meta, the cancellation signal, and request-local values.
