# Postgres Schema MCP

> Postgres Schema MCP is an open-source MCP server for databases. MCP server that gives AI agents only the relevant slice of a wide Postgres schema. It runs locally on your machine and is started by your AI client.

- **Kind:** MCP server
- **Pricing:** Open source
- **Platforms:** CLI, Self-hosted, API
- **Repository:** https://github.com/akshayyswami/postgres-schema-mcp
- **MCP Registry name:** io.github.akshayyswami/postgres-schema-mcp
- **Categories:** [databases](https://ai-powered.com/categories/databases)
- **Listing updated:** 2026-11-21

## About

Rather than handing an agent a full schema dump that can be truncated or overflow the context window, this server ranks tables against the question being asked and returns the subset most likely needed, along with the foreign-key neighbours that make joins possible. A separate describe_table tool fetches any table by name when ranking misses it.

Queries are gated in three layers: a SQL parser that accepts only a single read-only SELECT, and a database role limited to SELECT with session and resource limits. The tool annotations are treated as documentation rather than enforcement, which the README states explicitly.

The project suits developers connecting coding or analytics agents to a large Postgres database who want fewer schema tokens per request and a guarded read path. Its published measurements come from the AdventureWorks sample schema, so results on other schemas will differ.

## Features

- **Relevant schema retrieval:** Ranks tables against the question with BM25 and adds a damped boost from foreign-key neighbours so joinable tables appear together.
- **Direct table lookup:** A describe_table tool returns any table by name, bypassing ranking when a needed table falls below the cutoff.
- **Layered read-only enforcement:** Combines an AST-based SQL guard, a SELECT-only database role and transaction settings that force read-only access.
- **Query plan inspection:** An explain_query tool returns the execution plan for a SQL statement without running it.
- **Bounded result sets:** Row count, per-cell and total size caps apply to query results, and the model is told when a cut occurs.
- **Local or HTTP transport:** Runs over stdio by default and can serve Streamable HTTP instead.

## Good for

- Letting a coding agent write SQL against a large production-style schema without loading every table definition
- Giving an analytics assistant read-only access to a Postgres database
- Reducing schema context tokens on each request for wide databases
- Exploring unfamiliar tables by name and inspecting their structure before querying

## Install

### Claude Code: Add with the CLI (Terminal)

```sh
claude mcp add postgres-schema-mcp -- uvx postgres-schema-mcp
```

Add --scope user to use it in every project, or --scope project to share it in .mcp.json.

### Claude Code: Or share it with your project (.mcp.json)

```json
{
  "mcpServers": {
    "postgres-schema-mcp": {
      "command": "uvx",
      "args": [
        "postgres-schema-mcp"
      ]
    }
  }
}
```

### Claude Desktop (claude_desktop_config.json)

```json
{
  "mcpServers": {
    "postgres-schema-mcp": {
      "command": "uvx",
      "args": [
        "postgres-schema-mcp"
      ]
    }
  }
}
```

Settings → Developer → Edit Config, then quit and reopen Claude Desktop.

### Cursor (~/.cursor/mcp.json)

```json
{
  "mcpServers": {
    "postgres-schema-mcp": {
      "command": "uvx",
      "args": [
        "postgres-schema-mcp"
      ]
    }
  }
}
```

Use .cursor/mcp.json in a project to share it with the project.

### VS Code (~/.copilot/mcp-config.json)

```json
{
  "mcpServers": {
    "postgres-schema-mcp": {
      "type": "stdio",
      "command": "uvx",
      "args": [
        "postgres-schema-mcp"
      ]
    }
  }
}
```

Or put the same entry in .mcp.json at your workspace root to share it.

### Codex: Add with the CLI (Terminal)

```sh
codex mcp add postgres-schema-mcp -- uvx postgres-schema-mcp
```

### Codex: Or add to config.toml (~/.codex/config.toml)

```toml
[mcp_servers.postgres-schema-mcp]
command = "uvx"
args = ["postgres-schema-mcp"]
```

### Gemini CLI and Antigravity: Gemini CLI (~/.gemini/settings.json)

```json
{
  "mcpServers": {
    "postgres-schema-mcp": {
      "command": "uvx",
      "args": [
        "postgres-schema-mcp"
      ]
    }
  }
}
```

Or run: gemini mcp add -s user postgres-schema-mcp uvx -- postgres-schema-mcp

### Gemini CLI and Antigravity: Antigravity (~/.gemini/config/mcp_config.json)

```json
{
  "mcpServers": {
    "postgres-schema-mcp": {
      "command": "uvx",
      "args": [
        "postgres-schema-mcp"
      ]
    }
  }
}
```

Use .agents/mcp_config.json to add it to one workspace only.

### Devin Desktop (~/.config/devin/mcp_config.json)

```json
{
  "mcpServers": {
    "postgres-schema-mcp": {
      "command": "uvx",
      "args": [
        "postgres-schema-mcp"
      ]
    }
  }
}
```

On Windows the file is %APPDATA%\\devin\\mcp_config.json. Use .devin/mcp_config.json to share it with a project.

### Cline (cline_mcp_settings.json)

```json
{
  "mcpServers": {
    "postgres-schema-mcp": {
      "command": "uvx",
      "args": [
        "postgres-schema-mcp"
      ]
    }
  }
}
```

Open it from the MCP Servers icon → Configure → Configure MCP Servers.

### Zed (Zed settings.json)

```json
{
  "context_servers": {
    "postgres-schema-mcp": {
      "command": "uvx",
      "args": [
        "postgres-schema-mcp"
      ]
    }
  }
}
```

Open it with zed: open settings file. Merge context_servers into the settings you already have.

### JetBrains AI Assistant and Junie: AI Assistant (Settings → Tools → AI Assistant → Model Context Protocol (MCP) → Add)

```json
{
  "mcpServers": {
    "postgres-schema-mcp": {
      "command": "uvx",
      "args": [
        "postgres-schema-mcp"
      ]
    }
  }
}
```

### JetBrains AI Assistant and Junie: Junie (~/.junie/mcp/mcp.json)

```json
{
  "mcpServers": {
    "postgres-schema-mcp": {
      "command": "uvx",
      "args": [
        "postgres-schema-mcp"
      ]
    }
  }
}
```

Use .junie/mcp/mcp.json to share it with a project.

### Kiro (~/.kiro/settings/mcp.json)

```json
{
  "mcpServers": {
    "postgres-schema-mcp": {
      "command": "uvx",
      "args": [
        "postgres-schema-mcp"
      ]
    }
  }
}
```

Use .kiro/settings/mcp.json to add it to one workspace only.

### Other clients (your client's MCP settings (most use this shape))

```json
{
  "mcpServers": {
    "postgres-schema-mcp": {
      "command": "uvx",
      "args": [
        "postgres-schema-mcp"
      ]
    }
  }
}
```

## Tools

From the tool list in its README, going by the names, 1 of 4 tools changes data. From the server's own tool labels and tool names; not verified by us.

- `search_schema` (name suggests: reads): Ranks schema tables against a natural-language question and returns a slice.
- `describe_table` (name suggests: reads): Returns detail for a table by name.
- `explain_query` (name suggests: reads): Returns the query plan for a SQL statement.
- `run_query` (name suggests: changes): Runs a read-only SQL query with a row limit.

## FAQ

### Can the server modify data?

The server is built to be read-only. Queries pass an AST check that rejects anything other than a single SELECT, and the database role used holds only SELECT privileges.

### How is Postgres Schema MCP installed?

It is available on PyPI and can be run with uvx using the postgres-schema-mcp command, with PGSS_DSN set to a database connection string for a role that can only SELECT.

### What tools does Postgres Schema MCP expose?

Four tools: search_schema, describe_table, explain_query and run_query.

### What is the token saving?

On the AdventureWorks benchmark with 68 tables, the mean retrieved slice was about 1,816 tokens against 10,927 for the full schema DDL, a reduction of roughly 83 percent for schema context only.

### Is Postgres Schema MCP free?

Yes. Postgres Schema MCP is open source, so you can use and self-host it for free.

### How do I add Postgres Schema MCP to Claude Code?

Run this command in your terminal: claude mcp add postgres-schema-mcp -- uvx postgres-schema-mcp

### What are the best alternatives to Postgres Schema MCP?

The closest alternatives to Postgres Schema MCP are Postgres MCP, PostgreSQL MCP Server, Postgres MCP, Postgres MCP and Dbridge MCP.

## Where this comes from

- Description: written from the project's README and its MCP Registry entry.
- Install steps: from the official MCP Registry entry.

## Alternatives

- [Postgres MCP](https://ai-powered.com/mcp/postgres-mcp): Postgres MCP is an open-source MCP server for databases.
- [PostgreSQL MCP Server](https://ai-powered.com/mcp/postgresql-mcp-server-2): PostgreSQL MCP Server is an open-source MCP server for databases.
- [Postgres MCP](https://ai-powered.com/mcp/postgres-mcp-2): Postgres MCP is an open-source MCP server for databases.
- [Postgres MCP](https://ai-powered.com/mcp/postgres-mcp-3): Postgres MCP is an open-source MCP server for databases.
- [Dbridge MCP](https://ai-powered.com/mcp/dbridge-mcp): Dbridge MCP is an open-source MCP server for databases.
- [PostgreSQL](https://ai-powered.com/mcp/postgresql): PostgreSQL is an open-source MCP server for databases.
- [PostgreSQL MCP Server](https://ai-powered.com/mcp/postgresql-mcp-server-4): PostgreSQL MCP Server is an open-source MCP server for databases.
- [PostgreSQL MCP Server](https://ai-powered.com/mcp/postgresql-mcp-server-3): PostgreSQL MCP Server is an open-source MCP server for databases.

---
Source: https://ai-powered.com/mcp/postgres-schema-mcp
