Skip to main content

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",
}

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.

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_native_mcp-0.1.0.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_native_mcp-0.1.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file django_native_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: django_native_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for django_native_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 45112b153847ee254971552790b197e73aaad5e55d6659932dd727dbabf5e481
MD5 30ef3579f8d8c263a0b54e4087777fd6
BLAKE2b-256 bb7a273a9de9be70adb597bbd9b3541c27d2d5a1a778e1c2d238c4baf5b4684c

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_native_mcp-0.1.0.tar.gz:

Publisher: release.yml on xelaxela13/django-native-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_native_mcp-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_native_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 303ee2f562ac7a6572e34299a716ba61b474387f1f6928f2d73a25559b12c407
MD5 9a53f3fc9e90cdd4097e8a0a74485874
BLAKE2b-256 ba823f0deb7ccf1f0a61739cec069060bb34daa6951742423d9c4e7f4db111a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_native_mcp-0.1.0-py3-none-any.whl:

Publisher: release.yml on xelaxela13/django-native-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.2

2 files

0.1.1

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page