get-table
Retrieve a specific table by name from Microsoft SQL Server using the SQL Server MCP server, enabling direct database interactions for AI assistants.
Instructions
Get a specific table by name
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tableName | Yes | The name of the table to retrieve |
Implementation Reference
- src/tools/schema.ts:76-93 (handler)The handler function that implements the 'get-table' tool logic. It queries the database INFORMATION_SCHEMA for the specified table's columns and returns a formatted text result with column details.async getTable({ tableName }: { tableName: string }) { const table = await database.query(` SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @tableName ORDER BY ORDINAL_POSITION `, { tableName }); if (!table.length) return this.toResult(`Table with name: ${tableName} not found.`); const columns = table.map((col) => ({ columnName: col.COLUMN_NAME, dataType: col.DATA_TYPE, isNullable: col.IS_NULLABLE === "YES", })); return this.toResult(`Table: ${tableName}\nColumns:\n${JSON.stringify(columns)}`); }
- src/tools/schema.ts:16-21 (registration)Registration of the 'get-table' tool on the MCP server, including name, description, input schema, and binding to the handler method.server.tool( "get-table", "Get a specific table by name", { tableName: z.string().describe("The name of the table to retrieve") }, tools.getTable.bind(tools) )
- src/tools/schema.ts:19-19 (schema)Input schema definition using Zod for the 'get-table' tool, specifying the required 'tableName' string parameter.{ tableName: z.string().describe("The name of the table to retrieve") },