JavaScript APImcp

Core

Instrumentation

Integrations

JavaScript · Instrumentation

@arizeai/openinference-instrumentation-mcp

OpenInference instrumentation for MCP

Version
0.2.40
Instruments
@modelcontextprotocol/sdk >=1.0.0

Install

npm install @arizeai/openinference-instrumentation-mcp

Usage

Register the instrumentation once, at startup, before the library is imported. The MCPInstrumentation reference below lists its options.

import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
import { MCPInstrumentation } from "@arizeai/openinference-instrumentation-mcp";

const provider = new NodeTracerProvider({
  // ...a span processor that exports to Phoenix or any OTLP backend.
});
provider.register();

registerInstrumentations({
  instrumentations: [new MCPInstrumentation()],
});

If the library is imported first (as ES modules often are), patch it directly with manuallyInstrument().

@arizeai/openinference-instrumentation-mcp

isPatched

functionSource ↗
function isPatched(
  moduleName: "@modelcontextprotocol/sdk/client/sse" | "@modelcontextprotocol/sdk/server/sse" | "@modelcontextprotocol/sdk/client/stdio" | "@modelcontextprotocol/sdk/server/stdio" | "@modelcontextprotocol/sdk/client/streamableHttp" | "@modelcontextprotocol/sdk/server/streamableHttp",
): boolean

function to check if instrumentation is enabled / disabled for the module

MCPInstrumentation

classSource ↗
class MCPInstrumentation extends InstrumentationBase<InstrumentationConfig>

Instrumentation for the MCP SDK which propagates context between client and server to allow traces to be connected across tool calls.

new MCPInstrumentation

constructorSource ↗
new MCPInstrumentation(
  options?: { instrumentationConfig?: InstrumentationConfig },
): MCPInstrumentation

Parameters

NameTypeDescription
instrumentationConfig?InstrumentationConfig

The config for the instrumentation

manuallyInstrument

methodSource ↗
manuallyInstrument(
  modules: {
    clientSSEModule?: __module;
    serverSSEModule?: __module;
    clientStdioModule?: __module;
    serverStdioModule?: __module;
    clientStreamableHTTPModule?: __module;
    serverStreamableHTTPModule?: __module;
  },
): void

Manually instruments the MCP client and/or server modules. Currently, auto-instrumentation does not work with the MCP SDK and this method must be used to enable instrumentation.

Parameters

NameTypeDescription
modules{ clientSSEModule?: __module; serverSSEModule?: __module; clientStdioModule?: __module; serverStdioModule?: __module; clientStreamableHTTPModule?: __module; serverStreamableHTTPModule?: __module }

The modules to manually instrument.

modules.clientSSEModule?__module

The MCP client SSE module, e.g. require(‘@modelcontextprotocol/sdk/client/sse.js’)

modules.serverSSEModule?__module

The MCP server SSE module, e.g. require(‘@modelcontextprotocol/sdk/server/sse.js’)

modules.clientStdioModule?__module

The MCP client stdio module, e.g. require(‘@modelcontextprotocol/sdk/server/stdio.js’)

modules.serverStdioModule?__module

The MCP server stdio module, e.g. require(‘@modelcontextprotocol/sdk/client/stdio.js’)

modules.clientStreamableHTTPModule?__module

The MCP client streamable HTTP module, e.g. require(‘@modelcontextprotocol/sdk/client/streamableHttp.js’)

modules.serverStreamableHTTPModule?__module

The MCP server streamable HTTP module, e.g. require(‘@modelcontextprotocol/sdk/server/streamableHttp.js’)