LabscoMCP early access ↗
abiswas97MCP SERVER

Postgres MCP Server

Query a PostgreSQL database and read its schema — tables, columns, constraints, indexes, views and functions — with read-only enforced by default.

by abiswas97 ↗Relational SQL DatabasesCommunity

LABSCO SUMMARY

Reads a database the way a careful analyst would: schema first, then rows.

The schema tools are the reason to reach for this rather than a bare SQL socket — constraints, indexes, views and function listings give a model enough to write a correct join instead of guessing at column names. Pagination, a query timeout and a read-only default keep an exploratory session from becoming an incident.

What it is

A PostgreSQL MCP server built on Kysely, aimed at letting a client read a live database safely. Queries are parameterized and paginated; alongside them sits a full schema-inspection surface — tables, columns, constraints, indexes, views, functions and table statistics — plus EXPLAIN for a plan without running the statement. READ_ONLY defaults to on, restricting execution to SELECT, WITH and EXPLAIN.

What you get

  • SQL executed with bound parameters and page-size and offset handling, up to 500 rows per page — query
  • A query's execution plan without running it, optionally with ANALYZE, in text, json, xml or yaml — explain_query
  • A table's structure and column detail, and its constraints including primary and foreign keys — describe_table, get_constraints
  • The schemas in the database and the tables in a schema, with system schemas excluded unless you ask for them — list_schemas, list_tables
  • Indexes for a table or a whole schema, so a slow query can be read against what is actually indexed — list_indexes
  • Views, and the functions and stored procedures in a schema — list_views, list_functions
  • Table size and statistics for one table or the whole schema — get_table_stats

Requirements

Credentials for a PostgreSQL database, passed as environment variables: DB_HOST, DB_PORT (5432), DB_USER, DB_PASSWORD, DB_NAME and DB_SSL. The package is @abiswas97/postgres-mcp 2.0.0 with a postgres-mcp binary, run over stdio. READ_ONLY is true unless you change it, which is the setting that decides whether an agent can write to this database at all — leave it on for anything you care about. QUERY_TIMEOUT cuts a statement off at 30000 milliseconds, MAX_PAGE_SIZE caps a page at 500 rows and DEFAULT_PAGE_SIZE sets 100 when the call does not say.

Setup effort

One command plus credentials — npx @abiswas97/postgres-mcp, then supply credentials