mcp-postgres-query
Connects to any PostgreSQL database, allowing schema exploration, SQL query execution, and performance analysis through natural conversation.
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., "@mcp-postgres-queryWhat tables are in this database?"
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.
mcp-postgres-query
MCP server that connects Claude to any PostgreSQL database. Explore schemas, run queries, analyze performance — all through natural conversation.
Built by THRYXAGI.
Install
npm install -g mcp-postgres-queryOr run directly:
npx mcp-postgres-queryConfiguration
Set the DATABASE_URL environment variable with your PostgreSQL connection string:
DATABASE_URL=postgresql://user:password@localhost:5432/mydbClaude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "mcp-postgres-query"],
"env": {
"DATABASE_URL": "postgresql://user:password@localhost:5432/mydb"
}
}
}
}Claude Code
Add to your .mcp.json:
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "mcp-postgres-query"],
"env": {
"DATABASE_URL": "postgresql://user:password@localhost:5432/mydb"
}
}
}
}Tools (7)
Tool | Description | Params |
| Execute a SQL query |
|
| List all tables in the public schema | none |
| Get column details (type, nullable, default) |
|
| List indexes on a table |
|
| Get EXPLAIN ANALYZE plan (safe, rolls back) |
|
| Row counts and table size |
|
| Database overview (version, size, table count) | none |
Example Usage
Once connected, ask Claude things like:
"What tables are in this database?"
"Describe the users table"
"SELECT * FROM orders WHERE created_at > '2024-01-01' LIMIT 10"
"Explain this slow query: SELECT ..."
"How big is the events table?"
Security Notes
The
querytool executes arbitrary SQL. Connect with a read-only database user for safety.The
explain_querytool wraps EXPLAIN ANALYZE in a transaction that always rolls back, so it never modifies data.Parameterized queries are supported via the
paramsargument to prevent SQL injection.Never expose
DATABASE_URLin public repositories or logs.
License
MIT
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/lordbasilaiassistant-sudo/mcp-postgres-query'
If you have feedback or need assistance with the MCP directory API, please join our Discord server