postgres-mcp
Provides tools for executing SQL queries, obtaining query execution plans, and inspecting table schemas in a PostgreSQL database.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@postgres-mcpshow me the schema of the users table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
postgres-mcp
An MCP server that exposes PostgreSQL query, EXPLAIN, and schema inspection tools to Claude Desktop (or any MCP-compatible client).
Tools
Tool | Parameters | Description |
|
| Run any SQL statement; SELECT returns rows as JSON, DML returns affected row count |
|
| Get the query execution plan. When |
|
| List columns (type, nullability, default) and indexes for a table |
Related MCP server: pg-mcp
Project layout
src/postgres_mcp/
server.py # FastMCP entry point, tool registrations
tools.py # SQL execution logic
db.py # Connection helper (reads DATABASE_URL)
tests/
test_tools.py
examples/
claude_desktop_config.jsonSetup
1. Prerequisites
Python 3.10+
uv —
brew install uvA running PostgreSQL instance
Claude Desktop (or another MCP client)
2. Clone and install
git clone https://github.com/RachelHuangZW/postgres-mcp
cd postgres-mcp
uv sync3. Configure your database
Copy .env.example to .env and fill in your connection string:
cp .env.example .env
# edit .env: DATABASE_URL=postgresql://user:password@localhost:5432/dbname4. Register with Claude Desktop
Edit ~/Library/Application Support/Claude/claude_desktop_config.json and merge in the mcpServers block (see examples/claude_desktop_config.json):
{
"mcpServers": {
"postgres-mcp": {
"command": "uv",
"args": ["run", "--directory", "/path/to/postgres-mcp", "python", "-m", "postgres_mcp.server"],
"env": {
"DATABASE_URL": "postgresql://user:password@localhost:5432/dbname"
}
}
}
}Replace /path/to/postgres-mcp with the absolute path to this repo and fill in your DATABASE_URL. Then fully quit and reopen Claude Desktop.
Tip: You can also run the server directly with
uv run postgres-mcpafteruv sync.
5. Verify
Open a new Claude Desktop conversation and ask:
"Use get_table_schema to show me the schema for the users table."
Claude should call the tool and return the column list.
Development
uv sync --group dev
uv run pytestSecurity note
execute_query runs whatever SQL you pass — use a read-only database role in production, or restrict access to trusted users only.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/RachelHuangZW/postgres-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server