drf-mcp-docs
Exposes Django REST Framework API documentation via MCP for AI coding agents to read, understand, and write frontend integration code.
README
<p align="center"> <h1 align="center">drf-mcp-docs</h1> <p align="center"> <strong>API documentation via MCP for AI coding agents</strong> </p> <p align="center"> <a href="https://pypi.org/project/drf-mcp-docs/"><img src="https://img.shields.io/pypi/v/drf-mcp-docs.svg" alt="PyPI version"></a> <a href="https://pypi.org/project/drf-mcp-docs/"><img src="https://img.shields.io/pypi/pyversions/drf-mcp-docs.svg" alt="Python versions"></a> <a href="https://github.com/Abdulkhalek-1/drf-mcp-docs/blob/main/LICENSE"><img src="https://img.shields.io/github/license/Abdulkhalek-1/drf-mcp-docs.svg" alt="License"></a> <a href="https://github.com/Abdulkhalek-1/drf-mcp-docs/actions"><img src="https://img.shields.io/github/actions/workflow/status/Abdulkhalek-1/drf-mcp-docs/ci.yml?branch=main" alt="CI"></a> <a href="https://abdulkhalek-1.github.io/drf-mcp-docs/"><img src="https://img.shields.io/badge/docs-online-blue" alt="Docs"></a> </p> </p>
drf-mcp-docs exposes your Django REST Framework API documentation through the Model Context Protocol (MCP) so AI coding agents can read, understand, and help you write correct frontend integration code.
How is this different from other Django+MCP packages?
Packages like
django-mcp-serveranddjango-rest-framework-mcpexpose DRF actions as MCP tools — the AI agent calls your endpoints directly. drf-mcp-docs is fundamentally different: it exposes API documentation so AI agents can help developers write frontend code (React, Vue, Angular, etc.).Think of it as: drf-spectacular generates docs for humans in a browser → drf-mcp-docs generates docs for AI agents via MCP.
Features
- MCP Resources — Browse your API structure: overview, endpoints, schemas, auth methods
- MCP Tools — Search endpoints, get detailed docs, generate request/response examples
- Code Generation — Generate integration code with real types and docs (JS/TS: fetch, axios, ky — Python: requests, httpx — cURL)
- Multi-adapter — Works with drf-spectacular, drf-yasg, or DRF's built-in schema generation
- Zero risk — Read-only documentation exposure, no data mutation possible
- Two transports — stdio for local AI tools, streamable-http for remote/network access
Quick Start
1. Install
pip install drf-mcp-docs
With a specific schema generator:
pip install drf-mcp-docs[spectacular] # recommended
pip install drf-mcp-docs[yasg]
2. Configure
Add to your Django settings:
INSTALLED_APPS = [
# ...
'rest_framework',
'drf_mcp_docs',
]
That's it for basic usage. drf-mcp-docs auto-detects your schema generator.
3. Run
stdio transport (for local AI tools like Claude Code, Cursor, etc.):
python manage.py runmcpserver --transport stdio
Streamable HTTP transport (for network access):
python manage.py runmcpserver --transport streamable-http --host 0.0.0.0 --port 8100
Check configuration (validate settings, adapter, and schema):
python manage.py checkmcpconfig
4. Connect your AI tool
Claude Code (~/.claude.json):
{
"mcpServers": {
"my-api-docs": {
"command": "python",
"args": ["manage.py", "runmcpserver", "--transport", "stdio"],
"cwd": "/path/to/your/django/project"
}
}
}
Cursor (.cursor/mcp.json):
{
"mcpServers": {
"my-api-docs": {
"command": "python",
"args": ["manage.py", "runmcpserver", "--transport", "stdio"],
"cwd": "/path/to/your/django/project"
}
}
}
What AI Agents Can Do
Once connected, your AI coding agent can:
You: "Show me all the product endpoints"
Agent: [reads api://endpoints resource, filters by tag]
You: "Generate a React hook to create a new product"
Agent: [calls get_endpoint_detail for POST /api/products/]
[calls get_request_example for the request body]
[calls generate_code_snippet with typescript + fetch]
→ Generates a complete, typed React hook with correct fields
Available Resources
| Resource URI | Description |
|---|---|
api://overview |
API title, version, base URL, auth summary, tags, endpoint count |
api://endpoints |
All endpoints: path, method, summary, tags (compact listing) |
api://endpoints/{method}/{path} |
Full detail for one endpoint |
api://schemas |
All schema/model definitions (names + field summaries) |
api://schemas/{name} |
Full schema with properties, types, constraints |
api://auth |
Authentication guide with all auth methods |
Available Tools
| Tool | Parameters | Description |
|---|---|---|
search_endpoints |
query, method?, tag? |
Search endpoints by keyword |
get_endpoint_detail |
path, method |
Full endpoint documentation |
get_request_example |
path, method |
Example request body and parameters |
get_response_example |
path, method, status_code? |
Example response |
generate_code_snippet |
path, method, language?, client? |
Integration code (JS/TS, Python, cURL) with pagination support |
list_schemas |
— | All data model names and descriptions |
get_schema_detail |
name |
Full schema with all fields and types |
Configuration
All settings are optional. Add a DRF_MCP_DOCS dict to your Django settings:
DRF_MCP_DOCS = {
# Server
'SERVER_NAME': 'my-api', # MCP server name (default: 'drf-mcp-docs')
'SERVER_INSTRUCTIONS': 'Custom prompt...', # Instructions shown to AI agents
# Schema
'SCHEMA_ADAPTER': None, # Auto-detect, or full dotted path
'SCHEMA_PATH_PREFIX': '/api/', # Only include endpoints under this prefix
'EXCLUDE_PATHS': ['/api/internal/'], # Paths to exclude
'CACHE_SCHEMA': not DEBUG, # Cache in production, refresh in dev
'CACHE_TTL': None, # Schema cache TTL in seconds (None = no expiry)
# Transport
'TRANSPORT': 'streamable-http', # Default transport: 'streamable-http' or 'stdio'
'MCP_ENDPOINT': '/mcp/', # URL path for HTTP transport
# Code generation
'DEFAULT_CODE_LANGUAGE': 'javascript', # 'javascript', 'typescript', or 'python'
'DEFAULT_HTTP_CLIENT': 'fetch', # 'fetch', 'axios', 'ky', 'requests', or 'httpx'
}
Schema Adapter Selection
drf-mcp-docs auto-detects your schema generator in this priority order:
- drf-spectacular (recommended) — most complete OpenAPI 3.x output
- drf-yasg — Swagger 2.0 auto-converted to OpenAPI 3.0
- DRF built-in — basic fallback with limited schema detail
To force a specific adapter:
DRF_MCP_DOCS = {
'SCHEMA_ADAPTER': 'drf_mcp_docs.adapters.spectacular.SpectacularAdapter',
}
ASGI Integration
For projects using ASGI, mount the MCP endpoint alongside your Django app:
# asgi.py
from django.core.asgi import get_asgi_application
from drf_mcp_docs.urls import mount_mcp
django_app = get_asgi_application()
application = mount_mcp(django_app) # Mounts at /mcp/ by default
With custom path:
application = mount_mcp(django_app, path="/api-docs-mcp/")
Development
git clone https://github.com/Abdulkhalek-1/drf-mcp-docs.git
cd drf-mcp-docs
pip install -e ".[dev]"
pytest
How It Works
┌─────────────┐ ┌──────────────┐ ┌─────────────────┐ ┌───────────┐
│ AI Agent │────>│ MCP Server │────>│ Schema Processor │────>│ Adapter │
│ (Claude, │<────│ (FastMCP) │<────│ (OpenAPI dict │<────│ (spectac- │
│ Cursor...) │ │ │ │ → structured) │ │ ular, │
└─────────────┘ └──────────────┘ └─────────────────┘ │ yasg, │
Resources + Tools Dataclasses + Search │ DRF) │
└───────────┘
- Adapter pulls the OpenAPI schema from your chosen generator
- Processor transforms the raw dict into structured, AI-friendly dataclasses
- MCP Server exposes resources (browsable docs) and tools (search, examples, code gen)
- AI Agent connects via stdio or HTTP, reads your API docs, helps write frontend code
License
MIT License. See LICENSE for details.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.