Quick Configuration
Choose the setup that matches your environment.
Before You Start
- Confirm you have the account, endpoint, or API key required for PostgreSQL.
- Start with minimum scopes and read-only access where possible.
- Keep secrets in environment variables instead of hardcoding them in JSON.
Last verified: 2026-06-13
Environment: uvx with postgres-mcp (Postgres MCP Pro), restricted read-only access mode
Install command:
uvx postgres-mcp --access-mode=restrictedLocal config
JSON Local config json
{
"postgres": {
"command": "uvx",
"args": ["postgres-mcp", "--access-mode=restricted"],
"env": {
"DATABASE_URI": "postgresql://USER:PASSWORD@HOST:5432/DBNAME"
}
}
} After copying
Check the PostgreSQL JSON before running it in OpenClaw, then verify the server with a real prompt.
Verify prompt
List all tables in the public schema and describe their columns.
Expected success output
You should see the schema (tables and columns) returned read-only, with no write attempts.
Common Pitfalls & Fixes
- ⚠️ Watch out: Connection strings, SSL, schema discovery.
- 🔑 Always store API keys in environment variables, never hardcode them in JSON.
- 🛡️ Start with read-only scopes if available to verify connection safely.
Security checklist
- The old @modelcontextprotocol/server-postgres reference server is deprecated; this guide uses the maintained Postgres MCP Pro (postgres-mcp).
- Keep DATABASE_URI in an environment variable and prefer a read-only database role plus restricted access mode.
Common errors
| Error | Cause | Fix |
|---|---|---|
uvx not found | uv is not installed or not on PATH. | Install uv (which provides uvx), or use pipx install postgres-mcp and run the postgres-mcp command directly. |
Connection refused or authentication failed | DATABASE_URI is wrong, or the DB rejects the host/SSL settings. | Verify host, port, user, password, and database name; add sslmode=require for managed Postgres. |
Permission denied on write | restricted access mode blocks mutations by design. | Keep restricted mode for production; switch to --access-mode=unrestricted only in a safe dev database. |
Example Prompts
Once connected, try these prompts to test capabilities:
- List tables in the database schema.
- Run a sample query to fetch the latest 5 records.
- Describe the columns in the users table.
Verification Checklist
- Run 1-2 real prompts to confirm PostgreSQL returns usable data.
- Check that error messages are clear enough for troubleshooting.
- Document the required scopes, dependencies, and env vars for future reuse.