@@ -447,6 +447,83 @@ const handler = async (req: Request) => {
447447 } ;
448448 }
449449 ) ;
450+
451+ // Tool 6: Trigger Security Events (for testing)
452+ server . tool (
453+ "trigger_security_events" ,
454+ "Triggers various security events for testing the security monitoring system" ,
455+ {
456+ eventType : z . enum ( [
457+ "AUTH_FAILURE" ,
458+ "INVALID_TOKEN" ,
459+ "SUSPICIOUS_ACTIVITY" ,
460+ "RATE_LIMIT_EXCEEDED" ,
461+ "UNAUTHORIZED_ACCESS" ,
462+ "TOKEN_REUSE" ,
463+ "UNUSUAL_LOCATION" ,
464+ "PRIVILEGE_ESCALATION" ,
465+ "MALFORMED_REQUEST" ,
466+ "BRUTE_FORCE_ATTEMPT"
467+ ] ) . describe ( "Type of security event to trigger" ) ,
468+ count : z . number ( ) . int ( ) . min ( 1 ) . max ( 10 ) . default ( 1 ) . describe ( "Number of events to generate (1-10)" ) ,
469+ severity : z . enum ( [ "low" , "medium" , "high" , "critical" ] ) . optional ( ) . describe ( "Override severity level" )
470+ } ,
471+ async ( { eventType, count, severity } ) => {
472+ try {
473+ // Convert event type to lowercase format expected by logSecurityEvent
474+ const legacyEventType = eventType . toLowerCase ( ) . replace ( / _ / g, '_' ) ;
475+
476+ // Log security event through the existing security monitoring system
477+ await logSecurityEvent (
478+ nextReq ,
479+ legacyEventType ,
480+ `Test ${ eventType } event triggered via MCP tool (count: ${ count } )` ,
481+ accessToken ?. clientId
482+ ) ;
483+
484+ // Also trigger through the test API for batch generation
485+ const host = nextReq . headers . get ( 'host' ) ;
486+ const protocol = process . env . NODE_ENV === 'production' ? 'https' : 'http' ;
487+ const baseUrl = `${ protocol } ://${ host } ` ;
488+
489+ const response = await fetch ( `${ baseUrl } /api/test/security-events` , {
490+ method : 'POST' ,
491+ headers : {
492+ 'Content-Type' : 'application/json' ,
493+ } ,
494+ body : JSON . stringify ( {
495+ eventType,
496+ count : count - 1 , // Subtract 1 since we already logged one above
497+ severity
498+ } )
499+ } ) ;
500+
501+ let apiResult = "API call failed" ;
502+ if ( response . ok ) {
503+ const result = await response . json ( ) ;
504+ apiResult = result . message || "Additional events generated successfully" ;
505+ }
506+
507+ return {
508+ content : [
509+ {
510+ type : "text" ,
511+ text : `🚨 Security Event Test Triggered\n\nEvent Type: ${ eventType } \nCount: ${ count } \nSeverity: ${ severity || 'default' } \n\nEvents have been generated for testing the security monitoring system.\n\nAPI Response: ${ apiResult } \n\n⚠️ This tool is for testing purposes only. Check the analytics dashboard to see the generated events.` ,
512+ } ,
513+ ] ,
514+ } ;
515+ } catch ( error ) {
516+ return {
517+ content : [
518+ {
519+ type : "text" ,
520+ text : `❌ Failed to trigger security events: ${ error instanceof Error ? error . message : 'Unknown error' } ` ,
521+ } ,
522+ ] ,
523+ } ;
524+ }
525+ }
526+ ) ;
450527 } ,
451528 {
452529 // Optionally add server capabilities here
0 commit comments