Skip to main content
Glama
KannaKim

PostgreSQL MCP Server

by KannaKim
README.md
# 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.

## Prerequisites

- Python 3.13+
- [uv](https://github.com/astral-sh/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

```bash
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`):

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

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 issues