import { z } from 'zod'; import { TimeStringSchema } from '../utils/validation.js'; /** * Schema for CloudWatch Log Groups tool parameters */ export const CloudWatchLogGroupsSchema = z.object({ prefix: z.string() .optional() .describe('Filter log groups by prefix'), limit: z.number() .int() .positive() .max(1000) .optional() .describe('Maximum number of log groups to return') }); /** * Schema for CloudWatch Logs tool parameters */ export const CloudWatchLogsSchema = z.object({ logGroupName: z.string() .min(1, 'Log group name is required') .describe('The name of the log group to query'), logStreamName: z.string() .optional() .describe('Optional specific log stream name'), filterPattern: z.string() .optional() .describe('Filter pattern to apply to logs'), startTime: TimeStringSchema .optional() .describe('Start time for log retrieval (ISO format or relative like -30m, -1h, -1d)'), endTime: TimeStringSchema .optional() .describe('End time for log retrieval (ISO format)'), limit: z.number() .int() .positive() .max(10000) .optional() .describe('Maximum number of log events to return') }) .refine( (data) => { // If both startTime and endTime are provided, make sure startTime is before endTime if (data.startTime && data.endTime) { const startDate = new Date(data.startTime); const endDate = new Date(data.endTime); return startDate < endDate; } return true; }, { message: 'Start time must be before end time', path: ['startTime'] } ); /** * Schema for CloudTrail Events tool parameters */ export const CloudTrailEventsSchema = z.object({ eventName: z.string() .optional() .describe('Filter events by name (e.g., "CreateFunction", "InvokeFunction")'), username: z.string() .optional() .describe('Filter events by AWS username'), resourceName: z.string() .optional() .describe('Filter events by resource name'), resourceType: z.string() .optional() .describe('Filter events by resource type'), startTime: TimeStringSchema .optional() .describe('Start time for event retrieval (ISO format or relative like -30m, -1h, -1d)'), endTime: TimeStringSchema .optional() .describe('End time for event retrieval (ISO format)'), limit: z.number() .int() .positive() .max(1000) .optional() .describe('Maximum number of events to return') }) .refine( (data) => { // If both startTime and endTime are provided, make sure startTime is before endTime if (data.startTime && data.endTime) { const startDate = new Date(data.startTime); const endDate = new Date(data.endTime); return startDate < endDate; } return true; }, { message: 'Start time must be before end time', path: ['startTime'] } ) .refine( (data) => { // At least one filter should be provided return !!(data.eventName || data.username || data.resourceName || data.resourceType); }, { message: 'At least one filter criteria should be provided', path: ['eventName'] } ); /** * Type for CloudWatch Log Groups tool parameters */ export type CloudWatchLogGroupsParams = z.infer; /** * Type for CloudWatch Logs tool parameters */ export type CloudWatchLogsParams = z.infer; /** * Type for CloudTrail Events tool parameters */ export type CloudTrailEventsParams = z.infer;