describe_table
Retrieve schema information for a SQL Server table to understand its structure, including column names, data types, and constraints.
Instructions
Get the schema information for a specific table
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | Name of the table to describe | |
| database | No | Database name (optional) | |
| schema | No | Schema name (optional, defaults to dbo) |
Implementation Reference
- Core handler function that constructs and executes a SQL query to retrieve detailed schema information (columns, types, nullability, primary keys) for the specified table using INFORMATION_SCHEMA views.async describeTable(tableName, database = null, schema = 'dbo') { let query; if (database) { query = ` SELECT c.COLUMN_NAME as column_name, c.DATA_TYPE as data_type, c.IS_NULLABLE as is_nullable, c.COLUMN_DEFAULT as column_default, c.CHARACTER_MAXIMUM_LENGTH as max_length, c.NUMERIC_PRECISION as precision, c.NUMERIC_SCALE as scale, CASE WHEN pk.COLUMN_NAME IS NOT NULL THEN 'YES' ELSE 'NO' END as is_primary_key FROM [${database}].INFORMATION_SCHEMA.COLUMNS c LEFT JOIN [${database}].INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON c.TABLE_NAME = tc.TABLE_NAME AND c.TABLE_SCHEMA = tc.TABLE_SCHEMA AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' LEFT JOIN [${database}].INFORMATION_SCHEMA.KEY_COLUMN_USAGE pk ON c.COLUMN_NAME = pk.COLUMN_NAME AND c.TABLE_NAME = pk.TABLE_NAME AND c.TABLE_SCHEMA = pk.TABLE_SCHEMA AND tc.CONSTRAINT_NAME = pk.CONSTRAINT_NAME WHERE c.TABLE_NAME = '${tableName}' AND c.TABLE_SCHEMA = '${schema}' ORDER BY c.ORDINAL_POSITION `; } else { query = ` SELECT c.COLUMN_NAME as column_name, c.DATA_TYPE as data_type, c.IS_NULLABLE as is_nullable, c.COLUMN_DEFAULT as column_default, c.CHARACTER_MAXIMUM_LENGTH as max_length, c.NUMERIC_PRECISION as precision, c.NUMERIC_SCALE as scale, CASE WHEN pk.COLUMN_NAME IS NOT NULL THEN 'YES' ELSE 'NO' END as is_primary_key FROM INFORMATION_SCHEMA.COLUMNS c LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON c.TABLE_NAME = tc.TABLE_NAME AND c.TABLE_SCHEMA = tc.TABLE_SCHEMA AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY' LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE pk ON c.COLUMN_NAME = pk.COLUMN_NAME AND c.TABLE_NAME = pk.TABLE_NAME AND c.TABLE_SCHEMA = pk.TABLE_SCHEMA AND tc.CONSTRAINT_NAME = pk.CONSTRAINT_NAME WHERE c.TABLE_NAME = '${tableName}' AND c.TABLE_SCHEMA = '${schema}' ORDER BY c.ORDINAL_POSITION `; } const result = await this.executeQuery(query, 'describe_table'); return this.formatResults(result); }
- lib/tools/tool-registry.js:39-50 (schema)Tool metadata definition including name, description, and input schema for parameter validation (table_name required, database and schema optional).name: 'describe_table', description: 'Get the schema information for a specific table', inputSchema: { type: 'object', properties: { table_name: { type: 'string', description: 'Name of the table to describe' }, database: { type: 'string', description: 'Database name (optional)' }, schema: { type: 'string', description: 'Schema name (optional, defaults to dbo)' } }, required: ['table_name'] } },
- index.js:266-273 (registration)Tool call dispatching in the main MCP server switch statement, mapping 'describe_table' calls to the DatabaseToolsHandler.describeTable method.case 'describe_table': return { content: await this.databaseTools.describeTable( args.table_name, args.database, args.schema ) };
- index.js:241-242 (registration)MCP server registration for listing available tools, which includes 'describe_table' via getAllTools() from tool-registry.this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: getAllTools()