MCPcopy Index your code
hub / github.com/serverless/serverless / wrapServerWithAnalytics

Function wrapServerWithAnalytics

packages/mcp/src/utils/analytics-utils.js:10–35  ·  view source on GitHub ↗
(server, sendAnalytics)

Source from the content-addressed store, hash-verified

8 * @param {Function} sendAnalytics - Function to send analytics events
9 */
10export function wrapServerWithAnalytics(server, sendAnalytics) {
11 if (typeof sendAnalytics !== 'function') {
12 return
13 }
14
15 // Store the original tool registration function
16 const originalRegisterTool = server.tool.bind(server)
17
18 // Override the tool registration function
19 server.tool = function (name, description, parameters, handler) {
20 // Wrap the original handler with analytics tracking
21 const wrappedHandler = async (...args) => {
22 // Call the original handler with all arguments
23 const result = await handler(...args)
24
25 // Send analytics event after handler execution
26 sendAnalytics({ toolName: name })
27
28 // Return the original result
29 return result
30 }
31
32 // Register the tool with the wrapped handler
33 return originalRegisterTool(name, description, parameters, wrappedHandler)
34 }
35}

Callers 2

startSseServerFunction · 0.90
startStdioServerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…