Production-ready ASP.NET Core MCP server that exposes PostgreSQL inspection and SQL execution tools over the Model Context Protocol (HTTP, stateless). Designed for isolated Docker deployment.
| Variable | Required | Default | Description |
|---|---|---|---|
POSTGRES_HOST | Yes | — | PostgreSQL hostname or IP |
POSTGRES_PORT | No | 5432 | PostgreSQL port |
POSTGRES_USER | Yes | — | Database user |
POSTGRES_PASSWORD | Yes | — | Database password |
POSTGRES_DATABASE | Yes | — | Database name |
API_KEY | Yes | — | Shared secret sent by clients in the x-api-key header |
ASPNETCORE_URLS | No | http://+:8080 in the image | Bind URL(s) for Kestrel |
The server fails fast at startup if any required variable is missing or empty.
x-api-key: <API_KEY>401 Unauthorized/health is unauthenticated for container health checks| Tool | Description |
|---|---|
list_tables | Lists base tables as schema-qualified names (schema.table) |
get_table_structure | Returns columns, types, nullability, defaults, and primary-key flags |
execute_sql | Executes caller-supplied SQL (read/write); 30s command timeout |
$env:POSTGRES_HOST = "localhost"
$env:POSTGRES_PORT = "5432"
$env:POSTGRES_USER = "postgres"
$env:POSTGRES_PASSWORD = "CHANGE_ME"
$env:POSTGRES_DATABASE = "mydb"
$env:API_KEY = "CHANGE_ME_API_KEY"
$env:ASPNETCORE_URLS = "http://localhost:8080"
dotnet run --project PostgreSQL-MCP-Toolkit.csproj
Health check:
GET http://localhost:8080/health
MCP client example (VS Code / Cursor):
{
"servers": {
"PostgreSQL-MCP-Toolkit": {
"type": "http",
"url": "http://localhost:8080",
"headers": {
"x-api-key": "CHANGE_ME_API_KEY"
}
}
}
}
Build (from this directory):
docker build -t postgresql-mcp-toolkit .
Run:
docker run --rm -p 8080:8080 \
-e POSTGRES_HOST=postgres.example.com \
-e POSTGRES_PORT=5432 \
-e POSTGRES_USER=app_user \
-e POSTGRES_PASSWORD=CHANGE_ME \
-e POSTGRES_DATABASE=app_db \
-e API_KEY=CHANGE_ME_API_KEY \
-e ASPNETCORE_URLS=http://+:8080 \
postgresql-mcp-toolkit
services:
postgresql-mcp-toolkit:
build: .
ports:
- "8080:8080"
environment:
POSTGRES_HOST: postgres
POSTGRES_PORT: "5432"
POSTGRES_USER: app_user
POSTGRES_PASSWORD: CHANGE_ME
POSTGRES_DATABASE: app_db
API_KEY: CHANGE_ME_API_KEY
ASPNETCORE_URLS: http://+:8080
Replace all CHANGE_ME* placeholders before use. Do not bake secrets into the image.
Content type
Image
Digest
sha256:3194de28a…
Size
97.1 MB
Last updated
2 days ago
docker pull tuitentuan/postgresql-mcp-toolkit:v1.0.5