home / mcp / mcp postgresql server
MCP PostgreSQL Server
Configuration
View docs{
"mcpServers": {
"antonorlov-mcp-postgres-server": {
"command": "npx",
"args": [
"-y",
"mcp-postgres-server"
],
"env": {
"PG_HOST": "your_host",
"PG_PORT": "5432",
"PG_USER": "your_user",
"PG_DATABASE": "your_database",
"PG_PASSWORD": "your_password"
}
}
}
}You can use the MCP PostgreSQL Server to interact with PostgreSQL databases through a standardized interface. It handles secure connections, prepared statements, multi-schema operations, and convenient tooling to query, modify, and inspect database structures from an MCP client.
Connect your MCP client to the PostgreSQL MCP server using the provided connection configuration. Once connected, you can establish a database connection with connect_db, then perform read and write operations with query and execute. You can inspect the database structure with list_schemas, list_tables, and describe_table to understand schemas, tables, and their columns. These tools support prepared statements for safe parameter handling and allow you to work across multiple schemas.
Prerequisites: you need a recent Node.js environment (which includes npm). Install or run the MCP PostgreSQL Server as described below.
Option A: Install as a package in your project
- Run the following command to install locally in your project
npm install mcp-postgres-server
Option B: Run directly without installing
- Start the server using npx to run it on demand
npx mcp-postgres-server
{
"mcpServers": {
"postgres": {
"type": "stdio",
"command": "npx",
"args": ["-y", "mcp-postgres-server"],
"env": {
"PG_HOST": "your_host",
"PG_PORT": "5432",
"PG_USER": "your_user",
"PG_PASSWORD": "your_password",
"PG_DATABASE": "your_database"
}
}
}
}Establish a connection to the PostgreSQL database using the provided credentials.
Execute SELECT queries with optional prepared statement parameters. Supports both PostgreSQL-style ($n) and MySQL-style (?) placeholders.
Execute INSERT, UPDATE, or DELETE queries with optional prepared statement parameters. Supports both PostgreSQL-style ($n) and MySQL-style (?) placeholders.
List all schemas in the connected database.
List tables in the connected database, with an optional schema parameter (defaults to public).
Get the structure of a specific table, with an optional schema parameter (defaults to public).