Skip to main content
Glama
MadeByNando

MCP Postgres Server

by MadeByNando

list_tables

Retrieve all tables within a specified schema on a PostgreSQL database using the Model Context Protocol (MCP) for secure and efficient database exploration.

Instructions

List all tables in a schema

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNo

Implementation Reference

  • The handler function that lists all tables in the public schema by querying information_schema.tables and returns a JSON array of table names.
    async () => { try { debugLog("Listing database tables"); return await executeDbQuery(async (client) => { const result = await withTimeout( client.query( "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'" ), API_TIMEOUT_MS, "Listing database tables" ) as pg.QueryResult; debugLog(`Found ${result.rows.length} tables`); const tableList = result.rows.map((row: { table_name: string }) => row.table_name); return { content: [ { type: "text", text: JSON.stringify(tableList, null, 2), }, ], }; }, "Failed to list database tables"); } catch (error) { handleError(error, "Failed to list database tables"); throw error; } }
  • index.ts:215-249 (registration)
    Registration of the postgres_list_tables tool on the MCP server, including empty input schema and inline handler.
    server.tool( "postgres_list_tables", {}, async () => { try { debugLog("Listing database tables"); return await executeDbQuery(async (client) => { const result = await withTimeout( client.query( "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'" ), API_TIMEOUT_MS, "Listing database tables" ) as pg.QueryResult; debugLog(`Found ${result.rows.length} tables`); const tableList = result.rows.map((row: { table_name: string }) => row.table_name); return { content: [ { type: "text", text: JSON.stringify(tableList, null, 2), }, ], }; }, "Failed to list database tables"); } catch (error) { handleError(error, "Failed to list database tables"); throw error; } } );
  • Input/output schema declaration for the tool in the MCP server capabilities. No parameters required.
    postgres_list_tables: { description: "List all tables in the PostgreSQL database", parameters: {},

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

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