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-postgres list 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).
Available Tools
4 toolsdescribe_tableA
Describe the columns of a PostgreSQL table: name, data type, nullability, default value, and whether it is part of the primary key.
Inputs: table (required), schema.
list_schemasA
List all user-defined schemas in the connected PostgreSQL database.
Inputs: no named parameters.
list_tablesA
List all user tables in the connected PostgreSQL database, including schema name, table name, row count estimate, and size.
Inputs: no named parameters.
queryA
Execute a read-only SELECT query against PostgreSQL. Only SELECT (and CTEs starting with WITH) are permitted. Write operations, system functions, DoS constructs, and multiple statements are all blocked.
Inputs: sql (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
The three metadata tools (list_tables, describe_table, list_schemas) target clearly distinct objects, and query is obviously the general-purpose execution tool. The only mild overlap is that query could technically satisfy anything the metadata helpers do, but the read-only SELECT restriction keeps boundaries reasonably clear.
list_tables, describe_table, and list_schemas follow a clear verb_noun lowercase-snake pattern. The bare verb 'query' breaks the pattern slightly, but it remains readable and the deviation is minor.
Four tools is a reasonable, tightly scoped surface for read-only PostgreSQL access, with each tool earning its place. It sits at the thin end of the ideal range, though the small set is appropriate for a deliberately read-only server.
The surface covers the core read-only workflows: running queries, discovering schemas, listing tables, and inspecting columns. Minor gaps exist (no view/index/constraint inspection, no query-plan/EXPLAIN helper), and write operations are intentionally absent, but agents can work around most of these via query.
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 gradedqualityBmaintenanceA 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.146 npmMIT
- AlicenseAqualityDmaintenanceA secure, read-only PostgreSQL MCP server that provides safe database introspection and querying capabilities.1417 npmMIT
- AlicenseNot gradedqualityDmaintenanceRead-only MCP server for PostgreSQL, enabling schema discovery, table metadata, and safe SELECT queries via READ ONLY transactions.MIT
- FlicenseNot gradedqualityBmaintenanceRead-only MCP server for PostgreSQL enabling schema introspection and SELECT queries via MCP clients like Claude, with multi-layered write protection.-