describe_table
Get column names and data types for SQL Server tables to understand database structure and schema details.
Instructions
Return column names and types for a table.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table | Yes | Table name (e.g. dbo.MyTable or MyTable) | |
| schema | No | Schema name (e.g. dbo). Defaults to dbo if table has no schema prefix. |
Implementation Reference
- src/index.ts:215-247 (registration)Tool registration for 'describe_table' with MCP server, including description and input schema definition using zod.
mcp.registerTool( "describe_table", { description: "Return column names and types for a table.", inputSchema: { table: z.string().describe("Table name (e.g. dbo.MyTable or MyTable)"), schema: z.string().optional().describe("Schema name (e.g. dbo). Defaults to dbo if table has no schema prefix."), }, }, async ({ table, schema }) => { try { const p = await getPool(); const schemaName = schema ?? "dbo"; const query = ` SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = @schema AND TABLE_NAME = @table ORDER BY ORDINAL_POSITION `; const result = await p .request() .input("schema", sql.NVarChar(128), schemaName) .input("table", sql.NVarChar(128), table) .query(query); const rows = (result.recordset ?? []) as Record<string, unknown>[]; const text = formatTable(rows); return { content: [{ type: "text" as const, text }] }; } catch (err) { const msg = err instanceof Error ? err.message : String(err); return { content: [{ type: "text" as const, text: `Error: ${msg}` }], isError: true }; } } ); - src/index.ts:224-246 (handler)Handler function that queries INFORMATION_SCHEMA.COLUMNS to retrieve column names, data types, max length, and nullability for a specified table.
async ({ table, schema }) => { try { const p = await getPool(); const schemaName = schema ?? "dbo"; const query = ` SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = @schema AND TABLE_NAME = @table ORDER BY ORDINAL_POSITION `; const result = await p .request() .input("schema", sql.NVarChar(128), schemaName) .input("table", sql.NVarChar(128), table) .query(query); const rows = (result.recordset ?? []) as Record<string, unknown>[]; const text = formatTable(rows); return { content: [{ type: "text" as const, text }] }; } catch (err) { const msg = err instanceof Error ? err.message : String(err); return { content: [{ type: "text" as const, text: `Error: ${msg}` }], isError: true }; } } - src/index.ts:219-222 (schema)Input schema validation defining 'table' (required) and 'schema' (optional) parameters for the describe_table tool.
inputSchema: { table: z.string().describe("Table name (e.g. dbo.MyTable or MyTable)"), schema: z.string().optional().describe("Schema name (e.g. dbo). Defaults to dbo if table has no schema prefix."), },