Skip to main content
Glama
TranChiHuu

MCP SQL Server

by TranChiHuu

list_tables

Retrieve all table names from your connected database to inspect schema structure and identify available data sources.

Instructions

List all tables in the connected database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The primary handler function for the 'list_tables' tool. It checks for an active database connection and executes database-specific queries to retrieve and return a list of tables in JSON format for both PostgreSQL and MySQL.
    async listTables() {
      if (!this.currentConfig) {
        throw new Error('Not connected to any database. Call connect_database first.');
      }
    
      if (this.currentConfig.type === 'postgresql') {
        if (!this.postgresPool) {
          throw new Error('PostgreSQL connection not initialized');
        }
    
        const query = `
          SELECT table_name 
          FROM information_schema.tables 
          WHERE table_schema = 'public' 
          ORDER BY table_name;
        `;
        const result = await this.postgresPool.query(query);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  tables: result.rows.map((row) => row.table_name),
                },
                null,
                2
              ),
            },
          ],
        };
      } else if (this.currentConfig.type === 'mysql') {
        if (!this.mysqlConnection) {
          throw new Error('MySQL connection not initialized');
        }
    
        const [rows] = await this.mysqlConnection.query(
          `SHOW TABLES FROM ${this.currentConfig.database}`
        );
        const tableKey = `Tables_in_${this.currentConfig.database}`;
        const tables = rows.map((row) => row[tableKey]);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  tables: tables,
                },
                null,
                2
              ),
            },
          ],
        };
      } else {
        throw new Error(`Unsupported database type: ${this.currentConfig.type}`);
      }
    }
  • index.js:175-182 (registration)
    Tool registration in the ListToolsRequestSchema handler, defining the name, description, and empty input schema for the 'list_tables' tool.
    {
      name: 'list_tables',
      description: 'List all tables in the connected database',
      inputSchema: {
        type: 'object',
        properties: {},
      },
    },
  • Input schema definition for the 'list_tables' tool, which requires no parameters.
    inputSchema: {
      type: 'object',
      properties: {},
    },
  • Dispatch case in the CallToolRequestSchema handler that invokes the listTables method for the 'list_tables' tool.
    case 'list_tables':
      return await this.listTables();

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

B3.1/5.0
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 the action ('List all tables') but doesn't mention any behavioral traits like whether this is a read-only operation, if it requires specific permissions, how results are formatted, or if there are rate limits. This leaves significant gaps for a tool that interacts with a database.

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 with no wasted words. It's front-loaded with the core action and resource, making it easy to parse quickly. Every part of the sentence contributes directly to understanding the tool's purpose.

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 of database interactions and the lack of annotations and output schema, the description is incomplete. It doesn't address what the output looks like (e.g., list format, error handling), behavioral aspects like safety or permissions, or how it fits with siblings. For a tool with no structured support, more context is needed.

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 appropriately doesn't add parameter details, as there are none to explain. This meets the baseline for tools with no parameters.

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 verb ('List') and resource ('all tables in the connected database'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_table_info' or 'describe_table', which might also provide table-related information but with different scopes or details.

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 'get_table_info' or 'describe_table'. It lacks context about prerequisites (e.g., needing to connect to a database first) or exclusions, leaving the agent to infer usage based on tool names alone.

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