describe_table
Retrieve the structure and schema of a MySQL database table to understand its columns, data types, and constraints.
Instructions
Get the structure/schema of a table
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table | Yes | Table name | |
| database | No | Database name (optional) |
Implementation Reference
- src/index.ts:272-297 (handler)Handler function executes DESCRIBE query on the specified table (optionally in a database) and returns the column structure including Field, Type, Null, Key, Default, Extra.async ({ table, database }) => { const p = await getPool(); const tableName = database ? `\`${database}\`.\`${table}\`` : `\`${table}\``; const [rows] = await p.query<RowDataPacket[]>(`DESCRIBE ${tableName}`); const columns = rows as Array<{ Field: string; Type: string; Null: string; Key: string; Default: string | null; Extra: string; }>; const output = { table, database: database || null, columns }; return { content: [ { type: "text" as const, text: JSON.stringify(rows, null, 2), }, ], structuredContent: output, }; }
- src/index.ts:268-271 (schema)Zod input schema defining required 'table' name and optional 'database'.{ table: z.string().describe("Table name"), database: z.string().optional().describe("Database name (optional)"), },
- src/index.ts:265-298 (registration)Registration of the 'describe_table' tool using McpServer.tool method, including description, input schema, and inline handler.server.tool( "describe_table", "Get the structure/schema of a table", { table: z.string().describe("Table name"), database: z.string().optional().describe("Database name (optional)"), }, async ({ table, database }) => { const p = await getPool(); const tableName = database ? `\`${database}\`.\`${table}\`` : `\`${table}\``; const [rows] = await p.query<RowDataPacket[]>(`DESCRIBE ${tableName}`); const columns = rows as Array<{ Field: string; Type: string; Null: string; Key: string; Default: string | null; Extra: string; }>; const output = { table, database: database || null, columns }; return { content: [ { type: "text" as const, text: JSON.stringify(rows, null, 2), }, ], structuredContent: output, }; } );