Skip to main content
Glama
vini-cius

SQL Server MCP Service

by vini-cius

list_tables

Retrieve a list of all tables in your SQL Server database, with optional filtering by schema name.

Instructions

Lists all the tables in the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNameNoSchema name to filter tables (default: dbo)dbo

Implementation Reference

  • The core handler function 'listTables' that queries INFORMATION_SCHEMA.TABLES for base tables, optionally filtered by schema name, and returns results as JSON.
    export async function listTables(
      db: DatabaseConnection,
      schemaName?: string
    ): Promise<CallToolResult> {
      try {
        const pool = db.getPool()
    
        let query = `
          SELECT 
            TABLE_SCHEMA,
            TABLE_NAME,
            TABLE_TYPE
          FROM INFORMATION_SCHEMA.TABLES
          WHERE TABLE_TYPE = 'BASE TABLE'
        `.trim()
    
        const request = pool.request()
    
        if (schemaName) {
          query += ' AND TABLE_SCHEMA = @schemaName'
          request.input('schemaName', schemaName)
        }
    
        query += ' ORDER BY TABLE_SCHEMA, TABLE_NAME'
    
        const result = await request.query(query)
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  tables: result.recordset,
                  count: result.recordset.length,
                },
                null,
                2
              ),
            },
          ],
        }
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Erro: ${error instanceof Error ? error.message : 'Erro desconhecido'}`,
            },
          ],
          isError: true,
        }
      }
    }
  • Zod schema definition for 'listTablesInput' with an optional 'schemaName' string parameter.
    export const listTablesInput = z.object({
      schemaName: z
        .string()
        .optional()
        .describe('Schema name to filter tables (default: dbo)')
        .default('dbo'),
    })
  • Registration of 'list_tables' in the toolsSchemas mapping (line 67) and the ListTablesInput type export (line 78).
    export const toolsSchemas = {
      execute_query: executeQueryInput,
      get_table_schema: getTableSchemaInput,
      list_tables: listTablesInput,
      get_database_info: getDatabaseInfoInput,
      list_procedures: listProceduresInput,
      list_functions: listFunctionsInput,
      get_procedure_schema: getProcedureSchemaInput,
      get_function_schema: getFunctionSchemaInput,
      execute_procedure: executeProcedureInput,
    } as const
  • Re-export of the listTables handler (line 23) and registration of 'list_tables' tool in the toolsList() function (lines 38-41) with description and JSON schema.
    export { listTables } from './list-tables'
    
    export function toolsList() {
      return [
        {
          name: 'execute_query',
          description: 'Executes a SQL query in SQL Server',
          inputSchema: zodToJsonSchema(executeQueryInput),
        },
        {
          name: 'get_table_schema',
          description: 'Gets the schema of a specific table',
          inputSchema: zodToJsonSchema(getTableSchemaInput),
        },
        {
          name: 'list_tables',
          description: 'Lists all the tables in the database',
          inputSchema: zodToJsonSchema(listTablesInput),
        },
  • Handler wire-up in the createHandlerMap() method: maps 'list_tables' string to a lambda that parses args and delegates to the imported listTables function.
    handlers.set('list_tables', async (database, args) => {
      const { schemaName } = args as ListTablesInput
      return await listTables(database, schemaName)
    })
Behavior2/5

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

No annotations are provided, so the description carries the burden of disclosure. It fails to mention any behavioral traits such as whether the tool returns only table names or includes metadata, pagination behavior, or access restrictions. The description is too minimal to inform the agent of important behaviors.

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

Conciseness4/5

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

The description is a single short sentence, which is concise and front-loaded. However, it could be slightly improved by mentioning the optional schema filter for clarity.

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 low complexity (1 optional parameter, no output schema), the description is mostly complete but lacks behavioral context such as authentication assumptions or result format. Without annotations, the agent may miss important usage constraints.

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% (the parameter schemaName is well-described). The description adds no further meaning beyond the schema, but given full coverage, a baseline of 3 is appropriate. The description implies listing all tables without mentioning the filtering capability.

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

Purpose5/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: 'Lists all the tables in the database', with a specific verb and resource. It effectively distinguishes from sibling tools like get_table_schema (which returns schema of a specific table) and list_functions (which lists functions).

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, such as when to filter by schemaName or when to use get_table_schema instead. No exclusions or context for selection are given.

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

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/vini-cius/mcp-sqlserver'

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