describe_table
Retrieve column details, data types, nullability, identity, primary key, and default values for a specified table.
Instructions
Return columns, data types, nullability, identity, primary key, and defaults for a table.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| schema | Yes | Schema name (e.g. "dbo"). | |
| table | Yes | Table name. |
Implementation Reference
- src/db.ts:112-144 (handler)The `describeTable` method on `DbManager` that executes the SQL query against sys.columns, sys.tables, sys.indexes, and sys.default_constraints to return column metadata (name, type, max_length, precision, scale, nullability, identity, primary key, default value).
async describeTable(schema: string, table: string) { const r = await (await this.getPool()) .request() .input('schema', sql.NVarChar, schema) .input('table', sql.NVarChar, table).query(` SELECT c.name AS column_name, TYPE_NAME(c.user_type_id) AS data_type, c.max_length, c.precision, c.scale, c.is_nullable, c.is_identity, CASE WHEN pk.column_id IS NOT NULL THEN 1 ELSE 0 END AS is_primary_key, dc.definition AS default_value FROM sys.columns c INNER JOIN sys.tables t ON c.object_id = t.object_id INNER JOIN sys.schemas s ON t.schema_id = s.schema_id LEFT JOIN ( SELECT ic.object_id, ic.column_id FROM sys.indexes i INNER JOIN sys.index_columns ic ON i.object_id = ic.object_id AND i.index_id = ic.index_id WHERE i.is_primary_key = 1 ) pk ON pk.object_id = c.object_id AND pk.column_id = c.column_id LEFT JOIN sys.default_constraints dc ON dc.parent_object_id = c.object_id AND dc.parent_column_id = c.column_id WHERE s.name = @schema AND t.name = @table ORDER BY c.column_id `); return r.recordset; } - src/index.ts:83-86 (schema)Zod schema for describe_table input parameters: `schema` (string, required, describes 'Schema name (e.g. "dbo")') and `table` (string, required, describes 'Table name.').
{ schema: z.string().describe('Schema name (e.g. "dbo").'), table: z.string().describe('Table name.'), }, - src/index.ts:80-88 (registration)Registration of the 'describe_table' tool with the MCP server via `server.tool(...)`. Binds the tool name, description, and handler.
server.tool( 'describe_table', 'Return columns, data types, nullability, identity, primary key, and defaults for a table.', { schema: z.string().describe('Schema name (e.g. "dbo").'), table: z.string().describe('Table name.'), }, async ({ schema, table }) => runTool(() => db.describeTable(schema, table)) );