home / mcp / postgresql mcp server
MCP Server for PostgreSQL
Configuration
View docs{
"mcpServers": {
"asadudin-mcp-server-postgres": {
"command": "python",
"args": [
"mcp_server_postgres.py"
],
"env": {
"HOST": "0.0.0.0",
"PORT": "8056",
"PG_HOST": "localhost",
"PG_PORT": "5432",
"PG_USER": "postgres",
"PG_DATABASE": "postgres",
"PG_PASSWORD": "YOUR_PASSWORD"
}
}
}
}You operate an MCP server that bridges your PostgreSQL databases with your MCP client, enabling safe, parameterized SQL queries, data manipulation, and schema management through a unified API. It streamlines database interactions and can be deployed locally or in containers for consistent development and production environments.
You will connect to the MCP server from your client and call the available endpoints to perform common database tasks. Use sql_query to fetch data, sql_execute to apply DML statements, create_database to add new databases, create_or_update_table to manage table schemas, and debug_postgres_connection to verify connectivity. Each operation accepts a set of parameters that you provide from your MCP client, and the server translates those requests into PostgreSQL actions.
Prerequisites you need before running the MCP server:
- Python 3.8 or newer
- PostgreSQL 10 or newer
- Docker (optional, for containerized deployment)
- Docker Compose (optional, for development)
# Step 1: Clone the MCP PostgreSQL server repository
git clone https://github.com/asadudin/mcp-server-postgres.git
cd mcp-server-postgres
# Step 2: Copy the example environment file
cp .env.example .env
# Step 3: Update the .env file with your PostgreSQL credentials
```
```env
PG_HOST=postgres
PG_PORT=5432
PG_USER=postgres
PG_PASSWORD=your_password
PG_DATABASE=your_database
HOST=0.0.0.0
PORT=8056
```
```bash
# Step 4: Start the service in detached mode
docker-compose up -d# Step 1: Clone the repository
git clone https://github.com/asadudin/mcp-server-postgres.git
cd mcp-server-postgres
# Step 2: Create and activate a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: .\venv\Scripts\activate
# Step 3: Install dependencies
pip install -r requirements.txt
# Step 4: Copy the example environment file and update it
cp .env.example .env
# Edit .env with your configuration
# Step 5: Run the MCP server
python mcp_server_postgres.pyExecute a SELECT query and return results as JSON.
Execute INSERT/UPDATE/DELETE statements with optional parameters.
Create a new PostgreSQL database.
Create or update a table schema using SQL statements.
Test and debug the PostgreSQL connection