-
Notifications
You must be signed in to change notification settings - Fork 67
feat(mcp): add mcp official sdk instrumentation #829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f72c0ef
feat(mcp): add mcp official sdk instrumentation
galkleinman 646d260
fix lint and build
galkleinman 94d74ff
chore(sdk): add MCP to allowed instrumentation libraries
galkleinman 7516255
prettier
galkleinman a49e5cc
wip
galkleinman fc4eb3d
wip
galkleinman f86b600
fix(mcp): make session span parent of all request spans
nirga 0ffd6b5
feat(mcp): add client name to session span as workflow name
nirga 0503b89
fix(mcp): set workflow name on all request spans and use enum for unk…
nirga 9b9ea4b
Merge branch 'main' into gk/mcp-instrumentation
nirga fea22f7
refactor(mcp): match Python MCP client instrumentation exactly
nirga c288fc9
chore(mcp): fix lint - remove unused TraceloopSpanKindValues import
nirga c44b472
chore(mcp): bump version to 0.20.2
nirga 36a3c4e
chore(mcp): run prettier to fix formatting
nirga dda8013
chore: lint
nirga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| dist | ||
| node_modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # OpenTelemetry MCP Instrumentation for Node.js | ||
|
|
||
| [![NPM Published Version][npm-img]][npm-url] | ||
| [![Apache License][license-image]][license-image] | ||
|
|
||
| This library allows tracing of agentic workflows implemented with MCP (Model Context Protocol) framework using the [@modelcontextprotocol/sdk](https://github.com/modelcontextprotocol/typescript-sdk). | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| npm install --save @traceloop/instrumentation-mcp | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ```javascript | ||
| const { McpInstrumentation } = require("@traceloop/instrumentation-mcp"); | ||
| const { registerInstrumentations } = require("@opentelemetry/instrumentation"); | ||
|
|
||
| registerInstrumentations({ | ||
| instrumentations: [new McpInstrumentation()], | ||
| }); | ||
| ``` | ||
|
|
||
| ## Privacy | ||
|
|
||
| By default, this instrumentation logs prompts, completions, and embeddings to span attributes. This gives you a clear visibility into how your LLM application is working, and can make it easy to debug and evaluate the quality of the outputs. | ||
|
|
||
| However, you may want to disable this logging for privacy reasons, as they may contain highly sensitive data from your users. You may also want to disable this logging to reduce the size of your traces. | ||
|
|
||
| To disable logging, set the `traceContent` config option to `false`: | ||
|
|
||
| ```javascript | ||
| const { McpInstrumentation } = require("@traceloop/instrumentation-mcp"); | ||
|
|
||
| const mcpInstrumentation = new McpInstrumentation({ | ||
| traceContent: false, | ||
| }); | ||
| ``` | ||
|
|
||
| ## Instrumented Operations | ||
|
|
||
| This instrumentation tracks the following MCP operations: | ||
|
|
||
| ### Client Operations | ||
|
|
||
| - Session lifecycle management | ||
| - Tool invocations | ||
| - Resource access | ||
| - Prompt templates | ||
| - MCP protocol methods | ||
|
|
||
| ### Server Operations | ||
|
|
||
| - Request handling | ||
| - Tool execution | ||
| - Resource serving | ||
| - Server-side spans | ||
|
|
||
| ## License | ||
|
|
||
| Apache 2.0 - See [LICENSE][license-url] for more information. | ||
|
|
||
| [npm-url]: https://www.npmjs.com/package/@traceloop/instrumentation-mcp | ||
| [npm-img]: https://badge.fury.io/js/%40traceloop%2Finstrumentation-mcp.svg | ||
| [license-url]: https://github.com/traceloop/openllmetry-js/blob/main/LICENSE | ||
| [license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| const js = require("@eslint/js"); | ||
| const rootConfig = require("../../eslint.config.cjs"); | ||
|
|
||
| const { FlatCompat } = require("@eslint/eslintrc"); | ||
|
|
||
| const compat = new FlatCompat({ | ||
| baseDirectory: __dirname, | ||
| recommendedConfig: js.configs.recommended, | ||
| allConfig: js.configs.all, | ||
| }); | ||
|
|
||
| module.exports = [ | ||
| { | ||
| ignores: ["!**/*", "**/node_modules", "dist/**/*"], | ||
| }, | ||
| ...rootConfig, | ||
| { | ||
| files: ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx"], | ||
| rules: {}, | ||
| }, | ||
| { | ||
| files: ["**/*.ts", "**/*.tsx"], | ||
| rules: {}, | ||
| }, | ||
| { | ||
| files: ["**/*.js", "**/*.jsx"], | ||
| rules: {}, | ||
| }, | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| { | ||
| "name": "@traceloop/instrumentation-mcp", | ||
| "version": "0.20.2", | ||
| "description": "MCP (Model Context Protocol) Instrumentation", | ||
| "main": "dist/index.js", | ||
| "module": "dist/index.mjs", | ||
| "types": "dist/index.d.ts", | ||
| "repository": "traceloop/openllmetry-js", | ||
| "scripts": { | ||
| "build": "rollup -c", | ||
| "lint": "eslint .", | ||
| "lint:fix": "eslint . --fix", | ||
| "test": "ts-mocha -p tsconfig.json 'test/**/*.test.ts'" | ||
| }, | ||
| "keywords": [ | ||
| "opentelemetry", | ||
| "nodejs", | ||
| "tracing", | ||
| "mcp", | ||
| "model-context-protocol" | ||
| ], | ||
| "author": "Traceloop", | ||
| "license": "Apache-2.0", | ||
| "engines": { | ||
| "node": ">=14" | ||
| }, | ||
| "files": [ | ||
| "dist/**/*.js", | ||
| "dist/**/*.mjs", | ||
| "dist/**/*.js.map", | ||
| "dist/**/*.d.ts", | ||
| "doc", | ||
| "LICENSE", | ||
| "README.md", | ||
| "package.json" | ||
| ], | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@opentelemetry/api": "^1.9.0", | ||
| "@opentelemetry/core": "^2.0.1", | ||
| "@opentelemetry/instrumentation": "^0.203.0", | ||
| "@opentelemetry/semantic-conventions": "^1.36.0", | ||
| "@traceloop/ai-semantic-conventions": "workspace:*", | ||
| "tslib": "^2.8.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@modelcontextprotocol/sdk": "^1.0.4", | ||
| "@opentelemetry/context-async-hooks": "^2.0.1", | ||
| "@opentelemetry/sdk-trace-node": "^2.0.1", | ||
| "@pollyjs/adapter-fetch": "^6.0.7", | ||
| "@pollyjs/adapter-node-http": "^6.0.6", | ||
| "@pollyjs/core": "^6.0.6", | ||
| "@pollyjs/persister-fs": "^6.0.6", | ||
| "@types/mocha": "^10.0.10", | ||
| "ts-mocha": "^11.1.0", | ||
| "zod": "^3.25.76" | ||
| }, | ||
| "homepage": "https://github.com/traceloop/openllmetry-js/tree/main/packages/instrumentation-mcp" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| const dts = require("rollup-plugin-dts"); | ||
| const typescript = require("@rollup/plugin-typescript"); | ||
| const json = require("@rollup/plugin-json"); | ||
|
|
||
| const name = require("./package.json").main.replace(/\.js$/, ""); | ||
|
|
||
| const bundle = (config) => ({ | ||
| ...config, | ||
| input: "src/index.ts", | ||
| external: (id) => !/^[./]/.test(id), | ||
| }); | ||
|
|
||
| exports.default = [ | ||
| bundle({ | ||
| plugins: [ | ||
| typescript.default({ exclude: ["test/**/*", "tests/**/*"] }), | ||
| json.default(), | ||
| ], | ||
| output: [ | ||
| { | ||
| file: `${name}.js`, | ||
| format: "cjs", | ||
| sourcemap: true, | ||
| }, | ||
| { | ||
| file: `${name}.mjs`, | ||
| format: "es", | ||
| sourcemap: true, | ||
| }, | ||
| ], | ||
| }), | ||
| bundle({ | ||
| plugins: [dts.default({ exclude: ["test/**/*", "tests/**/*"] })], | ||
| output: { | ||
| file: `${name}.d.ts`, | ||
| format: "es", | ||
| }, | ||
| }), | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| * Copyright Traceloop | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| export { McpInstrumentation } from "./instrumentation"; | ||
| export { McpInstrumentationConfig } from "./types"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Verify MCP SDK version compatibility.
Ensure that version
^1.0.4of@modelcontextprotocol/sdkis the latest stable version and compatible with the instrumentation implementation.🌐 Web query:
💡 Result:
The latest stable version is 1.22.0 (released Nov 13, 2025). [1][2]
Sources:
[1] GitHub releases for modelcontextprotocol/typescript-sdk.
[2] ReleaseAlert listing for @modelcontextprotocol/sdk.
🌐 Web query:
💡 Result:
Summary of notable breaking or migration-relevant changes from @modelcontextprotocol/sdk v1.0.4 → v1.22.0 and migration steps
Key changes you must review and adapt for:
Practical migration steps
References
If you want, I can:
Length of output: 239
🏁 Script executed:
Length of output: 27425
🏁 Script executed:
Length of output: 305
🏁 Script executed:
Length of output: 540
🏁 Script executed:
Length of output: 1633
Update
@modelcontextprotocol/sdkdevDependency to a more recent version.The registerTool ZodType support added in v1.22.0 is backwards-compatible with existing plain-object schema definitions, so the current test code remains compatible. However, the pinned version
^1.0.4in devDependencies is significantly outdated. Version 1.22.0 (released Nov 13, 2025) includes multiple improvements including request payload decoupling, TypeScript typecheck fixes, and stricter tool name format validation. While the instrumentation's version constraint (>=1.0.0) remains broad, updating to^1.22.0or a recent stable version will ensure tests run against the latest SDK with latest bugfixes and features. No code changes are required since the test patterns usingregisterToolwith plain descriptive objects remain compatible.🤖 Prompt for AI Agents