Skip to main content
Glama
Nozomuts

Datadog MCP Server

by Nozomuts

search_logs

Search and filter Datadog logs by query, time range, and pagination for efficient monitoring and analysis on the Datadog MCP Server.

Instructions

Datadogのログを検索するツール

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filterFromNo検索開始時間(UNIXタイムスタンプ、秒単位、オプション、デフォルトは15分前)
filterQueryNoログを検索するためのクエリ文字列(オプション、デフォルトは「*」)*
filterToNo検索終了時間(UNIXタイムスタンプ、秒単位、オプション、デフォルトは現在時刻)
pageCursorNo次のページを取得するためのカーソル(オプション)
pageLimitNo取得するログの最大数(オプション、デフォルトは25)

Implementation Reference

  • MCP tool handler for 'search_logs': validates parameters, invokes core searchLogs function, generates markdown summary with log details and Datadog URL.
    export const searchLogsHandler = async ( parameters: z.infer<typeof searchLogsZodSchema> ): Promise<ToolResponse> => { const validation = searchLogsZodSchema.safeParse(parameters); if (!validation.success) { return createErrorResponse( `Parameter validation error: ${validation.error.message}` ); } try { // Convert to Date objects after validation const validatedParams = { ...validation.data, filterFrom: new Date(validation.data.filterFrom * 1000), filterTo: new Date(validation.data.filterTo * 1000), }; const result = await searchLogs(validatedParams); const summaryText = generateSummaryText(validation.data, result); const urlText = `[View in Datadog](https://app.datadoghq.com/logs?query=${encodeURIComponent( validation.data.filterQuery )}&start=${validation.data.filterFrom}&end=${validation.data.filterTo})`; return createSuccessResponse([summaryText, urlText]); } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); return createErrorResponse(`Log search error: ${errorMessage}`); } };
  • Zod schema defining input parameters for the search_logs tool: filterQuery, filterFrom, filterTo, pageLimit, pageCursor.
    export const searchLogsZodSchema = z.object({ filterQuery: z .string() .optional() .default("*") .describe("Query string to search logs (optional, default is '*')"), filterFrom: z .number() .optional() .default(Date.now() / 1000 - 15 * 60) .describe( "Search start time (UNIX timestamp in seconds, optional, default is 15 minutes ago)" ), filterTo: z .number() .optional() .default(Date.now() / 1000) .describe( "Search end time (UNIX timestamp in seconds, optional, default is current time)" ), pageLimit: z .number() .min(1) .max(1000) .optional() .default(25) .describe("Maximum number of logs to retrieve (optional, default is 25)"), pageCursor: z .string() .optional() .describe("Cursor to retrieve the next page (optional)"), });
  • src/index.ts:18-23 (registration)
    Registers the 'search_logs' tool with McpServer, providing name, description, schema, and handler function.
    server.tool( "search_logs", "Tool for searching Datadog logs", searchLogsZodSchema.shape, searchLogsHandler );
  • Core helper function that performs the Datadog Logs API search using listLogsGet, maps response to custom Log format, handles pagination cursor.
    export const searchLogs = async ( params: LogSearchParams ): Promise<LogSearchResult> => { try { const configuration = createConfiguration(); const logsApi = new v2.LogsApi(configuration); const response = await logsApi.listLogsGet(params); if (!response.data || response.data.length === 0) { return { logs: [] }; } const logs = response.data.map((logData) => ({ id: logData.id || "", host: logData.attributes?.host, service: logData.attributes?.service, status: logData.attributes?.status, timestamp: logData.attributes?.timestamp ? new Date(logData.attributes.timestamp).toISOString() : undefined, tags: logData.attributes?.tags || [], attributes: logData.attributes || {}, message: logData.attributes?.message, })); const nextCursor = response.meta?.page?.after; return { logs, nextCursor, }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); console.error(`Error searching logs: ${errorMessage}`); throw new Error(`Datadog API error: ${errorMessage}`); } };

Other Tools

Related 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/Nozomuts/datadog-mcp'

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