Run a read-only query
litescope_queryExecute read-only SQL queries on SQLite, Cloudflare D1, or Turso databases and retrieve results as JSON. Control output with column projection and row limits to manage context.
Instructions
Run a read-only SQL query on any SQLite or D1 database and return the results as JSON. Only SELECT statements and read-only PRAGMAs are allowed. This is the primary tool for an AI agent to explore data in a D1 database.
Token budgeting: results are capped at max_rows (default 200) so a large table won't blow your context window — the response reports total_rows and truncated. Use the columns argument to project only the fields you need. Narrow with LIMIT / WHERE for precise reads.
For D1: set CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID and use source=d1://DB_ID.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | A read-only SQL query (SELECT or read-only PRAGMA). Mutations are rejected. | |
| source | Yes | Database source: a local file path (./app.db), a Cloudflare D1 DSN (d1://DB_ID when CLOUDFLARE_API_TOKEN+CLOUDFLARE_ACCOUNT_ID are set, or d1://TOKEN@ACCOUNT_ID/DB_ID), or a Turso DSN (turso://TOKEN@ORG/DB). | |
| columns | No | Optional: keep only these columns in each row (projection) to save context. | |
| max_rows | No | Maximum rows to return (default 200, max 2000). Excess rows are dropped and reported via truncated. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rows | Yes | The result rows. | |
| count | Yes | Rows returned after truncation. | |
| truncated | Yes | True when total_rows exceeded max_rows. | |
| total_rows | Yes | Rows the query produced before truncation. |