home / mcp / db tools mcp server

DB Tools MCP Server

Provides tools to create PostgreSQL databases, enable extensions, update Django env, and run Django commands for automated DB+Django setup.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "chaitanyaiscoding-mcp_database_tools-": {
      "command": "python",
      "args": [
        "server.py"
      ],
      "env": {
        "DB_NAME": "sample_project_db",
        "PG_HOST": "localhost",
        "PG_PORT": "5432",
        "PG_USER": "postgres",
        "ENV_PATH": "/path/to/.env",
        "MANAGE_PY": "/path/to/manage.py",
        "PG_PASSWORD": "your_password",
        "PYTHON_EXEC": "/path/to/venv/bin/python"
      }
    }
  }
}

You deploy and operate a dedicated MCP server that automates Django database setup and management tasks. This server exposes tools to create PostgreSQL databases, enable extensions, update environment configuration, and run Django commands, all through MCP clients like VS Code Copilot or automated workflows.

How to use

You interact with the MCP server using a client that supports the MCP protocol. The server exposes tools you can call in sequence to set up a database-backed Django environment. Typical usage flows include creating a database, enabling necessary PostgreSQL extensions, updating the Django environment configuration file, and running Django management commands such as migrate. The workflow can be triggered from VS Code Copilot, a dedicated MCP client, or an automated workflow script.

How to install

Prerequisites: you need Python 3.12 or newer and a running PostgreSQL server. You should also have access to a Django project if you plan to run Django management commands.

Step 1. Prepare your project folder and virtual environment.

Step 2. Install dependencies from the requirements file.

Step 3. Configure PostgreSQL connection and Django paths in the server configuration.

Step 4. (Optional) Configure the MCP client, such as VS Code settings, to point to the MCP server entry point.

Configuration

Environment and runtime configuration is defined for the MCP server. The following constants control PostgreSQL access and Django integration. You set these values in the server so the tools can connect to your database and run Django commands.

PG_USER = "postgres"
PG_PASSWORD = "your_password"  # Update this!
PG_HOST = "localhost"
PG_PORT = 5432
DB_NAME = "sample_project_db"
ENV_PATH = "/path/to/.env"
MANAGE_PY = "/path/to/manage.py"
PYTHON_EXEC = "/path/to/venv/bin/python"

Troubleshooting

If you encounter issues, verify PostgreSQL connection credentials, confirm the virtual environment Python path, and ensure the .env file is loaded correctly when running Django commands. Common problems include authentication failures, missing Django packages, and incorrect database naming due to PostgreSQL naming rules.

Examples of common workflows

Complete a typical setup workflow by creating a database, enabling the hstore extension, updating the .env file, and applying migrations. This sequence can be invoked through an MCP client that calls the provided tools in order.

Notes on environment handling and naming

PostgreSQL treats unquoted database identifiers as lowercase. The server ensures database names are converted to lowercase before creation. The .env file must use the POSTGRES_DB_NAME variable to reflect the target database name.

Supported Django commands

Common commands you can run via the django tool include migrate, makemigrations, and runserver, along with any project-specific or custom commands such as create_text_search_config and update_fixtures. Commands run through the MCP server inherit environment variables loaded from the .env file.

Available tools

create_database

Creates a PostgreSQL database with a lowercase-converted name based on the provided db_name.

enable_hstore

Enables the hstore extension in the specified database to support key-value storage.

update_env

Updates the Django .env configuration file to reflect the target database name using POSTGRES_DB_NAME.

django

Executes a Django management command using the configured virtual environment and environment variables.