Skip to main content
Glama
NakiriYuuzu

MSSQL MCP Server

by NakiriYuuzu

list-tables

Retrieve and display a list of all tables within the current database on MSSQL MCP Server, simplifying database navigation and management.

Instructions

列出目前資料庫中的所有資料表

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'list-tables' MCP tool. It checks if connected to a database, verifies a current database is selected, calls mssqlManager.getTables() to fetch the list of tables, formats them as a bulleted list with schema, name, and type, and returns the result in MCP content format. Handles errors appropriately.
    async () => {
      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 tables = await mssqlManager.getTables()
    
        if (tables.length === 0) {
          return {
            content: [
              {
                type: 'text' as const,
                text: `資料庫 ${currentDb} 中沒有找到資料表。`
              }
            ]
          }
        }
    
        const tableList = tables.map(table =>
          `- ${table.table_schema}.${table.table_name} (${table.table_type})`
        ).join('\n')
    
        return {
          content: [
            {
              type: 'text' as const,
              text: `資料庫 ${currentDb} 中找到 ${tables.length} 個資料表:\n${tableList}`
            }
          ]
        }
      } catch (error) {
        return {
          content: [
            {
              type: 'text' as const,
              text: `列出資料表失敗: ${error instanceof Error ? error.message : String(error)}`
            }
          ]
        }
      }
    }
  • TableInfo interface defining the structure of table metadata returned by getTables(), used in the tool's output processing.
    export interface TableInfo {
      table_name: string
      table_schema: string
      table_type: string
    }
  • src/index.ts:199-266 (registration)
    Registration of the 'list-tables' tool with the MCP server, including title, description (no input schema), and reference to the inline handler function.
    server.registerTool(
      'list-tables',
      {
        title: '列出資料表',
        description: '列出目前資料庫中的所有資料表'
      },
      async () => {
        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 tables = await mssqlManager.getTables()
    
          if (tables.length === 0) {
            return {
              content: [
                {
                  type: 'text' as const,
                  text: `資料庫 ${currentDb} 中沒有找到資料表。`
                }
              ]
            }
          }
    
          const tableList = tables.map(table =>
            `- ${table.table_schema}.${table.table_name} (${table.table_type})`
          ).join('\n')
    
          return {
            content: [
              {
                type: 'text' as const,
                text: `資料庫 ${currentDb} 中找到 ${tables.length} 個資料表:\n${tableList}`
              }
            ]
          }
        } catch (error) {
          return {
            content: [
              {
                type: 'text' as const,
                text: `列出資料表失敗: ${error instanceof Error ? error.message : String(error)}`
              }
            ]
          }
        }
      }
    )
  • Core helper method MSSQLManager.getTables() that executes a SQL query against INFORMATION_SCHEMA.TABLES to retrieve all tables (name, schema, type) in the current database, returning typed TableInfo[] array.
    async getTables(): Promise<TableInfo[]> {
      if (!this.currentDatabase) {
        throw new Error('尚未選擇資料庫')
      }
    
      const query = `
        SELECT 
          TABLE_NAME as table_name,
          TABLE_SCHEMA as table_schema,
          TABLE_TYPE as table_type
        FROM INFORMATION_SCHEMA.TABLES
        ORDER BY TABLE_SCHEMA, TABLE_NAME
      `
      
      const result = await this.executeQuery(query)
      return result.recordset as TableInfo[]
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool lists tables but doesn't describe what 'current database' means, whether it requires an active connection, how results are formatted, or if there are limitations (e.g., pagination). For a tool with zero annotation coverage, this is a significant gap in transparency.

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: '列出目前資料庫中的所有資料表'. It is front-loaded with the core action and resource, with zero wasted words or redundancy, making it highly concise and well-structured.

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 complexity (a read operation with no parameters) and the lack of annotations and output schema, the description is incomplete. It doesn't explain what 'current database' refers to, whether a connection is required, or what the output looks like (e.g., a list of table names). For a tool with no structured support, more context is needed to be fully helpful.

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

Parameters4/5

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

The tool has 0 parameters, and the schema description coverage is 100% (since there are no parameters to describe). The description doesn't need to add parameter details, so it meets the baseline of 4 for tools with no parameters, as it doesn't have to compensate for any schema gaps.

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 clearly states the tool's purpose: '列出目前資料庫中的所有資料表' (List all tables in the current database). It specifies the verb '列出' (list) and the resource '資料表' (tables), making the action clear. However, it doesn't explicitly differentiate from sibling tools like 'list-databases' or 'describe-table', which would require a 5.

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. It doesn't mention prerequisites (e.g., needing a database connection), exclusions, or comparisons to siblings like 'list-databases' (which lists databases) or 'describe-table' (which describes a specific table). This leaves usage context ambiguous.

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