
Company News
Free Business Plan Upgrades for Open Source Maintainers
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.
@marcelo-ochoa/server-postgres
Advanced tools
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.
pg-query
sql (string): The SQL query to executepg-stats
name (string): The name of the table to get statistics forpg-explain
sql (string): The SQL query to explainpg-connect
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 passwordExample: pg-connect host.docker.internal:5432/postgres postgres pg_2025
The server provides schema information for each table in the database:
postgres://<dbname>/<table>/schema)
See Change Log for the history of changes.
The PostgreSQL server uses environment variables or the pg-connect tool for secure credential management:
PG_USER: PostgreSQL username (optional if using pg-connect)PG_PASSWORD: PostgreSQL password (optional if using pg-connect)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/dbnameTo enable encryption (SSL), append ?sslmode=require to the connection string or set the PG_SSL environment variable to true.
To use this server with the Claude Desktop app, add the following configuration to the "mcpServers" section of your claude_desktop_config.json:
host.docker.internal if the PostgreSQL server is running on the host network (e.g., localhost)PG_USER and PG_PASSWORD{
"mcpServers": {
"postgres": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e", "PG_USER=myuser",
"-e", "PG_PASSWORD=mypassword",
"mochoa/mcp-postgres"
]
}
}
}
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"].
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": [
"-y",
"@marcelo-ochoa/server-postgres",
"postgresql://localhost:5432/mydb"
],
"env": {
"PG_USER": "myuser",
"PG_PASSWORD": "mypassword"
}
}
}
}
Replace /mydb with your database name.
Note: Replace the following placeholders with your actual values:
myuser and mypassword with your PostgreSQL credentialslocalhost:5432 with your PostgreSQL server host and portmydb with your database nameFor quick installation, use one of the one-click install buttons below...
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.
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.
{
"mcp": {
"inputs": [
{
"type": "promptString",
"id": "pg_user",
"description": "PostgreSQL username"
},
{
"type": "promptString",
"id": "pg_password",
"description": "PostgreSQL password",
"password": true
}
],
"servers": {
"postgres": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e", "PG_USER=${input:pg_user}",
"-e", "PG_PASSWORD=${input:pg_password}",
"mochoa/mcp-postgres",
"postgresql://localhost:5432/mydb"
]
}
}
}
}
Note: You can add an input for pg_url and append it to args if you want to connect on startup.
{
"mcp": {
"inputs": [
{
"type": "promptString",
"id": "pg_user",
"description": "PostgreSQL username"
},
{
"type": "promptString",
"id": "pg_password",
"description": "PostgreSQL password",
"password": true
}
],
"servers": {
"postgres": {
"command": "npx",
"args": [
"-y",
"@marcelo-ochoa/server-postgres",
"postgresql://localhost:5432/mydb"
],
"env": {
"PG_USER": "${input:pg_user}",
"PG_PASSWORD": "${input:pg_password}"
}
}
}
}
}
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.
See Demos for usage examples with Claude Desktop, Docker AI, Gemini CLI, and Antigravity Code Editor.
Docker:
docker build -t mochoa/mcp-postgres -f src/postgres/Dockerfile .
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.
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.
FAQs
An MCP server for PostgreSQL databases.
The npm package @marcelo-ochoa/server-postgres receives a total of 64 weekly downloads. As such, @marcelo-ochoa/server-postgres popularity was classified as not popular.
We found that @marcelo-ochoa/server-postgres demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.

Security News
The supply chain control that delays freshly published gems now covers lockfile generation and gem vendoring in Ruby projects.

Security News
During a UK cyber test, a Mythos 5 agent used sockpuppets, social engineering, and prompt injection to try to get a maintainer to merge malware.