list_tables
Retrieve a list of all tables in an SQLite database to identify and manage data structures efficiently.
Instructions
List all tables in the connected database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:221-244 (handler)The core handler function for the 'list_tables' tool. It checks if a database is connected, queries the sqlite_master table to list all user tables (excluding internal ones), formats the list, and returns it as a CallToolResult.private async listTables(): Promise<CallToolResult> { if (!this.db) { throw new Error("No database connected. Use connect_database first."); } try { const tables = this.db .prepare("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' ORDER BY name") .all() as { name: string }[]; const tableList = tables.map(t => t.name).join(", "); return { content: [ { type: "text", text: `Tables in database (${tables.length}): ${tableList || "No tables found"}`, } satisfies TextContent, ], }; } catch (error) { throw new Error(`Failed to list tables: ${error instanceof Error ? error.message : String(error)}`); } }
- src/index.ts:78-85 (registration)Tool registration definition returned by ListToolsRequestHandler, specifying the tool name, description, and input schema (empty properties, no arguments required).{ name: "list_tables", description: "List all tables in the connected database", inputSchema: { type: "object", properties: {}, }, },
- src/index.ts:165-166 (helper)Dispatcher switch case in CallToolRequestHandler that invokes the listTables handler when the 'list_tables' tool is called.case "list_tables": return await this.listTables();