Skip to main content

DRF MCP

PyPI version Python 3.10+ Django 4.2+ License: MIT

Enterprise-grade Model Context Protocol (MCP) integration for Django REST Framework with FastMCP 3.0

Automatically expose your Django REST Framework APIs as tools for AI agents via the Model Context Protocol. Zero configuration, maximum security, enterprise-ready.

Overview

DRF MCP transforms your Django REST Framework views into AI-native tools via the Model Context Protocol standard. Built on FastMCP 3.0, it automatically:

  • 🔍 Discovers all DRF views and ViewSets in your Django URLconf
  • 🔧 Exposes them as MCP tools with auto-generated JSON schemas
  • 🔐 Secures with DRF's permission system (no security bypass)
  • ⚡ Async-first execution for non-blocking LLM interactions
  • 📊 Traces with OpenTelemetry for observability
  • 🚀 Scales with stateless, transport-agnostic architecture

Quick Start

# In your Django project
from drf_mcp import DRFMCP
from myapp.views import CustomerViewSet

# Initialize MCP server
mcp = DRFMCP("MyEnterpriseAPI")

# Option 1: Register specific ViewSets
mcp.register_viewset(CustomerViewSet, namespace="crm")

# Option 2: Auto-discover all DRF views
mcp.autodiscover()

# Run server (stdio, HTTP, or SSE transport)
if __name__ == "__main__":
    mcp.run()

Your DRF serializers automatically become MCP tool parameters. No extra configuration needed.

Architecture

Discovery

Scans Django's URLconf to find all DRF APIView and ViewSet classes.

Schema Generation

Uses drf-spectacular to convert DRF serializers into JSON schemas for MCP tool arguments.

Execution

Wraps DRF view invocations with async support, permission checking, and error handling.

Security

Enforces DRF's authentication and permission classes on every tool call. Agents are authenticated users.

Transport

Supports stdio, HTTP, and SSE via FastMCP's built-in transports.

Features

  • ✅ Automatic DRF view discovery and MCP tool generation
  • ✅ drf-spectacular schema integration (nested serializers, complex validators)
  • ✅ DRF permission system integration (no security bypass)
  • ✅ Async-first executor (non-blocking LLM execution)
  • ✅ OAuth2/OIDC agent authentication
  • ✅ OpenTelemetry tracing for observability
  • ✅ Interactive manage.py mcp_inspector CLI
  • ✅ Type hints and Pydantic v2 schemas
  • ✅ Django 4.2 LTS and 5.0+ support
  • ✅ Python 3.10+ support

Installation

uv add drf-mcp

Or with pip:

pip install drf-mcp

Documentation

Full documentation is available at drf-mcp.readthedocs.io

Requirements

  • Python: 3.10+
  • Django: 4.2+ (LTS) or 5.0+
  • Django REST Framework: 3.14+
  • FastMCP: 3.0+

Development

# Clone and setup
git clone https://github.com/ziyacivan/drf-mcp.git
cd drf-mcp
uv venv
uv pip install -e ".[dev]"

# Run tests
pytest

# Format code
black src/drf_mcp tests
isort src/drf_mcp tests

# Type checking
mypy src/drf_mcp

License

MIT License - See LICENSE file for details.

Contributing

Contributions welcome! Please see CONTRIBUTING.md for guidelines.

Acknowledgments

Metadata

Release files for drf-mcp 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drf-mcp 0.1.1
File Size Uploaded
drf_mcp-0.1.1.tar.gz 35.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for drf-mcp 0.1.1
File Interpreter ABI Platform
drf_mcp-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 54.7 kB

Release files / drf_mcp-0.1.1.tar.gz

Download URL drf_mcp-0.1.1.tar.gz
Size 35.8 kB
Tags Source
SHA-256 checksum
How to use checksums
793224e7065d1f832dff1e60db737b830ef15966caac976e6cf29022f57e9c17
BLAKE2b-256 checksum
How to use checksums
632896b05517fe96fb96cf0a0e1c7b952632f12e4078181b02ac7a1b5af117bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / drf_mcp-0.1.1-py3-none-any.whl

Download URL drf_mcp-0.1.1-py3-none-any.whl
Size 18.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a27d1327ca1d52bd5c0475d0e7a5b907afa377e6514d7d663fc84fb75b983971
BLAKE2b-256 checksum
How to use checksums
7b8d38f0b06b319a9f29f053683cc06dfd09aec21336d246ce8b94f2543221d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release 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