PostgreSQL MCP Server
Query and manage PostgreSQL databases directly from Claude Code with read-only or full access modes. Ideal for developers who need to explore schemas, run queries, and debug database issues without leaving their AI coding workflow.
MCP Server Configuration
Read-Only Mode (Recommended for Production)
{ "mcpServers": { "postgres": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-postgres", "postgresql://user:password@localhost:5432/mydb" ] } } }
Full Access Mode
{ "mcpServers": { "postgres": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-postgres", "postgresql://user:password@localhost:5432/mydb", "--access-mode=unrestricted" ] } } }
Available Tools
| Tool | Description |
|---|---|
query | Execute SQL queries against the connected database |
list_tables | List all tables in the current schema |
describe_table | Get column definitions, types, and constraints |
list_schemas | List all available schemas |
Connection String Format
postgresql://[user]:[password]@[host]:[port]/[database]?[params]
Examples:
# Local development postgresql://postgres:secret@localhost:5432/myapp_dev # With SSL (production) postgresql://user:[email protected]:5432/production?sslmode=require # With specific schema postgresql://user:pass@localhost:5432/mydb?search_path=public
Setup
- Ensure PostgreSQL is running and accessible
- Create a dedicated read-only user (recommended):
CREATE ROLE claude_reader WITH LOGIN PASSWORD 'secure_password'; GRANT CONNECT ON DATABASE mydb TO claude_reader; GRANT USAGE ON SCHEMA public TO claude_reader; GRANT SELECT ON ALL TABLES IN SCHEMA public TO claude_reader; ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO claude_reader;
- Replace the connection string with your actual credentials
Security Notes
- Always use read-only credentials for production databases
- Never expose production connection strings in committed files
- Use environment variables for sensitive connection details
- Consider connecting through an SSH tunnel for remote databases
- The server does NOT sandbox queries in read-only mode by default - create a read-only PostgreSQL user
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Database MCP Integration
MCP server configuration for connecting Claude Code to PostgreSQL, MySQL, and MongoDB databases. Enables schema inspection, query building, and migration generation.
Elevenlabs Server
Streamline your workflow with this official, elevenlabs, text, speech. Includes structured workflows, validation checks, and reusable patterns for audio.
Browser Use Portal
Powerful mcp for server, enables, agents, control. Includes structured workflows, validation checks, and reusable patterns for browser_automation.