Postgres MCP Pro is a server implementation of the Model Context Protocol (MCP) that provides advanced database management capabilities for PostgreSQL databases, including health analysis, index optimization, query plan evaluation, and safe SQL execution.
Before getting started, ensure you have:
Pull the Docker image:
docker pull crystaldba/postgres-mcp
Install with pipx (recommended):
pipx install postgres-mcp
Or with uv:
uv pip install postgres-mcp
Edit the Claude Desktop configuration file located at:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"postgres": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"DATABASE_URI",
"crystaldba/postgres-mcp",
"--access-mode=unrestricted"
],
"env": {
"DATABASE_URI": "postgresql://username:password@localhost:5432/dbname"
}
}
}
}
{
"mcpServers": {
"postgres": {
"command": "postgres-mcp",
"args": [
"--access-mode=unrestricted"
],
"env": {
"DATABASE_URI": "postgresql://username:password@localhost:5432/dbname"
}
}
}
}
Postgres MCP Pro offers two access modes:
To use restricted mode, replace --access-mode=unrestricted
with --access-mode=restricted
in your configuration.
For shared server setups, you can use the SSE transport:
docker run -p 8000:8000 \
-e DATABASE_URI=postgresql://username:password@localhost:5432/dbname \
crystaldba/postgres-mcp --access-mode=unrestricted --transport=sse
Then update your client configuration:
{
"mcpServers": {
"postgres": {
"type": "sse",
"url": "http://localhost:8000/sse"
}
}
}
For full functionality, install two extensions in your database:
CREATE EXTENSION IF NOT EXISTS pg_statements;
CREATE EXTENSION IF NOT EXISTS hypopg;
These extensions enable comprehensive workload analysis and index simulation capabilities.
Ask your AI assistant:
Check the health of my database and identify any issues.
Ask:
What are the slowest queries in my database? And how can I speed them up?
Ask:
My app is slow. How can I make it faster?
Ask:
Analyze my database workload and suggest indexes to improve performance.
Ask:
Help me optimize this query: SELECT * FROM orders JOIN customers ON orders.customer_id = customers.id WHERE orders.created_at > '2023-01-01';
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.