mcp-postgresql-ops 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Anthony Lapenna
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ #include src/mcp_postgresql_ops/test.txt
@@ -0,0 +1,231 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcp-postgresql-ops
3
+ Version: 0.0.2
4
+ Summary: Add your description here
5
+ Author-email: JungJungIn <call518@gmail.com>
6
+ Requires-Python: >=3.11
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: fastmcp>=2.11.1
10
+ Requires-Dist: asyncpg>=0.29.0
11
+ Requires-Dist: psycopg2-binary>=2.9.7
12
+ Provides-Extra: dev
13
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
14
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
15
+ Dynamic: license-file
16
+
17
+ # MCP PostgreSQL Operations Server
18
+
19
+ 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.
20
+
21
+ ## Features
22
+
23
+ - ✅ **PostgreSQL Monitoring**: Performance analysis based on pg_stat_statements and pg_stat_monitor
24
+ - ✅ **Structure Exploration**: Database, table, and user listing
25
+ - ✅ **Performance Analysis**: Slow query identification and index usage analysis
26
+ - ✅ **Capacity Management**: Database and table size analysis
27
+ - ✅ **Configuration Retrieval**: PostgreSQL configuration parameter verification
28
+ - ✅ **Safe Read-Only**: All operations are read-only and safe
29
+
30
+ ## Quick start
31
+
32
+ 1) Environment Setup
33
+
34
+ ```bash
35
+ # Check and modify .env file
36
+ cp .env.example .env
37
+ # Configure PostgreSQL connection information:
38
+ # POSTGRES_HOST=host.docker.internal
39
+ # POSTGRES_PORT=5432
40
+ # POSTGRES_USER=postgres
41
+ # POSTGRES_PASSWORD=your-password
42
+ # POSTGRES_DB=postgres
43
+ ```
44
+
45
+ 2) Install Dependencies
46
+
47
+ ```bash
48
+ uv venv --python 3.11 --seed
49
+ uv sync
50
+ ```
51
+
52
+ 3) Run Server
53
+
54
+ ```bash
55
+ # Development & Testing (recommended)
56
+ ./scripts/run-mcp-inspector-local.sh
57
+
58
+ # Direct execution for debugging
59
+ python -m src.mcp_postgresql_ops.mcp_main --log-level DEBUG
60
+ ```
61
+
62
+ ## Available Tools
63
+
64
+ ### 📊 Server Information & Status
65
+ - `get_server_info` - PostgreSQL server information and extension status
66
+ - `get_active_connections` - Current active connections and session information
67
+ - `get_postgresql_config` - PostgreSQL configuration parameters with keyword search capability
68
+
69
+ ### 🗄️ Structure Exploration
70
+ - `get_database_list` - All database list and size information
71
+ - `get_table_list` - Table list and size information
72
+ - `get_user_list` - Database user list and permissions
73
+
74
+ ### ⚡ Performance Monitoring
75
+ - `get_pg_stat_statements_top_queries` - Slow query analysis based on performance statistics
76
+ - `get_pg_stat_monitor_recent_queries` - Real-time query monitoring
77
+ - `get_index_usage_stats` - Index usage rate and efficiency analysis
78
+
79
+ ### 💾 Capacity Management
80
+ - `get_database_size_info` - Database capacity analysis
81
+ - `get_table_size_info` - Table and index size analysis
82
+ - `get_vacuum_analyze_stats` - VACUUM/ANALYZE status and history
83
+
84
+ ## Usage Examples
85
+
86
+ ### Claude Desktop Integration
87
+ Add to your Claude Desktop configuration file:
88
+
89
+ ```json
90
+ {
91
+ "mcpServers": {
92
+ "postgresql-ops": {
93
+ "command": "uv",
94
+ "args": ["run", "python", "-m", "src.mcp_postgresql_ops.mcp_main"],
95
+ "cwd": "/path/to/MCP-PostgreSQL-Ops",
96
+ "env": {
97
+ "POSTGRES_HOST": "host.docker.internal",
98
+ "POSTGRES_PORT": "5432",
99
+ "POSTGRES_USER": "postgres",
100
+ "POSTGRES_PASSWORD": "your-password",
101
+ "POSTGRES_DB": "postgres"
102
+ }
103
+ }
104
+ }
105
+ }
106
+ ```
107
+
108
+ ### Command Line Usage
109
+
110
+ ```bash
111
+ # HTTP mode for testing
112
+ python -m src.mcp_postgresql_ops.mcp_main \
113
+ --type streamable-http \
114
+ --host 127.0.0.1 \
115
+ --port 8080 \
116
+ --log-level DEBUG
117
+ ```
118
+
119
+ ### Configuration Search Examples
120
+
121
+ The `get_postgresql_config` tool supports flexible parameter searching:
122
+
123
+ ```bash
124
+ # Search for specific parameter
125
+ "Show the shared_buffers configuration"
126
+
127
+ # Search by keyword for related parameters
128
+ "Find all memory-related configuration settings"
129
+ "Show logging configuration parameters"
130
+ "Display connection-related settings"
131
+ "Find all timeout configurations"
132
+
133
+ # Browse all configurations
134
+ "Show all PostgreSQL configuration parameters"
135
+ ```
136
+
137
+ ## Environment Variables
138
+
139
+ | Variable | Description | Default | Example |
140
+ |----------|-------------|---------|---------|
141
+ | `MCP_LOG_LEVEL` | Logging level | `INFO` | `DEBUG` |
142
+ | `FASTMCP_TYPE` | Transport type | `stdio` | `streamable-http` |
143
+ | `FASTMCP_HOST` | HTTP host address | `127.0.0.1` | `0.0.0.0` |
144
+ | `FASTMCP_PORT` | HTTP port number | `8080` | `9090` |
145
+ | `POSTGRES_HOST` | PostgreSQL host | `localhost` | `host.docker.internal` |
146
+ | `POSTGRES_PORT` | PostgreSQL port | `5432` | `5432` |
147
+ | `POSTGRES_USER` | PostgreSQL user | `postgres` | `your-user` |
148
+ | `POSTGRES_PASSWORD` | PostgreSQL password | `` | `your-password` |
149
+ | `POSTGRES_DB` | PostgreSQL database | `postgres` | `your-db` |
150
+
151
+ ## Prerequisites
152
+
153
+ ### Required PostgreSQL Extensions
154
+
155
+ For full functionality, your PostgreSQL instance should have these extensions installed:
156
+
157
+ ```sql
158
+ -- Query performance statistics (required)
159
+ CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
160
+
161
+ -- Advanced monitoring (optional)
162
+ CREATE EXTENSION IF NOT EXISTS pg_stat_monitor;
163
+ ```
164
+
165
+ ### Minimum Requirements
166
+ - PostgreSQL 12+ (tested with PostgreSQL 16)
167
+ - Python 3.11
168
+ - Network access to PostgreSQL server
169
+ - Read permissions on system catalogs
170
+
171
+ ## Sample Prompts
172
+
173
+ ### 🔍 Server Health Check
174
+ - "Check PostgreSQL server status"
175
+ - "Verify if extensions are installed"
176
+ - "Show current active connection count"
177
+
178
+ ### 📊 Performance Analysis
179
+ - "Show top 20 slowest queries"
180
+ - "Find unused indexes"
181
+ - "Analyze recent query activity"
182
+
183
+ ### 💾 Capacity Management
184
+ - "Check database sizes"
185
+ - "Find largest tables"
186
+ - "Show tables that need VACUUM"
187
+
188
+ ## Troubleshooting
189
+
190
+ ### Connection Issues
191
+ 1. Check PostgreSQL server status
192
+ 2. Verify connection parameters in `.env` file
193
+ 3. Ensure network connectivity
194
+ 4. Check user permissions
195
+
196
+ ### Extension Errors
197
+ 1. Run `get_server_info` to check extension status
198
+ 2. Install missing extensions:
199
+ ```sql
200
+ CREATE EXTENSION pg_stat_statements;
201
+ CREATE EXTENSION pg_stat_monitor;
202
+ ```
203
+ 3. Restart PostgreSQL if needed
204
+
205
+ ### Performance Issues
206
+ 1. Use `limit` parameters to reduce result size
207
+ 2. Run monitoring during off-peak hours
208
+ 3. Check database load before running analysis
209
+
210
+ ## Development
211
+
212
+ ### Testing & Development
213
+
214
+ ```bash
215
+ # Test with MCP Inspector
216
+ ./scripts/run-mcp-inspector-local.sh
217
+
218
+ # Direct execution for debugging
219
+ python -m src.mcp_postgresql_ops.mcp_main --log-level DEBUG
220
+
221
+ # Run tests (if you add any)
222
+ uv run pytest
223
+ ```
224
+
225
+ ## Security Notes
226
+
227
+ - All tools are **read-only** - no data modification capabilities
228
+ - Sensitive information (passwords) are masked in outputs
229
+ - No direct SQL execution - only predefined queries
230
+ - Follows principle of least privilege
231
+
@@ -0,0 +1,215 @@
1
+ # MCP PostgreSQL Operations Server
2
+
3
+ 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.
4
+
5
+ ## Features
6
+
7
+ - ✅ **PostgreSQL Monitoring**: Performance analysis based on pg_stat_statements and pg_stat_monitor
8
+ - ✅ **Structure Exploration**: Database, table, and user listing
9
+ - ✅ **Performance Analysis**: Slow query identification and index usage analysis
10
+ - ✅ **Capacity Management**: Database and table size analysis
11
+ - ✅ **Configuration Retrieval**: PostgreSQL configuration parameter verification
12
+ - ✅ **Safe Read-Only**: All operations are read-only and safe
13
+
14
+ ## Quick start
15
+
16
+ 1) Environment Setup
17
+
18
+ ```bash
19
+ # Check and modify .env file
20
+ cp .env.example .env
21
+ # Configure PostgreSQL connection information:
22
+ # POSTGRES_HOST=host.docker.internal
23
+ # POSTGRES_PORT=5432
24
+ # POSTGRES_USER=postgres
25
+ # POSTGRES_PASSWORD=your-password
26
+ # POSTGRES_DB=postgres
27
+ ```
28
+
29
+ 2) Install Dependencies
30
+
31
+ ```bash
32
+ uv venv --python 3.11 --seed
33
+ uv sync
34
+ ```
35
+
36
+ 3) Run Server
37
+
38
+ ```bash
39
+ # Development & Testing (recommended)
40
+ ./scripts/run-mcp-inspector-local.sh
41
+
42
+ # Direct execution for debugging
43
+ python -m src.mcp_postgresql_ops.mcp_main --log-level DEBUG
44
+ ```
45
+
46
+ ## Available Tools
47
+
48
+ ### 📊 Server Information & Status
49
+ - `get_server_info` - PostgreSQL server information and extension status
50
+ - `get_active_connections` - Current active connections and session information
51
+ - `get_postgresql_config` - PostgreSQL configuration parameters with keyword search capability
52
+
53
+ ### 🗄️ Structure Exploration
54
+ - `get_database_list` - All database list and size information
55
+ - `get_table_list` - Table list and size information
56
+ - `get_user_list` - Database user list and permissions
57
+
58
+ ### ⚡ Performance Monitoring
59
+ - `get_pg_stat_statements_top_queries` - Slow query analysis based on performance statistics
60
+ - `get_pg_stat_monitor_recent_queries` - Real-time query monitoring
61
+ - `get_index_usage_stats` - Index usage rate and efficiency analysis
62
+
63
+ ### 💾 Capacity Management
64
+ - `get_database_size_info` - Database capacity analysis
65
+ - `get_table_size_info` - Table and index size analysis
66
+ - `get_vacuum_analyze_stats` - VACUUM/ANALYZE status and history
67
+
68
+ ## Usage Examples
69
+
70
+ ### Claude Desktop Integration
71
+ Add to your Claude Desktop configuration file:
72
+
73
+ ```json
74
+ {
75
+ "mcpServers": {
76
+ "postgresql-ops": {
77
+ "command": "uv",
78
+ "args": ["run", "python", "-m", "src.mcp_postgresql_ops.mcp_main"],
79
+ "cwd": "/path/to/MCP-PostgreSQL-Ops",
80
+ "env": {
81
+ "POSTGRES_HOST": "host.docker.internal",
82
+ "POSTGRES_PORT": "5432",
83
+ "POSTGRES_USER": "postgres",
84
+ "POSTGRES_PASSWORD": "your-password",
85
+ "POSTGRES_DB": "postgres"
86
+ }
87
+ }
88
+ }
89
+ }
90
+ ```
91
+
92
+ ### Command Line Usage
93
+
94
+ ```bash
95
+ # HTTP mode for testing
96
+ python -m src.mcp_postgresql_ops.mcp_main \
97
+ --type streamable-http \
98
+ --host 127.0.0.1 \
99
+ --port 8080 \
100
+ --log-level DEBUG
101
+ ```
102
+
103
+ ### Configuration Search Examples
104
+
105
+ The `get_postgresql_config` tool supports flexible parameter searching:
106
+
107
+ ```bash
108
+ # Search for specific parameter
109
+ "Show the shared_buffers configuration"
110
+
111
+ # Search by keyword for related parameters
112
+ "Find all memory-related configuration settings"
113
+ "Show logging configuration parameters"
114
+ "Display connection-related settings"
115
+ "Find all timeout configurations"
116
+
117
+ # Browse all configurations
118
+ "Show all PostgreSQL configuration parameters"
119
+ ```
120
+
121
+ ## Environment Variables
122
+
123
+ | Variable | Description | Default | Example |
124
+ |----------|-------------|---------|---------|
125
+ | `MCP_LOG_LEVEL` | Logging level | `INFO` | `DEBUG` |
126
+ | `FASTMCP_TYPE` | Transport type | `stdio` | `streamable-http` |
127
+ | `FASTMCP_HOST` | HTTP host address | `127.0.0.1` | `0.0.0.0` |
128
+ | `FASTMCP_PORT` | HTTP port number | `8080` | `9090` |
129
+ | `POSTGRES_HOST` | PostgreSQL host | `localhost` | `host.docker.internal` |
130
+ | `POSTGRES_PORT` | PostgreSQL port | `5432` | `5432` |
131
+ | `POSTGRES_USER` | PostgreSQL user | `postgres` | `your-user` |
132
+ | `POSTGRES_PASSWORD` | PostgreSQL password | `` | `your-password` |
133
+ | `POSTGRES_DB` | PostgreSQL database | `postgres` | `your-db` |
134
+
135
+ ## Prerequisites
136
+
137
+ ### Required PostgreSQL Extensions
138
+
139
+ For full functionality, your PostgreSQL instance should have these extensions installed:
140
+
141
+ ```sql
142
+ -- Query performance statistics (required)
143
+ CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
144
+
145
+ -- Advanced monitoring (optional)
146
+ CREATE EXTENSION IF NOT EXISTS pg_stat_monitor;
147
+ ```
148
+
149
+ ### Minimum Requirements
150
+ - PostgreSQL 12+ (tested with PostgreSQL 16)
151
+ - Python 3.11
152
+ - Network access to PostgreSQL server
153
+ - Read permissions on system catalogs
154
+
155
+ ## Sample Prompts
156
+
157
+ ### 🔍 Server Health Check
158
+ - "Check PostgreSQL server status"
159
+ - "Verify if extensions are installed"
160
+ - "Show current active connection count"
161
+
162
+ ### 📊 Performance Analysis
163
+ - "Show top 20 slowest queries"
164
+ - "Find unused indexes"
165
+ - "Analyze recent query activity"
166
+
167
+ ### 💾 Capacity Management
168
+ - "Check database sizes"
169
+ - "Find largest tables"
170
+ - "Show tables that need VACUUM"
171
+
172
+ ## Troubleshooting
173
+
174
+ ### Connection Issues
175
+ 1. Check PostgreSQL server status
176
+ 2. Verify connection parameters in `.env` file
177
+ 3. Ensure network connectivity
178
+ 4. Check user permissions
179
+
180
+ ### Extension Errors
181
+ 1. Run `get_server_info` to check extension status
182
+ 2. Install missing extensions:
183
+ ```sql
184
+ CREATE EXTENSION pg_stat_statements;
185
+ CREATE EXTENSION pg_stat_monitor;
186
+ ```
187
+ 3. Restart PostgreSQL if needed
188
+
189
+ ### Performance Issues
190
+ 1. Use `limit` parameters to reduce result size
191
+ 2. Run monitoring during off-peak hours
192
+ 3. Check database load before running analysis
193
+
194
+ ## Development
195
+
196
+ ### Testing & Development
197
+
198
+ ```bash
199
+ # Test with MCP Inspector
200
+ ./scripts/run-mcp-inspector-local.sh
201
+
202
+ # Direct execution for debugging
203
+ python -m src.mcp_postgresql_ops.mcp_main --log-level DEBUG
204
+
205
+ # Run tests (if you add any)
206
+ uv run pytest
207
+ ```
208
+
209
+ ## Security Notes
210
+
211
+ - All tools are **read-only** - no data modification capabilities
212
+ - Sensitive information (passwords) are masked in outputs
213
+ - No direct SQL execution - only predefined queries
214
+ - Follows principle of least privilege
215
+
@@ -0,0 +1,31 @@
1
+ [project]
2
+ name = "mcp-postgresql-ops"
3
+ version = "0.0.2"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ authors = [{ name = "JungJungIn", email = "call518@gmail.com" }]
8
+ dependencies = [
9
+ "fastmcp>=2.11.1",
10
+ "asyncpg>=0.29.0",
11
+ "psycopg2-binary>=2.9.7"
12
+ ]
13
+
14
+ [project.optional-dependencies]
15
+ dev = [
16
+ "pytest>=7.0.0",
17
+ "pytest-asyncio>=0.21.0"
18
+ ]
19
+
20
+ [project.scripts]
21
+ mcp-postgresql-ops = "mcp_postgresql_ops.mcp_main:main"
22
+
23
+ [build-system]
24
+ requires = ["setuptools>=61.0", "wheel"]
25
+ build-backend = "setuptools.build_meta"
26
+
27
+ [tool.setuptools.packages.find]
28
+ where = ["src"]
29
+
30
+ [tool.setuptools.package-dir]
31
+ "" = "src"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,11 @@
1
+ """MCP Server package.
2
+
3
+ This module exposes the `mcp` FastMCP instance for convenience.
4
+ Importing this package will not start the server; use the CLI entrypoint or
5
+ call `mcp.run()` explicitly in your own launcher if needed.
6
+ """
7
+
8
+ from .mcp_main import mcp # noqa: F401
9
+
10
+ __all__ = ["mcp"]
11
+