
OpenTelemetry Instrumentation for Model Context Protocol (MCP) A TypeScript package that provides automatic OpenTelemetry instrumentation for the Model Context Protocol SDK, enabling observability...
概览
Automatic OpenTelemetry instrumentation for the Model Context Protocol SDK, enabling observability and telemetry collection for MCP-based applications with zero configuration required. - Production ready with enhanced OTEL headers parsing and streamlined configuration. Removed deprecated DYNATRACE_API_TOKEN support for cleaner configuration. Now uses only standard OpenTelemetry OTEL_EXPORTER_OTLP_HEADERS with improved parsing and validation. - 🔄 of MCP tool calls - 📊 with NodeSDK - 🚀 - no manual OpenTelemetry configuration needed - 📈 with Dynatrace support out of the box - 🔍 of tool execution with error handling - ⚡ - just import and go - 🔗 - maintains trace context across tool executions Simply import the register module at the very top of your application entry point: If you need more control over the OpenTelemetry configuration: When using the auto-registration approach, configure these environment variables: The OTEL_EXPORTER_OTLP_HEADERS environment variable supports...
README
以下为原文 README 节选,完整内容请查看原文。
OpenTelemetry Instrumentation for Model Context Protocol (MCP)
Automatic OpenTelemetry instrumentation for the Model Context Protocol SDK, enabling observability and telemetry collection for MCP-based applications with zero configuration required.
Version 1.0.4 - Production ready with enhanced OTEL headers parsing and streamlined configuration.
🆕 What’s New in v1.0.4: Removed deprecated
DYNATRACE_API_TOKENsupport for cleaner configuration. Now uses only standard OpenTelemetryOTEL_EXPORTER_OTLP_HEADERSwith improved parsing and validation.
Features
- 🔄 Automatic instrumentation of MCP tool calls
- 📊 Built-in OpenTelemetry setup with NodeSDK
- 🚀 Drop-in solution - no manual OpenTelemetry configuration needed
- 📈 OTLP export with Dynatrace support out of the box
- 🔍 Comprehensive tracing of tool execution with error handling
- ⚡ Zero-code integration - just import and go
- 🔗 Parent span stitching - maintains trace context across tool executions
Installation
npm install @theharithsa/opentelemetry-instrumentation-mcp
Quick Start
Option 1: Auto-Registration (Recommended)
Simply import the register module at the very top of your application entry point:
// At the top of your src/index.ts or main file
import '@theharithsa/opentelemetry-instrumentation-mcp/register';
// Your existing MCP server code...
import { McpServer } from '@modelcontextprotocol/sdk';
// ... rest of your application
Option 2: Manual Setup
If you need more control over the OpenTelemetry configuration:
import { McpInstrumentation } from '@theharithsa/opentelemetry-instrumentation-mcp';
import { NodeSDK } from '@opentelemetry/sdk-node';
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
const sdk = new NodeSDK({
instrumentations: [
getNodeAutoInstrumentations(),
new McpInstrumentation(),
],
// Your custom configuration...
});
sdk.start();
Environment Variables
When using the auto-registration approach, configure these environment variables:
# Required: OTLP endpoint for trace export
OTEL_EXPORTER_OTLP_ENDPOINT=https://your-dynatrace-endpoint.com/api/v2/otlp/v1/traces
# Required: OTLP headers including authorization
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →