describe_table
Retrieve column names and data types for a specified MSSQL database table to understand its structure and schema.
Instructions
Describes the schema (columns and types) of a specified MSSQL Database table.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tableName | Yes | Name of the table to describe |
Implementation Reference
- src/tools/DescribeTableTool.ts:17-34 (handler)The main handler function that executes the tool logic by querying the database's INFORMATION_SCHEMA.COLUMNS for the specified table's columns and types.async run(params: { tableName: string }) { try { const { tableName } = params; const request = new sql.Request(); const query = `SELECT COLUMN_NAME as name, DATA_TYPE as type FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @tableName`; request.input("tableName", sql.NVarChar, tableName); const result = await request.query(query); return { success: true, columns: result.recordset, }; } catch (error) { return { success: false, message: `Failed to describe table: ${error}`, }; } }
- src/tools/DescribeTableTool.ts:7-15 (schema)The tool's name, description, and input schema defining the required 'tableName' parameter.name = "describe_table"; description = "Describes the schema (columns and types) of a specified MSSQL Database table."; inputSchema = { type: "object", properties: { tableName: { type: "string", description: "Name of the table to describe" }, }, required: ["tableName"], } as any;
- src/index.ts:109-113 (registration)Registration of the tool in the ListToolsRequestHandler, where describeTableTool is included in the list of available tools based on readonly mode.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: isReadOnly ? [listTableTool, readDataTool, describeTableTool] // todo: add searchDataTool to the list of tools available in readonly mode once implemented : [insertDataTool, readDataTool, describeTableTool, updateDataTool, createTableTool, createIndexTool, dropTableTool, listTableTool], // add all new tools here }));
- src/index.ts:141-149 (registration)Dispatch logic in CallToolRequestHandler that validates arguments and invokes the describeTableTool.run method.case describeTableTool.name: if (!args || typeof args.tableName !== "string") { return { content: [{ type: "text", text: `Missing or invalid 'tableName' argument for describe_table tool.` }], isError: true, }; } result = await describeTableTool.run(args as { tableName: string }); break;
- src/index.ts:90-90 (registration)Instantiation of the DescribeTableTool instance used throughout the server.const describeTableTool = new DescribeTableTool();