d1_list_tables
Retrieve a list of all tables in your Cloudflare D1 database to understand database structure and plan SQL operations.
Instructions
List tables available in the Cloudflare D1 database.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server.ts:83-92 (handler)Handler for the 'd1_list_tables' tool in the CallToolRequestSchema. It calls client.listTables() and formats the result as JSON text response.} else if (name === "d1_list_tables") { const tables = await client.listTables(); return { content: [ { type: "text", text: JSON.stringify(tables, null, 2) } ] };
- src/server.ts:50-58 (registration)Tool registration in the ListToolsRequestSchema handler, including name, description, and empty input schema.{ name: "d1_list_tables", description: "List tables available in the Cloudflare D1 database.", inputSchema: { type: "object", properties: {}, additionalProperties: false } }
- src/client.ts:41-61 (helper)Implementation of listTables() method in D1Client, which queries sqlite_master for table names using a SQL statement and processes the result.async listTables(): Promise<string[]> { const sql = `SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name;`; const result = await this.executeQuery(sql); if (!result.success) { const error = result.errors?.[0]?.message ?? "Unknown D1 error"; throw new Error(`Failed to list tables: ${error}`); } const rows = Array.isArray(result.result) ? result.result : []; const firstResult = Array.isArray(rows[0]) ? rows[0] : rows; if (!Array.isArray(firstResult)) { return []; } // D1 returns rows as array of objects { name: string } return firstResult .filter((item): item is { name: string } => typeof item === "object" && item !== null && "name" in item) .map((row) => row.name); }