# Installation
## Claude Desktop Configuration
### Docker (Recommended)
**Note**: When running Docker on macOS, use `host.docker.internal` if the PostgreSQL server is running on the host network (e.g., localhost). Username/password can be added to the PostgreSQL URL with `postgresql://user:password@host:port/db-name`.
```json
{
"mcpServers": {
"postgres": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp/postgres",
"postgresql://host.docker.internal:5432/mydb"
]
}
}
}
```
### NPX
```json
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://localhost/mydb"
]
}
}
}
```
Replace `mydb` with your database name.
## VS Code Configuration
### Docker
**Note**: When using Docker and connecting to a PostgreSQL server on your host machine, use `host.docker.internal` instead of `localhost` in the connection URL.
```json
{
"mcp": {
"inputs": [
{
"type": "promptString",
"id": "pg_url",
"description": "PostgreSQL URL (e.g. postgresql://user:pass@host.docker.internal:5432/mydb)"
}
],
"servers": {
"postgres": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp/postgres",
"${input:pg_url}"
]
}
}
}
}
```
### NPX
```json
{
"mcp": {
"inputs": [
{
"type": "promptString",
"id": "pg_url",
"description": "PostgreSQL URL (e.g. postgresql://user:pass@localhost:5432/mydb)"
}
],
"servers": {
"postgres": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"${input:pg_url}"
]
}
}
}
}
```
## Connection URL Format
The PostgreSQL connection URL should follow this format:
```
postgresql://[user[:password]@][host][:port][/dbname][?param1=value1&...]
```
Examples:
- `postgresql://localhost/mydb`
- `postgresql://user:password@localhost:5432/mydb`
- `postgresql://user@host.docker.internal:5432/mydb`
## Security Notes
- This server provides **read-only** access to PostgreSQL databases
- All queries are executed within a READ ONLY transaction
- Schema information is automatically discovered and exposed as resources
- Ensure your database user has appropriate read permissions