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.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
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: postgres-mcp-readonly
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).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Hosted MCP server for PostgreSQL diagnostics: slow queries, missing indexes, connection pressure.
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
Managed Postgres MCP: projects, SQL, docs search, and storage buckets via OAuth.
Draxlr's remote MCP server connects AI assistants to your SQL databases and dashboards. Explore schemas, run read-only queries, manage saved queries and dashboards, and export results, all with row-level security so each user sees only their own data.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA read-only PostgreSQL MCP server that enables AI agents to perform schema introspection and execute SELECT-only queries. It supports secure database connections through SSL and SSH tunnels while offering a structure-only mode to restrict query access.21 npmMIT
- AlicenseAqualityDmaintenanceA secure, read-only PostgreSQL MCP server that provides safe database introspection and querying capabilities.149 npmMIT
- AlicenseNot gradedqualityDmaintenanceRead-only MCP server for PostgreSQL, enabling schema discovery, table metadata, and safe SELECT queries via READ ONLY transactions.12 npmMIT
- FlicenseNot gradedqualityBmaintenanceRead-only MCP server for PostgreSQL enabling schema introspection and SELECT queries via MCP clients like Claude, with multi-layered write protection.-