Skip to main content
Glama
andyl25

Google Cloud MCP Server

by andyl25

query-logs

Filter and retrieve log entries from Google Cloud services using natural language queries, with customizable limits for efficient data extraction.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filterYesThe filter to apply to logs
limitNoMaximum number of log entries to return

Implementation Reference

  • Executes the query-logs tool: fetches project ID, queries Cloud Logging entries with given filter and limit, formats results using formatLogEntry, returns markdown text response or error.
    async ({ filter, limit }, _extra) => { try { const projectId = await getProjectId(); const logging = getLoggingClient(); const [entries] = await logging.getEntries({ pageSize: limit, filter }); if (!entries || entries.length === 0) { return { content: [{ type: 'text', text: `No log entries found matching filter: ${filter}` }] }; } const formattedLogs = entries .map((entry) => { try { return formatLogEntry(entry as unknown as LogEntry); } catch (err: unknown) { const errorMessage = err instanceof Error ? err.message : 'Unknown error'; return `## Error Formatting Log Entry\n\nAn error occurred while formatting a log entry: ${errorMessage}`; } }) .join('\n\n'); return { content: [{ type: 'text', text: `# Log Query Results\n\nProject: ${projectId}\nFilter: ${filter}\nEntries: ${entries.length}\n\n${formattedLogs}` }] }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : 'Unknown error'; // Return a user-friendly error message instead of throwing return { content: [{ type: 'text', text: `# Error Querying Logs An error occurred while querying logs: ${errorMessage} Please check your filter syntax and try again. For filter syntax help, see: https://cloud.google.com/logging/docs/view/logging-query-language` }], isError: true }; } } );
  • Zod input schema for query-logs tool: filter (required string), limit (optional number, 1-1000, default 50).
    { filter: z.string().describe('The filter to apply to logs'), limit: z.number().min(1).max(1000).default(50).describe('Maximum number of log entries to return') },
  • Registers the 'query-logs' MCP tool on the server within registerLoggingTools function, specifying name, input schema, and handler.
    server.tool( 'query-logs', { filter: z.string().describe('The filter to apply to logs'), limit: z.number().min(1).max(1000).default(50).describe('Maximum number of log entries to return') }, async ({ filter, limit }, _extra) => { try { const projectId = await getProjectId(); const logging = getLoggingClient(); const [entries] = await logging.getEntries({ pageSize: limit, filter }); if (!entries || entries.length === 0) { return { content: [{ type: 'text', text: `No log entries found matching filter: ${filter}` }] }; } const formattedLogs = entries .map((entry) => { try { return formatLogEntry(entry as unknown as LogEntry); } catch (err: unknown) { const errorMessage = err instanceof Error ? err.message : 'Unknown error'; return `## Error Formatting Log Entry\n\nAn error occurred while formatting a log entry: ${errorMessage}`; } }) .join('\n\n'); return { content: [{ type: 'text', text: `# Log Query Results\n\nProject: ${projectId}\nFilter: ${filter}\nEntries: ${entries.length}\n\n${formattedLogs}` }] }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : 'Unknown error'; // Return a user-friendly error message instead of throwing return { content: [{ type: 'text', text: `# Error Querying Logs An error occurred while querying logs: ${errorMessage} Please check your filter syntax and try again. For filter syntax help, see: https://cloud.google.com/logging/docs/view/logging-query-language` }], isError: true }; } } );
  • src/index.ts:132-132 (registration)
    Calls registerLoggingTools(server) in main server setup, which in turn registers the query-logs tool.
    registerLoggingTools(server);

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/andyl25/googlecloud-mcp'

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