Read-only PostgreSQL introspection for AI agents, delivered through MCP.
Give an agent schema discovery, join paths, real column values, read-only SQL, query plans, and database health checks without giving it write access.
uvx pglensPython 3.11+ and a reachable PostgreSQL server are required. To install in an environment instead:
pip install pglensPoint your client at pglens and pass PostgreSQL's standard PG* environment
variables:
{
"mcpServers": {
"pglens": {
"command": "uvx",
"args": ["pglens"],
"env": {
"PGHOST": "localhost",
"PGPORT": "5432",
"PGUSER": "myuser",
"PGPASSWORD": "mypassword",
"PGDATABASE": "mydb"
}
}
}
}Client examples and configuration reference
| Ask | pglens uses |
|---|---|
| What tables, columns, keys, and policies exist? | list_objects, describe_object |
| How do these tables join? | find_join_path |
| What values should this filter use? | column_profile |
| What does the data say? | query, explain_query |
| Is the database healthy or blocked? | health, activity |
For example, before an agent writes WHERE status = 'active', it can inspect the
actual values and avoid guessing between active, Active, and enabled.
pglens sets every database connection to read-only, validates user SQL as a single
SELECT, quotes identifiers, and applies statement and lock timeouts. It exposes no
DDL tools.
Read-only access still depends on the PostgreSQL role you configure. Use a role with only the data the agent should access.
- Configuration: environment variables, multiple databases, and HTTP transport.
- Tools: all nine MCP tools and the usual workflow.
- Safety: enforcement layers and role guidance.
- Architecture: design and implementation details.
- Evaluation: tool-surface benchmark harness.
MIT