22 * Model Context Protocol (MCP) server for Apify Actors
33 */
44
5- import * as crypto from 'node:crypto' ;
6-
75import type { Client } from '@modelcontextprotocol/sdk/client/index.js' ;
86import { Server } from '@modelcontextprotocol/sdk/server/index.js' ;
97import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js' ;
@@ -761,13 +759,13 @@ Please verify the tool name and ensure the tool is properly registered.`;
761759 * Calculates execution time, sets final status, and sends the telemetry event.
762760 *
763761 * @param telemetryData - Telemetry data to finalize and track (null if telemetry is disabled)
764- * @param userId - Apify user ID
762+ * @param userId - Apify user ID (string or null if not available)
765763 * @param startTime - Timestamp when the tool call started
766764 * @param toolStatus - Final status of the tool call ('succeeded', 'failed', or 'aborted')
767765 */
768766 private finalizeAndTrackTelemetry (
769767 telemetryData : ToolCallTelemetryProperties | null ,
770- userId : string ,
768+ userId : string | null ,
771769 startTime : number ,
772770 toolStatus : 'succeeded' | 'failed' | 'aborted' ,
773771 ) : void {
@@ -789,9 +787,9 @@ Please verify the tool name and ensure the tool is properly registered.`;
789787 */
790788 private async prepareTelemetryData (
791789 tool : HelperTool | ActorTool | ActorMcpTool , mcpSessionId : string | undefined , apifyToken : string ,
792- ) : Promise < { telemetryData : ToolCallTelemetryProperties | null ; userId : string } > {
790+ ) : Promise < { telemetryData : ToolCallTelemetryProperties | null ; userId : string | null } > {
793791 if ( this . options . telemetry ?. enabled !== true ) {
794- return { telemetryData : null , userId : crypto . randomUUID ( ) } ;
792+ return { telemetryData : null , userId : null } ;
795793 }
796794
797795 const toolFullName = tool . type === 'actor' ? tool . actorFullName : tool . name ;
@@ -813,11 +811,6 @@ Please verify the tool name and ensure the tool is properly registered.`;
813811 userId = await getUserIdFromTokenCached ( apifyToken , apifyClient ) ;
814812 log . debug ( 'Telemetry: fetched userId' , { userId } ) ;
815813 }
816- if ( ! userId ) {
817- userId = crypto . randomUUID ( ) ;
818- log . debug ( 'Telemetry: using random userId' , { userId } ) ;
819- }
820-
821814 const capabilities = this . options . initializeRequestData ?. params ?. capabilities ;
822815 const params = this . options . initializeRequestData ?. params as InitializeRequest [ 'params' ] ;
823816 const telemetryData : ToolCallTelemetryProperties = {
0 commit comments