11import { isPromise } from 'node:util/types'
22import { type ServerOptions } from '@modelcontextprotocol/sdk/server/index.js'
3- import { McpServer , type ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js'
4-
3+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
54import { type ZodRawShape } from 'zod'
65
76import { MetricsTracker , SessionStart , ToolCall } from '@repo/mcp-observability'
87
98import { McpError } from './mcp-error'
109
10+ import type { ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js'
11+
1112export class CloudflareMCPServer extends McpServer {
1213 private metrics
1314
1415 constructor (
15- private userId : string | undefined ,
16+ userId : string | undefined ,
1617 wae : AnalyticsEngineDataset ,
1718 serverInfo : {
1819 [ x : string ] : unknown
@@ -49,30 +50,30 @@ export class CloudflareMCPServer extends McpServer {
4950 // promise succeeds
5051 this . metrics . logEvent (
5152 new ToolCall ( {
52- userId,
5353 toolName : name ,
54+ userId,
5455 } )
5556 )
5657 return r
5758 } )
5859 . catch ( ( e : any ) => {
5960 // promise throws
60- this . trackToolCallError ( e , name )
61+ this . trackToolCallError ( e , name , userId )
6162 throw e
6263 } )
6364 } else {
6465 // non-promise succeeds
6566 this . metrics . logEvent (
6667 new ToolCall ( {
67- userId,
6868 toolName : name ,
69+ userId,
6970 } )
7071 )
7172 return toolCall
7273 }
7374 } catch ( e : any ) {
7475 // non-promise throws
75- this . trackToolCallError ( e , name )
76+ this . trackToolCallError ( e , name , userId )
7677 throw e
7778 }
7879 }
@@ -83,15 +84,15 @@ export class CloudflareMCPServer extends McpServer {
8384 }
8485 }
8586
86- private trackToolCallError ( e : any , toolName : string ) {
87+ private trackToolCallError ( e : any , toolName : string , userId ?: string ) {
8788 let errorCode = - 1
8889 if ( e instanceof McpError ) {
8990 errorCode = e . code
9091 }
9192 this . metrics . logEvent (
9293 new ToolCall ( {
9394 toolName,
94- userId : this . userId ,
95+ userId : userId ,
9596 errorCode : errorCode ,
9697 } )
9798 )
0 commit comments