Python
Get an OpenAPI spec from Django REST Framework
Install drf-spectacular and run one command to write openapi.yaml.
How it works
drf-spectacular reads your DRF views, viewsets, serializers and URL routes, and builds a detailed spec with fields and types.
Plain Django views that are not part of Django REST Framework are not included. For those, use From code (GitHub) or a Postman collection.
Step by step
Step 1: Install it
In the environment your project uses:
Terminalpip install drf-spectacularAdd drf-spectacular to requirements.txt too, so it is installed on your server.
Step 2: Add it to settings.py
Add the app, tell DRF to use it for schemas, and give the API a title. Keep your existing REST_FRAMEWORK settings and add the one line.
settings.pyINSTALLED_APPS = [ # ...your existing apps 'rest_framework', 'drf_spectacular', ] REST_FRAMEWORK = { # ...your existing settings 'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema', } SPECTACULAR_SETTINGS = { 'TITLE': 'My API', 'DESCRIPTION': 'What this API does, in one sentence.', 'VERSION': '1.0.0', 'SERVE_INCLUDE_SCHEMA': False, }Step 3: Write the file
Run one of these in the folder with manage.py. Warnings are normal: they point at views it could not fully understand, and the file is still written.
Terminal (YAML)python manage.py spectacular --color --file openapi.yamlTerminal (JSON)python manage.py spectacular --format openapi-json --file openapi.jsonStep 4: Optional: serve it from your API
So you can paste a link into MCPEasy instead of uploading. Add to your root urls.py:
urls.pyfrom django.urls import path from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView urlpatterns = [ # ...your existing urls path('api/schema/', SpectacularAPIView.as_view(), name='schema'), path('api/schema/docs/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'), ]The link is https://your-api.com/api/schema/ (YAML). Add ?format=json for JSON.
Step 5: Optional: fix views it cannot read
For an APIView without a serializer_class, tell drf-spectacular what goes in and out:
views.pyfrom drf_spectacular.utils import extend_schema class BookingView(APIView): @extend_schema(request=BookingSerializer, responses={201: BookingSerializer}, summary="Create a booking") def post(self, request): ...
Check that it worked
- openapi.yaml lists your endpoints under paths:, with request bodies that match your serializers.
Give it to MCPEasy
Have a link? Paste it (best)
In MCPEasy, create a server, choose OpenAPI URL and paste the link, for example https://api.example.com/openapi.json. Later changes to your API can be picked up with a sync.
Have a file? Upload it
Choose Upload file and drop in the .json or .yaml file (up to 5 MB). MCPEasy turns each endpoint into a tool, and you review them all before anything goes live.
If something goes wrong
- ModuleNotFoundError: No module named 'drf_spectacular'.
- It was installed in a different environment. Activate your project's virtual environment and install again.
- Many "unable to guess serializer" warnings.
- Those views have no serializer_class. The paths are still in the file; add @extend_schema (step 5) for better fields.
- Some endpoints are missing.
- They are plain Django views, not DRF views. Use From code (GitHub) in MCPEasy for those.
Still stuck, or no time to set this up? In MCPEasy choose From code (GitHub): it reads your routes straight from the repository, read-only, and tests every tool against your live API before it goes live.
Official documentation
Other frameworks
More guides for MCP and OpenAPI
- OpenAPI to MCP serverHow a spec maps to MCP tools, which endpoints to keep, and how auth works.
- REST API to MCP serverConvert any API, with or without a spec: Postman, cURL, code, plus a worked example.
- Get an OpenAPI spec from your frameworkExport an OpenAPI (Swagger) file from 11 frameworks, step by step.
- OpenAPI spec from FastAPINothing to install: FastAPI already serves your spec at /openapi.json.
- OpenAPI spec from ExpressThe packages, code and commands to produce a spec from an Express app.