Question-led guide · how-to
How do I trace MCP and tool calls across a gateway?
A tool-action envelope that joins agent, MCP client, gateway, server, downstream service, and verified external effect without leaking payloads.
Direct answer
Trace an MCP/tool call as one logical action with separate spans for agent decision, MCP client request, gateway policy, MCP server handling, and downstream effect. Propagate standard trace context where each hop supports it; otherwise use a stable action ID and span links. Record tool/schema versions, target, authorization-decision reference, idempotency key, outcome, and effect verification—without storing sensitive arguments by default.
Scope
Use this guide when an agent invokes a tool through MCP or a similar gateway and operators need to follow the action across process and trust boundaries. It concerns telemetry and correlation. Authorization remains enforced by identity, policy, gateway, and target systems.
Why it happens
Each layer sees a different name. The agent records send_email; MCP has a request ID; the gateway uses an audit ID; the service creates a job; the provider returns a message ID. A trace may stop at the gateway because the server lacks instrumentation or processes work asynchronously.
Teams often compensate by logging complete JSON payloads. This improves short-term search while exposing credentials, personal data, prompts, and untrusted content. It still may not prove which external effect occurred.
Diagnosis
Take one tool invocation and try to navigate from the agent trace to the target effect and back. Verify:
- stable logical action ID across retries and protocol IDs per attempt;
- tool name plus server and schema version;
- gateway policy-decision reference and current actor/target identity;
- downstream request and idempotency identity;
- accepted, committed, failed, compensated, or unknown effect state;
- retry and delegation relationships;
- content capture and redaction policy at every hop.
If the only join is timestamp plus tool name, concurrent calls will collide.
Solution
Generate an action ID before invocation and preserve it as validated metadata. Create spans at each meaningful processing boundary. Propagate W3C Trace Context only across trusted, compatible channels; validate incoming context and prevent arbitrary baggage from becoming indexed attributes.
Use separate protocol request IDs for attempts. A retry belongs to the same logical action but receives a new attempt identity. Record the policy-decision ID, not an entire authorization token. Record argument schema, safe field names, and a digest of the canonical proposal where useful.
After the tool returns, query or consume an effect receipt when the operation is asynchronous. The final agent message should not be the effect oracle.
Artifact
The tool-action envelope contains:
action: {id: act-..., task_id: ..., attempt: 2, parent_decision: ...}
tool: {name: send_email, server: comms-mcp, schema_version: 7}
trace: {trace_id: ..., client_span: ..., gateway_span: ..., server_span: ..., links: [...]}
authority: {actor_ref: ..., decision_id: ..., policy_version: ..., target_ref: ...}
proposal: {digest: sha256:..., idempotency_key: ..., data_class: confidential}
protocol: {mcp_request_id: ..., operation: tools/call, transport: ...}
result: {protocol_status: ..., tool_status: ..., error_type: ..., receipt_ref: ...}
effect: {state: committed, target_effect_id: ..., verified_at: ..., verifier: ...}
privacy: {capture_mode: metadata, redaction_policy: ..., retention_class: ...}
Common mistakes
- Reusing a protocol request ID as the durable business action ID.
- Treating the gateway’s 200 response as proof of the target effect.
- Logging raw arguments and results by default.
- Accepting user-supplied trace IDs without validation.
- Losing relationships when the server queues work after returning.
Evidence
MCP defines protocol roles, messages, capabilities, and tool invocation boundaries between hosts, clients, and servers.
The MCP core specification describes the protocol architecture, lifecycle, messages, capabilities, and security-related responsibilities.
Primary source · standard · checked Aug 26, 2026
Limit: Protocol conformance does not create end-to-end tracing, authorization, or proof of an external business effect.
OpenTelemetry's MCP semantic-convention work defines candidate span structures and attributes for MCP operations.
The pinned registry source describes MCP client/server span groups, operation names, and attributes in the evolving GenAI conventions.
Primary source · standard · checked Aug 26, 2026
Limit: The source is a development snapshot; generated documentation and SDK support may differ or change.
One action envelope should connect protocol requests to policy decisions and actual target effects even when a trace boundary is broken.
The envelope below adds stable action, authorization, idempotency, and effect references around protocol telemetry.
Signal Studio author framework · reviewed Aug 26, 2026
Limit: Correlation depends on every adapter preserving identifiers accurately; it is not a security proof.
Limitations
MCP and OpenTelemetry conventions evolve, and not all servers or gateways propagate context. User-controlled correlation fields can be spoofed. External effects may complete asynchronously or lack a queryable receipt, leaving outcome unknown.
FAQ
- Should the gateway create a new trace?
- Prefer continued standard context for the same causal request. When trust, async execution, or protocol boundaries require separation, start an appropriate trace and preserve the logical relationship with validated action IDs and span links.
- Should tool arguments be recorded for debugging?
- Record typed metadata or approved digests by default. Full arguments can contain secrets, personal data, or injected content and need separate capture, access, sampling, and retention controls.
Related guides
Continue within AI agent observability, or use one of these adjacent diagnostics:
Editorial QA: automated native-English, structure, source-presence, and link checks completed . This record is not an independent expert endorsement. Review boundary.
