Lists all tables in a database
list_tablesLists all tables in a Turso database. Provide the database name to retrieve its table names.
Instructions
Lists all tables in a database
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | No | Database name (optional, uses context if not provided) |
Implementation Reference
- src/tools/handler.ts:183-200 (handler)Tool handler for 'list_tables' - registers the tool via server.tool(), resolves database name, calls database_client.list_tables(), and returns the response.
// Database tools server.tool( { name: 'list_tables', description: 'Lists all tables in a database', schema: DatabaseOnlySchema, }, async ({ database }) => { try { const database_name = resolve_database_name(database); if (database) set_current_database(database); const tables = await database_client.list_tables(database_name); return create_tool_response({ database: database_name, tables }); } catch (error) { return create_tool_error_response(error); } }, - src/clients/database.ts:88-115 (helper)Core implementation of list_tables - queries sqlite_schema to get table names from the database, filtering out sqlite_ internal tables.
export async function list_tables( database_name: string, ): Promise<string[]> { try { const client = await get_database_client( database_name, 'read-only', ); // Query the sqlite_schema table to get all tables const result = await client.execute({ sql: `SELECT name FROM sqlite_schema WHERE type = 'table' AND name NOT LIKE 'sqlite_%' ORDER BY name`, }); // Extract table names from the result return result.rows.map((row) => row.name as string); } catch (error) { throw new TursoApiError( `Failed to list tables for database ${database_name}: ${ (error as Error).message }`, 500, ); } } - src/tools/handler.ts:32-34 (schema)Zod schema for the 'list_tables' tool input - accepts an optional database name.
const DatabaseOnlySchema = z.object({ database: z.string().optional().describe('Database name (optional, uses context if not provided)'), }); - src/tools/handler.ts:183-201 (registration)Registration of 'list_tables' tool via server.tool() with its name, description, schema, and handler callback.
// Database tools server.tool( { name: 'list_tables', description: 'Lists all tables in a database', schema: DatabaseOnlySchema, }, async ({ database }) => { try { const database_name = resolve_database_name(database); if (database) set_current_database(database); const tables = await database_client.list_tables(database_name); return create_tool_response({ database: database_name, tables }); } catch (error) { return create_tool_error_response(error); } }, );