steampipe_query
Query cloud infrastructure, SaaS, APIs, and code using SQL to analyze data from multiple sources with PostgreSQL syntax.
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
TableJSON 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 for the steampipe_query tool. It executes the provided SQL query using DatabaseService.executeQuery and returns the results as JSON string 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)The input schema defining the required 'sql' parameter as a string for the SQL query.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)Registration of the steampipe_query tool in the central tools export object, which is used by setupTools to register with the MCP server.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;