> ## 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.

# McpServerInstrumentation

> Internal class that patches McpServer methods. Exposed for advanced use.

```ts theme={null}
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

```ts theme={null}
new McpServerInstrumentation(server, telemetryManager)
```

<ParamField path="server" type="McpServer" required>
  The MCP server instance to patch.
</ParamField>

<ParamField path="telemetryManager" type="TelemetryManager" required>
  An initialized `TelemetryManager`.
</ParamField>

## 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](/concepts/tracing).

## 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](/metrics-and-traces/custom-instrumentation).

## Example: standalone use

```ts theme={null}
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

<Card title="instrumentServer" icon="plug" href="/api-reference/instrument-server">
  The convenient wrapper.
</Card>
