mcp-postgres
Provides read-only access to a PostgreSQL database, enabling tools for running SELECT queries, listing tables with row counts and sizes, describing table schemas, and listing user-defined schemas.
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., "@mcp-postgreslist all tables"
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.
mcp-postgres
Read-only PostgreSQL MCP server for Claude Desktop (and any MCP-compatible client).
Tools exposed
Tool | Description |
| Run a SELECT query |
| List all user tables with row-count estimate and size |
| Show columns, types, nullability, PK for a table |
| List user-defined schemas |
Related MCP server: PostgreSQL MCP Server
Security protections
Attack | Example | Status |
Direct writes |
| ✅ Blocked |
Multiple statements |
| ✅ Blocked |
System functions |
| ✅ Blocked |
DoS |
| ✅ Blocked |
Dollar-quoted bypass |
| ✅ Blocked |
Whitespace bypass | tabs and newlines between keywords | ✅ Blocked |
Comment bypass |
| ✅ Blocked |
Session write mode | Enforced via | ✅ Enforced |
Valid queries |
| ✅ Allowed |
Environment variables
PostgreSQL connection
Variable | Required | Default | Description |
| ✅ | — | Server hostname or IP |
| ✅ | — | Database name |
| ✅ | — | PostgreSQL username |
| ✅ | — | PostgreSQL password |
|
| TCP port | |
|
| Enable SSL ( | |
|
| Reject self-signed certs |
SSH tunnel (optional)
Set PG_SSH_HOST to activate the tunnel. Authentication requires either a private key file or a password.
Variable | Required | Default | Description |
| — | — | SSH server hostname (activates tunnel when set) |
|
| SSH server port | |
| ✅ (if tunnel) | — | SSH username |
| ✅ or password | — | Path to private key file (e.g. |
| — | Passphrase for the private key (if encrypted) | |
| ✅ or key | — | SSH password (used when no key file is provided) |
|
| Postgres host as seen from the SSH server |
Build
npm install
npm run buildClaude Desktop configuration
Add to %APPDATA%\Claude\claude_desktop_config.json:
Conexão direta:
{
"mcpServers": {
"postgres": {
"command": "node",
"args": ["C:/Projetos/mcp-postgres-readonly/dist/index.js"],
"env": {
"PG_HOST": "localhost",
"PG_DATABASE": "mydb",
"PG_USER": "postgres",
"PG_PASSWORD": "yourpassword"
}
}
}
}Conexão direta com SSL (certificado auto-assinado):
{
"mcpServers": {
"postgres": {
"command": "node",
"args": ["C:/Projetos/mcp-postgres-readonly/dist/index.js"],
"env": {
"PG_HOST": "db.example.com",
"PG_DATABASE": "mydb",
"PG_USER": "postgres",
"PG_PASSWORD": "yourpassword",
"PG_SSL": "true",
"PG_SSL_REJECT_UNAUTHORIZED": "false"
}
}
}
}Via SSH tunnel (private key):
{
"mcpServers": {
"postgres": {
"command": "node",
"args": ["C:/Projetos/mcp-postgres-readonly/dist/index.js"],
"env": {
"PG_HOST": "localhost",
"PG_DATABASE": "mydb",
"PG_USER": "postgres",
"PG_PASSWORD": "yourpassword",
"PG_SSH_HOST": "bastion.example.com",
"PG_SSH_USER": "ubuntu",
"PG_SSH_PRIVATE_KEY": "C:/Users/you/.ssh/id_rsa"
}
}
}
}Via SSH tunnel (password):
{
"mcpServers": {
"postgres": {
"command": "node",
"args": ["C:/Projetos/mcp-postgres-readonly/dist/index.js"],
"env": {
"PG_HOST": "localhost",
"PG_DATABASE": "mydb",
"PG_USER": "postgres",
"PG_PASSWORD": "yourpassword",
"PG_SSH_HOST": "bastion.example.com",
"PG_SSH_USER": "ubuntu",
"PG_SSH_PASSWORD": "sshpassword"
}
}
}
}Tip: When
PG_SSH_REMOTE_HOSTis omitted, the tunnel forwards toPG_HOSTas seen from the SSH server. If Postgres runs on a private address only reachable from the bastion (e.g.db.internal), setPG_SSH_REMOTE_HOST=db.internalandPG_HOSTto anything (it will be overridden).
This server cannot be installed
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/gbfeliped/mcp-postgres-readonly'
If you have feedback or need assistance with the MCP directory API, please join our Discord server