mssql_describe_table
Retrieve detailed table structure information including columns, data types, and constraints from Microsoft SQL Server databases for schema analysis and documentation.
Instructions
Get detailed information about a table structure
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| server | Yes | MSSQL Server hostname or IP address | |
| port | No | Port number (default: 1433) | |
| user | Yes | Username for authentication | |
| password | Yes | Password for authentication | |
| database | Yes | Database name | |
| table | Yes | Table name | |
| encrypt | No | Use encrypted connection (default: true) | |
| trustServerCertificate | No | Trust server certificate (default: true) |
Implementation Reference
- src/index.ts:527-572 (handler)The handler function that executes the mssql_describe_table tool. It parses input arguments using ConnectionSchema, establishes a database connection, queries INFORMATION_SCHEMA.COLUMNS with a LEFT JOIN to identify primary keys, and returns structured JSON with table column details including name, type, nullability, default, lengths, precision, scale, and primary key status.private async handleDescribeTable(args: any) { const config = ConnectionSchema.parse(args); const { table } = args; const pool = await this.getConnection(config); const request = pool.request(); const result = await request.query(` USE [${config.database}]; SELECT c.COLUMN_NAME as column_name, c.DATA_TYPE as data_type, c.IS_NULLABLE as is_nullable, c.COLUMN_DEFAULT as default_value, 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 ( SELECT ku.TABLE_CATALOG, ku.TABLE_SCHEMA, ku.TABLE_NAME, ku.COLUMN_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS ku ON tc.CONSTRAINT_TYPE = 'PRIMARY KEY' AND tc.CONSTRAINT_NAME = ku.CONSTRAINT_NAME ) pk ON c.TABLE_CATALOG = pk.TABLE_CATALOG AND c.TABLE_SCHEMA = pk.TABLE_SCHEMA AND c.TABLE_NAME = pk.TABLE_NAME AND c.COLUMN_NAME = pk.COLUMN_NAME WHERE c.TABLE_NAME = '${table}' ORDER BY c.ORDINAL_POSITION `); return { content: [ { type: 'text', text: JSON.stringify({ server: config.server, database: config.database, table: table, columns: result.recordset, }, null, 2), }, ], }; }
- src/index.ts:308-320 (schema)Input schema definition for the mssql_describe_table tool, specifying properties like server, port, credentials, database, table, and connection options, with required fields enforced.inputSchema: { type: 'object', properties: { server: { type: 'string', description: 'MSSQL Server hostname or IP address' }, port: { type: 'number', description: 'Port number (default: 1433)', default: 1433 }, user: { type: 'string', description: 'Username for authentication' }, password: { type: 'string', description: 'Password for authentication' }, database: { type: 'string', description: 'Database name' }, table: { type: 'string', description: 'Table name' }, encrypt: { type: 'boolean', description: 'Use encrypted connection (default: true)', default: true }, trustServerCertificate: { type: 'boolean', description: 'Trust server certificate (default: true)', default: true }, }, required: ['server', 'user', 'password', 'database', 'table'],
- src/index.ts:305-322 (registration)Tool registration in the ListTools response, defining the name, description, and input schema for mssql_describe_table.{ name: 'mssql_describe_table', description: 'Get detailed information about a table structure', inputSchema: { type: 'object', properties: { server: { type: 'string', description: 'MSSQL Server hostname or IP address' }, port: { type: 'number', description: 'Port number (default: 1433)', default: 1433 }, user: { type: 'string', description: 'Username for authentication' }, password: { type: 'string', description: 'Password for authentication' }, database: { type: 'string', description: 'Database name' }, table: { type: 'string', description: 'Table name' }, encrypt: { type: 'boolean', description: 'Use encrypted connection (default: true)', default: true }, trustServerCertificate: { type: 'boolean', description: 'Trust server certificate (default: true)', default: true }, }, required: ['server', 'user', 'password', 'database', 'table'], }, },
- src/index.ts:441-442 (registration)Dispatch registration in the CallToolRequest handler switch statement that routes calls to the mssql_describe_table handler function.case 'mssql_describe_table': return await this.handleDescribeTable(args);