home / mcp / postgresql mcp server
Provides an MCP-enabled interface to PostgreSQL for querying data and inspecting database structures.
Configuration
View docs{
"mcpServers": {
"gldc-mcp-postgres": {
"command": "/path/to/venv/bin/python",
"args": [
"/path/to/postgres_server.py"
],
"env": {
"POSTGRES_CONNECTION_STRING": "postgresql://username:password@host:5432/database"
}
}
}
}You can run a PostgreSQL MCP Server to let AI agents interact with your PostgreSQL databases through a standardized MCP interface. It exposes tools to explore schemas, tables, and query results, and it supports typed outputs for easy integration with MCP clients.
Start by running the server locally or in a container. You will connect an MCP client to the server to perform actions such as listing schemas, listing tables in a schema, describing table structures, retrieving foreign keys, and executing SQL queries. Typical workflows include inspecting a database structure before running analytics queries, and then executing read-only queries to fetch data in structured formats.
Prerequisites you need on your machine:
Follow these concrete steps to set up and run the server:
# 1) Create and activate a virtual environment
python -m venv venv
source venv/bin/activate # On Windows, use: venv\Scripts\activate
# 2) Install dependencies
pip install -r requirements.txtExecute SQL queries against the database. Supports parameters and row limits and can output in markdown or json formats.
List all available schemas in the connected database, with optional filters and pagination.
List tables within a specific schema, with optional name pattern filtering and table types.
Provide detailed information about a table’s columns, types, and constraints.
Retrieve foreign key relationships for a given table to understand cross-table references.
Discover both explicit and implied relationships for a table to aid data modeling.
Show current database identity information such as user, host, port, and search_path.
Typed tool to execute a SQL query with inputs for sql, parameters, row_limit, and output format.
Execute a query and return results as JSON-serializable rows.
Return schemas with filters for include_system, include_temp, require_usage, and row_limit.
Return tables within a schema with filters for name pattern, case sensitivity, and row_limit.
Optional reading of table resources via table:// URIs when supported.
Prompts registered for safe query construction and plan tips when supported.