pg-context
pg-context
AI 코딩 어시스턴트에게 깊은 PostgreSQL 컨텍스트(라이브 스키마를 DDL로, 인덱스 상태, 외래 키 연관 관계, 쿼리 실행 계획, 성능 통계)를 제공하는 Model Context Protocol(MCP) 서버입니다.
pg-context는 PostgreSQL 데이터베이스에 읽기 전용 모드로 직접 연결하여 Cursor, Claude Code, Cline, Antigravity 같은 AI 어시스턴트를 위한 도구와 리소스를 노출합니다.
왜 pg-context인가?
일반적인 SQL 도구는 AI 어시스턴트에게 구조적 컨텍스트를 제공하지 않은 채 임의의 쿼리를 실행하는 경우가 많습니다. 이로 인해 모델이 열 이름을 추측하고, 관계를 환각하며, 잘못된 조인을 생성하게 됩니다.
pg-context는 다음을 제공하여 이 문제를 해결합니다.
추측 없는 스키마 컨텍스트: 실제 테이블 구조를 외래 키 주석과 인덱스 정의가 포함된 PostgreSQL
CREATE TABLEDDL 문으로 내보냅니다.읽기 전용 보안: 모든 클라이언트 연결에
default_transaction_read_only = ON을 자동으로 설정하고 변경 쿼리(DROP,DELETE,UPDATE,INSERT,TRUNCATE,ALTER등)를 거부합니다.최적화 인사이트: 인덱스되지 않은 외래 키, 높은 순차 스캔 비율, 사용되지 않는 인덱스,
pg_stat_statements의 느린 쿼리를 감지합니다.확장 인식: PostGIS, TimescaleDB, pgvector 확장을 식별합니다.
Related MCP server: PostgreSQL MCP Server
빠른 시작
npx를 통해 pg-context를 수동 설치 없이 직접 실행할 수 있습니다:
npx -y pg-context-mcp또는 전역으로 설치할 수 있습니다:
npm install -g pg-context-mcp
pg-context-mcp설정
pg-context는 환경 변수 또는 표준 PostgreSQL 연결 문자열에서 연결 매개변수를 읽습니다:
변수 | 설명 | 기본값 |
| 표준 PostgreSQL 연결 URI |
|
| 데이터베이스 호스트 |
|
| 데이터베이스 포트 |
|
| 데이터베이스 이름 |
|
| 데이터베이스 사용자 |
|
| 데이터베이스 비밀번호 |
|
| SSL 연결 활성화 ( |
|
| 대상 스키마의 쉼표로 구분된 목록 |
|
| 연결 풀 크기 |
|
| 스키마 캐시 TTL(초) |
|
|
|
|
|
|
|
클라이언트 통합
1. Claude Desktop 및 Antigravity
claude_desktop_config.json 또는 Antigravity MCP 설정에 다음 항목을 추가하세요:
{
"mcpServers": {
"pg-context": {
"command": "npx",
"args": ["-y", "pg-context-mcp"],
"env": {
"DATABASE_URL": "postgresql://user:password@localhost:5432/my_database"
}
}
}
}2. Cursor
Cursor MCP 구성에 다음을 추가하세요 (.cursor/mcp.json 또는 Cursor 설정 > 기능 > 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 확장 프로그램)
cline_mcp_settings.json에 이 구성을 추가하세요:
{
"mcpServers": {
"pg-context": {
"command": "npx",
"args": ["-y", "pg-context-mcp"],
"env": {
"DATABASE_URL": "postgresql://user:password@localhost:5432/my_database"
}
}
}
}도구 참조
pg-context는 12개의 MCP 도구를 제공합니다:
도구 | 매개변수 | 설명 |
| 없음 | 데이터베이스의 모든 비시스템 스키마를 나열합니다. |
|
| 테이블과 뷰를 크기, 예상 행 수, 주석과 함께 나열합니다. |
|
| 열, 유형, 기본값, NOT NULL, 외래 키 및 인덱스를 포함한 테이블의 전체 구조 DDL을 반환합니다. |
|
| 외래 키 관계를 읽기 쉬운 |
|
| 인덱스, 정의, 크기 및 스캔 횟수를 표시합니다. |
|
| 인덱스되지 않은 외래 키, 순차 스캔 경고, 사용되지 않는 인덱스를 식별합니다. |
|
| 강제된 제한으로 읽기 전용 쿼리를 실행하고 Markdown 테이블을 반환합니다. |
|
| PostgreSQL |
| 없음 | PostgreSQL 버전, 전체 데이터베이스 크기, 연결 수 및 버퍼 설정을 반환합니다. |
|
| 순차 스캔 대 인덱스 스캔, 활성 행, 죽은 행 및 유지 관리 날짜를 반환합니다. |
|
|
|
| 없음 | 설치된 PostgreSQL 확장을 나열하고 PostGIS, TimescaleDB 및 pgvector의 기능을 표시합니다. |
리소스 참조
pg-context는 3개의 MCP 리소스를 제공합니다:
리소스 URI | MIME 유형 | 설명 |
|
| 구성된 모든 스키마에 걸친 모든 테이블의 전체 DDL 덤프. |
|
| 개별 테이블의 DDL 정의. |
|
| 데이터베이스 상태 개요: 스토리지 크기, 죽은 행 및 최적화 경고. |
개발
# 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 start라이선스
MIT (c) Semen
Available Tools
12 toolsdescribe_tableB
Get full structural details of a table as CREATE TABLE DDL, including columns, data types, constraints, foreign keys, and indexes
Inputs: table (required), schema.
explain_queryB
Get query execution plan via PostgreSQL EXPLAIN (or EXPLAIN ANALYZE) to debug performance bottlenecks
Inputs: sql (required), analyze.
get_database_infoA
Get high-level PostgreSQL database runtime information: version, size, active connection count, and server settings
Inputs: no named parameters.
get_slow_queriesB
Retrieve top slowest queries recorded by pg_stat_statements extension (if enabled in PostgreSQL)
Inputs: limit.
get_table_statsA
Get scan statistics, tuple counts, dead row accumulation, and maintenance history for tables
Inputs: table, schema.
list_extensionsA
List installed PostgreSQL extensions with version information and specialized framework detection (PostGIS, TimescaleDB, pgvector)
Inputs: no named parameters.
list_foreign_keysA
List foreign key relationships between tables to understand data model associations and joins
Inputs: table, schema.
list_indexesA
List indexes on tables with sizes and scan usage statistics to evaluate index health
Inputs: table, schema.
list_schemasA
List all available database schemas (excluding system schemas like pg_catalog and information_schema)
Inputs: no named parameters.
list_tablesA
List all tables and views in a given schema with estimated row counts, sizes, and comments
Inputs: schema.
read_queryA
Execute a safe read-only SQL query (SELECT, WITH, SHOW) with strict LIMIT enforcement and formatting
Inputs: sql (required), limit.
suggest_indexesB
Analyze query patterns, scan ratios, and missing foreign key indexes to provide index recommendations
Inputs: table, schema.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 12 tools
Each tool targets a distinct aspect of PostgreSQL database introspection: schemas, tables, relationships, indexes, query execution, performance stats, and extensions. There is no overlap in purpose.
All tools follow a consistent verb_noun pattern in snake_case (e.g., list_schemas, describe_table, read_query), making the API predictable and easy to navigate.
With 12 tools, the server covers the key areas of database analysis without being bloated. Each tool serves a distinct role, and the count is appropriate for the domain.
The set covers schema exploration, table details, indexing, query analysis, performance monitoring, and extension information. No obvious gaps for a read-only database context server.
Related MCP Connectors
Hosted PostgreSQL MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Hosted MCP server for PostgreSQL diagnostics: slow queries, missing indexes, connection pressure.
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that provides AI assistants with secure, read-only access to PostgreSQL databases while offering comprehensive tools for schema exploration, query validation, and performance optimization.MIT
- FlicenseNot gradedqualityDmaintenanceAn MCP server that enables AI assistants to interact with PostgreSQL databases by executing SQL queries and inspecting database schemas. It provides tools for standardized database exploration and management through the Model Context Protocol.-
- AlicenseAqualityCmaintenanceAn MCP server that gives AI agents direct read-only access to PostgreSQL databases, enabling natural language analytics through tools for schema exploration, querying, trend analysis, and data quality checks.115MIT
- AlicenseAqualityDmaintenanceA Model Context Protocol (MCP) server that gives AI assistants deep visibility into databases, inspecting schemas, detecting index problems, analyzing table bloat, and explaining query plans across PostgreSQL, MySQL, and SQLite.921 npm1MIT