Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.sedata-ai.tech/llms.txt

Use this file to discover all available pages before exploring further.

class McpServerInstrumentation {
  constructor(server: McpServer, telemetryManager: TelemetryManager)
  instrument(): void
}
The class behind the tools/call instrumentation. instrumentServer creates one of these for you and calls instrument(). You’d only construct one yourself if you’re managing the TelemetryManager lifecycle by hand or testing the patching behavior.

Constructor

new McpServerInstrumentation(server, telemetryManager)
server
McpServer
required
The MCP server instance to patch.
telemetryManager
TelemetryManager
required
An initialized TelemetryManager.

Methods

instrument(): void

Patches server.registerTool and several other server methods. Idempotent — calling twice is a no-op. After this call:
  • server.registerTool(name, config, handler) records tool metadata and wraps handler with the instrumented version.
  • Each subsequent invocation of a registered tool produces a span named tools/call <toolName> with the standard attribute set.

What gets patched

Today only instrumentTools does real work. The other patch points (instrumentCompletions, instrumentLogs, instrumentNotifications, instrumentPings, instrumentPrompts, instrumentResources, instrumentRoots, instrumentSampling) are placeholders for future auto-instrumentation. In the meantime you can record any of those yourself with the custom instrumentation API.

Example: standalone use

import { TelemetryManager, McpServerInstrumentation } from '@sedata-ai/mcp'
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'

const server = new McpServer({ name: 'X', version: '1.0.0' })

const manager = new TelemetryManager({
  serverName: 'X',
  serverVersion: '1.0.0',
  exporterEndpoint: 'https://otel.sedata-ai.tech/v1',
  exporterAuth: { type: 'bearer', token: process.env.SEDATA_TOKEN! },
})

const inst = new McpServerInstrumentation(server, manager)
inst.instrument()
This is exactly what instrumentServer does internally.

See also

instrumentServer

The convenient wrapper.