list_tables
Retrieve all table names from a Turso-hosted LibSQL database to view available data structures and plan queries.
Instructions
List all tables in the database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:51-63 (handler)Handler function that executes the list_tables tool: logs action, calls listTables helper, returns JSON of tables or error content.execute: async () => { try { logger.info("Executing list_tables"); const tables = await listTables(db); return content(JSON.stringify({ tables }, null, 2)); } catch (error) { logger.error("Failed to list tables", error); return content( `Error listing tables: ${error instanceof Error ? error.message : String(error)}`, true, ); } },
- src/index.ts:47-64 (registration)Registration of the list_tables tool using server.addTool, including name, description, empty input schema, and handler.server.addTool({ name: "list_tables", description: "List all tables in the database", parameters: z.object({}), execute: async () => { try { logger.info("Executing list_tables"); const tables = await listTables(db); return content(JSON.stringify({ tables }, null, 2)); } catch (error) { logger.error("Failed to list tables", error); return content( `Error listing tables: ${error instanceof Error ? error.message : String(error)}`, true, ); } }, });
- src/index.ts:50-50 (schema)Zod schema for input parameters: empty object (no parameters required).parameters: z.object({}),
- src/utils.ts:18-25 (helper)Helper function that queries sqlite_master to list user tables (excluding sqlite_ internals), returns array of table names.export async function listTables(client: Client): Promise<string[]> { const result = await client.execute({ sql: "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'", args: [], }); return result.rows.map((row) => row.name as string); }