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
- Python 3.10 or newer
- Django 5.2 or newer (
CompositePrimaryKeyis required by the generator) - Redis 6.2 or newer (the framework uses
GETEXfor sliding session TTLs — earlier versions returnunknown command) - Optional: pydantic 2+ for typed schemas
Install
pip install django-zeromcp
MCP server, REST API and OpenAPI come included — the base package wires all three.
Optional extras:
pip install 'django-zeromcp[schemas]'— Pydantic 2+ for typed input/output schemas. Without it the framework infers schemas straight from your Django models.pip install 'django-zeromcp[gen-mysql]'—0-mcp initfor MySQL/MariaDB (introspects an existing database and generates a working project). See MCP from your DB ⚡.pip install 'django-zeromcp[gen-postgres]'— same, for Postgres.
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