pg-context
Provides deep PostgreSQL context including live schemas as DDL, index health, foreign key associations, query execution plans, and performance statistics.
Detects TimescaleDB extensions and flags its capabilities within PostgreSQL.
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., "@pg-contextExplain the query plan for SELECT * FROM orders WHERE user_id = 42"
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.
pg-context
Model Context Protocol (MCP) server that gives AI coding assistants deep PostgreSQL context: live schemas as DDL, index health, foreign key associations, query execution plans, and performance statistics.
pg-context connects directly to your PostgreSQL database in read-only mode and exposes tools and resources for AI assistants such as Cursor, Claude Code, Cline, and Antigravity.
Why pg-context?
Generic SQL tools often execute arbitrary queries without giving the AI assistant structural context. This causes models to guess column names, hallucinate relations, and generate invalid joins.
pg-context resolves this problem by providing:
Zero-guess schema context: Exports real table structures formatted as PostgreSQL
CREATE TABLEDDL statements with foreign key comments and index definitions.Read-only security: Automatically sets
default_transaction_read_only = ONon every client connection and rejects mutating SQL statements (such asDROP,DELETE,UPDATE,INSERT,TRUNCATE,ALTER).Optimization insights: Detects unindexed foreign keys, high sequential scan ratios, unused indexes, and slow queries from
pg_stat_statements.Extension awareness: Identifies PostGIS, TimescaleDB, and pgvector extensions.
Quick Start
You can run pg-context directly via npx without manual installation:
npx -y pg-context-mcpOr install it globally:
npm install -g pg-context-mcp
pg-context-mcpConfiguration
pg-context reads connection parameters from environment variables or standard PostgreSQL connection strings:
Variable | Description | Default |
| Standard PostgreSQL connection URI |
|
| Database host |
|
| Database port |
|
| Database name |
|
| Database user |
|
| Database password |
|
| Enable SSL connection ( |
|
| Comma-separated list of target schemas |
|
| Connection pool size |
|
| Schema cache TTL in seconds |
|
| Default row limit for |
|
| Hard upper limit for |
|
Client Integration
1. Claude Desktop & Antigravity
Add the following entry to your claude_desktop_config.json or Antigravity MCP settings:
{
"mcpServers": {
"pg-context": {
"command": "npx",
"args": ["-y", "pg-context-mcp"],
"env": {
"DATABASE_URL": "postgresql://user:password@localhost:5432/my_database"
}
}
}
}2. Cursor
Add the following to your Cursor MCP configuration (.cursor/mcp.json or Cursor Settings > Features > MCP):
{
"mcpServers": {
"pg-context": {
"command": "npx",
"args": ["-y", "pg-context-mcp"],
"env": {
"DATABASE_URL": "postgresql://user:password@localhost:5432/my_database"
}
}
}
}3. Cline (VS Code Extension)
Add this configuration into cline_mcp_settings.json:
{
"mcpServers": {
"pg-context": {
"command": "npx",
"args": ["-y", "pg-context-mcp"],
"env": {
"DATABASE_URL": "postgresql://user:password@localhost:5432/my_database"
}
}
}
}Tools Reference
pg-context exposes 12 MCP tools:
Tool | Parameters | Description |
| none | Lists all non-system schemas in the database. |
|
| Lists tables and views with sizes, estimated row counts, and comments. |
|
| Returns full structural DDL of a table including columns, types, defaults, NOT NULL, foreign keys, and indexes. |
|
| Displays foreign key relationships as readable |
|
| Displays indexes, definitions, sizes, and scan counts. |
|
| Identifies unindexed foreign keys, sequential scan warnings, and unused indexes. |
|
| Executes read-only queries with enforced limits and returns Markdown tables. |
|
| Returns query execution plans from PostgreSQL |
| none | Returns PostgreSQL version, total database size, connection counts, and buffer settings. |
|
| Returns sequential vs index scans, live rows, dead rows, and maintenance dates. |
|
| Fetches top slowest queries recorded by |
| none | Lists installed PostgreSQL extensions and flags capabilities for PostGIS, TimescaleDB, and pgvector. |
Resources Reference
pg-context exposes 3 MCP resources:
Resource URI | MIME Type | Description |
|
| Full DDL dump of all tables across configured schemas. |
|
| DDL definition for an individual table. |
|
| Database health overview: storage sizes, dead rows, and optimization alerts. |
Development
# Clone the repository
git clone https://github.com/mewsyy/pg-context.git
cd pg-context
# Install dependencies
npm install
# Run test suite
npm test
# Build TypeScript
npm run build
# Start local server
npm startLicense
MIT (c) Semen
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 Connectors
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
MCP server for managing Prisma Postgres.
MCP server for interacting with the Supabase platform
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/mewsyy/pg-context'
If you have feedback or need assistance with the MCP directory API, please join our Discord server