describe_table
Retrieve the schema of a MySQL table to view its columns, data types, and structure details.
Instructions
Show the schema for a specific table
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | No | Database name (optional, uses default if not specified) | |
| table | Yes | Table name |
Implementation Reference
- src/index.ts:89-105 (registration)Tool registration for 'describe_table' — defines the tool name, description, and input schema (requires table name, optional database).
{ name: "describe_table", description: "Show the schema for a specific table", inputSchema: { type: "object", properties: { database: { type: "string", description: "Database name (optional, uses default if not specified)" }, table: { type: "string", description: "Table name" } }, required: ["table"] } - src/index.ts:171-194 (handler)Handler for 'describe_table' — extracts database/table arguments, validates table is provided, executes DESCRIBE SQL query, and returns table schema as JSON.
case "describe_table": { console.error('[Tool] Executing describe_table'); const database = request.params.arguments?.database as string | undefined; const table = request.params.arguments?.table as string; if (!table) { throw new McpError(ErrorCode.InvalidParams, "Table name is required"); } const { rows } = await executeQuery( pool, `DESCRIBE \`${table}\``, [], database ); return { content: [{ type: "text", text: JSON.stringify(rows, null, 2) }] }; } - src/index.ts:89-105 (schema)Input schema for describe_table — defines 'database' (optional string) and 'table' (required string) properties with type and description.
{ name: "describe_table", description: "Show the schema for a specific table", inputSchema: { type: "object", properties: { database: { type: "string", description: "Database name (optional, uses default if not specified)" }, table: { type: "string", description: "Table name" } }, required: ["table"] } - src/connection.ts:63-109 (helper)Helper function executeQuery used by describe_table handler — acquires a connection, optionally switches database via USE, executes the DESCRIBE SQL, applies row limits, and returns results.
export async function executeQuery( pool: mysql.Pool, sql: string, params: any[] = [], database?: string ): Promise<{ rows: any; fields: mysql.FieldPacket[] }> { console.error(`[Query] Executing: ${sql}`); let connection: mysql.PoolConnection | null = null; try { // Get connection from pool connection = await pool.getConnection(); // Use specific database if provided if (database) { console.error(`[Query] Using database: ${database}`); await connection.query(`USE \`${database}\``); } // Execute query with timeout const [rows, fields] = await Promise.race([ connection.query(sql, params), new Promise<never>((_, reject) => { setTimeout(() => reject(new Error('Query timeout')), DEFAULT_TIMEOUT); }), ]); // Apply row limit if result is an array const limitedRows = Array.isArray(rows) && rows.length > DEFAULT_ROW_LIMIT ? rows.slice(0, DEFAULT_ROW_LIMIT) : rows; // Log result summary console.error(`[Query] Success: ${Array.isArray(rows) ? rows.length : 1} rows returned`); return { rows: limitedRows, fields }; } catch (error) { console.error('[Error] Query execution failed:', error); throw error; } finally { // Release connection back to pool if (connection) { connection.release(); } } }