All Integrations/Backend Framework

Convert Django REST Framework (drf-spectacular) to MCP

Turn Django REST Framework ViewSets and Serializers (exported via drf-spectacular) into an async Python FastMCP server without touching your Django WSGI/ASGI stack.

DRF Token / JWT Bearer / API Key HeaderRecommended: Python FastMCP
Presets:
Context Footprint~958 tok
Lean context footprintOpenAPI 3.0.3

MCP Tool Selection

10 / 10 Free

12 endpoints parsed • 1 safety-guarded

12 endpoints detected — Free tier compiles up to 10

Unlock unlimited endpoints, hosted Remote MCP URL, OAuth2 proxy & GitHub CI auto-sync with Pro Cloud.

GET/tasks~126t

List workspace tasks with status & assignee filters

tool:
readOnly3 params
POST/tasks~130t

Create a new engineering or CRM task

tool:
4 params
GET/tasks/{task_id}~67t

Get task details and subtasks

tool:
readOnly1 param
PATCH/tasks/{task_id}~135t

Update task status, priority, or assignee

tool:
4 params
DELETE/tasks/{task_id}~70t

Permanently delete a task

tool:
1 param
GET/projects~72t

List active workspace projects

tool:
readOnly1 param
POST/projects~86t

Create a new project milestone

tool:
2 params
GET/contacts~100t

Search CRM contacts by email or company

tool:
readOnly2 params
POST/contacts~103t

Add a new CRM contact

tool:
3 params
GET/deals~69t

List pipeline deals and ARR values

tool:
readOnly1 param
POST/deals/{deal_id}/notes~92t

Attach a call summary or note to a deal

tool:
2 params
DELETE/contacts/{contact_id}~75t

GDPR purge a CRM contact record

