Skip to main content
Glama
antonorlov

MCP PostgreSQL Server

list_tables

Retrieve a list of tables within a PostgreSQL database using schema name. Ideal for inspecting and managing database structures efficiently.

Instructions

List tables in the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNoSchema name (default: public)

Implementation Reference

  • The main handler function for the 'list_tables' tool. It connects to the database if needed, queries the information_schema.tables for the specified schema (default 'public'), and returns the list of table names as JSON.
    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 definition for the 'list_tables' tool, allowing an optional 'schema' 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 handler's tools array.
    { 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 case in the CallToolRequestSchema handler that invokes the list_tables handler.
    case 'list_tables': return await this.handleListTables(request.params.arguments);

Other Tools

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

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