django-native-mcp
A small Django-native MCP application and tool registration framework inspired by Celery.
It delegates protocol handling, schemas, validation, serialization, stdio, and Streamable HTTP
to the official mcp Python SDK.
This is not another wrapper around FastMCP, the dependencies are only native Python SDK
Installation
pip install django-native-mcp
Add the application and its configuration:
# settings.py
INSTALLED_APPS = [
# ...
"django_native_mcp",
]
DJANGO_NATIVE_MCP = {
"APP": "config.mcp:app",
}
For a public Streamable HTTP host, configure the SDK host and DNS rebinding allowlists explicitly:
DJANGO_NATIVE_MCP = {
"APP": "config.mcp:app",
"HOST": "0.0.0.0",
"TRANSPORT_SECURITY_SETTINGS": {
"ENABLE_DNS_REBINDING_PROTECTION": True,
"ALLOWED_HOSTS": ["mysite.com"],
"ALLOWED_ORIGINS": ["https://mysite.com"],
},
}
The optional settings preserve the official SDK defaults when omitted.
Streamable HTTP MCP is protected by bearer tokens by default. The package provides an
MCPToken model in the Django admin; its generated 40-character key is sent as
Authorization: Bearer <key>. Tokens support last_used tracking and optional expiration.
Set DJANGO_NATIVE_MCP["DEFAULT_AUTHENTICATION_CLASSES"] to a list of dotted backend paths to
replace the default django_native_mcp.authentication.MCPTokenBackend. Set it to None or []
to make the HTTP MCP endpoint public.
Create the application:
# config/mcp.py
from django_native_mcp import MCP
app = MCP("backend")
app.autodiscover_tools()
Declare tools explicitly in installed Django apps:
# orders/mcp.py
from django_native_mcp import shared_tool
from .models import Order
@shared_tool
async def get_order(order_id: int) -> dict:
"""Get an order."""
order = await Order.objects.aget(pk=order_id)
return {"id": order.pk, "status": order.status}
The registered name is orders.get_order, using the Django application label.
python manage.py mcp_list
python manage.py mcp_inspect orders.get_order
python manage.py mcp_call orders.get_order '{"order_id": 1}'
python manage.py mcp_serve --transport stdio
Tools must use async def. The framework does not add implicit threads or sync_to_async.
Direct application tools
from django_native_mcp import MCP
app = MCP("backend")
@app.tool(name="system.health")
async def health() -> dict:
return {"ok": True}
@app.tool binds immediately to one application. @shared_tool remains application-independent
until autodiscovery binds it.
Django permissions
Both decorators accept an optional iterable of Django permission names:
@shared_tool(permissions=["orders.view_order", "orders.change_order"])
async def update_order(order_id: int) -> dict: ...
@app.tool(permissions=["auth.view_user"])
async def count_users() -> int: ...
Every listed permission is required. Before executing the tool, the server calls
await user.ahas_perms(permissions) on the user authenticated for the current HTTP request.
Django's configured AUTHENTICATION_BACKENDS determine permission access, including user
permissions, group permissions, and active superuser behavior. MCP authentication backends
authenticate tokens; Django authorization backends evaluate permissions.
Omitting permissions, passing None, or passing an empty iterable preserves unrestricted
tool access after transport authentication. Permission names are copied into an immutable tuple
at registration. The decorators return the original functions and preserve their schemas.
A protected tool returns an MCP tool error with Permission denied. when the user is absent,
anonymous, or lacks any required permission; its body does not execute. Making HTTP public
does not bypass this check. Stdio, mcp_call, and the in-process test client have no authenticated
HTTP user and cannot execute protected tools. Direct Python calls to the original decorated
function do not pass through MCP authorization. Tool listing remains common to all users.
Streamable HTTP with Django
The official SDK ASGI app can be served alone:
application = app.asgi_app()
Or route /mcp to MCP and everything else to Django:
# config/asgi.py
import os
from django.core.asgi import get_asgi_application
from django_native_mcp.asgi import MCPApplication
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
django_application = get_asgi_application()
# Import the MCP app only after Django's application registry is ready.
from config.mcp import app as mcp_app
application = MCPApplication(
django=django_application,
mcp=mcp_app,
mcp_path="/mcp",
)
The dispatcher forwards ASGI lifespan to the official MCP application, so its transport lifecycle is started and stopped by the outer ASGI server.
Testing
Use the thin wrapper around the official in-process client:
from django_native_mcp.testing import MCPTestClient
async with MCPTestClient(app) as client:
result = await client.call_tool("orders.get_order", {"order_id": 1})
End-to-end example
The example/ directory contains a runnable Django project using the built-in auth
User, a Streamable HTTP MCP endpoint, and a standalone OpenAI Responses API client that discovers
and calls the Django tool through MCP.
Architecture
Django apps / mcp.py
↓
shared_tool → ToolDefinition → ToolRegistry → MCP
↓
official MCPServer
↙ ↘
stdio Streamable HTTP
The registry is process-local and becomes read-only when its official server is created. Each worker builds the same registry from source during startup.
Non-goals
This package is not an MCP protocol implementation, ORM-to-MCP generator, REST/DRF adapter, Celery replacement, background queue, or AI-agent framework. It does not automatically expose Django models and does not infer permissions from them.
License
MIT
Publishing to PyPI
The existing .github/workflows/release.yml builds and checks distributions, then publishes
through PyPI Trusted Publishing when a GitHub Release is published. Configure a Trusted
Publisher for PyPI project django-native-mcp, GitHub owner xelaxela13, repository
django-native-mcp, workflow release.yml, and GitHub environment pypi.
For version 0.1.3, commit the verified release changes and create the tag v0.1.3 on that
commit. Publish a GitHub Release for that tag using the notes in CHANGELOG.md. The tag must
contain version = "0.1.3" in pyproject.toml. Publication is a separate action; building the
package locally does not publish it.
Metadata
Release files for django-native-mcp 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_native_mcp-0.1.3.tar.gz | 28.6 kB | With provenance | Details for django_native_mcp-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_native_mcp-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for django_native_mcp-0.1.3-py3-none-any.whl |
Total release size: 51.5 kB
Release files / django_native_mcp-0.1.3.tar.gz
| Download URL | django_native_mcp-0.1.3.tar.gz |
|---|---|
| Size | 28.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
12a83efeb5e654b04c1f6631460556f7b3edc7081934527c7f03e73b86912edf
|
|
BLAKE2b-256 checksum How to use checksums |
01d8989c064ebcb587de0105f707266fbadbd5ed727e024a0647b4606e7010b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logRelease files / django_native_mcp-0.1.3-py3-none-any.whl
| Download URL | django_native_mcp-0.1.3-py3-none-any.whl |
|---|---|
| Size | 22.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
33f8ff91adf3c3441bce606ea2a239b93f9e97ee7a437d2ded2950597a281bb8
|
|
BLAKE2b-256 checksum How to use checksums |
e8f5e4f6d771e03a1391071038165e3586dcedeab8df7209a2485c29216f2191
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logSecurity for django-native-mcp 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for django_native_mcp-0.1.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.