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();
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, implying a read-only operation, but doesn't specify whether this requires specific permissions, what the output format looks like (e.g., list of names, metadata), or if there are limitations like pagination or rate limits. The description is minimal and misses key behavioral details for a tool with zero annotation coverage.

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 that front-loads the core purpose ('List all tables') with necessary context ('in the connected database'). There is zero waste—every word contributes directly to understanding the tool's function, 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.

Completeness3/5

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

Given the tool's low complexity (0 parameters, no output schema, no annotations), the description is adequate but has gaps. It covers the basic purpose and implies a read operation, but lacks details on output format, permissions, or behavioral traits. Without annotations or output schema, the description should do more to compensate, but it's minimally viable for this simple tool.

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 schema description coverage is 100% (though empty). The description doesn't need to add parameter details, as there are none to document. It appropriately focuses on the tool's purpose without redundant parameter explanations, meeting the baseline for zero 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 action ('List') and resource ('all tables in the connected database'), making the purpose immediately understandable. It distinguishes from siblings like 'describe_table' (details about specific tables) and 'execute_query' (general queries), though it doesn't explicitly mention these distinctions. The description avoids tautology by not just restating the tool name.

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

Usage Guidelines3/5

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

The description implies usage when needing to see all tables, but provides no explicit guidance on when to use this tool versus alternatives like 'describe_table' or 'execute_query'. It mentions the prerequisite of a 'connected database', which hints at needing 'connect_database' first, but lacks clear when/when-not instructions or named alternatives.

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/TranChiHuu/postgres-mysql-mcp-server'

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