describe_table
Retrieve schema information for a database table to understand its structure, including column names, data types, and constraints.
Instructions
Get schema information for a specific table
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tableName | Yes | Name of the table to describe |
Implementation Reference
- index.js:451-513 (handler)The main handler function that implements the logic for the 'describe_table' tool. It queries the database information schema for PostgreSQL or uses DESCRIBE for MySQL to retrieve column information for the specified table.async describeTable(tableName) { if (!this.currentConfig) { throw new Error('Not connected to any database. Call connect_database first.'); } if (this.currentConfig.type === 'postgresql') { if (!this.postgresPool) { throw new Error('PostgreSQL connection not initialized'); } const query = ` SELECT column_name, data_type, is_nullable, column_default FROM information_schema.columns WHERE table_schema = 'public' AND table_name = $1 ORDER BY ordinal_position; `; const result = await this.postgresPool.query(query, [tableName]); return { content: [ { type: 'text', text: JSON.stringify( { table: tableName, columns: result.rows, }, null, 2 ), }, ], }; } else if (this.currentConfig.type === 'mysql') { if (!this.mysqlConnection) { throw new Error('MySQL connection not initialized'); } const [rows] = await this.mysqlConnection.query( `DESCRIBE ${tableName}` ); return { content: [ { type: 'text', text: JSON.stringify( { table: tableName, columns: rows, }, null, 2 ), }, ], }; } else { throw new Error(`Unsupported database type: ${this.currentConfig.type}`); } }
- index.js:186-195 (schema)The input schema definition for the 'describe_table' tool, specifying that it requires a 'tableName' string parameter.inputSchema: { type: 'object', properties: { tableName: { type: 'string', description: 'Name of the table to describe', }, }, required: ['tableName'], },
- index.js:183-196 (registration)The registration of the 'describe_table' tool in the ListTools response, including name, description, and input schema.{ name: 'describe_table', description: 'Get schema information for a specific table', inputSchema: { type: 'object', properties: { tableName: { type: 'string', description: 'Name of the table to describe', }, }, required: ['tableName'], }, },
- index.js:222-223 (handler)The dispatch case in the CallToolRequestSchema handler that invokes the describeTable method for the 'describe_table' tool.case 'describe_table': return await this.describeTable(args.tableName);