Skip to content

Commit 1d0b413

Browse files
committed
Enhance Docker support and update dependencies
- Updated Dockerfile to include TypeScript configuration and set up a non-root user for improved security. - Added an entrypoint script for flexible configuration during container startup. - Updated package.json and package-lock.json to reflect the latest versions of dependencies, including pg and vitest. - Revised README.md to include new Docker usage instructions and prerequisites for running the server in a containerized environment.
1 parent 08f175c commit 1d0b413

7 files changed

Lines changed: 1791 additions & 34 deletions

File tree

.dockerignore

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Dependencies
2+
node_modules
3+
npm-debug.log*
4+
5+
# Build outputs
6+
build
7+
dist
8+
9+
# Development files
10+
*.log
11+
.env
12+
.env.local
13+
.env.development.local
14+
.env.test.local
15+
.env.production.local
16+
17+
# IDE files
18+
.vscode
19+
.idea
20+
*.swp
21+
*.swo
22+
23+
# OS files
24+
.DS_Store
25+
Thumbs.db
26+
27+
# Git
28+
.git
29+
.gitignore
30+
31+
# Documentation
32+
docs
33+
*.md
34+
!README.md
35+
36+
# Test files
37+
test
38+
tests
39+
*.test.ts
40+
*.test.js
41+
*.spec.ts
42+
*.spec.js
43+
44+
# Coverage
45+
coverage
46+
47+
# Misc
48+
.eslintrc*
49+
.prettierrc*
50+
vitest.config.*
51+
52+
# Docker
53+
Dockerfile*
54+
docker-compose*
55+
.dockerignore

Dockerfile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,30 @@ WORKDIR /app
66
COPY package.json package-lock.json ./
77
RUN npm ci --ignore-scripts
88

9+
# Copy TypeScript configuration
10+
COPY tsconfig.json ./
11+
912
# Copy all source files
1013
COPY . .
1114

1215
# Build the TypeScript source
1316
RUN npm run build
1417

18+
# Copy and set up entrypoint script
19+
COPY docker-entrypoint.sh /usr/local/bin/
20+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
21+
22+
# Create non-root user for security
23+
RUN addgroup -g 1001 -S nodejs
24+
RUN adduser -S postgres-mcp -u 1001
25+
26+
# Change ownership of the app directory
27+
RUN chown -R postgres-mcp:nodejs /app
28+
USER postgres-mcp
29+
1530
# Expose any necessary ports if needed (optional)
1631
# EXPOSE 3000
1732

18-
CMD ["node", "build/index.js"]
33+
# Use entrypoint script for flexible configuration
34+
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
35+
CMD []

README.md

Lines changed: 143 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ A Model Context Protocol (MCP) server that provides comprehensive PostgreSQL dat
77

88
## Quick Start
99

