Skip to main content
Glama
martymarkenson

PostgreSQL MCP Server

Get All Tables Query

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;
    };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'Execute SQL queries' which implies a read operation, but doesn't specify whether this requires specific permissions, what database it targets, potential side effects, or response format. This leaves significant gaps in understanding the tool's behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without any wasted words. It's appropriately sized and front-loaded with the essential information, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (0 parameters, no output schema) and lack of annotations, the description is incomplete. It doesn't address key contextual elements like what database system it works with, whether it returns metadata or actual data, error handling, or how it differs from the 'execute-sql-query' sibling tool. The description should provide more context for proper usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has 0 parameters with 100% schema description coverage, so the schema already fully documents the parameter situation. The description doesn't need to add parameter information, and it appropriately doesn't mention any parameters. A baseline of 4 is appropriate for zero-parameter tools.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Execute SQL queries') and target resource ('get all tables in the database'), providing a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'execute-sql-query' which might also retrieve tables, so it doesn't reach the highest clarity level.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'execute-sql-query' or 'test-postgres-connection'. It lacks context about prerequisites, exclusions, or specific scenarios where this tool is preferred, leaving usage decisions ambiguous.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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

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