Skip to content

Conversation

@lukeina2z
Copy link
Contributor

Add automatic OpenTelemetry instrumentation for the Model Context Protocol (MCP) SDK to enable distributed tracing across MCP client–server boundaries.

Features

  1. Automatic span creation for client requests and server handlers.
  2. OpenTelemetry context propagation via request metadata.
  3. Support for MCP semantic conventions.

Reference:
MCP semantic conventions
open-telemetry/semantic-conventions#2083

Tests

  1. End-to-end test with HTTP-based MCP client and server
  2. End-to-end test with stdio-based MCP client and server
  3. All unit tests pass

Implementation Notes

According to the MCP SDK documentation https://github.com/modelcontextprotocol/typescript-sdk/blob/main/README.md, the following modules are used to create the MCP client and server:

Client
Module name: '@modelcontextprotocol/sdk/client/index.js' basedir: '/Users/someone/http-client-server/client/node_modules/@modelcontextprotocol/sdk'

Server
Module name: '@modelcontextprotocol/sdk/server/mcp.js' basedir: '/Users/someone/http-client-server/server/node_modules/@modelcontextprotocol/sdk'

The existing InstrumentationBase could not wrap both modules from the @modelcontextprotocol/sdk package. This PR introduces a custom hook within the MCP instrumentation library to support both.

Add automatic OpenTelemetry instrumentation for the Model Context Protocol (MCP) SDK to enable distributed tracing across MCP client–server boundaries.

Features
1. Automatic span creation for client requests and server handlers.
2. OpenTelemetry context propagation via request metadata.
3. Support for MCP semantic conventions.

Reference:
MCP semantic conventions
open-telemetry/semantic-conventions#2083

Tests
1. End-to-end test with HTTP-based MCP client and server
2. End-to-end test with stdio-based MCP client and server
3. All unit tests pass

Implementation Notes

According to the MCP SDK documentation https://github.com/modelcontextprotocol/typescript-sdk/blob/main/README.md, the following modules are used to create the MCP client and server:

Client
Module name: '@modelcontextprotocol/sdk/client/index.js'
basedir: '/Users/someone/http-client-server/client/node_modules/@modelcontextprotocol/sdk'

Server
Module name: '@modelcontextprotocol/sdk/server/mcp.js'
basedir: '/Users/someone/http-client-server/server/node_modules/@modelcontextprotocol/sdk'

The existing InstrumentationBase could not wrap both modules from the @modelcontextprotocol/sdk package. This PR introduces a custom hook within the MCP instrumentation library to support both.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants