describe_table
Retrieve detailed schema information for a specific PostgreSQL table, including column names, data types, and constraints, to understand and explore database structure.
Instructions
Get detailed schema information for a specific table
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| schema | No | Schema name (default: public) | public |
| table_name | Yes | Name of the table to describe |
Implementation Reference
- src/index.js:209-259 (handler)The main handler function that executes the describe_table tool. It connects to the PostgreSQL database, queries information_schema.columns for column details (name, data_type, nullable, default, lengths, precisions), processes the results, and returns a formatted text response describing the table schema.async describeTable(tableName, schema = 'public') { const client = await this.connectToDatabase(); try { const query = ` SELECT column_name, data_type, is_nullable, column_default, character_maximum_length, numeric_precision, numeric_scale, ordinal_position FROM information_schema.columns WHERE table_schema = $1 AND table_name = $2 ORDER BY ordinal_position; `; const result = await client.query(query, [schema, tableName]); if (result.rows.length === 0) { throw new Error(`Table "${tableName}" not found in schema "${schema}"`); } const tableInfo = result.rows.map(row => ({ column: row.column_name, type: row.data_type, nullable: row.is_nullable === 'YES', default: row.column_default, maxLength: row.character_maximum_length, precision: row.numeric_precision, scale: row.numeric_scale, position: row.ordinal_position })); return { content: [ { type: 'text', text: `Schema for table "${schema}.${tableName}":\n\n` + tableInfo.map(col => `${col.column} | ${col.type}${col.maxLength ? `(${col.maxLength})` : ''}${col.precision ? `(${col.precision}${col.scale ? `,${col.scale}` : ''})` : ''} | ${col.nullable ? 'NULL' : 'NOT NULL'}${col.default ? ` | DEFAULT ${col.default}` : ''}` ).join('\n'), }, ], }; } finally { await client.end(); } }
- src/index.js:74-88 (schema)Input schema definition for the describe_table tool, specifying properties for table_name (required string) and optional schema (string with default 'public').inputSchema: { type: 'object', properties: { table_name: { type: 'string', description: 'Name of the table to describe', }, schema: { type: 'string', description: 'Schema name (default: public)', default: 'public' } }, required: ['table_name'], },
- src/index.js:72-89 (registration)Tool registration in the list_tools response, including name, description, and input schema for describe_table.name: 'describe_table', description: 'Get detailed schema information for a specific table', inputSchema: { type: 'object', properties: { table_name: { type: 'string', description: 'Name of the table to describe', }, schema: { type: 'string', description: 'Schema name (default: public)', default: 'public' } }, required: ['table_name'], }, },
- src/index.js:148-149 (registration)Dispatcher in the call_tool request handler that routes describe_table calls to the describeTable method.case 'describe_table': return await this.describeTable(args.table_name, args?.schema || 'public');