Skip to main content
Glama

search-logs

Search and filter Datadog logs to investigate application issues using time ranges, query terms, and sorting options.

Instructions

Search logs in Datadog with advanced filtering options. Use filter.query for search terms (e.g., 'service:web-app status:error'), from/to for time ranges (e.g., 'now-15m', 'now'), and sort to order results. Essential for investigating application issues.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filterNo
sortNo
pageNo
limitNo

Implementation Reference

  • The core handler function that performs the POST request to Datadog's /api/v2/logs/events/search endpoint using fetch, handles authentication, applies limits, and processes errors.
    execute: async (params: SearchLogsParams) => {
      try {
        const {
          apiKey = process.env.DD_API_KEY,
          appKey = process.env.DD_APP_KEY,
          filter,
          sort,
          page,
          limit
        } = params;
    
        if (!apiKey || !appKey) {
          throw new Error("API Key and App Key are required");
        }
    
        const apiInstance = new v2.LogsApi(configuration);
    
        // Use a more flexible approach with POST
        // Create the search request based on API docs
        const body = {
          filter: filter,
          sort: sort,
          page: page
        };
    
        // Use DD_LOGS_SITE environment variable instead of DD_SITE
        const apiUrl = `https://${
          process.env.DD_LOGS_SITE || "datadoghq.com"
        }/api/v2/logs/events/search`;
    
        const headers = {
          "Content-Type": "application/json",
          "DD-API-KEY": apiKey,
          "DD-APPLICATION-KEY": appKey
        };
    
        const response = await fetch(apiUrl, {
          method: "POST",
          headers: headers,
          body: JSON.stringify(body)
        });
    
        if (!response.ok) {
          throw {
            status: response.status,
            message: await response.text()
          };
        }
    
        const data = await response.json();
    
        // Apply client-side limit if specified
        if (limit && data.data && data.data.length > limit) {
          data.data = data.data.slice(0, limit);
        }
    
        return data;
      } catch (error: any) {
        if (error.status === 403) {
          console.error(
            "Authorization failed (403 Forbidden): Check that your API key and Application key are valid and have sufficient permissions to access logs."
          );
          throw new Error(
            "Datadog API authorization failed. Please verify your API and Application keys have the correct permissions."
          );
        } else {
          console.error("Error searching logs:", error);
          throw error;
        }
      }
    }
  • Zod schema defining the input parameters for the search-logs tool, including filter query, time ranges, sorting, pagination, and limit.
      filter: z
        .object({
          query: z.string().optional(),
          from: z.string().optional(),
          to: z.string().optional(),
          indexes: z.array(z.string()).optional()
        })
        .optional(),
      sort: z.string().optional(),
      page: z
        .object({
          limit: z.number().optional(),
          cursor: z.string().optional()
        })
        .optional(),
      limit: z.number().default(100)
    },
  • src/index.ts:215-242 (registration)
    Registers the search-logs tool with the MCP server, specifying the tool name, description, input schema, and a thin wrapper handler that delegates to searchLogs.execute.
    server.tool(
      "search-logs",
      "Search logs in Datadog with advanced filtering options. Use filter.query for search terms (e.g., 'service:web-app status:error'), from/to for time ranges (e.g., 'now-15m', 'now'), and sort to order results. Essential for investigating application issues.",
      {
        filter: z
          .object({
            query: z.string().optional(),
            from: z.string().optional(),
            to: z.string().optional(),
            indexes: z.array(z.string()).optional()
          })
          .optional(),
        sort: z.string().optional(),
        page: z
          .object({
            limit: z.number().optional(),
            cursor: z.string().optional()
          })
          .optional(),
        limit: z.number().default(100)
      },
      async (args) => {
        const result = await searchLogs.execute(args);
        return {
          content: [{ type: "text", text: JSON.stringify(result) }]
        };
      }
    );
  • Initializes the Datadog API client configuration with auth keys and site-specific server variables for the logs API.
    initialize: () => {
      const configOpts = {
        authMethods: {
          apiKeyAuth: process.env.DD_API_KEY,
          appKeyAuth: process.env.DD_APP_KEY
        }
      };
    
      configuration = client.createConfiguration(configOpts);
    
      if (process.env.DD_LOGS_SITE) {
        configuration.setServerVariables({
          site: process.env.DD_LOGS_SITE
        });
      }
    
      // Enable any unstable operations
      configuration.unstableOperations["v2.listLogsGet"] = true;
    },
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions 'advanced filtering options' and 'essential for investigating application issues,' but fails to describe critical behaviors like pagination handling (implied by 'page' parameter), rate limits, authentication requirements, or what the output looks like. For a search tool with complex parameters, this is a significant gap.

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 sized with two sentences: the first front-loads purpose and parameter guidance, the second provides usage context. Every sentence adds value, though the second could be more specific. No wasted words, but could be slightly more structured.

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

Completeness2/5

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

Given the tool's complexity (4 parameters with nested objects, no annotations, no output schema), the description is incomplete. It covers basic parameter usage but misses behavioral aspects like pagination, output format, error handling, and doesn't fully address all parameters. For a search tool with filtering and pagination, this leaves significant gaps.

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 0%, so the description must compensate. It adds value by explaining 'filter.query for search terms (e.g., 'service:web-app status:error'), from/to for time ranges (e.g., 'now-15m', 'now'), and sort to order results,' covering 3 of 4 parameters. However, it doesn't explain 'indexes' or 'page' parameters, leaving some semantics undocumented.

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 as 'Search logs in Datadog with advanced filtering options' which specifies the verb ('Search'), resource ('logs in Datadog'), and scope ('advanced filtering options'). It distinguishes from siblings like 'aggregate-logs' by focusing on search rather than aggregation, though it doesn't explicitly contrast with all siblings.

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

Usage Guidelines3/5

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

The description provides implied usage guidance with 'Essential for investigating application issues,' suggesting when this tool is appropriate. However, it lacks explicit guidance on when to use this versus alternatives like 'get-events' or 'aggregate-logs,' and doesn't mention prerequisites or exclusions.

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/GeLi2001/datadog-mcp-server'

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