home / mcp / postgres mcp server
MCP Server for Postgres
Configuration
View docs{
"mcpServers": {
"ericzakariasson-pg-mcp-server": {
"url": "http://localhost:3000/mcp",
"headers": {
"DEBUG": "true",
"DATABASE_URL": "postgresql://postgres:postgres@localhost:5432/postgres",
"PG_SSL_ROOT_CERT": "/path/to/ca.pem",
"DANGEROUSLY_ALLOW_WRITE_OPS": "false"
}
}
}
}The Postgres MCP Server lets you query and analyze PostgreSQL databases through a controlled, servlet-like interface that your language models can interact with. It exposes your PostgreSQL data as browsable endpoints and queryable commands, so you can work with data securely and efficiently via your MCP client.
You connect to the Postgres MCP Server from your MCP client. Use the http transport for remote access and the stdio transport for a local, script-driven setup. The server accepts a PostgreSQL connection string via the environment and exposes commands to run SQL queries and inspect database structures.
Prerequisites you need before installation: Node.js and a package manager (npm or bun). You also need a running PostgreSQL instance you can connect to.
Step 1: Prepare your environment variables. You must provide a PostgreSQL connection string using DATABASE_URL. Example values are provided below, but use your actual connection details.
Step 2: Run the server using the stdio transport if you want a local, interactive setup.
Step 3: Run the server using the http transport if you want remote HTTP access.
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["--yes", "pg-mcp-server", "--transport", "stdio"],
"env": {
"DATABASE_URL": "postgresql://postgres:postgres@localhost:5432/postgres"
}
}
}
}Configure your connection and behavior with the following environment variables.
DATABASE_URL defines the PostgreSQL connection string and is required.
DANGEROUSLY_ALLOW_WRITE_OPS enables writes to the database from the MCP server; default is false for safety.
DEBUG turns on verbose logging to help diagnose issues.
PG_SSL_ROOT_CERT optionally points to a TLS CA bundle when connecting to TLS-enabled PostgreSQL servers (for example, when using AWS RDS).
Default transport is stdio; switch to HTTP with the --transport flag. The HTTP mode exposes a streamable MCP endpoint at /mcp on port 3000 by default. Clients that support Streamable HTTP can connect to http://localhost:3000/mcp.
Common actions you can perform include listing tables, inspecting schemas, and running SQL queries through the query tool.
Execute SQL queries against the connected PostgreSQL database