Skip to content

Commit 24594df

Browse files
committed
Merge remote changes and resolve conflicts
2 parents 97425cc + e47c37b commit 24594df

File tree

1 file changed

+147
-188
lines changed

1 file changed

+147
-188
lines changed

README.md

Lines changed: 147 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -1,244 +1,203 @@
1-
# PostgreSQL MCP Server
1+
# 🔄 PostgreSQL MCP Server – AI-Powered PostgreSQL Management & Monitoring
22

3-
A comprehensive Model Context Protocol (MCP) server for PostgreSQL database integration. This server provides extensive tools, resources, and prompts for complete PostgreSQL database management through AI assistants like Claude.
3+
> A powerful, AI-integrated PostgreSQL Model Context Protocol (MCP) server for **automated database operations, monitoring, security, diagnostics, and optimization**. Seamlessly manage PostgreSQL with tools and prompts designed for **AI assistants like Claude and ChatGPT**.
44
5-
## Features
5+
[![Python](https://img.shields.io/badge/Python-3.8%2B-blue.svg)](https://python.org)
6+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7+
[![PostgreSQL](https://img.shields.io/badge/PostgreSQL-Compatible-blue?logo=postgresql)](https://www.postgresql.org/)
8+
[![MCP](https://img.shields.io/badge/MCP%20Server-PostgreSQL%20Integration-brightgreen)]()
69

7-
This server offers over 200 specialized PostgreSQL tools covering all aspects of database administration, monitoring, and optimization.
10+
**GitHub Repository**: [https://github.com/mukul975/postgres-mcp-server.git](https://github.com/mukul975/postgres-mcp-server.git)
11+
12+
---
13+
14+
## 📌 Why Use This?
15+
16+
* 🔍 Explore, diagnose & optimize PostgreSQL databases with **over 200 specialized tools**.
17+
* 💬 Interact naturally using **AI prompts** for SQL generation, health checks, and performance reviews.
18+
* 🛡️ Built-in security, permission validation, and error handling.
19+
* ⚙️ Developer-ready integration for **Claude**, **ChatGPT**, and custom agents.
20+
21+
---
22+
23+
## 🔑 Features at a Glance
824

925
### 🔧 Core Database Operations
10-
- **Database Management**: Create, list, and manage databases
11-
- **Schema Operations**: Create, drop, and manage schemas
12-
- **Table Operations**: List, describe, analyze tables with detailed statistics
13-
- **Query Execution**: Safe SELECT queries and controlled UPDATE/INSERT/DELETE operations
14-
- **Index Management**: Create, drop, analyze index usage and effectiveness
15-
16-
### 📊 Advanced Analytics & Monitoring
17-
- **Performance Analysis**: Query performance, slow query analysis, execution plan examination
18-
- **Resource Monitoring**: Buffer cache analysis, memory usage, I/O statistics
19-
- **Lock Analysis**: Deadlock detection, lock contention monitoring, blocking queries
20-
- **Replication Monitoring**: Replication status, lag analysis, slot management
21-
- **Vacuum & Maintenance**: Autovacuum monitoring, table bloat analysis, maintenance recommendations
22-
23-
### 🛡️ Security & Administration
24-
- **User Management**: Create, drop, manage users and roles with detailed permissions
25-
- **Privilege Management**: Grant/revoke permissions, security auditing
26-
- **Connection Management**: Monitor active connections, analyze connection patterns
27-
- **Backup Analysis**: Backup status monitoring and recovery readiness assessment
28-
29-
### 🚀 Performance Optimization
30-
- **Index Optimization**: Unused index detection, redundancy analysis, effectiveness metrics
31-
- **Query Optimization**: Plan cache analysis, query complexity assessment
32-
- **Buffer Pool Tuning**: Hit ratio analysis, cache efficiency metrics
33-
- **Configuration Tuning**: Parameter recommendations and system health checks
34-
35-
### 📈 Advanced Diagnostics
36-
- **Transaction Analysis**: Long-running transactions, wraparound monitoring
37-
- **Checkpoint Monitoring**: Checkpoint efficiency and timing analysis
38-
- **WAL Analysis**: Write-ahead log generation and archiving status
39-
- **Extension Management**: Installed extensions and usage analysis
40-
41-
### 📊 Resources
42-
- **postgres://tables/{schema}**: Get table information for a schema
43-
- **postgres://table/{schema}/{table_name}**: Get detailed table structure
44-
45-
### 💬 Prompts
46-
- **analyze_table**: Generate analysis prompts for database tables
47-
- **query_builder**: Help build SQL queries with proper guidance
48-
49-
## Installation
50-
51-
1. Create a virtual environment (recommended):
52-
```bash
53-
# Create virtual environment
54-
python -m venv venv
5526

56-
# Activate virtual environment
57-
# On Windows:
58-
venv\Scripts\activate
59-
# On macOS/Linux:
60-
source venv/bin/activate
61-
```
27+
* ✅ Create/list databases & schemas
28+
* ✅ Describe tables, analyze indexes
29+
* ✅ Safe SELECT, UPDATE, DELETE execution
30+
31+
### 📊 Monitoring & Performance
32+
33+
* 📈 Query performance & execution plan insights
34+
* 🔒 Lock analysis, replication lag checks
35+
* 🚀 Index, query, and buffer pool optimization
36+
37+
### 🛡️ Security & Access Control
38+
39+
* 👥 User creation, role auditing
40+
* 🔐 Privilege granting & connection monitoring
41+
42+
### ⚙️ Diagnostic Utilities
43+
44+
* 🧪 Table bloat check, autovacuum insights
45+
* 💽 WAL logs, checkpoints, long transaction alerts
46+
47+
---
48+
49+
## 🚀 Quick Start
50+
51+
### 1. Installation
6252

63-
2. Install dependencies:
6453
```bash
54+
python -m venv venv
55+
source venv/bin/activate # or venv\Scripts\activate on Windows
6556
pip install -r requirements.txt
6657
```
6758

68-
3. Set up your database connection:
69-
```bash
70-
# Copy the example environment file
71-
copy .env.example .env
59+
### 2. Configuration
7260

73-
# Edit .env with your PostgreSQL connection details
74-
DATABASE_URL=postgresql://username:password@localhost:5432/database_name
61+
```bash
62+
cp .env.example .env # or use copy on Windows
63+
# Update with:
64+
DATABASE_URL=postgresql://username:password@localhost:5432/db
7565
```
7666

77-
## Usage
67+
### 3. Run the Server
7868

79-
### Running the Server
80-
81-
#### Direct execution:
8269
```bash
8370
python postgres_server.py
8471
```
8572

86-
#### With MCP development tools (if mcp CLI is installed):
73+
> ✅ For **MCP CLI users**:
74+
8775
```bash
8876
mcp dev postgres_server.py
8977
```
9078

91-
### Configuration with Claude Desktop
79+
---
80+
81+
## 🧠 Integrate with Claude Desktop
82+
83+
#### Example config (`claude_desktop_config.json`):
9284

93-
Add the following to your Claude Desktop configuration file (`claude_desktop_config.json`):
85+
<details>
86+
<summary>Windows</summary>
9487

95-
**Windows:**
9688
```json
9789
{
9890
"mcpServers": {
9991
"postgres": {
10092
"command": "python",
101-
"args": [
102-
"postgres_server.py"
103-
],
93+
"args": ["postgres_server.py"],
10494
"cwd": "C:\\path\\to\\postgres-mcp-server",
10595
"env": {
106-
"DATABASE_URL": "postgresql://username:password@localhost:5432/database_name"
96+
"DATABASE_URL": "postgresql://username:password@localhost:5432/database"
10797
}
10898
}
10999
}
110100
}
111101
```
112102

113-
**macOS/Linux:**
103+
</details>
104+
105+
<details>
106+
<summary>macOS/Linux</summary>
107+
114108
```json
115109
{
116110
"mcpServers": {
117111
"postgres": {
118112
"command": "python",
119-
"args": [
120-
"postgres_server.py"
121-
],
113+
"args": ["postgres_server.py"],
122114
"cwd": "/absolute/path/to/postgres-mcp-server",
123115
"env": {
124-
"DATABASE_URL": "postgresql://username:password@localhost:5432/database_name"
116+
"DATABASE_URL": "postgresql://username:password@localhost:5432/database"
125117
}
126118
}
127119
}
128120
}
129121
```
130122

131-
## Tool Categories
132-
133-
### Database Structure & Metadata
134-
- `PostgreSQL_list_tables` - List all tables in a schema
135-
- `PostgreSQL_describe_table` - Get detailed table column information
136-
- `PostgreSQL_list_schemas` - List all database schemas
137-
- `PostgreSQL_list_indexes` - Show indexes for a table
138-
- `PostgreSQL_get_foreign_keys` - Display foreign key relationships
139-
- `PostgreSQL_get_table_constraints` - Show all table constraints
140-
141-
### Query Execution & Analysis
142-
- `PostgreSQL_execute_select_query` - Execute SELECT queries safely
143-
- `PostgreSQL_execute_update_query` - Execute INSERT/UPDATE/DELETE queries
144-
- `PostgreSQL_explain_query` - Show query execution plans
145-
- `PostgreSQL_get_slow_queries` - Analyze slow running queries
146-
- `PostgreSQL_analyze_query_complexity` - Assess query performance characteristics
147-
148-
### Performance Monitoring
149-
- `PostgreSQL_get_cache_hit_ratios` - Buffer cache performance metrics
150-
- `PostgreSQL_get_index_usage_stats` - Index utilization analysis
151-
- `PostgreSQL_get_table_statistics` - Comprehensive table statistics
152-
- `PostgreSQL_check_long_running_queries` - Monitor active long queries
153-
- `PostgreSQL_get_blocking_locks` - Identify blocking transactions
154-
155-
### Maintenance & Optimization
156-
- `PostgreSQL_get_bloated_tables` - Find tables needing maintenance
157-
- `PostgreSQL_get_unused_indexes` - Identify unused indexes
158-
- `PostgreSQL_vacuum_analyze_table` - Perform table maintenance
159-
- `PostgreSQL_get_autovacuum_activity` - Monitor autovacuum operations
160-
- `PostgreSQL_analyze_database` - Update table statistics
161-
162-
### Security & User Management
163-
- `PostgreSQL_create_user` - Create database users
164-
- `PostgreSQL_grant_privileges` - Assign user permissions
165-
- `PostgreSQL_get_active_connections` - Monitor user connections
166-
- `PostgreSQL_list_users_and_roles` - Display all users and roles
167-
- `PostgreSQL_get_table_permissions` - Show table-level permissions
168-
169-
### Replication & Backup
170-
- `PostgreSQL_get_replication_status` - Monitor replication health
171-
- `PostgreSQL_get_replication_slots` - Manage replication slots
172-
- `PostgreSQL_get_backup_status` - Check backup configuration
173-
- `PostgreSQL_get_wal_stats` - Write-ahead log statistics
174-
175-
## Example Interactions
176-
177-
### Database Exploration
178-
```
179-
"Show me all tables in the public schema"
180-
"What's the structure of the users table?"
181-
"List all foreign key relationships for the orders table"
182-
```
123+
</details>
183124

184-
### Performance Analysis
185-
```
186-
"Analyze the performance of my database and suggest optimizations"
187-
"Show me the slowest queries from the last hour"
188-
"Which indexes are not being used and can be dropped?"
189-
"What's the buffer cache hit ratio?"
190-
```
125+
---
191126

192-
### Monitoring & Diagnostics
193-
```
194-
"Are there any blocking queries right now?"
195-
"Show me tables with high bloat that need maintenance"
196-
"Check the replication lag status"
197-
"What connections are currently active?"
198-
```
127+
## 🧰 Tooling Highlights
199128

200-
### Maintenance Operations
201-
```
202-
"Run VACUUM ANALYZE on the products table"
203-
"Update statistics for the entire database"
204-
"Show me autovacuum activity for today"
205-
```
129+
| Category | Tools |
130+
| --------------- | ---------------------------------------------------- |
131+
| 🧱 Structure | `list_tables`, `describe_table`, `get_foreign_keys` |
132+
| 📄 Queries | `execute_select_query`, `analyze_query_complexity` |
133+
| 📈 Monitoring | `get_cache_hit_ratios`, `check_long_running_queries` |
134+
| 🛠️ Maintenance | `get_bloated_tables`, `vacuum_analyze_table` |
135+
| 🔐 Security | `create_user`, `grant_privileges`, `list_users` |
136+
| 🔁 Replication | `get_replication_status`, `get_backup_status` |
206137

207-
### Security Auditing
208-
```
209-
"Show me all users and their privileges"
210-
"What permissions does user 'app_user' have?"
211-
"List all active database connections"
212-
```
138+
---
139+
140+
## 💬 Prompt Examples for AI Agents
141+
142+
### 👁️ Database Insight
143+
144+
> "List all indexes in the public schema"
145+
> "Show detailed structure of the `orders` table"
146+
147+
### 🚀 Performance
148+
149+
> "What are the slowest queries?"
150+
> "Analyze unused indexes"
151+
152+
### ⚙ Maintenance
153+
154+
> "VACUUM ANALYZE the `products` table"
155+
> "Find bloated tables in the database"
156+
157+
### 🔒 Security
158+
159+
> "List all users and their roles"
160+
> "Show active connections and privilege levels"
161+
162+
---
163+
164+
## 📚 Use Cases
165+
166+
### ✅ Health & Diagnostics
167+
168+
* Full PostgreSQL system health check
169+
* Query and index optimization
170+
171+
### ⚙ Admin & Automation
172+
173+
* AI-based schema exploration
174+
* SQL query building with NLP
175+
176+
### 🔐 Security & Auditing
177+
178+
* Role auditing, connection analysis
179+
* Secure query validation and permission check
180+
181+
---
182+
183+
## 🗞️ License
184+
185+
This project is licensed under the MIT License – see the [LICENSE](./LICENSE) file for details.
186+
187+
---
188+
189+
## ⭐ Contribute & Support
190+
191+
If you find this useful, please:
192+
193+
* ⭐ Star the repo
194+
* 🍝 Fork it
195+
* 🛠️ Submit issues or PRs
196+
197+
> 🧠 Let’s build smarter PostgreSQL automation – one prompt at a time.
198+
199+
---
200+
201+
## 🔍 GitHub Search Tags
213202

214-
## Advanced Use Cases
215-
216-
### Database Health Assessment
217-
The server can perform comprehensive health checks including:
218-
- Buffer pool efficiency analysis
219-
- Index usage optimization
220-
- Table bloat assessment
221-
- Replication lag monitoring
222-
- Connection pool analysis
223-
224-
### Performance Tuning
225-
- Identify slow queries and suggest optimizations
226-
- Analyze execution plans for query improvement
227-
- Monitor resource utilization patterns
228-
- Recommend index strategies
229-
230-
### Proactive Monitoring
231-
- Set up monitoring for long-running transactions
232-
- Track database growth trends
233-
- Monitor backup and recovery readiness
234-
- Analyze connection patterns and bottlenecks
235-
236-
## Security Features
237-
238-
- **Query Validation**: Only allows specific query types (SELECT for reads, INSERT/UPDATE/DELETE for writes)
239-
- **Connection Pooling**: Efficient database connection management with proper cleanup
240-
- **Parameter Sanitization**: Prevents SQL injection through parameterized queries
241-
- **Error Handling**: Comprehensive error handling with informative messages
242-
- **Logging**: Contextual logging for monitoring and debugging
243-
- **Environment Variables**: Secure credential management
244-
- **Permission Checks**: Respects database user permissions and access controls
203+
`#PostgreSQL` `#MCP` `#AI_Database_Tools` `#Claude` `#Query_Optimizer` `#Database_Health_Check` `#Python_PostgreSQL` `#DevOps_AI` `#Database_Monitoring` `#OpenSource`

0 commit comments

Comments
 (0)