Postgres MCP Server
Server Configuration
Describes the environment variables required to run the server.
| Name | Required | Description | Default |
|---|---|---|---|
| LLM_MODEL | No | Model used to write SQL. | gpt-4o-mini |
| LLM_API_KEY | No | API key for the ask tool. | |
| DATABASE_URL | No | Single database connection URL. | |
| LLM_BASE_URL | No | Any OpenAI-compatible endpoint. | OpenAI |
| PG_MCP_MAX_ROWS | No | Maximum rows returned per query. | 200 |
| PG_MCP_DATABASES | No | JSON map of database name to connection URL. Overrides DATABASE_URL. | |
| PG_MCP_STATEMENT_TIMEOUT_MS | No | Per-query timeout in milliseconds. | 5000 |
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 PostgreSQL access. Start with list_databases and list_tables, use describe_table before writing SQL, then run_query. Use ask to let the server write the SQL from a plain-English question. All queries are read-only and row-limited.
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_databasesA | List the configured database names. |
| list_tablesB | List tables and views with approximate row counts. |
| describe_tableB | Show columns, types, primary key and foreign keys for a table (e.g. 'public.orders'). |
| run_queryA | Run a single read-only SELECT. Writes, DDL and unsafe functions are rejected; rows are capped. |
| explain_queryB | Show the PostgreSQL query plan for a SELECT without running it. |
| askB | Answer a plain-English question: writes safe SQL from the live schema and (optionally) runs it. |
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 6 tools
Most tools target clearly distinct actions: listing databases/tables, describing a table, running a SELECT, and explaining a query plan. The only real overlap is between 'ask' and 'run_query', since 'ask' can also generate and execute SQL, but the natural-language vs raw-SQL distinction and the optional execution flag make them separable.
Five of six tools follow a clean verb_noun or verb_object pattern (list_databases, list_tables, describe_table, run_query, explain_query). 'ask' is a stylistic outlier but is still a single readable verb, so the set remains predictable.
Six tools is well-scoped for a read-only Postgres inspection server — each one covers a distinct step in the explore-inspect-query workflow. Nothing feels padded or missing at the count level.
The surface covers the core read-only lifecycle: discover databases, browse tables, inspect schema, execute, and plan queries, with 'ask' as a convenience layer. Minor gaps exist — no schema-level listing beyond table names, no index/constraint detail beyond PK/FK, and writes/DDL are intentionally excluded, which an agent can work around for read-only tasks.