Connect an AI assistant to a Postgres database for read access to schema and data.
Preview full content
Lets an AI assistant inspect a Postgres database's schema and run queries against it — useful for asking questions about your data, debugging a query, or having it draft a query for you to review rather than writing raw SQL yourself.
```json
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://user:password@localhost:5432/mydatabase"
]
}
}
}
```
Use a connection string for a read-only database role, not your admin credentials — most reference implementations of this server are read-only by design, but don't rely on that alone; scope the database user's actual permissions to match what you intend to allow.
Never put a production connection string with real credentials into a config file you might share, screenshot, or commit — treat it exactly like any other database credential.