pg-readonly-mcp
Server Configuration
Describes the environment variables required to run the server.
| Name | Required | Description | Default |
|---|---|---|---|
| MCP_PG_DSN | Yes | libpq connection string or URL. Prefer ~/.pgpass or PGPASSWORD to a password in the string. | |
| MCP_PG_AUDIT_LOG | No | Where the audit log goes (created with mode 600). | ~/.pg-readonly-mcp/audit.jsonl |
| MCP_PG_ROW_LIMIT | No | Most rows one run_query returns (hard maximum 10,000). Claude can ask for fewer. | 200 |
| MCP_PG_TIMEOUT_MS | No | Statement timeout for each query. | 10000 |
| MCP_PG_SEARCH_PATH | No | Schemas searched for unqualified table names. | public |
| MCP_PG_ALLOWED_TABLES | Yes | Comma-separated schema.table entries, or schema.* for a whole schema. A bare name means public.name. Quote mixed-case names: "Sales"."Q1 Orders". | |
| MCP_PG_MAX_CELL_CHARS | No | Long text values are cut to this length so one cell cannot flood the context. | 2000 |
| MCP_PG_ALLOW_SUPERUSER | No | Set to 1 only for a throwaway local database. | off |
| MCP_PG_EXTRA_FUNCTIONS | No | Extra function names to allow, e.g. similarity, unaccent. |
Instructions
Guidance the server publishes about itself, which clients place ahead of the tool catalog so the model reads it before choosing anything.
Read-only access to one PostgreSQL database. Start with list_tables, then describe_table for the columns you need. run_query takes exactly one SELECT (CTEs, joins, window functions and aggregates are fine) and returns at most the server's row limit, so aggregate or filter in SQL instead of pulling raw rows. Only allow-listed tables can be read; writes, multiple statements and functions that touch files or settings are refused, and every call is written to an audit log. If a query is refused, the error says why: fix the query rather than retrying.
Capabilities
Features and capabilities supported by this server
Protocol revision2025-11-25
| Capability | Details |
|---|---|
| tools | {
"listChanged": false
} |
| prompts | {
"listChanged": false
} |
| resources | {
"subscribe": false,
"listChanged": false
} |
Tools
Functions exposed to the LLM to take actions
| Name | Description |
|---|---|
| list_tablesA | List the tables and views this server may read, with approximate row counts and comments, plus the row limit and timeout that apply to run_query. |
| describe_tableA | Show the columns (name, type, nullable, default, comment), primary key and foreign keys of one allow-listed table or view. Pass schema.table, or just the table name for the default schema. |
| run_queryA | Run one read-only SQL SELECT (PostgreSQL dialect) and return columns and rows.
At most |
| explain_queryA | Show PostgreSQL's query plan for one SELECT without running it (EXPLAIN, no ANALYZE). Use it before a query that might be slow on a large table. |
Prompts
Interactive templates invoked by user choice
| Name | Description |
|---|---|
No prompts | |
Resources
Contextual data attached and managed by the client
| Name | Description |
|---|---|
No resources | |
TDQS
Scored across 4 tools
Each tool has a clearly distinct role: discovering tables, inspecting one table's schema, executing a read-only SELECT, and explaining a query plan. The list_tables vs describe_table distinction is obvious from scope and output. There is no meaningful overlap that would cause misselection.
All four names follow a consistent snake_case verb_noun convention: list_tables, describe_table, run_query, explain_query. The pattern is predictable and readable throughout.
Four tools is appropriately scoped for a read-only PostgreSQL inspection server. Each tool earns its place, and there is no unnecessary surface area.
The set covers the core read-only workflow: discover tables, inspect schema, execute queries, and preview query plans. Minor gaps exist in schema introspection, such as indexes and unique constraints beyond primary/foreign keys, but agents can work around them.