@@ -25,32 +25,144 @@ const endParam = z
2525 . optional ( )
2626 . describe ( 'ISO 8601 datetime string marking end of search range. Defaults to now if omitted.' )
2727
28+ // Boolean flags
29+ const actionLogParam = z
30+ . boolean ( )
31+ . optional ( )
32+ . describe ( 'Include the message action log in response when true.' )
33+
34+ const detectionsOnlyParam = z
35+ . boolean ( )
36+ . optional ( )
37+ . describe ( 'When true, results include only detection information.' )
38+
39+ // Simple string params
40+ const alertIdParam = z . string ( ) . optional ( ) . describe ( 'Filter by alert_id' )
41+ const domainParam = z . string ( ) . optional ( ) . describe ( 'Filter by sender domain' )
42+ const messageIdParam = z . string ( ) . optional ( ) . describe ( 'Filter by message_id' )
43+ const metricParam = z . string ( ) . optional ( ) . describe ( 'Metric filter (reserved)' )
44+ const recipientParam = z . string ( ) . optional ( ) . describe ( 'Filter by recipient email' )
45+ const senderParam = z . string ( ) . optional ( ) . describe ( 'Filter by sender email' )
46+
47+ // Enumerations
48+ const finalDispositionParam = z
49+ . enum ( [
50+ 'MALICIOUS' ,
51+ 'MALICIOUS-BEC' ,
52+ 'SUSPICIOUS' ,
53+ 'SPOOF' ,
54+ 'BENIGN' ,
55+ 'UNKNOWN' ,
56+ ] )
57+ . optional ( )
58+ . describe ( 'Filter by final disposition' )
59+
60+ const messageActionParam = z
61+ . enum ( [ 'PREVIEW' , 'QUARANTINE_RELEASED' , 'MOVED' ] )
62+ . optional ( )
63+ . describe ( 'Filter by message action' )
64+
65+ // Pagination
66+ const pageParam = z . number ( ) . int ( ) . positive ( ) . optional ( ) . describe ( 'Result page number' )
67+ const perPageParam = z
68+ . number ( )
69+ . int ( )
70+ . positive ( )
71+ . max ( 100 )
72+ . optional ( )
73+ . describe ( 'Results per page (max 100)' )
74+
2875export function registerEmailSecurityTools ( agent : EmailSecurityMCP ) {
2976 agent . server . tool (
3077 'email_security_search_messages' ,
3178 'Search Cloudflare Email Security messages via Investigate list endpoint' ,
32- { query : searchQueryParam , start : startParam , end : endParam } ,
79+ {
80+ query : searchQueryParam ,
81+ start : startParam ,
82+ end : endParam ,
83+ actionLog : actionLogParam ,
84+ alertId : alertIdParam ,
85+ detectionsOnly : detectionsOnlyParam ,
86+ domain : domainParam ,
87+ finalDisposition : finalDispositionParam ,
88+ messageAction : messageActionParam ,
89+ messageId : messageIdParam ,
90+ metric : metricParam ,
91+ page : pageParam ,
92+ perPage : perPageParam ,
93+ recipient : recipientParam ,
94+ sender : senderParam ,
95+ } ,
3396 withAccountCheck < {
3497 query ?: string
3598 start ?: string
3699 end ?: string
100+ actionLog ?: boolean
101+ alertId ?: string
102+ detectionsOnly ?: boolean
103+ domain ?: string
104+ finalDisposition ?: string
105+ messageAction ?: string
106+ messageId ?: string
107+ metric ?: string
108+ page ?: number
109+ perPage ?: number
110+ recipient ?: string
111+ sender ?: string
37112 } > (
38113 agent ,
39- async ( { query, start, end, accountId, apiToken } : {
114+ async ( {
115+ query,
116+ start,
117+ end,
118+ actionLog,
119+ alertId,
120+ detectionsOnly,
121+ domain,
122+ finalDisposition,
123+ messageAction,
124+ messageId,
125+ metric,
126+ page,
127+ perPage,
128+ recipient,
129+ sender,
130+ } : {
40131 query ?: string
41132 start ?: string
42133 end ?: string
43- accountId : string | null
44- apiToken : string
134+ actionLog ?: boolean
135+ alertId ?: string
136+ detectionsOnly ?: boolean
137+ domain ?: string
138+ finalDisposition ?: string
139+ messageAction ?: string
140+ messageId ?: string
141+ metric ?: string
142+ page ?: number
143+ perPage ?: number
144+ recipient ?: string
145+ sender ?: string
45146 } ) => {
46- const client = getCloudflareClient ( apiToken )
147+ const accountId = await agent . getActiveAccountId ( )
148+ const client = getCloudflareClient ( agent . props . accessToken )
47149
48150 const params : any = { account_id : accountId }
49151 if ( query ) params . query = query
50152 if ( start ) params . start = start
51153 if ( end ) params . end = end
52- // Limit page result count per_page to PAGE_SIZE
53- params . per_page = PAGE_SIZE
154+ if ( actionLog !== undefined ) params . action_log = actionLog
155+ if ( alertId ) params . alert_id = alertId
156+ if ( detectionsOnly !== undefined ) params . detections_only = detectionsOnly
157+ if ( domain ) params . domain = domain
158+ if ( finalDisposition ) params . final_disposition = finalDisposition
159+ if ( messageAction ) params . message_action = messageAction
160+ if ( messageId ) params . message_id = messageId
161+ if ( metric ) params . metric = metric
162+ if ( page ) params . page = page
163+ params . per_page = perPage ?? PAGE_SIZE
164+ if ( recipient ) params . recipient = recipient
165+ if ( sender ) params . sender = sender
54166
55167 const messages : any [ ] = [ ]
56168 try {
0 commit comments