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 "Deploy 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: 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).
This server cannot be deployed
Maintenance
Related MCP Connectors
- dataOAuthco.thinair
Read-only PostgreSQL, MySQL, SQL Server access via MCP — 24 dialect-aware hosted tools.
Hosted MCP server for PostgreSQL diagnostics: slow queries, missing indexes, connection pressure.
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.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceA 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.10MIT
- AlicenseAqualityDmaintenanceA secure, read-only PostgreSQL MCP server that provides safe database introspection and querying capabilities.1410MIT
- AlicenseNot gradedqualityBmaintenanceRead-only MCP server for PostgreSQL, enabling schema discovery, table metadata, and safe SELECT queries via READ ONLY transactions.25MIT
- FlicenseNot gradedqualityBmaintenanceRead-only MCP server for PostgreSQL enabling schema introspection and SELECT queries via MCP clients like Claude, with multi-layered write protection.-