Skip to content

Commit 457b485

Browse files
committed
feat(instrumentation-mcp): add OpenTelemetry instrumentation for MCP SDK
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.
1 parent 23c5f4e commit 457b485

File tree

18 files changed

+1757
-43
lines changed

18 files changed

+1757
-43
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,6 @@ version.ts
8585
/.vs
8686
.cursor/rules/nx-rules.mdc
8787
.github/instructions/nx.instructions.md
88+
89+
# generated by tests.
90+
packages/instrumentation-typeorm/connection2.db

.release-please-manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"packages/instrumentation-ioredis": "0.54.0",
4646
"packages/instrumentation-knex": "0.51.0",
4747
"packages/instrumentation-koa": "0.55.0",
48+
"packages/instrumentation-mcp": "0.0.1",
4849
"packages/instrumentation-memcached": "0.50.0",
4950
"packages/instrumentation-mongodb": "0.59.0",
5051
"packages/instrumentation-mysql": "0.52.0",

0 commit comments

Comments
 (0)