mysql_describe_table
Retrieve the structure and schema of a MySQL table to understand column definitions, data types, and constraints for database analysis or query planning.
Instructions
Get the structure/schema of a specific table
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table | Yes | Table name to describe | |
| database | No | Database name (uses current database if not specified) |
Input Schema (JSON Schema)
{
"properties": {
"database": {
"description": "Database name (uses current database if not specified)",
"type": "string"
},
"table": {
"description": "Table name to describe",
"type": "string"
}
},
"required": [
"table"
],
"type": "object"
}
Implementation Reference
- src/index.ts:393-419 (handler)The handler function that implements the core logic for the 'mysql_describe_table' tool by executing a 'DESCRIBE' SQL query on the specified table.private async handleDescribeTable(args: any) { if (!this.pool) { throw new Error("Not connected to MySQL. Use mysql_connect first."); } const { table, database } = args; if (!table) { throw new Error("Table name is required"); } const fullTableName = database ? `\`${database}\`.\`${table}\`` : `\`${table}\``; try { const [results] = await this.pool.execute(`DESCRIBE ${fullTableName}`); return { content: [ { type: "text", text: `Table structure for '${table}':\n${JSON.stringify(results, null, 2)}`, }, ], }; } catch (error) { throw new Error(`Failed to describe table: ${error instanceof Error ? error.message : String(error)}`); } }
- src/index.ts:181-194 (schema)The input schema definition for the 'mysql_describe_table' tool, specifying parameters like table and optional database.inputSchema: { type: "object", properties: { table: { type: "string", description: "Table name to describe", }, database: { type: "string", description: "Database name (uses current database if not specified)", }, }, required: ["table"], },
- src/index.ts:178-195 (registration)The tool registration in the listTools response, including name, description, and input schema.{ name: "mysql_describe_table", description: "Get the structure/schema of a specific table", inputSchema: { type: "object", properties: { table: { type: "string", description: "Table name to describe", }, database: { type: "string", description: "Database name (uses current database if not specified)", }, }, required: ["table"], }, },
- src/index.ts:257-258 (registration)The switch case that routes calls to the 'mysql_describe_table' handler function.case "mysql_describe_table": return await this.handleDescribeTable(args);