Skip to main content
Glama
NakiriYuuzu

MSSQL MCP Server

by NakiriYuuzu

list-databases

Retrieve a list of all user databases on an MSSQL Server using the MCP interface, enabling efficient database identification and management.

Instructions

列出伺服器上的所有使用者資料庫

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP tool handler for 'list-databases': validates connection, retrieves databases via MSSQLManager.getDatabases(), formats output as a text list with count, names, creation dates, and collations, handles errors.
    async () => {
      try {
        if (!mssqlManager.isConnected()) {
          return {
            content: [
              {
                type: 'text' as const,
                text: '錯誤: 尚未連接到資料庫伺服器。請先使用 connect-database 工具建立連接。'
              }
            ]
          }
        }
    
        const databases = await mssqlManager.getDatabases()
    
        if (databases.length === 0) {
          return {
            content: [
              {
                type: 'text' as const,
                text: '沒有找到使用者資料庫。'
              }
            ]
          }
        }
    
        const databaseList = databases.map(db =>
          `- ${db.name} (建立時間: ${new Date(db.create_date).toLocaleDateString()}, 定序: ${db.collation_name})`
        ).join('\n')
    
        return {
          content: [
            {
              type: 'text' as const,
              text: `找到 ${databases.length} 個資料庫:\n${databaseList}`
            }
          ]
        }
      } catch (error) {
        return {
          content: [
            {
              type: 'text' as const,
              text: `列出資料庫失敗: ${error instanceof Error ? error.message : String(error)}`
            }
          ]
        }
      }
    }
  • Type definition for DatabaseInfo, used in getDatabases() return type and tool output formatting.
    export interface DatabaseInfo {
      name: string
      database_id: number
      create_date: string
      collation_name: string
    }
  • src/index.ts:94-149 (registration)
    Registers the 'list-databases' tool with the MCP server using server.registerTool, defining title, description (no inputSchema), and inline handler.
    server.registerTool(
      'list-databases',
      {
        title: '列出資料庫',
        description: '列出伺服器上的所有使用者資料庫'
      },
      async () => {
        try {
          if (!mssqlManager.isConnected()) {
            return {
              content: [
                {
                  type: 'text' as const,
                  text: '錯誤: 尚未連接到資料庫伺服器。請先使用 connect-database 工具建立連接。'
                }
              ]
            }
          }
    
          const databases = await mssqlManager.getDatabases()
    
          if (databases.length === 0) {
            return {
              content: [
                {
                  type: 'text' as const,
                  text: '沒有找到使用者資料庫。'
                }
              ]
            }
          }
    
          const databaseList = databases.map(db =>
            `- ${db.name} (建立時間: ${new Date(db.create_date).toLocaleDateString()}, 定序: ${db.collation_name})`
          ).join('\n')
    
          return {
            content: [
              {
                type: 'text' as const,
                text: `找到 ${databases.length} 個資料庫:\n${databaseList}`
              }
            ]
          }
        } catch (error) {
          return {
            content: [
              {
                type: 'text' as const,
                text: `列出資料庫失敗: ${error instanceof Error ? error.message : String(error)}`
              }
            ]
          }
        }
      }
    )
  • MSSQLManager.getDatabases() helper method: executes SQL query on sys.databases to list user databases (excludes system DBs), returns typed DatabaseInfo[] via executeQuery.
    async getDatabases(): Promise<DatabaseInfo[]> {
      const query = `
        SELECT 
          name,
          database_id,
          create_date,
          collation_name
        FROM sys.databases 
        WHERE name NOT IN ('master', 'tempdb', 'model', 'msdb')
        ORDER BY name
      `
      
      const result = await this.executeQuery(query)
      return result.recordset as DatabaseInfo[]
    }
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. It states what the tool does but lacks behavioral details such as whether it requires authentication, how results are formatted (e.g., list of names, JSON), if there are rate limits, or if it's a read-only operation. The description is minimal and doesn't compensate for the lack of annotations.

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, clear sentence that directly states the tool's purpose with zero waste. It's appropriately sized and front-loaded, making it easy to understand at a glance.

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

Completeness3/5

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

Given the tool's simplicity (0 parameters, no output schema, no annotations), the description is adequate but has gaps. It covers the basic purpose but lacks context on usage, behavioral traits, or output format. For a list operation with no structured data, more guidance would be helpful, but it meets the minimum viable threshold.

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 input schema has 0 parameters with 100% coverage, so no parameter documentation is needed. The description doesn't add parameter details, which is appropriate here. A baseline of 4 is applied since there are no parameters to document, and the description doesn't introduce confusion.

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 action (list) and target (user databases on the server). It's specific enough to understand the tool's function, though it doesn't explicitly differentiate from sibling tools like 'list-tables' or 'describe-table' beyond the scope of databases vs. tables.

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?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a connection first), exclusions, or comparisons to siblings like 'list-tables' (which lists tables within a database) or 'describe-table' (which describes table structure).

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