Enterprise-grade Model Context Protocol (MCP) integration for Django REST Framework with FastMCP 3.0
Project description
Django MCP
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
Django 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_inspectorCLI - ✅ Type hints and Pydantic v2 schemas
- ✅ Django 4.2 LTS and 5.0+ support
- ✅ Python 3.10+ support
Installation
uv add django-mcp
Or with pip:
pip install django-mcp
Documentation
Full documentation is available at django-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/django-mcp/django-mcp.git
cd django-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
- FastMCP - High-level MCP framework
- drf-spectacular - OpenAPI schema generation
- Django REST Framework - Best-in-class Python API framework
- gts360/django-mcp-server - Reference implementation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file drf_mcp-0.1.0.tar.gz.
File metadata
- Download URL: drf_mcp-0.1.0.tar.gz
- Upload date:
- Size: 34.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef129edb2d27be5aec04c379fb75d91ad2afed1dd57abf54b834a22788af2fb6
|
|
| MD5 |
e9895c54cbf17ef3eba5060998a6e371
|
|
| BLAKE2b-256 |
8ccd2643be55126e75d4729cbe7ab0afd1da23c003e100d6b84e9b9b7baed87f
|
File details
Details for the file drf_mcp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: drf_mcp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf941c001c0ed57126b14e98c2000442cd3f423098747bcf30faf8568dd891f3
|
|
| MD5 |
0fad2875bf6b9862fc7be76afb424e67
|
|
| BLAKE2b-256 |
72ba99faf7501512cd506217513a68b9e2c425ecc9061d3e160d10b50bee86bc
|