home / mcp / postgresql mcp server

PostgreSQL MCP Server

Provides MCP-enabled exploration and querying of PostgreSQL databases via standardized MCP tools.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "aadarshjain-postgres-mcp-server": {
      "command": "python",
      "args": [
        "/ABOSLUTE/PATH/TO/postgres-mcp-server/server.py",
        "postgresql://user:password@host:port/database"
      ]
    }
  }
}

You can run a PostgreSQL MCP Server to explore and query a PostgreSQL database through a standardized MCP interface. This server connects to your PostgreSQL instance and exposes tools to list tables, inspect schemas, run read-only queries, filter records, and collect database statistics, all via MCP-compatible clients like Claude Desktop.

How to use

Start the MCP server using the PostgreSQL connection string for your database. You will then connect an MCP client to this server to perform common data discovery and querying tasks. With the tools available, you can list tables, fetch table schemas, execute read-only queries, filter records, and retrieve database statistics.

How to install

Prerequisites you need before installing:

  • Python 3.7+
  • pip (Python package installer)

Install required Python packages using the provided requirements file.

pip install -r requirements.txt

Usage with a PostgreSQL connection

Run the server by providing a PostgreSQL connection string. The server will listen for MCP tool requests over the local process IO.

python server.py postgresql://username:password@hostname:port/database

Configuration for Claude Desktop

To integrate with Claude Desktop, add the following configuration to your Claude Desktop config file. This runs the server as a local process and connects to your PostgreSQL instance.

{
  "mcpServers": {
    "postgres": {
      "command": "python",
      "args": [
        "/ABOSLUTE/PATH/TO/postgres-mcp-server/server.py",
        "postgresql://user:password@host:port/database"
      ]
    }
  }
}

Configuration file location

Your Claude Desktop configuration file is typically located in your user directory under Claude settings. The exact path depends on your operating system.

Available tools (described capabilities)

The MCP server provides the following read-only tools to interact with your PostgreSQL database.

Security considerations

Only SELECT queries are allowed to prevent data modification. Connection credentials are provided at runtime in the command line and are not stored in the server. For production, consider environment variables or a secure configuration method.

Troubleshooting

If you encounter connection failures, verify your PostgreSQL connection string is correct and that the database accepts connections from your client. If the server cannot be located by the client, ensure the command path is absolute and correctly configured.

Notes and contact

For issues or questions, you can open issues on the project page and request guidance or bug fixes.

Available tools

execute_query

Execute a custom SELECT SQL query and return the results.

list_tables

List all tables in the current PostgreSQL database.

get_table_schema

Get the schema definition for a specified table.

filter_instances

Filter database records based on specified criteria.

get_database_stats

Get general statistics and metadata about the PostgreSQL database.

PostgreSQL MCP Server - aadarshjain/postgres-mcp-server