PostgreSQL Read-Only MCP Server
A secure MCP server that enables querying PostgreSQL databases through an SSH tunnel with enforced read-only access, connection pooling, and comprehensive data exploration tools.
README
PostgreSQL Read-Only MCP Server
A secure MCP (Model Context Protocol) server that provides read-only access to PostgreSQL databases through an SSH tunnel.
Features
- Secure SSH Tunnel: Connects to PostgreSQL through encrypted SSH tunnel
- Read-Only Enforcement: All queries run in read-only transactions
- Connection Pooling: Efficient database connection management
- Query Timeout: 15-second timeout for all operations
- Comprehensive Tools: Query, list tables, describe schemas, analyze data
Configuration
-
Copy the example configuration file:
cp .env.example ~/.pg_mcp/.env -
Edit
~/.pg_mcp/.envwith your credentials:# PostgreSQL Database Configuration POSTGRES_DB=your_database POSTGRES_USER=readonly_user POSTGRES_PASSWORD=your_password # SSH Tunnel Configuration SSH_HOST=your-ec2-instance.amazonaws.com SSH_USER=ec2-user SSH_KEY_PATH=/path/to/ssh/key # RDS Configuration RDS_HOST=your-database.rds.amazonaws.com -
Create a read-only database user:
CREATE USER readonly_mcp WITH PASSWORD 'secure_password'; GRANT CONNECT ON DATABASE your_database TO readonly_mcp; GRANT USAGE ON SCHEMA public TO readonly_mcp; GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly_mcp; ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly_mcp;
Installation
pnpm install
pnpm run build
Usage
Start the MCP server:
./start_mcp.sh
For development mode with hot reload:
./start_mcp.sh dev
Available MCP Tools
postgres_query: Execute read-only SQL queriespostgres_list_tables: List all tables with optional row countspostgres_describe_table: Get detailed schema informationpostgres_analyze_table: Analyze table for data quality issuespostgres_find_related: Find foreign key relationshipspostgres_explain_query: Get query execution plans
SSH Tunnel Management
The server implements a shared SSH tunnel system:
- Multiple instances share a single tunnel
- Reference counting prevents premature closure
- Automatic reconnection on failure
- Lock files in
/tmp/pg_mcp_tunnel/
Monitor tunnel status:
./check_tunnel.sh
Security
- All queries validated for read-only operations
- Enforced read-only transactions
- 15-second query timeout
- SSH encryption for all connections
- Credentials stored outside repository
Requirements
- Node.js v24+
- pnpm package manager
- PostgreSQL database
- SSH access to database server
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.