Installation

This page is for projects that already have Django wired up. Coming from a different stack? Jump to MCP from your DB ⚡0-mcp init reads your existing MySQL or Postgres schema and generates the whole Django + 0-mcp project for you, no Django knowledge required.

Requirements

Install

pip install django-zeromcp

MCP server, REST API and OpenAPI come included — the base package wires all three.

Optional extras:

Settings

zeromcp ships as a plain Python package — do not add it to INSTALLED_APPS. It registers itself through the middlewares and the get_routes URL helper.

Add the middlewares to your Django settings:

MIDDLEWARE = [
    # ...
    'zeromcp.SecurityMiddleware',
    'zeromcp.AuthMiddleware',
    'zeromcp.ExceptionMiddleware',
]

Configure environment variables (Redis must be running locally — start it with redis-server or docker run -p 6379:6379 redis:7):

REDIS_SERVER=localhost
REDIS_DB=0
REDIS_PREFIX=myapp        # optional, isolates Redis keys

Configure 0-mcp-owned settings inside the project's MCP bag in settings.py — anywhere at module level alongside the other Django settings (DRF/Celery-style namespace):

MCP = {
    'COOKIE_ID': 'sessionid',                          # cookie name your app uses for session id
    'ALLOWED_ORIGINS': ['localhost', 'example.com'],   # referer-based origin allow-list (add 'localhost' for dev)
    'TRUSTED_PROXIES': ['10.0.0.0/8'],                 # CIDRs allowed to set X-Real-IP
    'ENFORCE_TOKEN': False,                            # require X-Token anti-replay header
    # 'RATE_LIMITS': {...},                            # see Rate limiting page
    # 'CACHE_TTL': 120,                                # default 120s; per-resource cache_ttl wins
    # 'CACHE_TTL_ENABLE': True,                        # global kill switch for cache=True
}

Multi-tenant DB router

If you want per-tenant databases:

DATABASE_ROUTERS = ['zeromcp.DBRouter']

0-mcp by Stamatios Stamou Jr — github.com/ssjunior/0-mcp