Skip to main content
Glama
NakiriYuuzu

MSSQL MCP Server

by NakiriYuuzu

describe-table

Retrieve and analyze the structure of specified tables in Microsoft SQL Server, including column details and schema information, to streamline database management and query optimization.

Instructions

查看指定資料表的欄位結構

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNameNo結構描述名稱 (預設: dbo)dbo
tableNameYes資料表名稱

Implementation Reference

  • Executes the 'describe-table' tool: validates connection and database, sanitizes input names, fetches columns via MSSQLManager, formats and returns the table structure as a text list.
    async ({ tableName, schemaName }) => {
      try {
        if (!mssqlManager.isConnected()) {
          return {
            content: [
              {
                type: 'text' as const,
                text: '錯誤: 尚未連接到資料庫伺服器。請先使用 connect-database 工具建立連接。'
              }
            ]
          }
        }
    
        const currentDb = mssqlManager.getCurrentDatabase()
        if (!currentDb) {
          return {
            content: [
              {
                type: 'text' as const,
                text: '錯誤: 尚未選擇資料庫。請先使用 switch-database 工具選擇資料庫。'
              }
            ]
          }
        }
    
        const sanitizedTableName = sanitizeTableName(tableName)
        const sanitizedSchemaName = sanitizeTableName(schemaName)
    
        const columns = await mssqlManager.getTableColumns(sanitizedTableName, sanitizedSchemaName)
    
        if (columns.length === 0) {
          return {
            content: [
              {
                type: 'text' as const,
                text: `找不到資料表 ${sanitizedSchemaName}.${sanitizedTableName}。`
              }
            ]
          }
        }
    
        const columnList = columns.map(col => {
          let typeInfo = col.data_type
          if (col.character_maximum_length) {
            typeInfo += `(${col.character_maximum_length})`
          } else if (col.numeric_precision && col.numeric_scale !== null) {
            typeInfo += `(${col.numeric_precision},${col.numeric_scale})`
          }
    
          const nullable = col.is_nullable === 'YES' ? 'NULL' : 'NOT NULL'
          return `- ${col.column_name}: ${typeInfo} ${nullable}`
        }).join('\n')
    
        return {
          content: [
            {
              type: 'text' as const,
              text: `資料表 ${sanitizedSchemaName}.${sanitizedTableName} 的欄位結構:\n${columnList}`
            }
          ]
        }
      } catch (error) {
        return {
          content: [
            {
              type: 'text' as const,
              text: `查看資料表結構失敗: ${error instanceof Error ? error.message : String(error)}`
            }
          ]
        }
      }
    }
  • Zod input schema defining parameters for tableName (required string) and schemaName (optional string, default 'dbo').
    {
      title: '查看表格結構',
      description: '查看指定資料表的欄位結構',
      inputSchema: {
        tableName: z.string().describe('資料表名稱'),
        schemaName: z.string().optional().default('dbo').describe('結構描述名稱 (預設: dbo)'),
      }
    },
  • src/index.ts:269-351 (registration)
    Registers the 'describe-table' tool on the MCP server with title, description, input schema, and handler function.
    server.registerTool(
      'describe-table',
      {
        title: '查看表格結構',
        description: '查看指定資料表的欄位結構',
        inputSchema: {
          tableName: z.string().describe('資料表名稱'),
          schemaName: z.string().optional().default('dbo').describe('結構描述名稱 (預設: dbo)'),
        }
      },
      async ({ tableName, schemaName }) => {
        try {
          if (!mssqlManager.isConnected()) {
            return {
              content: [
                {
                  type: 'text' as const,
                  text: '錯誤: 尚未連接到資料庫伺服器。請先使用 connect-database 工具建立連接。'
                }
              ]
            }
          }
    
          const currentDb = mssqlManager.getCurrentDatabase()
          if (!currentDb) {
            return {
              content: [
                {
                  type: 'text' as const,
                  text: '錯誤: 尚未選擇資料庫。請先使用 switch-database 工具選擇資料庫。'
                }
              ]
            }
          }
    
          const sanitizedTableName = sanitizeTableName(tableName)
          const sanitizedSchemaName = sanitizeTableName(schemaName)
    
          const columns = await mssqlManager.getTableColumns(sanitizedTableName, sanitizedSchemaName)
    
          if (columns.length === 0) {
            return {
              content: [
                {
                  type: 'text' as const,
                  text: `找不到資料表 ${sanitizedSchemaName}.${sanitizedTableName}。`
                }
              ]
            }
          }
    
          const columnList = columns.map(col => {
            let typeInfo = col.data_type
            if (col.character_maximum_length) {
              typeInfo += `(${col.character_maximum_length})`
            } else if (col.numeric_precision && col.numeric_scale !== null) {
              typeInfo += `(${col.numeric_precision},${col.numeric_scale})`
            }
    
            const nullable = col.is_nullable === 'YES' ? 'NULL' : 'NOT NULL'
            return `- ${col.column_name}: ${typeInfo} ${nullable}`
          }).join('\n')
    
          return {
            content: [
              {
                type: 'text' as const,
                text: `資料表 ${sanitizedSchemaName}.${sanitizedTableName} 的欄位結構:\n${columnList}`
              }
            ]
          }
        } catch (error) {
          return {
            content: [
              {
                type: 'text' as const,
                text: `查看資料表結構失敗: ${error instanceof Error ? error.message : String(error)}`
              }
            ]
          }
        }
      }
    )
  • MSSQLManager method that queries INFORMATION_SCHEMA.COLUMNS to retrieve column information for the specified table and schema.
    async getTableColumns(tableName: string, schemaName: string = 'dbo'): Promise<ColumnInfo[]> {
      if (!this.currentDatabase) {
        throw new Error('尚未選擇資料庫')
      }
    
      const query = `
        SELECT 
          COLUMN_NAME as column_name,
          DATA_TYPE as data_type,
          IS_NULLABLE as is_nullable,
          CHARACTER_MAXIMUM_LENGTH as character_maximum_length,
          NUMERIC_PRECISION as numeric_precision,
          NUMERIC_SCALE as numeric_scale
        FROM INFORMATION_SCHEMA.COLUMNS
        WHERE TABLE_NAME = '${tableName}' AND TABLE_SCHEMA = '${schemaName}'
        ORDER BY ORDINAL_POSITION
      `
      
      const result = await this.executeQuery(query)
      return result.recordset as ColumnInfo[]
    }
  • TypeScript interface defining the structure of column information returned by getTableColumns.
    export interface ColumnInfo {
      column_name: string
      data_type: string
      is_nullable: string
      character_maximum_length: number | null
      numeric_precision: number | null
      numeric_scale: number | null
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states this is a read operation ('查看' - view), implying it's non-destructive, but doesn't mention authentication requirements, rate limits, error conditions, or what the output contains (e.g., column names, types, constraints). For a metadata tool with zero annotation coverage, this leaves significant gaps in understanding how the tool behaves.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence in Chinese that directly states the tool's purpose without any fluff. It's appropriately sized and front-loaded, with every word contributing to understanding what the tool does. No wasted space or unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (metadata inspection with 2 parameters), lack of annotations, and no output schema, the description is incomplete. It doesn't explain what '欄位結構' (field structure) includes, potential output format, error handling, or dependencies on other tools like 'connect-database'. For a tool that likely returns detailed schema information, more context is needed to use it effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with both parameters ('schemaName' and 'tableName') clearly documented in the schema. The description adds no additional parameter information beyond implying a 'tableName' is required. Since the schema does the heavy lifting, the baseline score of 3 is appropriate—the description doesn't compensate but doesn't need to given the comprehensive schema documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description '查看指定資料表的欄位結構' (View the field structure of a specified table) clearly states the tool's purpose with a specific verb ('查看' - view) and resource ('資料表的欄位結構' - table's field structure). It distinguishes this as a metadata inspection tool rather than a data query or connection management tool, though it doesn't explicitly differentiate from potential sibling tools like 'list-tables' beyond the obvious scope difference.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. While the purpose is clear, there's no mention of prerequisites (e.g., needing an active database connection), when this tool is appropriate versus 'list-tables' or 'execute-query', or any constraints on its use. The agent must infer usage from context alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related 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/NakiriYuuzu/Mssql-Mcp'

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