steampipe_query
Query cloud infrastructure, SaaS, APIs, and code with PostgreSQL syntax. Execute read-only SQL queries to access and analyze data efficiently. Use provided tools to explore available tables and columns before querying.
Instructions
Query cloud infrastructure, SaaS, APIs, code and more with SQL.
Queries are read-only and must use PostgreSQL syntax.
For best performance: limit columns requested, use materialized CTEs instead of joins. Trust the search path unless sure you need to specify a schema.
Check available tables and columns before querying using steampipe_table_list and steampipe_table_show.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | The SQL query to execute. Must use PostgreSQL syntax and be read-only. |
Implementation Reference
- src/tools/steampipe_query.ts:27-48 (handler)The main handler function that executes the SQL query using DatabaseService.executeQuery and returns the results as JSON or an error message.handler: async (db: DatabaseService | undefined, args: { sql: string }) => { if (!db) { return { content: [{ type: "text", text: "Database not available" }], isError: true, }; } try { const rows = await db.executeQuery(args.sql); return { content: [{ type: "text", text: JSON.stringify(rows) }], isError: false }; } catch (error) { logger.error('Error executing query:', error); return { content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }], isError: true }; } }
- src/tools/steampipe_query.ts:16-26 (schema)Input schema specifying the required 'sql' string parameter for the steampipe_query tool.inputSchema: { type: "object", properties: { sql: { type: "string", description: "The SQL query to execute. Must use PostgreSQL syntax and be read-only." } }, required: ["sql"], additionalProperties: false },
- src/tools/index.ts:24-30 (registration)The steampipe_query tool is registered in the exported 'tools' object, which is used by the MCP server handlers.export const tools = { steampipe_query: queryTool as DbTool, steampipe_table_list: tableListTool as DbTool, steampipe_table_show: tableShowTool as DbTool, steampipe_plugin_list: pluginListTool as DbTool, steampipe_plugin_show: pluginShowTool as DbTool, } as const;