Trace MCP (Model Context Protocol) clients and servers in TypeScript/Node.js
This module provides instrumentation for MCP (Model Context Protocol) clients and servers, enabling context propagation between MCP clients and servers to unify traces.
The @arizeai/openinference-instrumentation-mcp instrumentor enables context propagation between MCP clients and servers. It does not generate its own telemetry—you still need to generate OpenTelemetry traces in both the client and server to see a unified trace.
To instrument your MCP application, use the register function from @arizeai/phoenix-otel and set up the MCP instrumentation.Create the instrumentation.ts file:
Copy
Ask AI
import { register } from "@arizeai/phoenix-otel";import { MCPInstrumentation } from "@arizeai/openinference-instrumentation-mcp";// Initialize Phoenix tracingconst tracerProvider = register({ projectName: "mcp-app", // If using Phoenix Cloud: // url: "https://app.phoenix.arize.com/s/your-space-name", // apiKey: process.env.PHOENIX_API_KEY, // If using self-hosted Phoenix: // url: "http://localhost:6006",});// Set up MCP instrumentation for context propagationconst instrumentation = new MCPInstrumentation();instrumentation.enable();console.log("MCP instrumentation registered");
With MCP instrumentation enabled, traces from your MCP client and server will be connected in Phoenix, allowing you to see the full request flow across client-server boundaries.