tool:
1 param
server.py167 lines
1"""
2Generated by Spec2MCP (https://spec2mcp.com)
3Server: workspace-crm-tasks-api v2.1.0
4Tools exposed: 10
5"""
6from __future__ import annotations
7
8import json
9import os
10from typing import Any, Optional
11from urllib.parse import quote
12
13import httpx
14from mcp.server.fastmcp import FastMCP
15
16BASE_URL = os.environ.get("WORKSPACE_CRM_TASKS_API_BASE_URL", "https://api.workspace-crm.example.com/v2").rstrip("/")
17API_KEY = os.environ.get("WORKSPACE_CRM_TASKS_API_API_KEY", "")
18def build_auth_headers() -> dict[str, str]:
19 return {"X-Workspace-Key": API_KEY} if API_KEY else {}
20
21mcp = FastMCP("workspace-crm-tasks-api")
22
23
24async def call_upstream(
25 method: str,
26 path: str,
27 params: Optional[dict[str, Any]] = None,
28 json_body: Optional[dict[str, Any]] = None,
29) -> str:
30 url = f"{BASE_URL}{path}"
31 headers = {
32 "Accept": "application/json",
33 "User-Agent": "spec2mcp/workspace-crm-tasks-api",
34 **build_auth_headers(),
35 }
36 try:
37 async with httpx.AsyncClient(timeout=20.0) as client:
38 response = await client.request(
39 method=method,
40 url=url,
41 headers=headers,
42 params=params,
43 json=json_body,
44 )
45 try:
46 body_text = json.dumps(response.json(), indent=2)
47 except Exception:
48 body_text = response.text
49
50 if response.is_error:
51 return f"HTTP {response.status_code} from {method} {path}\n{body_text}"
52 return body_text or f"HTTP {response.status_code} (empty body)"
53 except httpx.HTTPError as exc:
54 return f"Network error calling {method} {url}: {exc}"
55
56
57@mcp.tool(name="list_tasks")
58async def list_tasks(status: Optional[str] = None, assignee_id: Optional[str] = None, limit: Optional[int] = None) -> str:
59 """List workspace tasks with status & assignee filters [GET /tasks]"""
60 query_params: dict[str, Any] = {}
61 if status is not None:
62 query_params["status"] = status
63 if assignee_id is not None:
64 query_params["assignee_id"] = assignee_id
65 if limit is not None:
66 query_params["limit"] = limit
67 return await call_upstream(method="GET", path="/tasks", params=query_params)
68
69
70@mcp.tool(name="create_task")
71async def create_task(title: str, project_id: str, priority: Optional[int] = None, due_date: Optional[str] = None) -> str:
72 """Create a new engineering or CRM task [POST /tasks]"""
73 json_body: dict[str, Any] = {}
74 if title is not None:
75 json_body["title"] = title
76 if project_id is not None:
77 json_body["project_id"] = project_id
78 if priority is not None:
79 json_body["priority"] = priority
80 if due_date is not None:
81 json_body["due_date"] = due_date
82 return await call_upstream(method="POST", path="/tasks", json_body=json_body)
83
84
85@mcp.tool(name="get_task")
86async def get_task(task_id: str) -> str:
87 """Get task details and subtasks [GET /tasks/{task_id}]"""
88 return await call_upstream(method="GET", path=f"/tasks/{quote(str(task_id), safe="")}")
89
90
91@mcp.tool(name="update_task")
92async def update_task(task_id: str, status: Optional[str] = None, priority: Optional[int] = None, assignee_id: Optional[str] = None) -> str:
93 """Update task status, priority, or assignee [PATCH /tasks/{task_id}]"""
94 json_body: dict[str, Any] = {}
95 if status is not None:
96 json_body["status"] = status
97 if priority is not None:
98 json_body["priority"] = priority
99 if assignee_id is not None:
100 json_body["assignee_id"] = assignee_id
101 return await call_upstream(method="PATCH", path=f"/tasks/{quote(str(task_id), safe="")}", json_body=json_body)
102
103
104@mcp.tool(name="delete_task")
105async def delete_task(task_id: str, confirm_destructive_action: bool = False) -> str:
106 """Permanently delete a task [DELETE /tasks/{task_id}]"""
107 if not confirm_destructive_action:
108 return "Blocked by safety guard: set confirm_destructive_action=True after user confirmation."
109 return await call_upstream(method="DELETE", path=f"/tasks/{quote(str(task_id), safe="")}")
110
111
112@mcp.tool(name="list_projects")
113async def list_projects(archived: Optional[bool] = None) -> str:
114 """List active workspace projects [GET /projects]"""
115 query_params: dict[str, Any] = {}
116 if archived is not None:
117 query_params["archived"] = archived
118 return await call_upstream(method="GET", path="/projects", params=query_params)
119
120
121@mcp.tool(name="create_project")
122async def create_project(name: str, lead_id: Optional[str] = None) -> str:
123 """Create a new project milestone [POST /projects]"""
124 json_body: dict[str, Any] = {}
125 if name is not None:
126 json_body["name"] = name
127 if lead_id is not None:
128 json_body["lead_id"] = lead_id
129 return await call_upstream(method="POST", path="/projects", json_body=json_body)
130
131
132@mcp.tool(name="search_crm_contacts")
133async def search_crm_contacts(q: Optional[str] = None, stage: Optional[str] = None) -> str:
134 """Search CRM contacts by email or company [GET /contacts]"""
135 query_params: dict[str, Any] = {}
136 if q is not None:
137 query_params["q"] = q
138 if stage is not None:
139 query_params["stage"] = stage
140 return await call_upstream(method="GET", path="/contacts", params=query_params)
141
142
143@mcp.tool(name="create_crm_contact")
144async def create_crm_contact(email: str, full_name: str, company: Optional[str] = None) -> str:
145 """Add a new CRM contact [POST /contacts]"""
146 json_body: dict[str, Any] = {}
147 if email is not None:
148 json_body["email"] = email
149 if full_name is not None:
150 json_body["full_name"] = full_name
151 if company is not None:
152 json_body["company"] = company
153 return await call_upstream(method="POST", path="/contacts", json_body=json_body)
154
155
156@mcp.tool(name="list_deals")
157async def list_deals(stage: Optional[str] = None) -> str:
158 """List pipeline deals and ARR values [GET /deals]"""
159 query_params: dict[str, Any] = {}
160 if stage is not None:
161 query_params["stage"] = stage
162 return await call_upstream(method="GET", path="/deals", params=query_params)
163
164
165if __name__ == "__main__":
166 mcp.run(transport="stdio")
167
$ pip install -r requirements.txt && WORKSPACE_CRM_TASKS_API_API_KEY=... python server.py
10 tools • ~958 tokens

