PostgreSQL MCP Server
Provides tools for schema introspection and read-only queries on PostgreSQL databases, enabling discovery of tables, columns, relationships, and safe data retrieval.
Works with Supabase-hosted PostgreSQL databases, allowing schema exploration and querying with the same tools.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@PostgreSQL MCP ServerShow me the schema for the customers table."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
PostgreSQL MCP Server
An open-source Model Context Protocol (MCP) server for PostgreSQL schema introspection and guarded read-only queries. It helps MCP clients discover schemas, tables, columns, indexes, relationships, and safe queryable data from one configured PostgreSQL database.
Works with standard PostgreSQL providers, including Supabase-hosted Postgres.
Features
Schema tools for tables, views, columns, primary keys, foreign keys, indexes, and approximate table statistics
PostgreSQL schema support with
DB_SCHEMAdefaulting topublicTable and column search with simple
*and?wildcardsRelationship discovery for join-path exploration
Optional read-only
execute_querytool with SELECT-only validation, access control, and automaticLIMITInternal
src/coreboundary for code that can later be shared with other database-specific MCP servers
Related MCP server: MCP PostgreSQL
Requirements
Node.js 18+
PostgreSQL 13+ or a compatible hosted Postgres service
A PostgreSQL role with read access to the configured database/schema
Setup
Fast path for users installing from npm:
npx -y @sigma4life/postgres-mcp-server initThen edit .env and check the connection:
npx -y @sigma4life/postgres-mcp-server doctorLocal development from this repository:
npm install
cp .env.example .env
npm run build
npm startConfigure .env:
DATABASE_URL=postgresql://app_user:app_user_password@localhost:5432/app_db
DB_SCHEMA=public
SCHEMA_ONLY_MODE=trueYou can also use individual DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD, and DB_SSL variables. Individual variables override DATABASE_URL.
This server connects to one configured database per process. Tool inputs may include database for compatibility, but it must match the configured database. Tool inputs may include schema; otherwise DB_SCHEMA or public is used.
Least-Privilege PostgreSQL User
CREATE ROLE app_user LOGIN PASSWORD 'app_user_password';
GRANT CONNECT ON DATABASE app_db TO app_user;
GRANT USAGE ON SCHEMA public TO app_user;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO app_user;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO app_user;Use a stronger host restriction and password in production.
MCP Client Example
Client-specific docs:
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "@sigma4life/postgres-mcp-server"],
"env": {
"DATABASE_URL": "postgresql://app_user:app_user_password@localhost:5432/app_db",
"DB_SCHEMA": "public",
"SCHEMA_ONLY_MODE": "true"
}
}
}
}To enable execute_query, set SCHEMA_ONLY_MODE=false and provide QUERY_ACCESS_CONFIG.
Access Control
execute_query is blocked unless QUERY_ACCESS_CONFIG points to a JSON policy file. Example:
{
"requireExplicitColumns": true,
"databases": {
"app_db": {
"schemas": {
"public": {
"tables": {
"mode": "whitelist",
"list": ["customers", "orders", "products", "order_items"],
"columnAccess": {
"customers": {
"mode": "exclusion",
"columns": ["password_hash", "api_token"]
}
}
}
}
}
}
}
}Tools
get_schemaget_table_infofind_tablessearch_objectsget_relationshipsvalidate_objectsget_accessible_schemaget_accessible_table_infoexecute_querywhen schema-only mode is disabled
Example prompts:
"Show me the schema for the customers and orders tables."
"Find tables with a column matching
*email*.""Show relationships from orders to customers."
"Run
SELECT id, email FROM customers ORDER BY id LIMIT 20."
Development
npm run build
npm test
npm run lintThe first implementation is PostgreSQL-specific. Shared logic lives under src/core so future database-specific repos can extract or reuse it without carrying PostgreSQL catalog code.
This server cannot be deployed
Maintenance
Related MCP Connectors
Hosted MCP server for PostgreSQL diagnostics: slow queries, missing indexes, connection pressure.
- SupabaseOAuthcom.supabase
MCP server for interacting with the Supabase platform
An MCP server that provides read access to your cloud storage providers, bank accounts and more.
Related MCP Servers
- AlicenseAqualityDmaintenanceA secure, read-only PostgreSQL MCP server that provides safe database introspection and querying capabilities.148 npmMIT
- AlicenseNot gradedqualityDmaintenanceA read-only MCP server for PostgreSQL that enables safe database introspection and querying via natural language.347 npmMIT
- AlicenseNot gradedqualityCmaintenanceA Python MCP server that enables schema discovery, read-only SQL queries, table previews, and index/relationship analysis on PostgreSQL databases.1MIT
- AlicenseAqualityCmaintenanceMCP server for PostgreSQL that enables safe read-only database queries, table schema inspection, and query execution planning.652 npmBSD 3-Clause