Skip to main content
Glama
krishamehta09

Postgres Analytics MCP Server

# Postgres Analytics MCP Server

A Model Context Protocol (MCP) server that lets AI assistants (Claude, Cursor, and other MCP-compatible clients) safely inspect and query a PostgreSQL database - with read-only enforcement, row/timeout limits, and full audit logging.

Built to answer a simple question: how do you let an AI agent touch a real database without giving it the ability to break anything?

What it does

Once connected, an AI client can ask things like:

  • "What tables are in my database?"

  • "Show me the 10 most recent orders."

  • "Why is this query slow?"

  • "Which tables are missing indexes?"

The server exposes 5 tools over MCP:

Tool

Purpose

list_schemas

List all non-system schemas

list_tables

List tables in a given schema

run_query

Execute a read-only SQL query (SELECT/WITH only)

explain_query

Return a query execution plan and flag if it is slow

get_table_stats

Return row estimates and index/seq scan counts for a table

Related MCP server: PostgreSQL MCP Server

Why this exists

Companies are increasingly connecting AI agents to internal systems (databases, Kubernetes, APIs), and the hard part is doing that safely. This project is a small, concrete example of that: a guarded bridge between an AI client and a production-style database.

Design decisions

Read-only by default, twice over: every query is validated against a blocklist and must start with SELECT, WITH, or EXPLAIN. The database connection itself is also opened in read-only mode as a second line of defense.

Row limits and query timeouts: every query is capped at a configurable row limit and statement timeout so it cannot return unbounded data or hang the server.

Auth lives in the process environment, not in chat: the API key is set via the MCP client config as an environment variable, so the AI model never sees or handles it directly.

Audit logging: every tool call is recorded with a timestamp, tool name, arguments, and outcome.

Setup

Requirements: Python 3.11+, PostgreSQL

  1. Create a virtual environment and install dependencies: python -m venv venv venv\Scripts\Activate.ps1 pip install -r requirements.txt

  2. Create a database and load the sample schema: psql -U postgres -c "CREATE DATABASE sampledb;" psql -U postgres -d sampledb -f seed.sql

  3. Copy .env.example to .env and fill in your own values.

  4. Run it directly to sanity check: python -m server.main

Connecting to Claude Desktop

Add to claude_desktop_config.json (Claude Desktop -> Settings -> Developer -> Edit Config):

"mcpServers": {
  "postgres-analytics": {
    "command": "C:\\path\\to\\venv\\Scripts\\python.exe",
    "args": ["-m", "server.main"],
    "env": {
      "PYTHONPATH": "C:\\path\\to\\project",
      "MCP_API_KEY": "same-value-as-in-.env"
    }
  }
}

Stack

Python, PostgreSQL, MCP Python SDK, psycopg2

F
license - not found
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to safely interact with PostgreSQL databases through read-only operations, providing schema discovery, table inspection, and query execution capabilities with structured context awareness.
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Provides read-only access to PostgreSQL databases, enabling users to list tables, view table structures and statistics, and execute SELECT queries safely through natural language.
    225
    MIT
  • F
    license
    A
    quality
    D
    maintenance
    Enables AI agents to inspect and query PostgreSQL databases safely, with features like listing tables, retrieving schemas, and running read-only SQL queries.
    3
  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to safely interact with PostgreSQL databases, perform queries, inspect schemas, and analyze query performance.
    2

View all related MCP servers

Related MCP Connectors

  • Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.

  • Comprehensive PostgreSQL documentation and best practices, including ecosystem tools

  • Explore, query, and inspect SQLite databases with ease. List tables, preview results, and view det…

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/krishamehta09/pg-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server