Skip to main content
Glama
sbfulfil

PostgreSQL MCP Server

by sbfulfil

list_tables

Retrieve all tables in a PostgreSQL database with basic information like schema details. Use this tool to explore database structure and understand table relationships.

Instructions

List all tables in the database with basic information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNoSchema name (default: public)public

Implementation Reference

  • The core handler function for the 'list_tables' tool. It connects to the PostgreSQL database, executes a query against information_schema.tables to list tables in the specified schema, formats the results as a text list, and returns the MCP-formatted response.
    async listTables(schema = 'public') {
      const client = await this.connectToDatabase();
      
      try {
        const query = `
          SELECT 
            table_name,
            table_type,
            is_insertable_into,
            is_typed
          FROM information_schema.tables 
          WHERE table_schema = $1
          ORDER BY table_name;
        `;
        
        const result = await client.query(query, [schema]);
        
        return {
          content: [
            {
              type: 'text',
              text: `Tables in schema "${schema}":\n\n` + 
                    result.rows.map(row => 
                      `• ${row.table_name} (${row.table_type})`
                    ).join('\n'),
            },
          ],
        };
      } finally {
        await client.end();
      }
    }
  • Input schema definition for the 'list_tables' tool, defining an optional 'schema' parameter with default 'public'.
    inputSchema: {
      type: 'object',
      properties: {
        schema: {
          type: 'string',
          description: 'Schema name (default: public)',
          default: 'public'
        }
      },
    },
  • src/index.js:57-70 (registration)
    Registration of the 'list_tables' tool in the ListToolsRequestSchema handler, including name, description, and input schema.
    {
      name: 'list_tables',
      description: 'List all tables in the database with basic information',
      inputSchema: {
        type: 'object',
        properties: {
          schema: {
            type: 'string',
            description: 'Schema name (default: public)',
            default: 'public'
          }
        },
      },
    },
  • Dispatch handler in the CallToolRequestSchema switch statement that routes 'list_tables' calls to the listTables method, passing the schema argument.
    case 'list_tables':
      return await this.listTables(args?.schema || 'public');
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 this is a list operation, implying it's read-only, but doesn't mention potential side effects, permissions required, rate limits, or what 'basic information' includes (e.g., table names, row counts). For a tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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 directly states the tool's purpose without unnecessary words. It's front-loaded with the core action ('List all tables'), making it easy to parse quickly. Every part of the sentence contributes meaning.

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?

For a simple list tool with one optional parameter and no output schema, the description is minimally adequate but lacks depth. It doesn't explain what 'basic information' includes, how results are formatted, or any limitations (e.g., pagination). With no annotations and incomplete behavioral context, it leaves the agent guessing about practical usage details.

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%, with the single parameter 'schema' fully documented in the input schema (including default value). The description doesn't add any parameter-specific details beyond what the schema provides, such as explaining why schema filtering is useful or how it interacts with the 'list all tables' claim. Baseline 3 is appropriate when the schema does the heavy lifting.

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 ('tables in the database') with scope ('all'), making the purpose unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'list_schemas' or 'describe_table', which would require more specific language about what distinguishes listing tables from listing schemas or describing individual 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?

The description provides no guidance on when to use this tool versus alternatives like 'list_schemas' or 'describe_table'. It mentions 'basic information' but doesn't specify what that entails or when a more detailed tool might be needed. No exclusions or prerequisites are stated.

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/sbfulfil/pg-mcp'

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