mcp-postgres
Provides tools for executing SQL queries (read-only by default), listing tables, and describing table structures in a PostgreSQL database.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-postgreslist all tables in the public schema"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mcp-postgres
MCP tool server providing PostgreSQL database access for AI agents.
Tools
Tool | Description |
| Execute SQL queries (read-only by default) |
| List all tables in a schema |
| Get table structure (columns, types, constraints) |
Related MCP server: PostgreSQL MCP Server
Quick Start
cp .env.example .env
# Edit .env with your Postgres connection details
make install
make serverEnvironment Variables
Variable | Default | Description |
|
| PostgreSQL host |
|
| PostgreSQL port |
|
| Database user |
| Database password | |
|
| Database name |
|
| Enforce read-only queries |
|
| Transport: |
|
| Server port (http only) |
Set
POSTGRES_READONLY=falseto enable read/write mode (INSERT, UPDATE, DELETE, etc.).
Endpoints
Path | Method | Description |
| GET | Health check for K8s probes |
| GET | Server info (name, version, transports) |
| POST | MCP Streamable-HTTP transport |
| GET | MCP SSE transport (legacy) |
Usage with .mcp.json
{
"mcpServers": {
"postgres": {
"type": "stdio",
"command": "docker",
"args": [
"run", "--rm", "-i",
"-e", "MCP_TRANSPORT=stdio",
"-e", "POSTGRES_HOST=host.docker.internal",
"-e", "POSTGRES_PORT=5432",
"-e", "POSTGRES_USER=postgres",
"-e", "POSTGRES_PASSWORD=secret",
"-e", "POSTGRES_DB=mydb",
"ghcr.io/mgcrea/mcp-postgres"
]
}
}
}Use
host.docker.internalto connect to a PostgreSQL instance running on the host machine.
Docker
make docker-build
make docker-runThis server cannot be deployed
Maintenance
Related MCP Connectors
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
PostgreSQL, MySQL, OpenAPI/Swagger, and shared Agent Memory with scoped access.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Related MCP Servers
- FlicenseAqualityDmaintenanceEnables AI agents to inspect and query PostgreSQL databases safely, with features like listing tables, retrieving schemas, and running read-only SQL queries.3-
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with PostgreSQL databases through natural language queries, schema inspection, and safe SQL execution.91-
- FlicenseNot gradedqualityDmaintenanceEnables AI models to execute SQL queries, list tables, and describe table structures on a local PostgreSQL database.1-
- AlicenseNot gradedqualityCmaintenanceEnables AI assistants to interact with PostgreSQL databases, providing tools for querying, table listing, schema exploration, and multi-environment management with write protection and schema scoping.1MIT