
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 passwordpg-awr
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 for secure credential management:
PG_USER: PostgreSQL username (required)PG_PASSWORD: PostgreSQL password (required)The connection string should contain only the host, port, and database information (without embedded credentials).
Supported connection string formats:
postgresql://host:port/dbnamehost:port/dbnameTo 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",
"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_url",
"description": "PostgreSQL URL (e.g. postgresql://host.docker.internal:5432/mydb)"
},
{
"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",
"${input:pg_url}"
]
}
}
}
}
{
"mcp": {
"inputs": [
{
"type": "promptString",
"id": "pg_url",
"description": "PostgreSQL URL (e.g. postgresql://localhost:5432/mydb)"
},
{
"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",
"${input:pg_url}"
],
"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.
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 MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.
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.