@@ -15,13 +15,16 @@ interface MCPEventPayload {
15
15
} ;
16
16
}
17
17
18
- export function trackMCPEvent (
18
+ export function trackMCP (
19
19
toolName : string ,
20
20
clientInfo : { name ?: string ; version ?: string } ,
21
+ error ?: unknown
21
22
) : void {
22
23
const instrumentationEndpoint = "https://api.browserstack.com/sdk/v1/event" ;
23
-
24
+ const isSuccess = ! error ;
24
25
const mcpClient = clientInfo ?. name || "unknown" ;
26
+
27
+ // Log client information
25
28
if ( clientInfo ?. name ) {
26
29
logger . info (
27
30
`Client connected: ${ clientInfo . name } (version: ${ clientInfo . version } )` ,
@@ -36,60 +39,15 @@ export function trackMCPEvent(
36
39
mcp_version : packageJson . version ,
37
40
tool_name : toolName ,
38
41
mcp_client : mcpClient ,
39
- success : true ,
42
+ success : isSuccess ,
40
43
} ,
41
44
} ;
42
45
43
- axios
44
- . post ( instrumentationEndpoint , event , {
45
- headers : {
46
- "Content-Type" : "application/json" ,
47
- Authorization : `Basic ${ Buffer . from (
48
- `${ config . browserstackUsername } :${ config . browserstackAccessKey } ` ,
49
- ) . toString ( "base64" ) } `,
50
- } ,
51
- timeout : 2000 ,
52
- } )
53
- . then ( ( response ) => {
54
- logger . info ( "MCP event tracked successfully" , {
55
- toolName,
56
- response,
57
- } ) ;
58
- } )
59
- . catch ( ( error : unknown ) => {
60
- logger . warn (
61
- `Failed to track MCP event: ${ error instanceof Error ? error . message : String ( error ) } ` ,
62
- {
63
- toolName,
64
- } ,
65
- ) ;
66
- } ) ;
67
- }
68
-
69
- export function trackMCPFailure (
70
- toolName : string ,
71
- error : unknown ,
72
- clientInfo : { name ?: string ; version ?: string } ,
73
- ) : void {
74
- const instrumentationEndpoint = "https://api.browserstack.com/sdk/v1/event" ;
75
-
76
- const mcpClient = clientInfo ?. name || "unknown" ;
77
- const errorMessage = error instanceof Error ? error . message : String ( error ) ;
78
- const errorType = error instanceof Error ? error . constructor . name : "Unknown" ;
79
-
80
- logger . error ( `Tool failure: ${ toolName } - ${ errorMessage } ` , { errorType } ) ;
81
-
82
- const event : MCPEventPayload = {
83
- event_type : "MCPInstrumentation" ,
84
- event_properties : {
85
- mcp_version : packageJson . version ,
86
- tool_name : toolName ,
87
- mcp_client : mcpClient ,
88
- success : false ,
89
- error_message : errorMessage ,
90
- error_type : errorType ,
91
- } ,
92
- } ;
46
+ // Add error details if applicable
47
+ if ( error ) {
48
+ event . event_properties . error_message = error instanceof Error ? error . message : String ( error ) ;
49
+ event . event_properties . error_type = error instanceof Error ? error . constructor . name : "Unknown" ;
50
+ }
93
51
94
52
axios
95
53
. post ( instrumentationEndpoint , event , {
@@ -102,17 +60,17 @@ export function trackMCPFailure(
102
60
timeout : 2000 ,
103
61
} )
104
62
. then ( ( response ) => {
105
- logger . info ( " MCP failure event tracked successfully" , {
63
+ logger . info ( ` MCP ${ isSuccess ? 'event' : ' failure event' } tracked successfully` , {
106
64
toolName,
107
65
response,
108
66
} ) ;
109
67
} )
110
68
. catch ( ( error : unknown ) => {
111
69
logger . warn (
112
- `Failed to track MCP failure event: ${ error instanceof Error ? error . message : String ( error ) } ` ,
70
+ `Failed to track MCP ${ isSuccess ? 'event' : ' failure event' } : ${ error instanceof Error ? error . message : String ( error ) } ` ,
113
71
{
114
72
toolName,
115
73
} ,
116
74
) ;
117
75
} ) ;
118
- }
76
+ }
0 commit comments