get-logs
Retrieve Cloud Logging entries for your current GCP project using filters and pagination to monitor and debug applications.
Instructions
Get Cloud Logging entries for the current project
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filter | No | Filter for the log entries (see Cloud Logging query syntax) | |
| pageSize | No | Maximum number of entries to return (default: 10) |
Implementation Reference
- index.ts:619-648 (handler)Main handler for the 'get-logs' tool. Parses input arguments using Zod schema, checks if a project is selected, initializes the Google Cloud Logging client, retrieves log entries with optional filter and page size, formats the response, and handles errors.
} else if (name === "get-logs") { const { filter, pageSize = 10 } = GetLogsSchema.parse(args); if (!selectedProject) { return createTextResponse("No project selected. Please select a project first."); } try { const logging = new Logging({ projectId: selectedProject }); const [entries] = await logging.getEntries({ pageSize, filter: filter || undefined, orderBy: 'timestamp desc' }); return createTextResponse(JSON.stringify({ entries: entries.map((entry: Entry) => ({ timestamp: entry.metadata.timestamp, severity: entry.metadata.severity, resource: entry.metadata.resource, textPayload: entry.data, jsonPayload: typeof entry.data === 'object' ? entry.data : null })) }, null, 2)); } catch (error: any) { console.error('Error getting logs:', error); return createTextResponse(`Error getting logs: ${error.message}`); } - index.ts:194-211 (registration)Registration of the 'get-logs' tool in the listTools response, defining its name, description, and input schema.
{ name: "get-logs", description: "Get Cloud Logging entries for the current project", inputSchema: { type: "object", properties: { filter: { type: "string", description: "Filter for the log entries (see Cloud Logging query syntax)", }, pageSize: { type: "number", description: "Maximum number of entries to return (default: 10)", } }, required: [], }, } - index.ts:245-248 (schema)Zod schema used for input validation of the 'get-logs' tool arguments in the handler.
const GetLogsSchema = z.object({ filter: z.string().optional(), pageSize: z.number().optional(), });