Enables querying of PostgreSQL databases, schema inspection, and retrieval of DDL with built-in read-only protection. It provides tools for connecting to databases, executing SQL queries, listing schemas, and fetching complete DDL structures.
Click on "Install 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., "@pg-mcplist all tables in the public schema"
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.
pg-mcp
MCP (Model Context Protocol) server for PostgreSQL databases. Enables Claude and other AI assistants to query databases, inspect schemas, and get DDL - with built-in read-only protection.
Features
pg_connect - Connect to PostgreSQL databases (URL or individual params)
pg_disconnect - Disconnect from databases
pg_query - Execute SQL queries
pg_list_schemas - List all schemas
pg_get_ddl - Get complete DDL (tables, indexes, constraints, foreign keys, views)
Read-only mode - Blocks INSERT, UPDATE, DELETE, and DDL operations (enabled by default)
Installation
Using npx (recommended)
npx pg-mcpGlobal install
npm install -g pg-mcpFrom source
git clone https://github.com/shedyhs/pg-mcp
cd pg-mcp
npm install
npm run buildConfiguration
Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["pg-mcp"]
}
}
}Claude Code
Add to your .claude/settings.json:
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["pg-mcp"]
}
}
}With environment variable
You can set DATABASE_URL to auto-connect:
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["pg-mcp"],
"env": {
"DATABASE_URL": "postgres://user:pass@localhost:5432/mydb"
}
}
}
}Usage
Connect to database
pg_connect({
connectionId: "main",
url: "postgres://user:pass@localhost:5432/mydb"
})Or with individual parameters:
pg_connect({
connectionId: "main",
host: "localhost",
port: 5432,
database: "mydb",
user: "postgres",
password: "secret"
})Read-only mode
By default, connections are read-only. This blocks:
DML: INSERT, UPDATE, DELETE, TRUNCATE, MERGE
DDL: CREATE, ALTER, DROP, RENAME
DCL: GRANT, REVOKE
To disable (use with caution):
pg_connect({
connectionId: "main",
url: "postgres://...",
readOnly: false
})Query examples
-- List tables
SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';
-- Query data
SELECT * FROM users LIMIT 10;
-- Get table structure
pg_get_ddl({ connectionId: "main", schema: "public" })Tools
Tool | Description |
| Connect to a PostgreSQL database |
| Disconnect from a database |
| Execute a SQL query |
| List all schemas in the database |
| Get complete DDL for the database |
License
MIT
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.