10+
## Prerequisites
11+
- Node.js ≥18.0.0
12+
- Access to a PostgreSQL server
13+
- (Optional) An MCP client like Cursor or Claude for AI integration
14+
1015
[![Install MCP Server](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/install-mcp?name=postgresql-mcp&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBoZW5rZXkvcG9zdGdyZXMtbWNwLXNlcnZlciIsIi0tY29ubmVjdGlvbi1zdHJpbmciLCJwb3N0Z3Jlc3FsOi8vdXNlcjpwYXNzd29yZEBob3N0OnBvcnQvZGF0YWJhc2UiXX0=)
1116

1217
### Option 1: npm (Recommended)
@@ -15,9 +20,16 @@ A Model Context Protocol (MCP) server that provides comprehensive PostgreSQL dat
1520
npm install -g @henkey/postgres-mcp-server
1621

1722
# Or run directly with npx (no installation)
23+
# Use env var for connection string (optional)
24+
export POSTGRES_CONNECTION_STRING="postgresql://user:pass@localhost:5432/db"
25+
npx @henkey/postgres-mcp-server
26+
# Or pass directly:
1827
npx @henkey/postgres-mcp-server --connection-string "postgresql://user:pass@localhost:5432/db"
1928
```
2029

30+
# Verify installation
31+
npx @henkey/postgres-mcp-server --help
32+
2133
Add to your MCP client configuration:
2234
```json
2335
{
@@ -38,7 +50,40 @@ Add to your MCP client configuration:
3850
npx -y @smithery/cli install @HenkDz/postgresql-mcp-server --client claude
3951
```
4052

41-
### Option 3: Manual Installation (Development)
53+
### Option 3: Docker (Recommended for Production)
54+
```bash
55+
# Build the Docker image
56+
docker build -t postgres-mcp-server .
57+
58+
# Run with environment variable
59+
docker run -i --rm \
60+
-e POSTGRES_CONNECTION_STRING="postgresql://user:password@host:port/database" \
61+
postgres-mcp-server
62+
```
63+
64+
Add to your MCP client configuration:
65+
```json
66+
{
67+
"mcpServers": {
68+
"postgresql-mcp": {
69+
"command": "docker",
70+
"args": [
71+
"run",
72+
"-i",
73+
"--rm",
74+
"henkey/postgres-mcp:latest",
75+
"-e",
76+
"POSTGRES_CONNECTION_STRING"
77+
],
78+
"env": {
79+
"POSTGRES_CONNECTION_STRING": "postgresql://user:password@host:port/database"
80+
}
81+
}
82+
}
83+
}
84+
```
85+
86+
### Option 4: Manual Installation (Development)
4287
```bash
4388
git clone <repository-url>
4489
cd postgresql-mcp-server
@@ -131,6 +176,21 @@ Add to your MCP client configuration:
131176
"minDuration": 100
132177
}
133178

179+
// Execute a parameterized SELECT query
180+
{
181+
"operation": "select",
182+
"query": "SELECT * FROM users WHERE id = $1",
183+
"parameters": [1]
184+
}
185+
186+
// Perform an INSERT mutation
187+
{
188+
"operation": "insert",
189+
"table": "products",
190+
"data": {"name": "New Product", "price": 99.99},
191+
"returning": "id"
192+
}
193+
134194
// Manage database object comments
135195
{
136196
"operation": "set",
@@ -169,9 +229,90 @@ For additional information, see the [`docs/`](./docs/) folder:
169229
**Security focused** - SQL injection prevention, parameterized queries
170230
**Robust architecture** - Connection pooling, comprehensive error handling
171231

232+
## Docker Usage
233+
234+
The PostgreSQL MCP Server is fully Docker-compatible and can be used in production environments.
235+
236+
### Building the Image
237+
```bash
238+
# Build locally
239+
docker build -t postgres-mcp-server .
240+
241+
# Or pull from Docker Hub
242+
docker pull henkey/postgres-mcp:latest
243+
```
244+
245+
### Running with Environment Variables
246+
```bash
247+
# Basic usage (using Docker Hub image)
248+
docker run -i --rm \
249+
-e POSTGRES_CONNECTION_STRING="postgresql://user:password@host:port/database" \
250+
henkey/postgres-mcp:latest
251+
252+
# Or with locally built image
253+
docker run -i --rm \
254+
-e POSTGRES_CONNECTION_STRING="postgresql://user:password@host:port/database" \
255+
postgres-mcp-server
256+
257+
# With tools configuration
258+
docker run -i --rm \
259+
-e POSTGRES_CONNECTION_STRING="postgresql://user:password@host:port/database" \
260+
-e POSTGRES_TOOLS_CONFIG="/app/config/tools.json" \
261+
-v /path/to/config:/app/config \
262+
postgres-mcp-server
263+
```
264+
265+
### Docker Compose Example
266+
```yaml
267+
version: '3.8'
268+
services:
269+
postgres-mcp:
270+
build: .
271+
environment:
272+
- POSTGRES_CONNECTION_STRING=postgresql://user:password@postgres:5432/database
273+
depends_on:
274+
- postgres
275+
stdin_open: true
276+
tty: true
277+
278+
postgres:
279+
image: postgres:15
280+
environment:
281+
- POSTGRES_DB=database
282+
- POSTGRES_USER=user
283+
- POSTGRES_PASSWORD=password
284+
ports:
285+
- "5432:5432"
286+
```
287+
288+
### MCP Client Configuration
289+
For use with MCP clients like Cursor or Claude Desktop:
290+
291+
```json
292+
{
293+
"mcpServers": {
294+
"postgresql-mcp": {
295+
"command": "docker",
296+
"args": [
297+
"run",
298+
"-i",
299+
"--rm",
300+
"henkey/postgres-mcp:latest",
301+
"-e",
302+
"POSTGRES_CONNECTION_STRING"
303+
],
304+
"env": {
305+
"POSTGRES_CONNECTION_STRING": "postgresql://user:password@host:port/database"
306+
}
307+
}
308+
}
309+
}
310+
```
311+
172312
## Prerequisites
173313

174-
- Node.js ≥ 18.0.0
314+
- Node.js ≥ 18.0.0 (for local development)
315+
- Docker (for containerized deployment)
175316
- PostgreSQL server access
176317
- Valid connection credentials
177318

docker-entrypoint.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Default values
5+
CONNECTION_STRING=""
6+
TOOLS_CONFIG=""
7+
8+
# Parse environment variables
9+
if [ -n "$POSTGRES_CONNECTION_STRING" ]; then
10+
CONNECTION_STRING="--connection-string $POSTGRES_CONNECTION_STRING"
11+
fi
12+
13+
if [ -n "$POSTGRES_TOOLS_CONFIG" ]; then
14+
TOOLS_CONFIG="--tools-config $POSTGRES_TOOLS_CONFIG"
15+
fi
16+
17+
# Build the command
18+
CMD="node build/index.js"
19+
20+
if [ -n "$CONNECTION_STRING" ]; then
21+
CMD="$CMD $CONNECTION_STRING"
22+
fi
23+
24+
if [ -n "$TOOLS_CONFIG" ]; then
25+
CMD="$CMD $TOOLS_CONFIG"
26+
fi
27+
28+
# Execute the command
29+
exec $CMD "$@"

0 commit comments

Comments
 (0)