djcrud_mcp

Django host package for MCP profile registration. Ships inside the djcrud wheel (requires djcrud_drf). Stdio MCP / FastMCP lives in the separate djcrud-client package — not here.

pip install --pre "djcrud[drf,mcp]"

djcrud[mcp] also pulls djcrud-client for agent subprocesses. See Agents (MCP bridge).

Design spec: djcrud_mcp design.

Server setup

  1. pip install --pre "djcrud[drf,mcp]"

  2. Enable djcrud_drf, djcrud_api, Bearer middleware, API URLs (DRF API)

  3. Register ModelViewSet subclasses on djcrud_drf.site

  4. Register permissions in djcrud.py

  5. Register one McpProfile on djcrud_mcp.site (see Agents (MCP bridge))

  6. Add djcrud_mcp to INSTALLED_APPS and include djcrud_drf.site URLs

INSTALLED_APPS = [
    # ...
    "djcrud_drf",
    "djcrud_mcp",
    "djcrud_example.mcp_example",
]

urlpatterns = (
    djcrud.site.build().urlpatterns
    + djcrud_drf.site.build().urlpatterns
)

MCP profile

Tutorial: djcrud_example.mcp_example (see Agents (MCP bridge)).

import djcrud_mcp
from djcrud_example.drf_example.djcrud import ArticleViewSet, ProductViewSet


class ExampleMcp(djcrud_mcp.McpProfile):
    viewsets = (ArticleViewSet, ProductViewSet)


djcrud_mcp.site.register(ExampleMcp)

build() instantiates the registered class and resolves api_prefixes. server_name, instructions, and info_tool_name are @property defaults from the ViewSet models unless you override class attributes.

Host profile API

Endpoint

Purpose

GET /api/mcp/profiles/

Host MCP profile key (single registered profile)

GET /api/mcp/profiles/{key}/

Profile JSON (instructions, api_prefixes, meta)

GET /api/mcp/viewsets/

Registered ViewSet {model, prefix} list

Public API

  • djcrud_mcp.siteregister(McpProfile), build(), get_profile(key)

  • McpProfile — declare on the host; built on site.build()

  • discover_viewsets(), api_path_for(), model_name_for()

Client (djcrud-client)

Remote stdio MCP subprocesses install djcrud-client only (mcp + httpx, no Django). FastMCP, schema tool building, and HTTP proxying live in djcrud_client.

pip install djcrud-client
export DJCRUD_TOKEN=<raw_key>
djcrud-client -mcp
djcrud-client --call article_list --json '{}'

Further reading