Skip to main content
Glama
antonorlov

MCP PostgreSQL Server

list_tables

Retrieve a list of database tables to inspect schema structure and identify available data sources for PostgreSQL operations.

Instructions

List tables in the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNoSchema name (default: public)

Implementation Reference

  • The handler function for list_tables tool. Ensures database connection, queries information_schema.tables for tables in the given schema (default 'public'), returns table names as JSON, handles errors.
    private async handleListTables(args: any = {}) {
      await this.ensureConnection();
    
      const schema = args.schema || 'public';
    
      try {
        const result = await this.client!.query(`
          SELECT table_name
          FROM information_schema.tables
          WHERE table_schema = $1
          ORDER BY table_name
        `, [schema]);
        
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result.rows, null, 2),
            },
          ],
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to list tables: ${getErrorMessage(error)}`
        );
      }
    }
  • Input schema for list_tables tool, defining an optional 'schema' string parameter.
    inputSchema: {
      type: 'object',
      properties: {
        schema: {
          type: 'string',
          description: 'Schema name (default: public)',
        },
      },
      required: [],
    },
  • src/index.ts:220-233 (registration)
    Registration of the list_tables tool in the ListToolsRequestSchema response, including name, description, and input schema.
    {
      name: 'list_tables',
      description: 'List tables in the database',
      inputSchema: {
        type: 'object',
        properties: {
          schema: {
            type: 'string',
            description: 'Schema name (default: public)',
          },
        },
        required: [],
      },
    },
  • src/index.ts:265-266 (registration)
    Routing logic in the CallToolRequestSchema handler that dispatches list_tables calls to the handleListTables method.
    case 'list_tables':
      return await this.handleListTables(request.params.arguments);

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

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