Postgres Analytics MCP Server
Provides tools for safely inspecting and querying a PostgreSQL database, including listing schemas and tables, running read-only queries, explaining query execution plans, and retrieving table statistics.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Postgres Analytics MCP ServerWhat tables are in the public schema?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
# 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
Create a virtual environment and install dependencies: python -m venv venv venv\Scripts\Activate.ps1 pip install -r requirements.txt
Create a database and load the sample schema: psql -U postgres -c "CREATE DATABASE sampledb;" psql -U postgres -d sampledb -f seed.sql
Copy .env.example to .env and fill in your own values.
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
This server cannot be installed
Maintenance
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
- AlicenseNot gradedqualityDmaintenanceEnables 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
- AlicenseNot gradedqualityDmaintenanceProvides read-only access to PostgreSQL databases, enabling users to list tables, view table structures and statistics, and execute SELECT queries safely through natural language.225MIT
- FlicenseAqualityDmaintenanceEnables AI agents to inspect and query PostgreSQL databases safely, with features like listing tables, retrieving schemas, and running read-only SQL queries.3
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to safely interact with PostgreSQL databases, perform queries, inspect schemas, and analyze query performance.2
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…
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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