Skip to main content
Glama

cloudtrail_find_anomalies

Detect security anomalies in CloudTrail logs by identifying non-AWS IP addresses, unusual API calls, role assumptions, and data exfiltration indicators through automated log analysis.

Instructions

Find anomalies in CloudTrail logs: non-AWS IPs, unusual API calls, role assumptions.

Returns: {"non_aws_ips": [str], "unusual_events": [str], "role_assumptions": [str], "data_exfil_indicators": [str]}.

Side effects: Read-only file analysis.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
log_dirYesDirectory containing CloudTrail JSON log files

Implementation Reference

  • The handler function for 'cloudtrail_find_anomalies' tool, which performs anomaly detection on CloudTrail logs using jq for shell-based log processing.
      "cloudtrail_find_anomalies",
      "Find anomalies in CloudTrail logs: non-AWS IPs, unusual API calls, role assumptions.\n\nReturns: {\"non_aws_ips\": [str], \"unusual_events\": [str], \"role_assumptions\": [str], \"data_exfil_indicators\": [str]}.\n\nSide effects: Read-only file analysis.",
      {
        log_dir: z
          .string()
          .describe("Directory containing CloudTrail JSON log files"),
      },
      async ({ log_dir }) => {
        requireTool("jq");
    
        const logPath = resolve(log_dir);
        if (!existsSync(logPath) || !statSync(logPath).isDirectory()) {
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify({ error: `Directory not found: ${logPath}` }),
              },
            ],
          };
        }
    
        // All unique source IPs
        const allIps = await runShell(
          `cat '${logPath}'/*.json 2>/dev/null | jq -r '.Records[].sourceIPAddress' 2>/dev/null | sort -u`,
          { timeout: 30 }
        );
    
        // Non-AWS IPs (not matching AWS internal patterns)
        const nonAws: string[] = [];
        for (const ip of parseLines(allIps.stdout)) {
          const trimmed = ip.trim();
          if (
            trimmed &&
            !trimmed.endsWith(".amazonaws.com") &&
            !trimmed.startsWith("AWS Internal")
          ) {
            nonAws.push(trimmed);
          }
        }
    
        // Role assumption events (lateral movement)
        const assumeRole = await runShell(
          `cat '${logPath}'/*.json 2>/dev/null | jq -r '.Records[] | select(.eventName == "AssumeRole") | [.eventTime, .sourceIPAddress, .requestParameters.roleArn // "unknown"] | @tsv' 2>/dev/null | head -20`,
          { timeout: 30 }
        );
    
        // Sensitive API calls
        const sensitiveEvents = [
          "CreateUser",
          "CreateAccessKey",
          "PutUserPolicy",
          "AttachUserPolicy",
          "CreateLoginProfile",
          "UpdateLoginProfile",
          "DeleteTrail",
          "StopLogging",
          "PutBucketPolicy",
          "PutBucketAcl",
          "GetObject",
          "PutObject",
          "CreateKeyPair",
          "RunInstances",
          "AuthorizeSecurityGroupIngress",
        ];
        const sensitiveFilter = sensitiveEvents
          .map((e) => `.eventName == "${e}"`)
          .join(" or ");
        const sensitive = await runShell(
          `cat '${logPath}'/*.json 2>/dev/null | jq -r '.Records[] | select(${sensitiveFilter}) | [.eventTime, .eventName, .sourceIPAddress, .userIdentity.userName // .userIdentity.principalId] | @tsv' 2>/dev/null | head -30`,
          { timeout: 30 }
        );
    
        // Data exfiltration indicators (GetObject, large downloads)
        const exfil = await runShell(
          `cat '${logPath}'/*.json 2>/dev/null | jq -r '.Records[] | select(.eventName == "GetObject" or .eventName == "ListBuckets" or .eventName == "ListObjects") | [.eventTime, .eventName, .sourceIPAddress, .requestParameters.bucketName // "unknown"] | @tsv' 2>/dev/null | head -30`,
          { timeout: 30 }
        );
    
        const result = {
          non_aws_source_ips: nonAws.slice(0, 20),
          role_assumptions: parseLines(assumeRole.stdout).slice(0, 20),
          sensitive_api_calls: parseLines(sensitive.stdout).slice(0, 30),
          data_access_events: parseLines(exfil.stdout).slice(0, 30),
        };
    
        return { content: [{ type: "text", text: JSON.stringify(result) }] };
      }
    );
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It successfully adds valuable context: it specifies the return format with detailed keys, explicitly states 'Read-only file analysis' (indicating no destructive operations), and mentions it analyzes files in a directory. However, it doesn't cover error conditions, performance characteristics, or authentication requirements.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately concise with three sentences that each serve distinct purposes: stating the tool's function, specifying the return format, and declaring side effects. It's front-loaded with the core purpose. Minor improvement could be made by integrating the return format more naturally into the first sentence.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (anomaly detection in logs), no annotations, no output schema, and 100% schema coverage, the description does a reasonably complete job. It explains what the tool does, what it returns, and its safety profile. However, it lacks information about error handling, performance expectations, and how it differs from the sibling 'cloudtrail_analyze' tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100% (the single parameter 'log_dir' has a clear description in the schema). The tool description doesn't add any additional parameter information beyond what's already in the schema. According to guidelines, when schema coverage is high (>80%), the baseline score is 3 even with no param info in the description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Find anomalies in CloudTrail logs' with specific examples (non-AWS IPs, unusual API calls, role assumptions). It uses a specific verb ('Find') and resource ('CloudTrail logs'), but doesn't explicitly differentiate from sibling 'cloudtrail_analyze' which might have overlapping functionality.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided about when to use this tool versus alternatives. The description doesn't mention the sibling 'cloudtrail_analyze' tool or explain what distinguishes this anomaly-finding tool from general CloudTrail analysis. There's no context about prerequisites or when-not-to-use scenarios.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/operantlabs/operant-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server