
PgLLens
par dmdufresne
Self-documenting PostgreSQL MCP server with 19 tools for schema introspection, semantic discovery, safe read-only queries, and domain context injection.
What it does
PgLLens connects any PostgreSQL database to AI assistants via the Model Context Protocol. It gives AI models 19 purpose-built tools to discover, understand, and query your data — entirely in read-only mode. Beyond basic schema listing, PgLLens auto-extracts PostgreSQL comments, constraints, enums, triggers, and view definitions, making your AI assistant aware of your schema the way your engineering team is. You can also inject a plain-markdown domain context file to embed business rules and query patterns directly into every tool response.
Tools
query— Execute read-only SELECT queries; results as markdown tables with row countsexplain_query— EXPLAIN / EXPLAIN ANALYZE for query planning and performance tuningvalidate_query— Syntax and reference check without executinglist_tables— Tables and views with descriptions and row countsdescribe_table— Column types, nullability, defaults, PKs, FKs, commentsschema_overview— Full database schema as a markdown summaryget_ontology— Semantic layer: CHECK constraints, ENUMs, unique keys, view definitions, indexes, triggers, and injected domain contextget_relationships— FK relationship map; outputs text or Mermaid ER diagramget_sample_data— Sample rows (1–20) from any tablesearch_columns— Cross-table column search by name patternget_table_stats— Row counts, null %, distinct values per columnget_table_health— Vacuum/analyze history, dead tuples, index usage statslist_hypertables— TimescaleDB hypertable details, chunk intervals, compression policies- Plus
list_functions,get_view_definition,get_function_source,list_extensions,list_roles,refresh_schema
Installation
Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"pgllens": {
"url": "http://localhost:3000/mcp"
}
}
}
Start the server first:
docker run -p 3000:3000 -e DATABASE_URL="postgresql://user:pass@host:5432/mydb" dmdufresne/pgllens:latest
With OAuth:
{
"mcpServers": {
"pgllens": {
"url": "http://localhost:3000/mcp",
"authorizationUrl": "http://localhost:3000/oauth/authorize",
"tokenUrl": "http://localhost:3000/oauth/token"
}
}
}
Supported hosts
Claude Desktop and Claude Code are explicitly confirmed in the README. Cursor, Windsurf, and VS Code are also listed as compatible clients.
Installation rapide
docker run -p 3000:3000 -e DATABASE_URL="postgresql://user:pass@host:5432/mydb" dmdufresne/pgllens:latest