Add your description here
Project description
MCP PostgreSQL Operations Server
A professional MCP server for PostgreSQL database server operations, monitoring, and management. Provides advanced performance analysis capabilities using pg_stat_statements and pg_stat_monitor extensions.
Features
- ✅ PostgreSQL Monitoring: Performance analysis based on pg_stat_statements and pg_stat_monitor
- ✅ Structure Exploration: Database, table, and user listing
- ✅ Performance Analysis: Slow query identification and index usage analysis
- ✅ Capacity Management: Database and table size analysis
- ✅ Configuration Retrieval: PostgreSQL configuration parameter verification
- ✅ Safe Read-Only: All operations are read-only and safe
Quick start
- Environment Setup
# Check and modify .env file
cp .env.example .env
# Configure PostgreSQL connection information:
# POSTGRES_HOST=host.docker.internal
# POSTGRES_PORT=5432
# POSTGRES_USER=postgres
# POSTGRES_PASSWORD=your-password
# POSTGRES_DB=postgres
- Install Dependencies
uv venv --python 3.11 --seed
uv sync
- Run Server
# Development & Testing (recommended)
./scripts/run-mcp-inspector-local.sh
# Direct execution for debugging
python -m src.mcp_postgresql_ops.mcp_main --log-level DEBUG
Available Tools
📊 Server Information & Status
get_server_info- PostgreSQL server information and extension statusget_active_connections- Current active connections and session informationget_postgresql_config- PostgreSQL configuration parameters with keyword search capability
🗄️ Structure Exploration
get_database_list- All database list and size informationget_table_list- Table list and size informationget_user_list- Database user list and permissions
⚡ Performance Monitoring
get_pg_stat_statements_top_queries- Slow query analysis based on performance statisticsget_pg_stat_monitor_recent_queries- Real-time query monitoringget_index_usage_stats- Index usage rate and efficiency analysis
💾 Capacity Management
get_database_size_info- Database capacity analysisget_table_size_info- Table and index size analysisget_vacuum_analyze_stats- VACUUM/ANALYZE status and history
Usage Examples
Claude Desktop Integration
Add to your Claude Desktop configuration file:
{
"mcpServers": {
"postgresql-ops": {
"command": "uv",
"args": ["run", "python", "-m", "src.mcp_postgresql_ops.mcp_main"],
"cwd": "/path/to/MCP-PostgreSQL-Ops",
"env": {
"POSTGRES_HOST": "host.docker.internal",
"POSTGRES_PORT": "5432",
"POSTGRES_USER": "postgres",
"POSTGRES_PASSWORD": "your-password",
"POSTGRES_DB": "postgres"
}
}
}
}
Command Line Usage
# HTTP mode for testing
python -m src.mcp_postgresql_ops.mcp_main \
--type streamable-http \
--host 127.0.0.1 \
--port 8080 \
--log-level DEBUG
Configuration Search Examples
The get_postgresql_config tool supports flexible parameter searching:
# Search for specific parameter
"Show the shared_buffers configuration"
# Search by keyword for related parameters
"Find all memory-related configuration settings"
"Show logging configuration parameters"
"Display connection-related settings"
"Find all timeout configurations"
# Browse all configurations
"Show all PostgreSQL configuration parameters"
Environment Variables
| Variable | Description | Default | Example |
|---|---|---|---|
MCP_LOG_LEVEL |
Logging level | INFO |
DEBUG |
FASTMCP_TYPE |
Transport type | stdio |
streamable-http |
FASTMCP_HOST |
HTTP host address | 127.0.0.1 |
0.0.0.0 |
FASTMCP_PORT |
HTTP port number | 8080 |
9090 |
POSTGRES_HOST |
PostgreSQL host | localhost |
host.docker.internal |
POSTGRES_PORT |
PostgreSQL port | 5432 |
5432 |
POSTGRES_USER |
PostgreSQL user | postgres |
your-user |
POSTGRES_PASSWORD |
PostgreSQL password | `` | your-password |
POSTGRES_DB |
PostgreSQL database | postgres |
your-db |
Prerequisites
Required PostgreSQL Extensions
For full functionality, your PostgreSQL instance should have these extensions installed:
-- Query performance statistics (required)
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
-- Advanced monitoring (optional)
CREATE EXTENSION IF NOT EXISTS pg_stat_monitor;
Minimum Requirements
- PostgreSQL 12+ (tested with PostgreSQL 16)
- Python 3.11
- Network access to PostgreSQL server
- Read permissions on system catalogs
Sample Prompts
🔍 Server Health Check
- "Check PostgreSQL server status"
- "Verify if extensions are installed"
- "Show current active connection count"
📊 Performance Analysis
- "Show top 20 slowest queries"
- "Find unused indexes"
- "Analyze recent query activity"
💾 Capacity Management
- "Check database sizes"
- "Find largest tables"
- "Show tables that need VACUUM"
Troubleshooting
Connection Issues
- Check PostgreSQL server status
- Verify connection parameters in
.envfile - Ensure network connectivity
- Check user permissions
Extension Errors
- Run
get_server_infoto check extension status - Install missing extensions:
CREATE EXTENSION pg_stat_statements; CREATE EXTENSION pg_stat_monitor;
- Restart PostgreSQL if needed
Performance Issues
- Use
limitparameters to reduce result size - Run monitoring during off-peak hours
- Check database load before running analysis
Development
Testing & Development
# Test with MCP Inspector
./scripts/run-mcp-inspector-local.sh
# Direct execution for debugging
python -m src.mcp_postgresql_ops.mcp_main --log-level DEBUG
# Run tests (if you add any)
uv run pytest
Security Notes
- All tools are read-only - no data modification capabilities
- Sensitive information (passwords) are masked in outputs
- No direct SQL execution - only predefined queries
- Follows principle of least privilege
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_postgresql_ops-0.0.3.tar.gz.
File metadata
- Download URL: mcp_postgresql_ops-0.0.3.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
602e4f7d26d74b8cc808cc0de708a013a4ba468935424c897e9af75c3a69e467
|
|
| MD5 |
7e0f7908e7e0c13119aa8634ead6e172
|
|
| BLAKE2b-256 |
3f4a9485fb8ac92f63c550c0829595cc18507ebdc7db0916693071511c72c8d8
|
Provenance
The following attestation bundles were made for mcp_postgresql_ops-0.0.3.tar.gz:
Publisher:
pypi-publish.yml on call518/MCP-PostgreSQL-Ops
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_postgresql_ops-0.0.3.tar.gz -
Subject digest:
602e4f7d26d74b8cc808cc0de708a013a4ba468935424c897e9af75c3a69e467 - Sigstore transparency entry: 412394195
- Sigstore integration time:
-
Permalink:
call518/MCP-PostgreSQL-Ops@26cd968a25cee79a399eedb636414e8b9f256455 -
Branch / Tag:
refs/tags/0.0.3 - Owner: https://github.com/call518
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@26cd968a25cee79a399eedb636414e8b9f256455 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mcp_postgresql_ops-0.0.3-py3-none-any.whl.
File metadata
- Download URL: mcp_postgresql_ops-0.0.3-py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84d7103d7f88f9df206e51faa205925898896d901904de4fca8f4eb85985c238
|
|
| MD5 |
ddf42f06d1feaf7360aaeb011451fdc6
|
|
| BLAKE2b-256 |
d80a9ba1ef16535bd31c638be9ecd8dce75c05adc6f6193913fd35b48350ac9a
|
Provenance
The following attestation bundles were made for mcp_postgresql_ops-0.0.3-py3-none-any.whl:
Publisher:
pypi-publish.yml on call518/MCP-PostgreSQL-Ops
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_postgresql_ops-0.0.3-py3-none-any.whl -
Subject digest:
84d7103d7f88f9df206e51faa205925898896d901904de4fca8f4eb85985c238 - Sigstore transparency entry: 412394212
- Sigstore integration time:
-
Permalink:
call518/MCP-PostgreSQL-Ops@26cd968a25cee79a399eedb636414e8b9f256455 -
Branch / Tag:
refs/tags/0.0.3 - Owner: https://github.com/call518
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@26cd968a25cee79a399eedb636414e8b9f256455 -
Trigger Event:
push
-
Statement type: