Get the FREE Ultimate OpenClaw Setup Guide →

mcp-postgreSql

MCP server from longgoll/mcp-postgreSql-server

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio longgoll-mcp-postgresql-server node build/index.js \
  --env DATABASE_URL="postgresql://<USER>:<PASSWORD>@<HOST>:<PORT>/<DATABASE>"

How to use

This MCP server provides a safe, queryable interface to a PostgreSQL database. It exposes tools for listing and inspecting schemas, performing read-only queries, and executing modification statements under separate safety boundaries. Clients can connect using the standard MCP protocol and leverage tools such as list_tables, describe_table, list_indexes, list_constraints, and search_in_table to explore data structures, while run_read_only_query and run_modification_query let you run safe read-only or DML/DDL commands as appropriate. You can also run explain_query to obtain JSON execution plans for tuning queries. The server uses a single DATABASE_URL connection string and can be accessed by MCP-enabled assistants or editor extensions to safely operate on your PostgreSQL data.

How to install

Prerequisites:

  • Node.js v18 or higher
  • A running PostgreSQL database

Installation steps:

  1. Clone the repository:
git clone <your-repo-url>
cd mcp-postgre-server
  1. Install dependencies:
npm install
  1. Configure environment:
  • Create a .env file (optional if you provide DATABASE_URL via the MCP config):
cp .env.example .env
  • Edit your DATABASE_URL in .env or provide the value via the mcp_config.json env section (recommended for absolute paths):
# Example
DATABASE_URL=postgresql://myuser:mypassword@localhost:5432/mydatabase
  1. Build the TypeScript code (if applicable):
npm run build
  1. Run the server locally:
npm start
  1. Optional: integrate with MCP clients by adding the appropriate mcp_config.json entry pointing to this server (see the JSON in the repository README for a sample configuration).

Additional notes

Tips:

  • Keep DATABASE_URL secure; do not commit it to version control. Use environment variables or the MCP config env block.
  • The server separates read-only and modification operations. Use run_read_only_query for SELECT-like statements and run_modification_query for INSERT/UPDATE/DELETE/CREATE, as appropriate.
  • Validate table names in tools that accept freeform input to prevent SQL injection. Use provided inspection tools to minimize untrusted input.
  • If you deploy behind a reverse proxy or inside a container, ensure the container has network access to the PostgreSQL instance and that SSL/TLS requirements are respected if needed.
  • When debugging, start the server in a development environment and inspect logs for connection issues or query errors.

Related MCP Servers

Sponsor this space

Reach thousands of developers