
Postgres
io.github.marcelo-ochoaPublished by GitHub account marcelo-ochoav1.0.8Updated Oct 24, 2026
MCP server for interacting with PostgreSQL databases
Overview
A local MCP server that gives an assistant read-only access to PostgreSQL databases: run queries, inspect schemas, explain plans and generate performance stats.
- What you can do
- Run read-only SQL queries inside a READ ONLY transaction and explain their query plans against a connected database. Retrieve per-table statistics and generate an Oracle-AWR-style performance report covering database statistics, top queries, table and index stats and optimization suggestions. Browse automatically discovered table schemas as resources, including column names and data types. Connect to a database at runtime by supplying a connection string, user and password.
- When to use it
- Useful when you want an assistant to explore or analyze an existing PostgreSQL database safely, for example answering questions about data, reviewing schemas, or diagnosing slow queries and performance issues without granting write access.
- Requirements
- Runs locally over stdio, installed via npm (npx) or Docker. Needs a reachable PostgreSQL server and a connection string with host, port and database name, plus a database user and password supplied through environment variables or the connect tool. SSL can be enabled with a connection-string option or an environment variable.
Installation
In SourceWeft
- Open Postgres in the dashboard and add it to a workspace.
- Enable the server for the chats that should use its tools.
Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.
Other MCP clients
Follow the launch instructions in the repository.
README
PostgreSQL
A Model Context Protocol server that provides read-only access to PostgreSQL databases. This server enables LLMs to inspect database schemas and execute read-only queries.
Components
Tools
-
pg-query
- Execute read-only SQL queries against the connected database
- Input:
sql(string): The SQL query to execute - All queries are executed within a READ ONLY transaction
-
pg-stats
- Get statistics for a specific table
- Input:
name(string): The name of the table to get statistics for
-
pg-explain
- Explain Plan for a given SQL query
- Input:
sql(string): The SQL query to explain
-
pg-connect
- Connect to a PostgreSQL database
- Inputs:
connectionString(string): The PostgreSQL connection string without credentials (e.g. postgresql://host:port/dbname or host:port/dbname)user(string): The PostgreSQL usernamepassword(string): The PostgreSQL password
Example: pg-connect host.docker.internal:5432/postgres postgres pg_2025
- pg-awr
- Generate a PostgreSQL performance report similar to Oracle AWR. Includes database statistics, top queries (requires pg_stat_statements extension), table/index statistics, connection info, and optimization recommendations.
Resources
The server provides schema information for each table in the database:
- Table Schemas (
postgres://<dbname>/<table>/schema)- JSON schema information for each table
- Includes column names and data types
- Automatically discovered from database metadata
Change Log
See Change Log for the history of changes.
Configuration
The PostgreSQL server uses environment variables or the pg-connect tool for secure credential management:
PG_USER: PostgreSQL username (optional if usingpg-connect)PG_PASSWORD: PostgreSQL password (optional if usingpg-connect)
Connection String
The connection string should contain only the host, port, and database information (without embedded credentials). Providing it as a command-line argument is optional. If omitted at startup, you must use the pg-connect tool to establish a connection before using other functionality.
Supported connection string formats:
postgresql://host:port/dbnamehost:port/dbname
To enable encryption (SSL), append ?sslmode=require to the connection string or set the PG_SSL environment variable to true.
Usage with Claude Desktop
To use this server with the Claude Desktop app, add the following configuration to the "mcpServers" section of your claude_desktop_config.json:
Docker
- When running Docker on macOS, use
host.docker.internalif the PostgreSQL server is running on the host network (e.g., localhost) - Credentials are passed via environment variables
PG_USERandPG_PASSWORD
Note: You can still provide the connection string as a final argument if you want to connect automatically on startup: "args": [..., "mochoa/mcp-postgres", "postgresql://host.docker.internal:5432/mydb"].
NPX
Replace /mydb with your database name.
Note: Replace the following placeholders with your actual values:
myuserandmypasswordwith your PostgreSQL credentialslocalhost:5432with your PostgreSQL server host and portmydbwith your database name
Usage with VS Code
For quick installation, use one of the one-click install buttons below...
[Install with NPX in VS Code] [Install with NPX in VS Code Insiders]
[Install with Docker in VS Code] [Install with Docker in VS Code Insiders]
For manual installation, add the following JSON block to your User Settings (JSON) file in VS Code. You can do this by pressing Ctrl + Shift + P and typing Preferences: Open User Settings (JSON).
Optionally, you can add it to a file called .vscode/mcp.json in your workspace. This will allow you to share the configuration with others.
Note that the
mcpkey is not needed in the.vscode/mcp.jsonfile.
Docker
Note: When using Docker and connecting to a PostgreSQL server on your host machine, use host.docker.internal instead of localhost in the connection URL.
Note: You can add an input for pg_url and append it to args if you want to connect on startup.
NPX
PostgreSQL AWR in action
See PostgreSQL AWR in action for an example of a performance report generated by the pg-awr tool for a production Moodle database, highlighting critical performance issues and optimization opportunities.
Demos
See Demos for usage examples with Claude Desktop, Docker AI, Gemini CLI, and Antigravity Code Editor.
Building
Docker:
Sources
As usual the code of this extension is at GitHub, feel free to suggest changes and make contributions, note that I am a beginner developer of React and TypeScript so contributions to make this UI better are welcome.
📜 License
This project is licensed under the Apache License, Version 2.0 for new contributions, with existing code under MIT - see the LICENSE file for details.
Source: src/postgres/README.md at commit bd2ce8f
Tools
0Version history
1- v1.0.8LatestSep 16, 2026
Score
40% of the applicable checks met
How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.
- Reached in the last 30 days25 pts
Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.
- Auth declared10 pts
Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.
- Tools listed15 pts
Answer tools/list without a credential, or ship a package that starts in a sandbox without one.
- DescriptionRequired15 pts
- Logo10 pts
- Documentation15 pts
- License10 pts
Declare a license in the repository or the registry entry.