OpenInference MCP Instrumentation
raw JSON → 2.0.0 verified Fri May 01 auth: no python
OpenInference instrumentation for MCP (Model Context Protocol) clients, enabling OpenTelemetry-based tracing of MCP tool calls and server interactions. Current version 2.0.0, requires Python >=3.10 <3.15. Part of the Arize AI OpenInference ecosystem. Active development with frequent releases.
pip install openinference-instrumentation-mcp Common errors
error No spans are being created ↓
cause Tracer provider not set up or instrumentation() not called before MCP client usage.
fix
Ensure you call trace.set_tracer_provider(provider) before MCPClientInstrumentor().instrument(), and ensure instrumentation is called before any MCP client session.
error MCPClientInstrumentor not found ↓
cause Wrong import path. The symbol is in the top-level package, not a submodule.
fix
Use 'from openinference_instrumentation_mcp import MCPClientInstrumentor'.
error Could not import wrapt ↓
cause wrapt is missing or incompatible version.
fix
Install wrapt: 'pip install wrapt'. For wrapt 2.x support, upgrade openinference-instrumentation to >=0.1.47.
Warnings
breaking Version 2.0.0 introduces a BREAKING CHANGE: support for streamable_http_client. Existing instrumentations using older MCP client versions may break. Update MCP library to compatible version. ↓
fix Upgrade MCP library to version that supports streamable_http_client (mcp>=1.6.0). Review your MCP server's streaming transport.
gotcha Instrumentation must be set up before creating any MCP client sessions. If MCP client is imported and used before calling MCPClientInstrumentor().instrument(), the instrumentation will not apply. ↓
fix Call MCPClientInstrumentor().instrument() immediately after setting up the tracer provider and before importing/using mcp.ClientSession or any MCP client.
gotcha The instrumentation only instruments the client side, not the server. Do not expect server-side spans unless you set up instrumentation on the server as well. ↓
fix Use a separate OpenInference instrumentation for your MCP server (e.g., openinference-instrumentation-mcp-server) if available.
deprecated Wrapt 2.x is supported, but older instrumentations may require wrapt<2. If you encounter import errors related to wrapt, check compatibility. ↓
fix Ensure wrapt is installed. For wrapt 2.x compatibility, use openinference-instrumentation>=0.1.47.
Imports
- MCPClientInstrumentor
from openinference_instrumentation_mcp import MCPClientInstrumentor
Quickstart
import os
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from openinference_instrumentation_mcp import MCPClientInstrumentor
# Set up OpenTelemetry tracer provider
provider = TracerProvider()
provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint=os.environ.get('OTEL_EXPORTER_OTLP_ENDPOINT', 'http://localhost:4318/v1/traces'))))
trace.set_tracer_provider(provider)
# Instrument MCP client
MCPClientInstrumentor().instrument()
# Now any MCP client sessions will be traced.