mapeg-postgres-mcp 1.0.0__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.
- mapeg_postgres_mcp-1.0.0/LICENSE +21 -0
- mapeg_postgres_mcp-1.0.0/PKG-INFO +323 -0
- mapeg_postgres_mcp-1.0.0/README.md +291 -0
- mapeg_postgres_mcp-1.0.0/pyproject.toml +63 -0
- mapeg_postgres_mcp-1.0.0/setup.cfg +4 -0
- mapeg_postgres_mcp-1.0.0/src/mapeg_postgres_mcp.egg-info/PKG-INFO +323 -0
- mapeg_postgres_mcp-1.0.0/src/mapeg_postgres_mcp.egg-info/SOURCES.txt +13 -0
- mapeg_postgres_mcp-1.0.0/src/mapeg_postgres_mcp.egg-info/dependency_links.txt +1 -0
- mapeg_postgres_mcp-1.0.0/src/mapeg_postgres_mcp.egg-info/entry_points.txt +2 -0
- mapeg_postgres_mcp-1.0.0/src/mapeg_postgres_mcp.egg-info/requires.txt +9 -0
- mapeg_postgres_mcp-1.0.0/src/mapeg_postgres_mcp.egg-info/top_level.txt +1 -0
- mapeg_postgres_mcp-1.0.0/src/mcp_server_postgres/__init__.py +12 -0
- mapeg_postgres_mcp-1.0.0/src/mcp_server_postgres/__main__.py +31 -0
- mapeg_postgres_mcp-1.0.0/src/mcp_server_postgres/query_logger.py +134 -0
- mapeg_postgres_mcp-1.0.0/src/mcp_server_postgres/server.py +795 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 mytsx
|
|
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,323 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mapeg-postgres-mcp
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: PostgreSQL MCP server for Model Context Protocol
|
|
5
|
+
Author: mytsx
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/mytsx/mcp-servers
|
|
8
|
+
Project-URL: Repository, https://github.com/mytsx/mcp-servers
|
|
9
|
+
Project-URL: Issues, https://github.com/mytsx/mcp-servers/issues
|
|
10
|
+
Keywords: mcp,model-context-protocol,postgresql,database,claude
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Database
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: mcp>=1.0.0
|
|
24
|
+
Requires-Dist: psycopg2-binary>=2.9.0
|
|
25
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
28
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
29
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
30
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# PostgreSQL MCP Server
|
|
34
|
+
|
|
35
|
+
[](https://python.org)
|
|
36
|
+
[](https://modelcontextprotocol.io)
|
|
37
|
+
[](LICENSE)
|
|
38
|
+
[](https://pypi.org/project/mapeg-postgres-mcp/)
|
|
39
|
+
|
|
40
|
+
A Model Context Protocol (MCP) server for PostgreSQL databases. Query, explore, and analyze your PostgreSQL databases directly from any MCP-compatible AI client.
|
|
41
|
+
|
|
42
|
+
## Features
|
|
43
|
+
|
|
44
|
+
- **Execute SQL** — Run any SQL query with automatic result formatting
|
|
45
|
+
- **Natural Language Queries** — Ask questions in plain English or Turkish
|
|
46
|
+
- **Schema Exploration** — List tables, describe columns, view statistics
|
|
47
|
+
- **Execution Plans** — EXPLAIN / EXPLAIN ANALYZE with buffer stats
|
|
48
|
+
- **Query History** — Review past queries scoped to your database and workspace
|
|
49
|
+
- **Read-Only Mode** — Optional write protection via `READ_ONLY=true`
|
|
50
|
+
- **Zero Install** — Works with `uvx`, no virtual environment needed
|
|
51
|
+
|
|
52
|
+
## Quick Start
|
|
53
|
+
|
|
54
|
+
### Claude Code
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
claude mcp add postgres \
|
|
58
|
+
-e DB_HOST=localhost \
|
|
59
|
+
-e DB_PORT=5432 \
|
|
60
|
+
-e DB_NAME=mydb \
|
|
61
|
+
-e DB_USER=postgres \
|
|
62
|
+
-e DB_PASSWORD=secret \
|
|
63
|
+
-- uvx mapeg-postgres-mcp
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Claude Desktop
|
|
67
|
+
|
|
68
|
+
Add to your config file:
|
|
69
|
+
|
|
70
|
+
- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
71
|
+
- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"mcpServers": {
|
|
76
|
+
"postgres": {
|
|
77
|
+
"command": "uvx",
|
|
78
|
+
"args": ["mapeg-postgres-mcp"],
|
|
79
|
+
"env": {
|
|
80
|
+
"DB_HOST": "localhost",
|
|
81
|
+
"DB_PORT": "5432",
|
|
82
|
+
"DB_NAME": "mydb",
|
|
83
|
+
"DB_USER": "postgres",
|
|
84
|
+
"DB_PASSWORD": "secret"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Cursor
|
|
92
|
+
|
|
93
|
+
Add to `~/.cursor/mcp.json`:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"mcpServers": {
|
|
98
|
+
"postgres": {
|
|
99
|
+
"command": "uvx",
|
|
100
|
+
"args": ["mapeg-postgres-mcp"],
|
|
101
|
+
"env": {
|
|
102
|
+
"DB_HOST": "localhost",
|
|
103
|
+
"DB_PORT": "5432",
|
|
104
|
+
"DB_NAME": "mydb",
|
|
105
|
+
"DB_USER": "postgres",
|
|
106
|
+
"DB_PASSWORD": "secret"
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Windsurf
|
|
114
|
+
|
|
115
|
+
Add to Windsurf MCP config:
|
|
116
|
+
|
|
117
|
+
```json
|
|
118
|
+
{
|
|
119
|
+
"mcpServers": {
|
|
120
|
+
"postgres": {
|
|
121
|
+
"command": "uvx",
|
|
122
|
+
"args": ["mapeg-postgres-mcp"],
|
|
123
|
+
"env": {
|
|
124
|
+
"DB_HOST": "localhost",
|
|
125
|
+
"DB_PORT": "5432",
|
|
126
|
+
"DB_NAME": "mydb",
|
|
127
|
+
"DB_USER": "postgres",
|
|
128
|
+
"DB_PASSWORD": "secret"
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### VS Code
|
|
136
|
+
|
|
137
|
+
Add to your VS Code settings (JSON):
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
"mcp": {
|
|
141
|
+
"servers": {
|
|
142
|
+
"postgres": {
|
|
143
|
+
"type": "stdio",
|
|
144
|
+
"command": "uvx",
|
|
145
|
+
"args": ["mapeg-postgres-mcp"],
|
|
146
|
+
"env": {
|
|
147
|
+
"DB_HOST": "localhost",
|
|
148
|
+
"DB_PORT": "5432",
|
|
149
|
+
"DB_NAME": "mydb",
|
|
150
|
+
"DB_USER": "postgres",
|
|
151
|
+
"DB_PASSWORD": "secret"
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Gemini CLI
|
|
159
|
+
|
|
160
|
+
Add to `~/.gemini/settings.json`:
|
|
161
|
+
|
|
162
|
+
```json
|
|
163
|
+
{
|
|
164
|
+
"mcpServers": {
|
|
165
|
+
"postgres": {
|
|
166
|
+
"command": "uvx",
|
|
167
|
+
"args": ["mapeg-postgres-mcp"],
|
|
168
|
+
"env": {
|
|
169
|
+
"DB_HOST": "localhost",
|
|
170
|
+
"DB_PORT": "5432",
|
|
171
|
+
"DB_NAME": "mydb",
|
|
172
|
+
"DB_USER": "postgres",
|
|
173
|
+
"DB_PASSWORD": "secret"
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### GitHub Copilot
|
|
181
|
+
|
|
182
|
+
Add to `~/.copilot/mcp-config.json`:
|
|
183
|
+
|
|
184
|
+
```json
|
|
185
|
+
{
|
|
186
|
+
"mcpServers": {
|
|
187
|
+
"postgres": {
|
|
188
|
+
"command": "uvx",
|
|
189
|
+
"args": ["mapeg-postgres-mcp"],
|
|
190
|
+
"env": {
|
|
191
|
+
"DB_HOST": "localhost",
|
|
192
|
+
"DB_PORT": "5432",
|
|
193
|
+
"DB_NAME": "mydb",
|
|
194
|
+
"DB_USER": "postgres",
|
|
195
|
+
"DB_PASSWORD": "secret"
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### OpenAI Codex
|
|
203
|
+
|
|
204
|
+
Add to `~/.codex/config.toml`:
|
|
205
|
+
|
|
206
|
+
```toml
|
|
207
|
+
[mcp_servers.postgres]
|
|
208
|
+
command = "uvx"
|
|
209
|
+
args = ["mapeg-postgres-mcp"]
|
|
210
|
+
|
|
211
|
+
[mcp_servers.postgres.env]
|
|
212
|
+
DB_HOST = "localhost"
|
|
213
|
+
DB_PORT = "5432"
|
|
214
|
+
DB_NAME = "mydb"
|
|
215
|
+
DB_USER = "postgres"
|
|
216
|
+
DB_PASSWORD = "secret"
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Install from Source
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
cd mapeg-postgres-mcp
|
|
223
|
+
pip install -e .
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Configuration
|
|
227
|
+
|
|
228
|
+
| Environment Variable | Required | Default | Description |
|
|
229
|
+
|---------------------|----------|---------|-------------|
|
|
230
|
+
| `DB_HOST` | No | `localhost` | PostgreSQL host |
|
|
231
|
+
| `DB_PORT` | No | `5432` | PostgreSQL port |
|
|
232
|
+
| `DB_NAME` | Yes | — | Database name |
|
|
233
|
+
| `DB_USER` | No | `postgres` | Database user |
|
|
234
|
+
| `DB_PASSWORD` | Yes | — | Database password |
|
|
235
|
+
| `READ_ONLY` | No | `false` | Block write operations (INSERT, UPDATE, DELETE, DROP, etc.) |
|
|
236
|
+
|
|
237
|
+
## Tools
|
|
238
|
+
|
|
239
|
+
<details>
|
|
240
|
+
<summary><code>execute_sql</code> — Run SQL queries</summary>
|
|
241
|
+
|
|
242
|
+
Execute any SQL query on the connected PostgreSQL database.
|
|
243
|
+
|
|
244
|
+
| Parameter | Type | Required | Description |
|
|
245
|
+
|-----------|------|----------|-------------|
|
|
246
|
+
| `sql` | string | Yes | SQL query to execute |
|
|
247
|
+
| `limit` | integer | No | Max rows to return (default: 100) |
|
|
248
|
+
|
|
249
|
+
</details>
|
|
250
|
+
|
|
251
|
+
<details>
|
|
252
|
+
<summary><code>natural_language_query</code> — Query in plain language</summary>
|
|
253
|
+
|
|
254
|
+
Convert natural language to SQL and execute. Supports Turkish and English.
|
|
255
|
+
|
|
256
|
+
| Parameter | Type | Required | Description |
|
|
257
|
+
|-----------|------|----------|-------------|
|
|
258
|
+
| `query` | string | Yes | Natural language query |
|
|
259
|
+
|
|
260
|
+
**Examples:** "show all tables", "tabloları listele", "show database info"
|
|
261
|
+
|
|
262
|
+
</details>
|
|
263
|
+
|
|
264
|
+
<details>
|
|
265
|
+
<summary><code>describe_table</code> — Table structure details</summary>
|
|
266
|
+
|
|
267
|
+
Get column definitions, row count, and table size.
|
|
268
|
+
|
|
269
|
+
| Parameter | Type | Required | Description |
|
|
270
|
+
|-----------|------|----------|-------------|
|
|
271
|
+
| `table_name` | string | Yes | Table name (`schema.table` or `table`) |
|
|
272
|
+
|
|
273
|
+
</details>
|
|
274
|
+
|
|
275
|
+
<details>
|
|
276
|
+
<summary><code>smart_query</code> — AI-powered query assistant</summary>
|
|
277
|
+
|
|
278
|
+
Analyzes your schema and suggests queries based on your question.
|
|
279
|
+
|
|
280
|
+
| Parameter | Type | Required | Description |
|
|
281
|
+
|-----------|------|----------|-------------|
|
|
282
|
+
| `question` | string | Yes | Question about your data |
|
|
283
|
+
|
|
284
|
+
</details>
|
|
285
|
+
|
|
286
|
+
<details>
|
|
287
|
+
<summary><code>explain_query</code> — Execution plan analysis</summary>
|
|
288
|
+
|
|
289
|
+
Show the EXPLAIN plan for a SQL query.
|
|
290
|
+
|
|
291
|
+
| Parameter | Type | Required | Description |
|
|
292
|
+
|-----------|------|----------|-------------|
|
|
293
|
+
| `sql` | string | Yes | SQL query to explain |
|
|
294
|
+
| `analyze` | boolean | No | Run EXPLAIN ANALYZE (default: false) |
|
|
295
|
+
| `format` | string | No | Output format: `text`, `json`, `yaml` (default: text) |
|
|
296
|
+
| `buffers` | boolean | No | Include buffer usage (requires analyze=true) |
|
|
297
|
+
|
|
298
|
+
</details>
|
|
299
|
+
|
|
300
|
+
<details>
|
|
301
|
+
<summary><code>get_query_history</code> — Review past queries</summary>
|
|
302
|
+
|
|
303
|
+
Retrieve recent query history scoped to this database and workspace.
|
|
304
|
+
|
|
305
|
+
| Parameter | Type | Required | Description |
|
|
306
|
+
|-----------|------|----------|-------------|
|
|
307
|
+
| `limit` | integer | No | Number of entries (default: 20) |
|
|
308
|
+
| `status` | string | No | Filter: `success` or `error` |
|
|
309
|
+
| `tool_name` | string | No | Filter by tool name |
|
|
310
|
+
|
|
311
|
+
</details>
|
|
312
|
+
|
|
313
|
+
## Resources
|
|
314
|
+
|
|
315
|
+
| URI | Description |
|
|
316
|
+
|-----|-------------|
|
|
317
|
+
| `postgresql://tables` | List all user tables |
|
|
318
|
+
| `postgresql://schema` | Detailed schema with columns |
|
|
319
|
+
| `postgresql://stats` | Database version and statistics |
|
|
320
|
+
|
|
321
|
+
## License
|
|
322
|
+
|
|
323
|
+
MIT
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
# PostgreSQL MCP Server
|
|
2
|
+
|
|
3
|
+
[](https://python.org)
|
|
4
|
+
[](https://modelcontextprotocol.io)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://pypi.org/project/mapeg-postgres-mcp/)
|
|
7
|
+
|
|
8
|
+
A Model Context Protocol (MCP) server for PostgreSQL databases. Query, explore, and analyze your PostgreSQL databases directly from any MCP-compatible AI client.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **Execute SQL** — Run any SQL query with automatic result formatting
|
|
13
|
+
- **Natural Language Queries** — Ask questions in plain English or Turkish
|
|
14
|
+
- **Schema Exploration** — List tables, describe columns, view statistics
|
|
15
|
+
- **Execution Plans** — EXPLAIN / EXPLAIN ANALYZE with buffer stats
|
|
16
|
+
- **Query History** — Review past queries scoped to your database and workspace
|
|
17
|
+
- **Read-Only Mode** — Optional write protection via `READ_ONLY=true`
|
|
18
|
+
- **Zero Install** — Works with `uvx`, no virtual environment needed
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
### Claude Code
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
claude mcp add postgres \
|
|
26
|
+
-e DB_HOST=localhost \
|
|
27
|
+
-e DB_PORT=5432 \
|
|
28
|
+
-e DB_NAME=mydb \
|
|
29
|
+
-e DB_USER=postgres \
|
|
30
|
+
-e DB_PASSWORD=secret \
|
|
31
|
+
-- uvx mapeg-postgres-mcp
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Claude Desktop
|
|
35
|
+
|
|
36
|
+
Add to your config file:
|
|
37
|
+
|
|
38
|
+
- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
39
|
+
- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"mcpServers": {
|
|
44
|
+
"postgres": {
|
|
45
|
+
"command": "uvx",
|
|
46
|
+
"args": ["mapeg-postgres-mcp"],
|
|
47
|
+
"env": {
|
|
48
|
+
"DB_HOST": "localhost",
|
|
49
|
+
"DB_PORT": "5432",
|
|
50
|
+
"DB_NAME": "mydb",
|
|
51
|
+
"DB_USER": "postgres",
|
|
52
|
+
"DB_PASSWORD": "secret"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Cursor
|
|
60
|
+
|
|
61
|
+
Add to `~/.cursor/mcp.json`:
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"mcpServers": {
|
|
66
|
+
"postgres": {
|
|
67
|
+
"command": "uvx",
|
|
68
|
+
"args": ["mapeg-postgres-mcp"],
|
|
69
|
+
"env": {
|
|
70
|
+
"DB_HOST": "localhost",
|
|
71
|
+
"DB_PORT": "5432",
|
|
72
|
+
"DB_NAME": "mydb",
|
|
73
|
+
"DB_USER": "postgres",
|
|
74
|
+
"DB_PASSWORD": "secret"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Windsurf
|
|
82
|
+
|
|
83
|
+
Add to Windsurf MCP config:
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"mcpServers": {
|
|
88
|
+
"postgres": {
|
|
89
|
+
"command": "uvx",
|
|
90
|
+
"args": ["mapeg-postgres-mcp"],
|
|
91
|
+
"env": {
|
|
92
|
+
"DB_HOST": "localhost",
|
|
93
|
+
"DB_PORT": "5432",
|
|
94
|
+
"DB_NAME": "mydb",
|
|
95
|
+
"DB_USER": "postgres",
|
|
96
|
+
"DB_PASSWORD": "secret"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### VS Code
|
|
104
|
+
|
|
105
|
+
Add to your VS Code settings (JSON):
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
"mcp": {
|
|
109
|
+
"servers": {
|
|
110
|
+
"postgres": {
|
|
111
|
+
"type": "stdio",
|
|
112
|
+
"command": "uvx",
|
|
113
|
+
"args": ["mapeg-postgres-mcp"],
|
|
114
|
+
"env": {
|
|
115
|
+
"DB_HOST": "localhost",
|
|
116
|
+
"DB_PORT": "5432",
|
|
117
|
+
"DB_NAME": "mydb",
|
|
118
|
+
"DB_USER": "postgres",
|
|
119
|
+
"DB_PASSWORD": "secret"
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Gemini CLI
|
|
127
|
+
|
|
128
|
+
Add to `~/.gemini/settings.json`:
|
|
129
|
+
|
|
130
|
+
```json
|
|
131
|
+
{
|
|
132
|
+
"mcpServers": {
|
|
133
|
+
"postgres": {
|
|
134
|
+
"command": "uvx",
|
|
135
|
+
"args": ["mapeg-postgres-mcp"],
|
|
136
|
+
"env": {
|
|
137
|
+
"DB_HOST": "localhost",
|
|
138
|
+
"DB_PORT": "5432",
|
|
139
|
+
"DB_NAME": "mydb",
|
|
140
|
+
"DB_USER": "postgres",
|
|
141
|
+
"DB_PASSWORD": "secret"
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### GitHub Copilot
|
|
149
|
+
|
|
150
|
+
Add to `~/.copilot/mcp-config.json`:
|
|
151
|
+
|
|
152
|
+
```json
|
|
153
|
+
{
|
|
154
|
+
"mcpServers": {
|
|
155
|
+
"postgres": {
|
|
156
|
+
"command": "uvx",
|
|
157
|
+
"args": ["mapeg-postgres-mcp"],
|
|
158
|
+
"env": {
|
|
159
|
+
"DB_HOST": "localhost",
|
|
160
|
+
"DB_PORT": "5432",
|
|
161
|
+
"DB_NAME": "mydb",
|
|
162
|
+
"DB_USER": "postgres",
|
|
163
|
+
"DB_PASSWORD": "secret"
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### OpenAI Codex
|
|
171
|
+
|
|
172
|
+
Add to `~/.codex/config.toml`:
|
|
173
|
+
|
|
174
|
+
```toml
|
|
175
|
+
[mcp_servers.postgres]
|
|
176
|
+
command = "uvx"
|
|
177
|
+
args = ["mapeg-postgres-mcp"]
|
|
178
|
+
|
|
179
|
+
[mcp_servers.postgres.env]
|
|
180
|
+
DB_HOST = "localhost"
|
|
181
|
+
DB_PORT = "5432"
|
|
182
|
+
DB_NAME = "mydb"
|
|
183
|
+
DB_USER = "postgres"
|
|
184
|
+
DB_PASSWORD = "secret"
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Install from Source
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
cd mapeg-postgres-mcp
|
|
191
|
+
pip install -e .
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Configuration
|
|
195
|
+
|
|
196
|
+
| Environment Variable | Required | Default | Description |
|
|
197
|
+
|---------------------|----------|---------|-------------|
|
|
198
|
+
| `DB_HOST` | No | `localhost` | PostgreSQL host |
|
|
199
|
+
| `DB_PORT` | No | `5432` | PostgreSQL port |
|
|
200
|
+
| `DB_NAME` | Yes | — | Database name |
|
|
201
|
+
| `DB_USER` | No | `postgres` | Database user |
|
|
202
|
+
| `DB_PASSWORD` | Yes | — | Database password |
|
|
203
|
+
| `READ_ONLY` | No | `false` | Block write operations (INSERT, UPDATE, DELETE, DROP, etc.) |
|
|
204
|
+
|
|
205
|
+
## Tools
|
|
206
|
+
|
|
207
|
+
<details>
|
|
208
|
+
<summary><code>execute_sql</code> — Run SQL queries</summary>
|
|
209
|
+
|
|
210
|
+
Execute any SQL query on the connected PostgreSQL database.
|
|
211
|
+
|
|
212
|
+
| Parameter | Type | Required | Description |
|
|
213
|
+
|-----------|------|----------|-------------|
|
|
214
|
+
| `sql` | string | Yes | SQL query to execute |
|
|
215
|
+
| `limit` | integer | No | Max rows to return (default: 100) |
|
|
216
|
+
|
|
217
|
+
</details>
|
|
218
|
+
|
|
219
|
+
<details>
|
|
220
|
+
<summary><code>natural_language_query</code> — Query in plain language</summary>
|
|
221
|
+
|
|
222
|
+
Convert natural language to SQL and execute. Supports Turkish and English.
|
|
223
|
+
|
|
224
|
+
| Parameter | Type | Required | Description |
|
|
225
|
+
|-----------|------|----------|-------------|
|
|
226
|
+
| `query` | string | Yes | Natural language query |
|
|
227
|
+
|
|
228
|
+
**Examples:** "show all tables", "tabloları listele", "show database info"
|
|
229
|
+
|
|
230
|
+
</details>
|
|
231
|
+
|
|
232
|
+
<details>
|
|
233
|
+
<summary><code>describe_table</code> — Table structure details</summary>
|
|
234
|
+
|
|
235
|
+
Get column definitions, row count, and table size.
|
|
236
|
+
|
|
237
|
+
| Parameter | Type | Required | Description |
|
|
238
|
+
|-----------|------|----------|-------------|
|
|
239
|
+
| `table_name` | string | Yes | Table name (`schema.table` or `table`) |
|
|
240
|
+
|
|
241
|
+
</details>
|
|
242
|
+
|
|
243
|
+
<details>
|
|
244
|
+
<summary><code>smart_query</code> — AI-powered query assistant</summary>
|
|
245
|
+
|
|
246
|
+
Analyzes your schema and suggests queries based on your question.
|
|
247
|
+
|
|
248
|
+
| Parameter | Type | Required | Description |
|
|
249
|
+
|-----------|------|----------|-------------|
|
|
250
|
+
| `question` | string | Yes | Question about your data |
|
|
251
|
+
|
|
252
|
+
</details>
|
|
253
|
+
|
|
254
|
+
<details>
|
|
255
|
+
<summary><code>explain_query</code> — Execution plan analysis</summary>
|
|
256
|
+
|
|
257
|
+
Show the EXPLAIN plan for a SQL query.
|
|
258
|
+
|
|
259
|
+
| Parameter | Type | Required | Description |
|
|
260
|
+
|-----------|------|----------|-------------|
|
|
261
|
+
| `sql` | string | Yes | SQL query to explain |
|
|
262
|
+
| `analyze` | boolean | No | Run EXPLAIN ANALYZE (default: false) |
|
|
263
|
+
| `format` | string | No | Output format: `text`, `json`, `yaml` (default: text) |
|
|
264
|
+
| `buffers` | boolean | No | Include buffer usage (requires analyze=true) |
|
|
265
|
+
|
|
266
|
+
</details>
|
|
267
|
+
|
|
268
|
+
<details>
|
|
269
|
+
<summary><code>get_query_history</code> — Review past queries</summary>
|
|
270
|
+
|
|
271
|
+
Retrieve recent query history scoped to this database and workspace.
|
|
272
|
+
|
|
273
|
+
| Parameter | Type | Required | Description |
|
|
274
|
+
|-----------|------|----------|-------------|
|
|
275
|
+
| `limit` | integer | No | Number of entries (default: 20) |
|
|
276
|
+
| `status` | string | No | Filter: `success` or `error` |
|
|
277
|
+
| `tool_name` | string | No | Filter by tool name |
|
|
278
|
+
|
|
279
|
+
</details>
|
|
280
|
+
|
|
281
|
+
## Resources
|
|
282
|
+
|
|
283
|
+
| URI | Description |
|
|
284
|
+
|-----|-------------|
|
|
285
|
+
| `postgresql://tables` | List all user tables |
|
|
286
|
+
| `postgresql://schema` | Detailed schema with columns |
|
|
287
|
+
| `postgresql://stats` | Database version and statistics |
|
|
288
|
+
|
|
289
|
+
## License
|
|
290
|
+
|
|
291
|
+
MIT
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mapeg-postgres-mcp"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "PostgreSQL MCP server for Model Context Protocol"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "mytsx"}
|
|
14
|
+
]
|
|
15
|
+
keywords = ["mcp", "model-context-protocol", "postgresql", "database", "claude"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Topic :: Database",
|
|
25
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
dependencies = [
|
|
29
|
+
"mcp>=1.0.0",
|
|
30
|
+
"psycopg2-binary>=2.9.0",
|
|
31
|
+
"python-dotenv>=1.0.0",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
dev = [
|
|
36
|
+
"pytest>=7.0.0",
|
|
37
|
+
"pytest-asyncio>=0.21.0",
|
|
38
|
+
"black>=23.0.0",
|
|
39
|
+
"ruff>=0.1.0",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[project.urls]
|
|
43
|
+
Homepage = "https://github.com/mytsx/mcp-servers"
|
|
44
|
+
Repository = "https://github.com/mytsx/mcp-servers"
|
|
45
|
+
Issues = "https://github.com/mytsx/mcp-servers/issues"
|
|
46
|
+
|
|
47
|
+
[project.scripts]
|
|
48
|
+
mapeg-postgres-mcp = "mcp_server_postgres.__main__:run"
|
|
49
|
+
|
|
50
|
+
[tool.setuptools]
|
|
51
|
+
packages = ["mcp_server_postgres"]
|
|
52
|
+
package-dir = {"" = "src"}
|
|
53
|
+
|
|
54
|
+
[tool.setuptools.package-data]
|
|
55
|
+
mcp_server_postgres = ["py.typed"]
|
|
56
|
+
|
|
57
|
+
[tool.black]
|
|
58
|
+
line-length = 100
|
|
59
|
+
target-version = ['py310']
|
|
60
|
+
|
|
61
|
+
[tool.ruff]
|
|
62
|
+
line-length = 100
|
|
63
|
+
target-version = "py310"
|