MCP server for read-only PostgreSQL database queries in Claude Desktop
Copy the AI prompt to install this server into Claude Code, Cursor, or another agent β or use 1-click editor setup below.
We haven't yet run this listing's install command through our automated sandbox check. This isn't a red flag β we're steadily working through the catalog.
π‘ Paste into ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows)
Inspect callable tools, capabilities, and parameters exposed to AI agents by Read Only Local Postgres Mcp Server.
connectConnect to a PostgreSQL database using a connection string. The connection persists for subsequent queries until changed or disconnected.
disconnectDisconnect from the current runtime database and revert to the default environment-configured connection.
queryRun a read-only SQL query against the currently connected database. Optionally override the connection for a single query.
A Model Context Protocol (MCP) server that enables Claude Desktop to interact with PostgreSQL databases through natural language queries.
Then set your database environment variables:
Done! Restart Claude Code and ask: "What tables are in my database?"
1. Open your config file:
2. Add this configuration:
3. Save, restart Claude Desktop, and test!
This server is published in the Model Context Protocol Registry as capital.hove/read-only-local-postgres-mcp-server.
Then configure your database credentials using environment variables. Restart Claude Code and you're done!
Benefits:
For Claude Desktop:
Edit ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):
For Claude Code:
Edit ~/.config/claude-code/settings.json (macOS/Linux) or %APPDATA%\claude-code\settings.json (Windows):
If you're using Claude Code, you can easily install this MCP server:
Then configure Claude Code by adding to your MCP settings.
Save the repository to a directory on your system:
Note: If you installed via Option 1 (MCP Registry with npx), you've already configured everything! This section is for users who chose Options 2, 3, or 4 (npm or manual installation).
If you're using Claude Code with a manual installation, add the PostgreSQL server to your MCP settings:
Open your Claude Code settings (typically in ~/.config/claude-code/settings.json on macOS/Linux or %APPDATA%\claude-code\settings.json on Windows)
Add the PostgreSQL MCP server configuration:
If you're using Claude Desktop with a manual installation, open your Claude Desktop configuration file:
macOS:
Windows:
Add the PostgreSQL server configuration:
If you're using mise for Node.js version management, make sure to use the full path to the Node.js executable in your configuration.
| Variable | Description | Default |
|---|---|---|
DB_HOST | PostgreSQL server hostname | localhost |
DB_PORT | PostgreSQL server port | 5432 |
DB_DATABASE | Database name | postgres |
DB_USERNAME | PostgreSQL username | postgres |
DB_PASSWORD | PostgreSQL password | (empty) |
DB_SSL | Enable SSL connection | false |
This MCP server exposes three tools that Claude can use to interact with PostgreSQL databases.
connectConnect to a PostgreSQL database using a connection string. The connection persists for subsequent queries until changed or disconnected.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
connectionString | string | Yes | PostgreSQL connection string |
Connection String Format:
SSL Modes Supported:
sslmode=require - Require SSL (recommended for remote connections)sslmode=verify-full - Require SSL with certificate verificationExample Usage (natural language):
Response:
disconnectDisconnect from the current runtime database and revert to the default environment-configured connection.
Parameters: None
Example Usage (natural language):
Response:
queryRun a read-only SQL query against the currently connected database. Optionally override the connection for a single query.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
sql | string | Yes | SQL query to execute (SELECT only) |
connectionString | string | No | Override connection for this query only |
Example Usage (natural language):
Response:
When using this MCP server, Claude can:
Query the default database (configured via environment variables):
Connect to a different database dynamically:
One-off query to a different database (without switching active connection):
Revert to default connection:
Basic queries (uses default/active connection):
Dynamic connection examples:
One-off queries to different databases:
Claude will automatically convert your natural language requests into appropriate SQL queries and execute them against your database.
The server enforces read-only access on all connections (both environment-configured and runtime dynamic connections). A query is rejected if it begins with any of the following statement keywords:
INSERT, UPDATE, DELETE, TRUNCATE, COPY, MERGECREATE, ALTER, DROP, COMMENT, RENAME, REASSIGNGRANT, REVOKE, SECURITYSET, RESET, DISCARD, LOADCALL, DO, EXECUTE, PREPARE, DEALLOCATEDECLARE, FETCH, MOVE, CLOSEBEGIN, START, COMMIT, ROLLBACK, SAVEPOINT, RELEASE, LOCKVACUUM, ANALYZE, REINDEX, CLUSTER, REFRESH, CHECKPOINTNOTIFY, LISTEN, UNLISTENOnly statements beginning with read verbs (e.g. SELECT, WITH, EXPLAIN, SHOW, TABLE, VALUES) are allowed through. Because EXPLAIN ANALYZE executes the statement it wraps, its inner statement is validated too β EXPLAIN ANALYZE DELETE ... is rejected, while EXPLAIN ANALYZE SELECT ... is allowed.
When using the connect tool or connectionString parameter:
connect tool response excludes passwordsFor enhanced security, create a dedicated read-only user for the MCP server:
dist/index.js is correctclaude_desktop_config.json formatTo see server logs, you can run the server manually:
Feel free to submit issues and enhancement requests!
This project is open source and available under the MIT License.
If you encounter issues:
Note: This server is designed for development and analysis purposes. For production use, consider additional security measures and monitoring.
Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.
[](https://allmcps.com/mcp/read-only-local-postgres-mcp-server)<a href="https://allmcps.com/mcp/read-only-local-postgres-mcp-server"><img src="https://allmcps.com/api/badge/read-only-local-postgres-mcp-server?style=directory" alt="Read Only Local Postgres Mcp Server on AllMCPs" /></a>