madmarin/mcp-postgres-server
A production-ready MCP server that exposes PostgreSQL databases via the Model Context Protocol
Platform-specific configuration:
{
"mcpServers": {
"mcp-postgres-server": {
"command": "npx",
"args": [
"-y",
"mcp-postgres-server"
]
}
}
}Add the config above to .claude/settings.json under the mcpServers key.
A production-ready Model Context Protocol (MCP) server that gives AI assistants (Claude, etc.) direct, safe access to your PostgreSQL database.
[](https://github.com/madmarin/mcp-postgres-server/actions/workflows/ci.yml) [](https://pypi.org/project/mcp-postgres-server/) [](https://pypi.org/project/mcp-postgres-server/) [](LICENSE)
---
mcp-postgres-server exposes five tools to any MCP-compatible client:
| Tool | Description | |------|-------------| | query | Execute a read-only SELECT statement and get JSON results | | execute | Run a write statement (INSERT, UPDATE, DELETE, DDL) — requires ALLOW_WRITE=true | | list_schemas | List all user schemas in the database | | list_tables | List tables/views in a schema with row estimates and sizes | | describe_table | Get columns, primary key, foreign keys, and indexes for a table |
---
pip install mcp-postgres-serverOr install from source:
git clone https://github.com/madmarin/mcp-postgres-server
cd mcp-postgres-server
pip install -e .Copy .env.example to .env and fill in your connection details:
cp .env.example .envMinimum required:
DATABASE_URL=postgresql+psycopg://user:password@localhost:5432/mydbIf your password contains special characters (for example @, :, /, #, %), URL-encode it in DATABASE_URL.
Example:
# Raw password: p@ss:w0rd/with#chars%
DATABASE_URL=postgresql+psycopg://postgres:p%40ss%3Aw0rd%2Fwith%23chars%25@localhost:5432/mydbYou can encode safely with Python:
python3 -c "import urllib.Loading reviews...