How to export & compile your Django DRF OpenAPI spec

Run python manage.py spectacular --format openapi-json --file schema.json and upload schema.json above.

$python manage.py spectacular --format openapi-json --file schema.json

High-Signal Django DRF MCP Tools to Expose First

MethodEndpoint PathMCP Tool Name
GET/api/projects/list_projects
POST/api/projects/create_project
PATCH/api/projects/{id}/partial_update_project

Best Practices for Django DRF

  • Use drf-spectacular's --format openapi-json flag to export clean JSON ready for Spec2MCP.
  • If your Django API uses DRF's classic TokenAuthentication (Authorization: Token <key>), replace 'Bearer ' with 'Token ' in build_auth_headers() (one-line tweak).
  • Keep Django trailing slashes consistent in your OpenAPI paths (e.g., /api/tasks/) to avoid POST 301 redirect drops.

Common Django DRF MCP Gotchas

  • Django APPEND_SLASH redirects POST requests missing a trailing slash—keep the exact paths exported by drf-spectacular.
  • DRF ModelViewSet generates 6 endpoints per model (list, create, retrieve, update, partial_update, destroy); uncheck PUT if you already expose PATCH to save 15% of tool tokens.
  • Use Django's SimpleJWT Bearer tokens or scoped API keys instead of superuser credentials.

Django REST Framework to MCP Server — Frequently Asked Questions

How do I get OpenAPI JSON from Django REST Framework?

Install drf-spectacular and run python manage.py spectacular --format openapi-json --file schema.json.

Why disable PUT when PATCH is already enabled on DRF ViewSets?

LLMs perform better with PATCH (partial updates) than full-object PUT replacements, and disabling redundant PUT endpoints cuts your MCP tool token footprint significantly.

Can I run the generated FastMCP server inside the same Python repo as Django?

Yes—save server.py in an mcp/ subdirectory and run it via uv or your existing virtualenv.

Related OpenAPI-to-MCP Converters

View all 20
Transparent Developer Pricing

Free locally forever. Upgrade when your team goes remote.

Compile focused local TypeScript & Python MCP servers in your browser for $0. Move to Pro Cloud or Team when you need unlimited endpoints, hosted Remote MCP URLs, OAuth2 proxying, and CI sync.

Free Local Studio
$0/ forever

Everything solo engineers need to turn REST APIs into local stdio MCP servers with zero login.

  • Local TypeScript SDK + Zod codegen
  • Local Python FastMCP + httpx codegen
  • Up to 10 endpoints per MCP server
  • Live context-window token estimator
  • Destructive action confirmation guards
  • Claude Desktop, Cursor, Windsurf & Antigravity mcp.json
  • 100% client-side — specs stay in browser
Use Free Studio Now
Most Popular
Pro Cloud
$29/ month

Compile unlimited endpoints and publish a hosted Remote MCP URL with encrypted credential vaulting.

  • Unlimited OpenAPI endpoints & tool grouping
  • 1-click hosted Remote MCP endpoint (Streamable HTTP)
  • Encrypted OAuth2 & API-Key secret vault
  • Custom tool presets & OpenAPI overlay persistence
  • Response payload truncation to stop context blowups
  • Priority email & Discord support
Team
$79/ month

Built for engineering orgs keeping internal MCP servers automatically synced with OpenAPI repos.

  • Everything in Pro Cloud
  • GitHub / GitLab CI auto-sync on OpenAPI PR merges
  • Per-tool invocation audit logs & latency metrics
  • Per-user rate limits & destructive-tool approval policies
  • Role-based access across engineering & ops teams
  • Dedicated onboarding & custom auth helpers