Skip to main content
Glama
michaelyuwh

Enhanced MCP MSSQL Server

by michaelyuwh

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
NameRequiredDescriptionDefault
serverYesMSSQL Server hostname or IP address
portNoPort number (default: 1433)
userYesUsername for authentication
passwordYesPassword for authentication
databaseYesDatabase name
tableYesTable name
encryptNoUse encrypted connection (default: true)
trustServerCertificateNoTrust server certificate (default: true)

Implementation Reference

  • 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),
          },
        ],
      };
    }
  • 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);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/michaelyuwh/mcp-mssql-connector'

If you have feedback or need assistance with the MCP directory API, please join our Discord server