Skip to main content
Glama
PostgreSQL MCP Server

PostgreSQL MCP Server

by KannaKim

PostgreSQL MCP Server

A generic Model Context Protocol (MCP) server for PostgreSQL, allowing AI agents to inspect and query PostgreSQL databases safely.

Features

  • list_tables: List all tables in the public schema.

  • get_schema: Get the schema (columns, types, nullability) of a specific table.

  • run_query: Run a read-only SQL query (only SELECT/WITH allowed) with a maximum limit of 100 rows to avoid large responses.

Related MCP server: PostgreSQL MCP Server

Prerequisites

  • Python 3.13+

  • uv

  • PostgreSQL database

Installation

You can run this directly using uvx or uv run if you clone the repository.

Usage

This server requires the DATABASE_URL environment variable to be set.

Example connection string: postgres://user:password@localhost:5432/mydatabase

Running directly

DATABASE_URL="postgresql://postgres:poggerpogger@localhost:5432/boxboxWeb" uv run main.py

Usage with Claude Desktop / MCP Clients

Add the following to your MCP client configuration (e.g., Claude Desktop's claude_desktop_config.json):

{
  "mcpServers": {
    "postgres": {
      "command": "uv",
      "args": [
        "run",
        "/path/to/2025postgresqlmcp/main.py"
      ],
      "env": {
        "DATABASE_URL": "postgres://user:password@localhost:5432/mydatabase"
      }
    }
  }
}

Available Tools

3 tools
get_schemaA

Get the schema (columns, types) of a specific table

Inputs: table_name (required).

list_tablesB

List all tables in the current database schema

Inputs: no named parameters.

run_queryA

Run a read-only SQL query against the database. ONLY SELECT queries are allowed for safety.

Inputs: query (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.8/5.0

    Scored across 3 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose: listing tables, retrieving table schema, and running arbitrary SQL queries. No overlap or ambiguity exists.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern (list_tables, get_schema, run_query), making them predictable and easy to understand.

    Tool Count4/5

    Three tools is on the lower end of the ideal range, but they cover the essential operations for a read-only database server. Slightly more tools (e.g., listing views) would improve scope without bloat.

    Completeness4/5

    The tool set provides core capabilities for exploring and querying a database, but lacks support for listing views, functions, or other database objects. This is acceptable for a focused MCP server.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to safely interact with PostgreSQL databases through read-only operations, providing schema discovery, table inspection, and query execution capabilities with structured context awareness.
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to safely interact with PostgreSQL databases, perform queries, inspect schemas, and analyze query performance.
      2
      ISC
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to query a PostgreSQL database through a small set of controlled, read-only tools for schema inspection, row lookup, and aggregate statistics.
      1
      MIT