OpenInference MCP Instrumentation
OpenTelemetry auto-instrumentation for the Model Context Protocol (MCP) Python SDK that propagates trace context across tool calls.
Repository Health
Technical Analysis
OpenInference MCP Instrumentation is a Python auto-instrumentation library for the Model Context Protocol (MCP) SDK, part of Arize’s OpenInference project for AI observability. It hooks MCP’s client and server transports so that the OpenTelemetry span active when a tool call is made stays connected to the spans generated while that call executes on the other side of the protocol.
Because MCP crosses a client/server boundary, traces would otherwise break at the transport. This package fixes that by injecting and extracting OpenTelemetry context through streamable HTTP, SSE, and stdio transports, giving you unbroken distributed traces across your agent and its MCP tool servers. It focuses purely on context propagation and does not emit its own telemetry.
What You Get
- A single MCPInstrumentor you register once to patch MCP client and server transports
- Automatic OpenTelemetry context propagation across streamable HTTP, SSE, and stdio transports
- Unbroken distributed traces spanning your agent and its MCP tool servers
- Seamless integration with Phoenix, Arize AX, and any OpenTelemetry-compatible backend
- A lightweight, dependency-light install that adds no telemetry of its own
Common Use Cases
- Tracing LLM agents that call tools over the Model Context Protocol
- Connecting client-side and server-side spans in an MCP-based system
- Feeding coherent agent traces into Phoenix or Arize AX for debugging
Under The Hood
Architecture
The package ships a single MCPInstrumentor extending OpenTelemetry’s BaseInstrumentor. On _instrument, it uses wrapt’s post-import hooks to wrap MCP’s transport entry points (mcp.client.streamable_http, mcp.server.streamable_http, mcp.client.sse, mcp.server.sse, and stdio) so that outgoing requests inject the current context via opentelemetry.propagate and incoming requests extract it, re-activating the span on the far side.
Tech Stack
Pure Python built directly on the OpenTelemetry API and instrumentation SDK, plus wrapt for non-invasive monkeypatching. It declares MCP as an instrumentation dependency and lives in the Arize-ai/openinference monorepo under python/instrumentation/openinference-instrumentation-mcp, versioned and published independently.
Code Quality The monorepo carries 132 Python test files across its instrumentation packages and a shared CI/tooling setup, and the MCP module itself is small and tightly scoped with typed signatures. Its narrow responsibility (context only, no telemetry) keeps the surface easy to reason about and audit.
API Design
Integration is a one-liner: instantiate MCPInstrumentor().instrument() and every supported MCP transport is patched automatically, requiring no changes to tool code. The design intentionally avoids emitting spans so it layers cleanly beneath framework-specific instrumentors.