@marcelo-ochoa/server-postgres 1.0.2 → 1.0.4
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.
- package/README.md +20 -23
- package/dist/db.js +2 -2
- package/dist/server.js +11 -10
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -26,6 +26,9 @@ A Model Context Protocol server that provides read-only access to PostgreSQL dat
|
|
|
26
26
|
- `user` (string): The PostgreSQL username
|
|
27
27
|
- `password` (string): The PostgreSQL password
|
|
28
28
|
|
|
29
|
+
Example:
|
|
30
|
+
pg-connect host.docker.internal:5432/postgres postgres pg_2025
|
|
31
|
+
|
|
29
32
|
- **pg-awr**
|
|
30
33
|
- Generate a PostgreSQL performance report similar to Oracle AWR. Includes database statistics, top queries (requires pg_stat_statements extension), table/index statistics, connection info, and optimization recommendations.
|
|
31
34
|
|
|
@@ -44,14 +47,14 @@ See [Change Log](https://github.com/marcelo-ochoa/servers/blob/main/src/postgres
|
|
|
44
47
|
|
|
45
48
|
## Configuration
|
|
46
49
|
|
|
47
|
-
|
|
50
|
+
The PostgreSQL server uses environment variables or the `pg-connect` tool for secure credential management:
|
|
48
51
|
|
|
49
|
-
|
|
52
|
+
- **`PG_USER`**: PostgreSQL username (optional if using `pg-connect`)
|
|
53
|
+
- **`PG_PASSWORD`**: PostgreSQL password (optional if using `pg-connect`)
|
|
50
54
|
|
|
51
|
-
|
|
52
|
-
- **`PG_PASSWORD`**: PostgreSQL password (required)
|
|
55
|
+
### Connection String
|
|
53
56
|
|
|
54
|
-
The connection string should contain only the host, port, and database information (without embedded credentials).
|
|
57
|
+
The connection string should contain only the host, port, and database information (without embedded credentials). Providing it as a command-line argument is **optional**. If omitted at startup, you must use the `pg-connect` tool to establish a connection before using other functionality.
|
|
55
58
|
|
|
56
59
|
**Supported connection string formats:**
|
|
57
60
|
- `postgresql://host:port/dbname`
|
|
@@ -77,14 +80,15 @@ To use this server with the Claude Desktop app, add the following configuration
|
|
|
77
80
|
"--rm",
|
|
78
81
|
"-e", "PG_USER=myuser",
|
|
79
82
|
"-e", "PG_PASSWORD=mypassword",
|
|
80
|
-
"mochoa/mcp-postgres"
|
|
81
|
-
"postgresql://host.docker.internal:5432/mydb"
|
|
83
|
+
"mochoa/mcp-postgres"
|
|
82
84
|
]
|
|
83
85
|
}
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
88
|
```
|
|
87
89
|
|
|
90
|
+
Note: You can still provide the connection string as a final argument if you want to connect automatically on startup: `"args": [..., "mochoa/mcp-postgres", "postgresql://host.docker.internal:5432/mydb"]`.
|
|
91
|
+
|
|
88
92
|
### NPX
|
|
89
93
|
|
|
90
94
|
```json
|
|
@@ -94,8 +98,7 @@ To use this server with the Claude Desktop app, add the following configuration
|
|
|
94
98
|
"command": "npx",
|
|
95
99
|
"args": [
|
|
96
100
|
"-y",
|
|
97
|
-
"@marcelo-ochoa/server-postgres"
|
|
98
|
-
"postgresql://localhost:5432/mydb"
|
|
101
|
+
"@marcelo-ochoa/server-postgres"
|
|
99
102
|
],
|
|
100
103
|
"env": {
|
|
101
104
|
"PG_USER": "myuser",
|
|
@@ -135,11 +138,6 @@ Optionally, you can add it to a file called `.vscode/mcp.json` in your workspace
|
|
|
135
138
|
{
|
|
136
139
|
"mcp": {
|
|
137
140
|
"inputs": [
|
|
138
|
-
{
|
|
139
|
-
"type": "promptString",
|
|
140
|
-
"id": "pg_url",
|
|
141
|
-
"description": "PostgreSQL URL (e.g. postgresql://host.docker.internal:5432/mydb)"
|
|
142
|
-
},
|
|
143
141
|
{
|
|
144
142
|
"type": "promptString",
|
|
145
143
|
"id": "pg_user",
|
|
@@ -161,8 +159,7 @@ Optionally, you can add it to a file called `.vscode/mcp.json` in your workspace
|
|
|
161
159
|
"--rm",
|
|
162
160
|
"-e", "PG_USER=${input:pg_user}",
|
|
163
161
|
"-e", "PG_PASSWORD=${input:pg_password}",
|
|
164
|
-
"mochoa/mcp-postgres"
|
|
165
|
-
"${input:pg_url}"
|
|
162
|
+
"mochoa/mcp-postgres"
|
|
166
163
|
]
|
|
167
164
|
}
|
|
168
165
|
}
|
|
@@ -170,17 +167,14 @@ Optionally, you can add it to a file called `.vscode/mcp.json` in your workspace
|
|
|
170
167
|
}
|
|
171
168
|
```
|
|
172
169
|
|
|
170
|
+
Note: You can add an input for `pg_url` and append it to `args` if you want to connect on startup.
|
|
171
|
+
|
|
173
172
|
### NPX
|
|
174
173
|
|
|
175
174
|
```json
|
|
176
175
|
{
|
|
177
176
|
"mcp": {
|
|
178
177
|
"inputs": [
|
|
179
|
-
{
|
|
180
|
-
"type": "promptString",
|
|
181
|
-
"id": "pg_url",
|
|
182
|
-
"description": "PostgreSQL URL (e.g. postgresql://localhost:5432/mydb)"
|
|
183
|
-
},
|
|
184
178
|
{
|
|
185
179
|
"type": "promptString",
|
|
186
180
|
"id": "pg_user",
|
|
@@ -198,8 +192,7 @@ Optionally, you can add it to a file called `.vscode/mcp.json` in your workspace
|
|
|
198
192
|
"command": "npx",
|
|
199
193
|
"args": [
|
|
200
194
|
"-y",
|
|
201
|
-
"@marcelo-ochoa/server-postgres"
|
|
202
|
-
"${input:pg_url}"
|
|
195
|
+
"@marcelo-ochoa/server-postgres"
|
|
203
196
|
],
|
|
204
197
|
"env": {
|
|
205
198
|
"PG_USER": "${input:pg_user}",
|
|
@@ -215,6 +208,10 @@ Optionally, you can add it to a file called `.vscode/mcp.json` in your workspace
|
|
|
215
208
|
|
|
216
209
|
See [PostgreSQL AWR in action](https://github.com/marcelo-ochoa/servers/blob/main/src/postgres/AWR_example.md) for an example of a performance report generated by the `pg-awr` tool for a production Moodle database, highlighting critical performance issues and optimization opportunities.
|
|
217
210
|
|
|
211
|
+
## Demos
|
|
212
|
+
|
|
213
|
+
See [Demos](https://github.com/marcelo-ochoa/servers/blob/main/src/postgres/Demos.md) for usage examples with Claude Desktop, Docker AI, Gemini CLI, and Antigravity Code Editor.
|
|
214
|
+
|
|
218
215
|
## Building
|
|
219
216
|
|
|
220
217
|
Docker:
|
package/dist/db.js
CHANGED
|
@@ -52,13 +52,13 @@ export async function initializePool(connectionString) {
|
|
|
52
52
|
}
|
|
53
53
|
export function getPool() {
|
|
54
54
|
if (!pool) {
|
|
55
|
-
throw new Error("Postgres connection pool not initialized.");
|
|
55
|
+
throw new Error("Postgres connection pool not initialized. Use pg-connect tool first.");
|
|
56
56
|
}
|
|
57
57
|
return pool;
|
|
58
58
|
}
|
|
59
59
|
export function getResourceBaseUrl() {
|
|
60
60
|
if (!resourceBaseUrl) {
|
|
61
|
-
throw new Error("Resource Base URL not initialized.");
|
|
61
|
+
throw new Error("Resource Base URL not initialized. Use pg-connect tool first.");
|
|
62
62
|
}
|
|
63
63
|
return resourceBaseUrl;
|
|
64
64
|
}
|
package/dist/server.js
CHANGED
|
@@ -7,7 +7,7 @@ import { listResourcesHandler, readResourceHandler, callToolHandler } from "./ha
|
|
|
7
7
|
import { tools } from "./tools.js";
|
|
8
8
|
const server = new Server({
|
|
9
9
|
name: "postgres-server",
|
|
10
|
-
version: "1.0.
|
|
10
|
+
version: "1.0.4",
|
|
11
11
|
}, {
|
|
12
12
|
capabilities: {
|
|
13
13
|
resources: {},
|
|
@@ -48,17 +48,18 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools }));
|
|
|
48
48
|
server.setRequestHandler(CallToolRequestSchema, callToolHandler);
|
|
49
49
|
export async function runServer() {
|
|
50
50
|
const args = process.argv.slice(2);
|
|
51
|
-
if (args.length === 0) {
|
|
52
|
-
console.error("Please provide a database URL as a command-line argument");
|
|
53
|
-
process.exit(1);
|
|
54
|
-
}
|
|
55
51
|
const databaseUrl = args[0];
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
if (databaseUrl) {
|
|
53
|
+
try {
|
|
54
|
+
await initializePool(databaseUrl);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
console.error("Failed to initialize database pool:", error);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
58
60
|
}
|
|
59
|
-
|
|
60
|
-
console.error("
|
|
61
|
-
process.exit(1);
|
|
61
|
+
else {
|
|
62
|
+
console.error("Warning: No database URL provided. Use pg-connect tool before using other functionality.");
|
|
62
63
|
}
|
|
63
64
|
const transport = new StdioServerTransport();
|
|
64
65
|
await server.connect(transport);
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marcelo-ochoa/server-postgres",
|
|
3
3
|
"mcpName": "io.github.marcelo-ochoa/postgres",
|
|
4
|
-
"version": "1.0.
|
|
5
|
-
"
|
|
4
|
+
"version": "1.0.4",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/marcelo-ochoa/servers.git",
|
|
8
|
+
"subfolder": "src/postgres"
|
|
9
|
+
},
|
|
10
|
+
"description": "An MCP server for PostgreSQL databases.",
|
|
6
11
|
"keywords": [
|
|
7
12
|
"read-only-mcp",
|
|
8
13
|
"postgres-database",
|