mcp-postgres-query
Connects Claude to any PostgreSQL database, enabling schema exploration, query execution, and performance analysis through natural conversation.
README
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-query
Or run directly:
npx mcp-postgres-query
Configuration
Set the DATABASE_URL environment variable with your PostgreSQL connection string:
DATABASE_URL=postgresql://user:password@localhost:5432/mydb
Claude 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 |
|---|---|---|
query |
Execute a SQL query | sql (string), params (optional array) |
list_tables |
List all tables in the public schema | none |
describe_table |
Get column details (type, nullable, default) | table_name |
list_indexes |
List indexes on a table | table_name |
explain_query |
Get EXPLAIN ANALYZE plan (safe, rolls back) | sql |
get_table_stats |
Row counts and table size | table_name |
get_db_info |
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
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.