Skip to main content
Glama

get-all-tables

Retrieve a complete list of all tables in your PostgreSQL database. This tool executes SQL queries to display every table, enabling database exploration and schema analysis.

Instructions

Execute SQL queries to get all tables in the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler function that executes a fixed SQL query to retrieve all table names from the public schema in the Postgres database, formats the results as JSON, and handles errors.
    async () => { const sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; try { const results = await initDb().unsafe(sql); return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }] }; } catch (err: unknown) { const error = err as Error; return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; } }
  • Metadata schema for the tool including title and description. No input schema as the tool takes no parameters.
    { title: "Get All Tables Query", description: "Execute SQL queries to get all tables in the database", },
  • src/server.ts:135-162 (registration)
    Registers the 'get-all-tables' tool with the MCP server, providing name, schema/metadata, and handler function.
    server.registerTool( "get-all-tables", { title: "Get All Tables Query", description: "Execute SQL queries to get all tables in the database", }, async () => { const sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; try { const results = await initDb().unsafe(sql); return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }] }; } catch (err: unknown) { const error = err as Error; return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; } } );
  • Helper function to initialize and lazily create the Postgres database connection, called within the tool handler.
    const initDb = () => { if(!dbConnection) { dbConnection = getDb(); } return dbConnection; };

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/martymarkenson/Postgres-Connector-MCP'

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