# postgres_mcp

> postgres_mcp is an open-source MCP server for databases. MCP server giving AI clients read-first access to PostgreSQL databases. It is available on CLI, Self-hosted and API.

- **Kind:** MCP server
- **Pricing:** Open source
- **Platforms:** CLI, Self-hosted, API
- **Repository:** https://github.com/javimaligno/postgres_mcp
- **GitHub stars:** 12
- **License:** MIT
- **Categories:** [databases](https://ai-powered.com/categories/databases)
- **Listing updated:** 2026-12-01

## About

Lets an AI assistant inspect and query PostgreSQL databases through the Model Context Protocol. Schemas, tables, views, functions, indexes and constraints can be browsed, and SQL can be run with read-only enforcement on by default. Writes are only possible when explicitly enabled.

Several connections can be declared under aliases so one client session can work across a production replica and a local database, with each connection carrying its own write permission. Credentials stay in environment variables and are never returned by tools. Optional layers mask emails, phone numbers, card numbers and other personal identifiers, or restrict results to an allow list of columns before the model sees them.

The server is published in TypeScript and Python builds and works with Claude Code, Claude Desktop, Cursor and other MCP-compatible clients. It suits developers and analysts who want an assistant to explore schemas, draft queries, check query plans or document a database.

## Features

- **Read-only by default:** Write statements are blocked unless ALLOW_WRITE_OPERATIONS or a per-connection setting enables them.
- **Schema exploration tools:** Lists and describes schemas, tables, views, functions, indexes and constraints.
- **Query plan analysis:** Runs EXPLAIN on queries and reports table statistics such as row count and size.
- **Multiple named connections:** Declares several databases by alias and selects one per call without exposing credentials.
- **Personal-data redaction:** Optionally masks detected personal identifiers, denied columns or all columns outside an allow list.
- **Guided prompts and resources:** Provides prompts for exploration and data dictionaries plus browsable markdown views of the schema.

## Good for

- Exploring an unfamiliar PostgreSQL database through natural-language questions
- Drafting and checking SQL queries against a development database
- Diagnosing slow queries with EXPLAIN output and index listings
- Generating a data dictionary for a schema
- Querying a production replica while keeping personal data masked

## Tools

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

- `query` (name suggests: reads): Execute read-only SQL queries against the database
- `execute` (name suggests: changes): Execute write operations (INSERT/UPDATE/DELETE) when enabled
- `explain_query` (name suggests: reads): Get EXPLAIN plan for query optimization
- `list_schemas` (name suggests: reads): List all schemas in the database
- `list_tables` (name suggests: reads): List tables in a specific schema
- `describe_table` (name suggests: reads): Get table structure (columns, types, constraints)
- `list_views` (name suggests: reads): List views in a schema
- `describe_view` (name suggests: reads): Get view definition and columns
- `list_functions` (name suggests: reads): List functions and procedures
- `table_stats`: Get table statistics (row count, size, bloat)
- `list_indexes` (name suggests: reads): List indexes for a table
- `list_constraints` (name suggests: reads): List constraints (PK, FK, UNIQUE, CHECK)
- `get_database_info` (name suggests: reads): Get database version and connection info
- `search_columns` (name suggests: reads): Search for columns by name across all tables
- `list_databases` (name suggests: reads): List the configured connections by alias

## FAQ

### Can the assistant change data by default?

No. Write operations such as INSERT, UPDATE and DELETE are blocked unless ALLOW_WRITE_OPERATIONS is set to true or the connection allows writes.

### Which clients does postgres_mcp work with?

It is documented for Claude Code, Claude Desktop, Cursor and any MCP-compatible client.

### Are database passwords sent to the model?

Credentials come only from environment variables and are not returned by any tool, including the one that lists connections.

### Which languages is postgres_mcp available in?

It is published as a TypeScript package installable through npm and as a Python package installable through pipx.

### Is postgres_mcp free?

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

### What are the best alternatives to postgres_mcp?

The closest alternatives to postgres_mcp are MCP Postgres, PostgreSQL MCP Server, sql-query-mcp, postgres-mcp and Postgres.

## Where this comes from

- Description: written from the project's README.

## Alternatives

- [MCP Postgres](https://ai-powered.com/mcp/mcp-postgres): MCP Postgres 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.
- [sql-query-mcp](https://ai-powered.com/mcp/sql-query-mcp): sql-query-mcp is an open-source MCP server for databases.
- [postgres-mcp](https://ai-powered.com/mcp/postgres-mcp-4): postgres-mcp is an open-source MCP server for databases.
- [Postgres](https://ai-powered.com/mcp/postgres-2): Postgres is an open-source MCP server for databases.
- [Postgres](https://ai-powered.com/mcp/postgres): Postgres is an open-source MCP server for databases.
- [pgmcp](https://ai-powered.com/mcp/pgmcp-2): pgmcp is an open-source MCP server for databases.
- [PostgreSQL](https://ai-powered.com/mcp/postgresql): PostgreSQL is an open-source MCP server for databases.

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