Labsco
aadarshjain logo

PostgreSQL MCP Server

โ˜… 2

from aadarshjain

An MCP server for exploring and querying PostgreSQL databases.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeQuick setup

PostgreSQL MCP Server

A Model Context Protocol (MCP) server implementation for PostgreSQL database exploration and querying.

Table of Contents

Overview

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.

Features

  • 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

Available Tools

The server provides the following MCP tools:

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.

Security Considerations

  • This server only allows SELECT queries to prevent database modifications
  • Connection credentials are provided via command line and not stored
  • Consider using environment variables or a secure configuration method in production environments

Example Interaction in Claude

Once connected to Claude Desktop, you can ask questions like:

  • "What tables are available in the database?"
  • "Show me the schema for the customers table"
  • "How many records are in the orders table?"
  • "What's the total size of the database?"

Output

Claude will use the appropriate MCP tools to answer these questions by querying your PostgreSQL database.

Contact

Feel free to raise issue on this repository.

SSE and Streamable-HTTP postgres-mcp-server is under development....