From 1069642b757737242a817b6ccc4d46f1d2b356d0 Mon Sep 17 00:00:00 2001 From: "mintlify[bot]" <109931778+mintlify[bot]@users.noreply.github.com> Date: Tue, 19 May 2026 10:44:24 +0000 Subject: [PATCH] docs: document run_sql structuredContent response shape --- references/integrations/lightdash-mcp.mdx | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/references/integrations/lightdash-mcp.mdx b/references/integrations/lightdash-mcp.mdx index 881df118..e5921622 100644 --- a/references/integrations/lightdash-mcp.mdx +++ b/references/integrations/lightdash-mcp.mdx @@ -277,6 +277,41 @@ MCP provides AI assistants with powerful tools to interact with your Lightdash d **Run SQL** requires the `manage SqlRunner` permission. The SQL is executed directly against your warehouse, so use the appropriate SQL dialect for your connection (e.g., PostgreSQL, BigQuery, Snowflake). + + When you call `run_sql` from a custom MCP client or live artifact, the tool returns both a CSV text payload and a `structuredContent` object. Prefer `structuredContent.rows` over parsing the CSV — values arrive as JSON-serializable primitives (numbers, strings, booleans, ISO date strings, or `null`), so you don't need `parseFloat` or `parseInt` on numeric columns. + + **Response envelope:** + + ```json + { + "content": [ + { "type": "text", "text": "" } + ], + "structuredContent": { + "rows": [ + { "status": "completed", "n": 94, "total_amount": 2397 } + ], + "columns": ["status", "n", "total_amount"], + "rowCount": 1 + } + } + ``` + + **Example usage:** + + ```ts + const result = await callMcpTool('run_sql', { sql, limit }); + const rows = result.structuredContent.rows; // [{ status: 'completed', n: 94, ... }, ...] + const columns = result.structuredContent.columns; // ['status', 'n', 'total_amount'] + ``` + + **Notes:** + + - Empty results still return `structuredContent` as `{ rows: [], columns, rowCount: 0 }` — distinct from a parse failure. + - On error, the response has `isError: true` and `content[0].text` contains the error message; `structuredContent` is omitted. + - `content[0].text` continues to carry the raw CSV, so existing clients that parse the text payload keep working. + + **Security best practice:** Ensure the database credentials configured in your Lightdash connection have **read-only (viewer) access** to your warehouse. Since `run_sql` executes arbitrary SQL, a connection with write permissions could allow AI agents to modify or delete warehouse data.