connect_db
Connect to PostgreSQL database. Only use when no default connection exists
Explore a PostgreSQL database and run SELECT, WITH, EXPLAIN and SHOW — with writes absent from the tool surface rather than blocked by convention.
LABSCO SUMMARY
Plenty of database servers offer a read-only mode. Here readonly is the default and it holds at two levels: the write tool, execute, is not registered at all, and the PostgreSQL session itself runs with default_transaction_read_only on. Writes come back only when someone starts it with --access-mode dml or full, or sets PG_ACCESS_MODE — so that flag, and a least-privilege database role for each mode, are what to check before a model that will eventually try to fix a problem by writing gets near production. The three introspection tools are what make the read side actually usable — an agent that can read the schema writes a query that runs, and one that cannot writes a query about columns it imagined.
A PostgreSQL client that starts in read-only mode with five tools: connect, query, and three that describe the database — schemas, tables and a single table's structure. A sixth, execute, is registered only in dml or full mode.
A PostgreSQL connection, normally configured as the default rather than supplied per call.
One command plus credentials — npx mcp-postgres-secure --access-mode readonly, then supply credentials
USE CASES
List the schemas, then the tables, then read one table's structure — enough to write a query that references real columns.
Run the SELECT or WITH query, using EXPLAIN first when the shape of the plan matters more than the rows.
Run it in the default readonly mode under a read-only database role: execute is not registered and the session itself refuses writes. Just never start it with --access-mode dml or full.
Counted once with only startup setup. Other versions, modes or optional credentials may expose a different list.
connect_dbConnect to PostgreSQL database. Only use when no default connection exists
describe_tableGet table structure
list_schemasList all schemas in the database
list_tablesList tables in the database
queryExecute a read-only SQL query (SELECT, WITH, EXPLAIN, SHOW)
BEFORE YOU INSTALL
5 tools when we connected; the project documents 6. The missing one is execute, the only write tool; it appears with --access-mode dml or --access-mode full, or PG_ACCESS_MODE. connect_db disappears when PG_LOCK_CONNECTION is on, the default when the connection comes from environment variables.
All 3 documented setups run the server on your machine.
INSTALLATION
npx mcp-postgres-secure --access-mode readonly{
"mcpServers": {
"postgres-readonly": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"mcp-postgres-secure",
"--access-mode",
"readonly"
],
"env": {
"PG_HOST": "localhost",
"PG_PORT": "5432",
"PG_USER": "mcp_readonly",
"PG_PASSWORD": "<YOUR_PG_PASSWORD>",
"PG_DATABASE": "<YOUR_PG_DATABASE>",
"PG_LOCK_CONNECTION": "true"
}
}
}
}{
"mcpServers": {
"postgres-dml": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"mcp-postgres-secure",
"--access-mode",
"dml"
],
"env": {
"PG_HOST": "localhost",
"PG_PORT": "5432",
"PG_USER": "mcp_dml",
"PG_PASSWORD": "<YOUR_PG_PASSWORD>",
"PG_DATABASE": "<YOUR_PG_DATABASE>",
"PG_LOCK_CONNECTION": "true"
}
}
}
}{
"mcpServers": {
"postgres-full": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"mcp-postgres-secure",
"--access-mode",
"full"
],
"env": {
"PG_HOST": "localhost",
"PG_PORT": "5432",
"PG_USER": "mcp_admin",
"PG_PASSWORD": "<YOUR_PG_PASSWORD>",
"PG_DATABASE": "<YOUR_PG_DATABASE>",
"PG_LOCK_CONNECTION": "true"
}
}
}
}