describe_all_tables
Show the schema of all tables in a database with a single query. Returns column details for every table, providing a comprehensive overview of the database structure.
Instructions
Show the schema of all tables at once. Much more efficient than calling describe_table for each table individually. Warning: response can be large for databases with many tables — prefer describe_table for specific tables when possible.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | No | Database name. Uses the current database if omitted. |
Implementation Reference
- src/tools/describe-all-tables.ts:21-87 (handler)The handler function that executes the describe_all_tables tool logic. It validates input, queries information_schema.COLUMNS for all tables in the database, groups columns by table, and returns formatted output.
export function createDescribeAllTablesHandler(runner: QueryRunner) { return async ({ database }: { database?: string }) => { if (database) { const dbValidation = validateIdentifier(database, 'Database'); if (!dbValidation.valid) { return { isError: true as const, content: [{ type: 'text' as const, text: dbValidation.message! }], }; } } try { return await runner.withConnection(async (query) => { const db = await resolveDatabase(query, database); if (!db) { return { isError: true as const, content: [ { type: 'text' as const, text: 'Error: No database selected. Specify a database name or set MYSQL_DATABASE.', }, ], }; } const sql = `SELECT TABLE_NAME, COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE, COLUMN_KEY, COLUMN_DEFAULT, EXTRA, COLUMN_COMMENT FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ${quoteStringValue(db)} ORDER BY TABLE_NAME, ORDINAL_POSITION`; const [rows] = await query(sql); const typedRows = rows as Record<string, unknown>[]; if (typedRows.length === 0) { return { content: [{ type: 'text' as const, text: '(no tables)' }] }; } const tableMap = new Map<string, string[]>(); for (const r of typedRows) { const tableName = String(r.TABLE_NAME); const line = formatColumn({ name: String(r.COLUMN_NAME), type: String(r.COLUMN_TYPE), nullable: r.IS_NULLABLE === 'YES', key: String(r.COLUMN_KEY ?? ''), defaultValue: r.COLUMN_DEFAULT, extra: String(r.EXTRA ?? ''), comment: String(r.COLUMN_COMMENT ?? ''), }); if (!tableMap.has(tableName)) { tableMap.set(tableName, []); } tableMap.get(tableName)!.push(line); } const parts = Array.from(tableMap.entries()).map(([table, lines]) => `${table}:\n${lines.join('\n')}`); return { content: [{ type: 'text' as const, text: parts.join('\n\n') }], }; }); } catch (error) { return { isError: true as const, content: [{ type: 'text' as const, text: formatError(error) }], }; } }; } - Input schema and description for the describe_all_tables tool. Accepts an optional 'database' string parameter.
export const describeAllTablesToolConfig = { title: 'Describe All Tables', description: 'Show the schema of all tables at once. Much more efficient than calling describe_table for each table individually. ' + 'Warning: response can be large for databases with many tables — prefer describe_table for specific tables when possible.', inputSchema: { database: z.string().optional().describe('Database name. Uses the current database if omitted.'), }, }; - src/tools/index.ts:41-46 (registration)Registration of describe_all_tables with the MCP server, including its name, description, input schema, and handler.
server.tool( describeAllTablesToolName, describeAllTablesToolConfig.description, describeAllTablesToolConfig.inputSchema, createDescribeAllTablesHandler(runner), ); - src/tools/index.ts:8-12 (registration)Import of describeAllTablesToolName, describeAllTablesToolConfig, and createDescribeAllTablesHandler from the module.
import { describeAllTablesToolName, describeAllTablesToolConfig, createDescribeAllTablesHandler, } from './describe-all-tables.js'; - src/tools/format-column.ts:1-22 (helper)The formatColumn helper used by describe_all_tables to format each column's output string (name, type, constraints, defaults, etc.).
export interface ColumnInfo { name: string; type: string; nullable: boolean; key: string; defaultValue: unknown; extra: string; comment: string; } export function formatColumn(col: ColumnInfo): string { let result = `${col.name} ${col.type}`; if (!col.nullable) result += ' NOT NULL'; if (col.key === 'PRI') result += ' PK'; else if (col.key === 'UNI') result += ' UNIQUE'; else if (col.key === 'MUL') result += ' INDEX'; if (col.defaultValue != null) result += ` DEFAULT ${col.defaultValue}`; if (col.extra) result += ` ${col.extra}`; if (col.comment) result += ` -- ${col.comment}`; return result; }