PostgreSQL MCP Server logo

PostgreSQL MCP Server

by aadarshjain

A Model Context Protocol (MCP) server implementation for PostgreSQL database exploration and querying. It exposes various data discovery and querying capabilities as MCP tools.

View on GitHub

Last updated: N/A

What is PostgreSQL MCP Server?

This project provides a Model Context Protocol (MCP) server that connects to a PostgreSQL database and exposes various data discovery and querying capabilities as MCP tools. These tools allow you to explore database structure, query data, and get database statistics through a standardized interface.

How to use PostgreSQL MCP Server?

To use the server, first install the required dependencies using pip install -r requirements.txt. Then, run the server using the command python server.py postgresql://username:password@hostname:port/database, replacing the connection string with your PostgreSQL database credentials. To integrate with Claude Desktop, add the provided configuration snippet to your Claude Desktop config file, ensuring the path to server.py is absolute.

Key features of PostgreSQL MCP Server

  • Connect to any PostgreSQL database using a standard connection string

  • Execute custom SELECT queries with results returned in a structured format

  • List all tables in the connected database

  • Get detailed schema information for any table

  • Filter database records with simple equality conditions

  • Get database statistics including size, table count, and largest tables

Use cases of PostgreSQL MCP Server

  • Exploring the structure of a PostgreSQL database

  • Querying data from a PostgreSQL database using natural language via Claude

  • Retrieving database statistics and metadata

  • Integrating PostgreSQL data access into applications using the MCP protocol

FAQ from PostgreSQL MCP Server

How do I install the server?

Clone the repository, create a virtual environment, and run pip install -r requirements.txt.

How do I run the server?

Run python server.py postgresql://username:password@hostname:port/database with your PostgreSQL connection string.

How do I integrate with Claude Desktop?

Add the provided configuration to your Claude Desktop config file, ensuring the path to server.py is absolute.

What tools are available?

The server provides tools like execute_query, list_tables, get_table_schema, filter_instances, and get_database_stats.

What if the server fails to connect?

Verify your PostgreSQL connection string is correct and that your PostgreSQL server allows connections from your client machine.