describe_table
View schema information for a specific table in a Turso-hosted LibSQL database to understand its structure and columns.
Instructions
View schema information for a specific table
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | Name of the table to describe |
Implementation Reference
- src/utils.ts:50-76 (handler)Core handler function that executes PRAGMA table_info to retrieve and map detailed column information for the specified table.export async function describeTable( tableName: string, client: Client, ): Promise<TableColumn[]> { if (!/^[a-zA-Z0-9_]+$/.test(tableName)) { throw new Error( "Invalid table name. Only alphanumeric characters and underscores are allowed.", ); } const result = await client.execute({ sql: `PRAGMA table_info(${tableName})`, args: [], }); if (result.rows.length === 0) { throw new Error(`Table '${tableName}' not found`); } return result.rows.map((row) => ({ name: row.name as string, type: row.type as string, notnull: row.notnull as number, dflt_value: row.dflt_value as string | null, pk: row.pk as number, })); }
- src/index.ts:83-105 (registration)Registers the describe_table tool with FastMCP server, defining name, description, input parameters schema, and execute wrapper that calls the handler.server.addTool({ name: "describe_table", description: "View schema information for a specific table", parameters: z.object({ table_name: z .string() .describe("Name of the table to describe") .min(1, "Table name is required"), }), execute: async ({ table_name }) => { try { logger.info(`Executing describe_table for table: ${table_name}`); const schema = await describeTable(table_name, db); return content(JSON.stringify({ schema }, null, 2)); } catch (error) { logger.error(`Failed to describe table ${table_name}`, error); return content( `Error describing table: ${error instanceof Error ? error.message : String(error)}`, true, ); } }, });
- src/types.ts:3-11 (schema)Zod schema and TypeScript type definition for TableColumn, used as the return type of the describeTable handler.export const TableColumnSchema = z.object({ name: z.string(), type: z.string(), notnull: z.number(), dflt_value: z.union([z.string(), z.null()]), pk: z.number(), }); export type TableColumn = z.infer<typeof TableColumnSchema>;