Skip to main content
Glama

get-all-tables

Retrieve a complete list of all database tables to explore PostgreSQL schema structure and available data sources.

Instructions

Execute SQL queries to get all tables in the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'get-all-tables' tool. It executes a fixed SQL query to retrieve all table names from the 'public' schema in the Postgres database using initDb().unsafe(sql), formats the results as JSON text content, and handles errors by returning an error message.
    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 }; } }
  • src/server.ts:135-162 (registration)
    Registration of the 'get-all-tables' tool using server.registerTool, including title, description, and the inline 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 lazily initialize and return the shared database connection (postgres.Sql), which is used by the get-all-tables handler.
    // Helper to initialize the database connection 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