get_db_schema
Retrieve the complete database schema to understand table structures and relationships for Turso-hosted LibSQL databases.
Instructions
Get the schema for all tables in the database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:66-81 (registration)Registration of the 'get_db_schema' tool, which calls the dbSchema helper function from utils.ts and formats the result as JSON content.server.addTool({ name: "get_db_schema", description: "Get the schema for all tables in the database", parameters: z.object({}), execute: async () => { try { const schema = await dbSchema(db); return content(JSON.stringify({ schema }, null, 2)); } catch (error) { return content( `Error getting schema: ${error instanceof Error ? error.message : String(error)}`, true, ); } }, });
- src/utils.ts:33-40 (handler)Core handler logic for retrieving SQL CREATE statements for all user tables from sqlite_master.export async function dbSchema(client: Client): Promise<string[]> { const result = await client.execute({ sql: "SELECT sql FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'", args: [], }); return result.rows.map((row) => row.sql as string); }