- Home
- MCP servers
- PostgreSQL
PostgreSQL
- typescript
0
GitHub Stars
typescript
Language
7 months ago
First Indexed
3 months ago
Catalog Refreshed
Documentation & install
Readme and setup notes from the catalogue, plus a client-ready config you can copy for your MCP host.
Installation
Add the following to your MCP client configuration file.
Configuration
View docs{
"mcpServers": {
"pyljain-mcp_server_template": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp/postgres",
"postgresql://host.docker.internal:5432/mydb"
]
}
}
}You run a Model Context Protocol (MCP) server that provides fast, read-only access to PostgreSQL databases. It lets you inspect database schemas and run safe read-only queries, which is ideal for LLMs and automated tools to understand your data without risking changes.
How to use
You can connect to the PostgreSQL MCP server from an MCP client using either a local stdio setup (running the server on your machine) or a remote URL configuration. The server exposes a read-only query tool and automatic table schemas so your client can explore data structures and run queries without modifying data.
Two explicit ways to run the MCP server are provided here. The first uses Docker to run the MCP image locally. The second uses NPX to execute the MCP package without installing it globally.
Docker example to run the MCP PostgreSQL server locally
docker run -i --rm mcp/postgres postgresql://host.docker.internal:5432/mydb
NPX example to run the MCP PostgreSQL server directly
npx -y @modelcontextprotocol/server-postgres postgresql://localhost/mydb
Replace /mydb with the name of your database and adjust hostnames as needed. The Docker example assumes you are on a system where host.docker.internal maps to the host network when you are using Docker on macOS or Windows.
How to install
Prerequisites you need before starting: a running PostgreSQL database and either Docker or Node.js with NPX installed.
Option A: Use Docker to run the MCP server
docker run -i --rm mcp/postgres postgresql://host.docker.internal:5432/mydb
Option B: Use NPX to run the MCP server without installing it globally
npx -y @modelcontextprotocol/server-postgres postgresql://localhost/mydb
Notes for installation and usage
- Ensure your PostgreSQL database is reachable from where you run the MCP server. Use the appropriate host, port, and database name in the connection URL.
Additional notes
Tools and resources exposed by this MCP server
-
query: Executes read-only SQL queries against the connected database inside a read-only transaction.
-
Table Schemas: Retrieve JSON schema information for each table at the endpoint postgres://<host>/<table>/schema, including column names and data types. The schemas are automatically discovered from database metadata.
Available tools
query
Executes read-only SQL queries against the connected PostgreSQL database inside a READ ONLY transaction.