Skip to main content
Glama
mlsloynaz

mcp-sqlserver

by mlsloynaz

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
NameRequiredDescriptionDefault
tableYesTable name (e.g. dbo.MyTable or MyTable)
schemaNoSchema 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 };
        }
      }
    );
  • 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 };
      }
    }
  • 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."),
    },

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

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/mlsloynaz/mcp-sql-server'

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