PostgreSQL Read-Only MCP Server
Provides safe, read-only access to a PostgreSQL database, including schema inspection, data previews, custom SELECT queries, foreign key relationship discovery, and database statistics.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
PostgreSQL Read-Only MCP Server
A Model Context Protocol (MCP) server that provides safe, read-only access to one configured PostgreSQL database.
The server exposes schema inspection, data preview, custom SELECT query execution, relationship discovery, database statistics, safe connection metadata, and a connection_info prompt for MCP clients such as Claude Desktop.
Features
Single database per MCP server instance
Strict PostgreSQL read-only validation (
SELECTonly)Schema-aware tools with optional
schemainput, defaulting topublicServer-side row limits and query timeout protection
Data preview with optional column selection, basic
wherefiltering, and text truncationForeign key relationship discovery
Database statistics with largest tables by rows and by size
Safe
db_infooutput that never exposes passwordsconnection_infoMCP prompt with connection context and usage guidance
Related MCP server: PostgreSQL MCP Server
Installation
Use directly with npx in your MCP client config:
npx -y postgres-readonly-mcpOr install globally:
npm install -g postgres-readonly-mcp
postgres-readonly-mcpFor local development only:
git clone https://github.com/beydemirfurkan/postgres-readonly-mcp.git
cd postgres-readonly-mcp
npm install
npm run buildClaude Desktop Config
Recommended npx setup:
{
"mcpServers": {
"postgres-readonly": {
"command": "npx",
"args": ["-y", "postgres-readonly-mcp"],
"env": {
"POSTGRES_HOST": "127.0.0.1",
"POSTGRES_PORT": "5432",
"POSTGRES_USER": "postgres",
"POSTGRES_PASSWORD": "your_password",
"POSTGRES_DATABASE": "your_database",
"POSTGRES_SSL": "true",
"POSTGRES_SSL_REJECT_UNAUTHORIZED": "true"
}
}
}
}Connection string setup:
{
"mcpServers": {
"postgres-readonly": {
"command": "npx",
"args": ["-y", "postgres-readonly-mcp"],
"env": {
"DATABASE_URL": "postgresql://USER:PASSWORD@HOST:5432/DB_NAME",
"POSTGRES_SSL": "true"
}
}
}
}Restart Claude Desktop after editing the config.
Multiple Databases
One server instance maps to one PostgreSQL database. To expose multiple databases, add multiple MCP server entries with different names and environment variables:
{
"mcpServers": {
"postgres-crm": {
"command": "npx",
"args": ["-y", "postgres-readonly-mcp"],
"env": {
"DATABASE_URL": "postgresql://USER:PASSWORD@HOST:5432/crm"
}
},
"postgres-analytics": {
"command": "npx",
"args": ["-y", "postgres-readonly-mcp"],
"env": {
"DATABASE_URL": "postgresql://USER:PASSWORD@HOST:5432/analytics"
}
}
}
}Environment Variables
POSTGRES_HOST: PostgreSQL host, defaultlocalhostPOSTGRES_PORT: PostgreSQL port, default5432POSTGRES_USER: PostgreSQL user, defaultpostgresPOSTGRES_PASSWORD: PostgreSQL password, default emptyPOSTGRES_DATABASE: PostgreSQL database name, defaultpostgresPOSTGRES_SSL: Enable TLS, defaulttruePOSTGRES_SSL_REJECT_UNAUTHORIZED: Reject unauthorized TLS certificates, defaulttruePOSTGRES_QUERY_TIMEOUT_MS: Query timeout in milliseconds, minimum1000, default30000DATABASE_URL: PostgreSQL connection URL fallbackPOSTGRES_URL: PostgreSQL connection URL alias
Explicit POSTGRES_* host fields override URL values when both are present.
If your password includes special characters (/, @, :), URL encode it in connection strings.
Tools
db_info
Returns safe connection metadata for the configured database.
Input:
{}list_tables
Lists tables/views in a schema.
Input:
{ "schema": "public" }describe_table
Describes columns, primary key, foreign keys, and indexes.
Input:
{
"schema": "public",
"table": "users"
}preview_data
Previews rows from a table with optional column selection and basic filtering.
Input:
{
"schema": "public",
"table": "users",
"columns": ["id", "email", "created_at"],
"where": "created_at >= '2026-01-01'",
"limit": 10
}run_query
Runs a custom read-only SQL query.
Input:
{
"query": "SELECT id, email FROM \"public\".\"users\" ORDER BY id DESC",
"limit": 100
}show_relations
Shows foreign key relations for a table.
Input:
{
"schema": "public",
"table": "orders"
}db_stats
Returns database size, table count, row estimates, largestByRows, and largestBySize.
Input:
{}Prompts
connection_info
Provides safe PostgreSQL connection context and read-only usage guidance. Passwords are never included.
Safety Model
Only
SELECTstatements are allowedMultiple SQL statements in one request are blocked
DML, DDL, grant/revoke, maintenance, and admin keywords are blocked
Risky PostgreSQL functions such as
pg_sleep,dblink, and file-read helpers are blockedResults are capped server-side even if a query requests more rows
Connection/runtime errors are sanitized to avoid credential leakage
Limits
preview_datadefault:10, max:100run_querydefault:1000, max:5000Query timeout:
30000msby defaultLong text truncation:
200chars
Development
npm install
npm run build
npm run dev
npm testLicense
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Query Postgres, MySQL, SQL Server, Oracle, BigQuery, ClickHouse and Redshift from your AI client.
Query, explore, and manage your databases through natural conversation.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to safely interact with PostgreSQL databases through read-only operations, providing schema discovery, table inspection, and query execution capabilities with structured context awareness.MIT
- AlicenseNot gradedqualityDmaintenanceProvides read-only access to PostgreSQL databases, enabling users to list tables, view table structures and statistics, and execute SELECT queries safely through natural language.MIT
- AlicenseNot gradedqualityBmaintenanceEnables secure read-only access to PostgreSQL databases, allowing users to list tables, query schemas, execute SELECT statements, and inspect table structures through natural language interactions.909 npm4MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI clients to explore a PostgreSQL database schema and run read-only queries, including listing tables, describing columns, executing SELECT queries, and retrieving foreign key relationships.ISC