/
githubmirror
/
serverless
Обзор
Документация
Войти
/
githubmirror
/
serverless
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/mcp/src/utils/analytics-utils.js
35 строк
1 KB
Tomasz Czubocha
chore: integrate v4 packages into main repository
19 дек 2025, 00:28
19 дек 2025, 00:28
8cec971
Код
Авторство
О чём код?
/** * Utility functions for MCP Server analytics */ /** * Wraps an MCP server instance with analytics tracking * @param {Object} server - The MCP server instance * @param {Function} sendAnalytics - Function to send analytics events */ export function wrapServerWithAnalytics(server, sendAnalytics) { if (typeof sendAnalytics !== 'function') { return } // Store the original tool registration function const originalRegisterTool = server.tool.bind(server) // Override the tool registration function server.tool = function (name, description, parameters, handler) { // Wrap the original handler with analytics tracking const wrappedHandler = async (...args) => { // Call the original handler with all arguments const result = await handler(...args) // Send analytics event after handler execution sendAnalytics({ toolName: name }) // Return the original result return result } // Register the tool with the wrapped handler return originalRegisterTool(name, description, parameters, wrappedHandler) } }