MCP Server: PostgreSQL Docker Initializer

by Flow-Research

334 downloads Not rated yet
GitHub

About

# MCP Server: PostgreSQL Docker Initializer This project implements a Model Context Protocol (MCP) server that provides a tool to initialize a PostgreSQL database running inside a new Docker container. The server exposes a single tool, `init-postgres-docker`, which takes a database name as input and performs the…

Explore

- Exposes a single tool, init-postgres-docker
- Pulls postgres:latest Docker image automatically
- Creates a PostgreSQL container with a specified database name
- Maps container port 5432 to a random available host port
- Sets container to auto-remove when stopped
- Returns a PostgreSQL connection URL (e.g., postgresql://pguser:mysecretpassword@localhost:<hostPort>/<dbName>)

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name MCP Server: PostgreSQL Docker Initializer
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Node.js and npm (or a compatible package manager)
Docker (must be running)
Make

A Makefile is provided for common tasks. Run these commands from the root directory of this project (mcp-server-postgres-init):

Install Dependencies:

    make install

(Runs npm install)

Build the Project:

    make build

(Runs npm run build, which compiles TypeScript to JavaScript in the build/ directory)

Inspect the Server:

    make inspect

(Runs make build first, then starts the MCP inspector using npx @modelcontextprotocol/inspector node build/index.js. You can then send a request to the init-postgres-docker tool.)

Install, Build, and Inspect (Default):

    make

or
    make all

(Runs make install, make build, and make inspect sequentially)

Clean Project:

    make clean

(Removes node_modules, build, and *.tsbuildinfo files)

If you prefer not to use Make:

1. Install dependencies: npm install
2. Build the project: npm run build
3. Run the server (e.g., with the inspector):

    npx @modelcontextprotocol/inspector node build/index.js

Or run the server directly if connecting with a client:
    node build/index.js

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "mcp server: postgresql docker initializer": {
            "mcp-server-postgres-init": {
                "command": "npx",
                "args": [
                    "@modelcontextprotocol/inspector",
                    "node",
                    "build/index.js"
                ]
            }
        }
    }
}

McpServers

{
    "mcp-server-postgres-init": {
        "command": "npx",
        "args": [
            "@modelcontextprotocol/inspector",
            "node",
            "build/index.js"
        ]
    }
}

This project implements a Model Context Protocol (MCP) server that provides a tool to initialize a PostgreSQL database running inside a new Docker container.

The server exposes a single tool, init-postgres-docker, which takes a database name as input and performs the following actions:

Pulls the postgres:latest Docker image if not already present.
Creates a new Docker container running PostgreSQL.
Configures the container with the specified database name (dbName), a default user (pguser), and a default password (mysecretpassword - Note: This is insecure and for demonstration purposes only).
Maps the container's internal port 5432 to a random available port on the host machine.
Sets the container to be automatically removed when stopped (AutoRemove: true).
Returns a success message including the PostgreSQL connection URL (e.g., postgresql://pguser:mysecretpassword@localhost:<hostPort>/<dbName>).

Prerequisites

Node.js and npm (or a compatible package manager)
Docker (must be running)
Make

Usage with Makefile

A Makefile is provided for common tasks. Run these commands from the root directory of this project (mcp-server-postgres-init):

Install Dependencies:

    make install

(Runs npm install)

Build the Project:

    make build

(Runs npm run build, which compiles TypeScript to JavaScript in the build/ directory)

Inspect the Server:

    make inspect

(Runs make build first, then starts the MCP inspector using npx @modelcontextprotocol/inspector node build/index.js. You can then send a request to the init-postgres-docker tool.)

Install, Build, and Inspect (Default):

    make

or
    make all

(Runs make install, make build, and make inspect sequentially)

Clean Project:

    make clean

(Removes node_modules, build, and .tsbuildinfo files)

Running Manually

If you prefer not to use Make:

1. Install dependencies: npm install
2. Build the project: npm run build
3. Run the server (e.g., with the inspector):

    npx @modelcontextprotocol/inspector node build/index.js

Or run the server directly if connecting with a client:
    node build/index.js

Important Notes

Docker Must Be Running: The Docker daemon needs to be active for this server to create containers.
Password Security: The default password (mysecretpassword) is hardcoded and insecure. For real-world use, implement a more secure method for handling passwords (e.g., generation, environment variables).
Resource Management: Containers are set to auto-remove. Consider the lifecycle needed for your use case.

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.