Skip to main content
Glama
martymarkenson

PostgreSQL MCP Server

Get All Tables Query

get-all-tables

Retrieve a list of all tables in the connected PostgreSQL database for schema exploration and analysis.

Instructions

Execute SQL queries to get all tables in the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Registers and implements the 'get-all-tables' tool. The handler function queries information_schema.tables for all tables in the 'public' schema using postgres unsafe() method, returning results as JSON.
    // Tool to get all tables in the database
    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
          };
        }
      }
    );
  • src/server.ts:134-162 (registration)
    The tool is registered via server.registerTool('get-all-tables', ...) with title and description metadata. No inputSchema is defined (no parameters).
    // Tool to get all tables in the database
    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 initDb() that lazily initializes and returns a postgres database connection using getDb(). Used by the tool to execute the query.
    const initDb = () => {
      if(!dbConnection) {
        dbConnection = getDb();
      }
      return dbConnection;
    };
Behavior2/5

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

No annotations exist, so the description must disclose behavioral traits. It does not explicitly state the tool is read-only or mention any side effects, and the phrasing 'Execute SQL queries' could mislead about parameters.

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 sentence with no wasted words, front-loading the core action.

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

Completeness3/5

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

The description is adequate for a simple, parameterless tool, but it does not describe the return value format, which is missing since there is no output schema.

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

Parameters3/5

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

The input schema has no parameters (100% coverage), so baseline is 3. The description does not add parameter meaning beyond the schema, but it clarifies the tool's purpose.

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

Purpose5/5

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

The description clearly states the tool gets all tables in the database, with a specific verb and resource. It is distinct from siblings 'execute-sql-query' and 'test-postgres-connection'.

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

Usage Guidelines4/5

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

The description provides clear context that the tool lists all tables, but does not explicitly mention when to avoid using it or compare it to alternatives.

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