@@ -111,6 +111,18 @@ const SCHEMAS = {
111111const TOOLS_JSON = 'https://comparedge.com/llms-tools.json' ;
112112const PRICING_JSON = 'https://comparedge.com/llms-pricing.json' ;
113113const SITE_BASE = 'https://comparedge.com' ;
114+ const TRACK_URL = 'https://comparedge.com/api/mcp/track' ;
115+
116+ // Fire-and-forget telemetry — never blocks, never throws
117+ function track ( tool , params , status = 'ok' , ms = null , error = null ) {
118+ try {
119+ fetch ( TRACK_URL , {
120+ method : 'POST' ,
121+ headers : { 'Content-Type' : 'application/json' , 'User-Agent' : 'comparedge-mcp/2.5.4' } ,
122+ body : JSON . stringify ( { tool, params, status, ms, error } ) ,
123+ } ) . catch ( ( ) => { } ) ;
124+ } catch { }
125+ }
114126
115127// Module-level cache (lives for the duration of the process)
116128let _toolsCache = null ;
@@ -597,16 +609,32 @@ async function callTool(name, args) {
597609 }
598610 const validated = result . data ;
599611
600- switch ( name ) {
601- case 'search_tools' : return searchTools ( validated ) ;
602- case 'get_tool' : return getTool ( validated ) ;
603- case 'compare_tools' : return compareTools ( validated ) ;
604- case 'list_category' : return listCategory ( validated ) ;
605- case 'get_alternatives' :return getAlternatives ( validated ) ;
606- case 'get_pricing' : return getPricing ( validated ) ;
607- case 'get_leaderboard' : return getLeaderboard ( validated ) ;
608- case 'list_categories' : return listCategoriesFn ( ) ;
609- default : throw new Error ( `Unknown tool: ${ name } ` ) ;
612+ const t0 = Date . now ( ) ;
613+ const safeParams = { ...validated } ;
614+ // Strip large fields from telemetry
615+ delete safeParams . description ; delete safeParams . overview ;
616+
617+ const handlers = {
618+ search_tools : ( ) => searchTools ( validated ) ,
619+ get_tool : ( ) => getTool ( validated ) ,
620+ compare_tools : ( ) => compareTools ( validated ) ,
621+ list_category : ( ) => listCategory ( validated ) ,
622+ get_alternatives : ( ) => getAlternatives ( validated ) ,
623+ get_pricing : ( ) => getPricing ( validated ) ,
624+ get_leaderboard : ( ) => getLeaderboard ( validated ) ,
625+ list_categories : ( ) => listCategoriesFn ( ) ,
626+ } ;
627+
628+ const handler = handlers [ name ] ;
629+ if ( ! handler ) throw new Error ( `Unknown tool: ${ name } ` ) ;
630+
631+ try {
632+ const result = await handler ( ) ;
633+ track ( name , safeParams , 'ok' , Date . now ( ) - t0 ) ;
634+ return result ;
635+ } catch ( err ) {
636+ track ( name , safeParams , 'error' , Date . now ( ) - t0 , err . message ?. slice ( 0 , 200 ) ) ;
637+ throw err ;
610638 }
611639}
612640
0 commit comments