-
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
Changes from 11 commits
f72c0ef
646d260
94d74ff
7516255
a49e5cc
fc4eb3d
f86b600
0ffd6b5
0503b89
9b9ea4b
fea22f7
c288fc9
c44b472
36a3c4e
dda8013
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| dist | ||
| node_modules |
| 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 | ||
| 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: {}, | ||
| }, | ||
| ]; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| { | ||
| "name": "@traceloop/instrumentation-mcp", | ||
| "version": "0.20.0", | ||
| "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", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify MCP SDK version compatibility. Ensure that version 🌐 Web query: 💡 Result: The latest stable version is 1.22.0 (released Nov 13, 2025). [1][2] Sources: 🌐 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: #!/bin/bash
# Search for MCP SDK imports and API usage in instrumentation-mcp
rg "@modelcontextprotocol/sdk|registerTool|Client|Server|Tool" packages/instrumentation-mcp -n -C3 --type ts --type jsLength of output: 27425 🏁 Script executed: #!/bin/bash
# Check the main entry point and structure of instrumentation-mcp
cat packages/instrumentation-mcp/package.json | grep -A5 -B5 '"main"\|"exports"'Length of output: 305 🏁 Script executed: #!/bin/bash
# Examine the instrumentation-mcp implementation files
ls -la packages/instrumentation-mcp/src/ 2>/dev/null || echo "src directory not found, checking structure:"
find packages/instrumentation-mcp -maxdepth 3 -type f -name "*.ts" -o -name "*.js" | grep -v node_modules | head -15Length of output: 540 🏁 Script executed: #!/bin/bash
# Look for any version constraints or compatibility notes in the package
cat packages/instrumentation-mcp/package.jsonLength of output: 1633 Update 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 🤖 Prompt for AI Agents |
||
| "@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" | ||
| } | ||
| 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", | ||
| }, | ||
| }), | ||
| ]; |
| 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"; |
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.
Fix license badge link to point at LICENSE URL
The Apache license badge currently links to the image itself instead of the LICENSE page:
Consider updating it to use the defined
license-urlreference:🤖 Prompt for AI Agents