Server facts
django-mcp-server
GitHub stars
393
Last commit
Mar 10, 2026
Runtime
python
License
MIT
Project
- Author
- omarbenhamid
- License
- MIT
- Category
- Cloud & DevOps
Tech
- Runtime
- python
- Transports
- streamable-httpstdio
- Remote access
- No
- Authentication
- Django REST Framework auth classes (TokenAuthentication or OAuth2 via django-oauth-toolkit)
Activity
- GitHub stars
- 393
- Last commit
- Data as of
Tags
- agentic ai
- ai
- django
- modelcontextprotocol
Overview
Backend teams building a `django mcp` integration inside an existing Python codebase can drop `omarbenhamid/django-mcp-server` (MIT license, PyPI `django-mcp-server`) straight into `INSTALLED_APPS` and `urls.py` without migrating away from WSGI or adopting separate infrastructure. Mounting `mcp_server.urls` exposes a Streamable HTTP endpoint at `/mcp` (customizable via `DJANGO_MCP_ENDPOINT`) on both WSGI and ASGI, while `python manage.py stdio_server` supports local Claude Desktop testing and `python manage.py mcp_inspect` validates registered schemas. For non-public data, configure `DJANGO_MCP_AUTHENTICATION_CLASSES` with Django REST Framework `TokenAuthentication` or OAuth2 (`django-oauth-toolkit`, plus the author's Dynamic Client Registration add-on for Claude AI remote integrations).
Instead of rewriting business logic, developers choose among declarative APIs: subclass `ModelQueryToolset` to expose queryset-filtered Django models in 2 lines (with optional DRF CSV/JSON output renderers or embedded resources), subclass `MCPToolset` to publish Python methods (optionally formatted via `@drf_serialize_output`), decorate DRF CRUD views via the `drf_publish_*_mcp_tool` helpers (supporting list, create, update, and delete mixins), or attach low-level FastMCP `@mcp.tool()` async functions using Django's async ORM. Sessions default to cookie-free Django `request.session` state (or stateless mode via `DJANGO_MCP_GLOBAL_SERVER_CONFIG`), and secondary endpoints can be mounted via `MCPServerStreamableHttpView.as_view(...)`.
Install & configure
Requirements
- Python and an existing Django project (`pip install django-mcp-server`)
- Add `'mcp_server'` to `INSTALLED_APPS` and include `'mcp_server.urls'` in `urls.py` (serves `/mcp` by default)
- Django REST Framework authentication (`DJANGO_MCP_AUTHENTICATION_CLASSES`), plus `django-oauth-toolkit` and Dynamic Client Registration for remote Claude AI OAuth2
pip install django-mcp-serverInstall with `pip install django-mcp-server`, declare tools in `mcp.py` via `ModelQueryToolset`, `MCPToolset`, DRF decorators, or `@mcp.tool()`, verify with `python manage.py mcp_inspect`, and connect remote clients to `/mcp` over Streamable HTTP or Claude Desktop locally via `manage.py stdio_server`.
Examples are translated from the published configuration. Supply your own credentials and verify requirements in the upstream README. Remote connectors are shown only where a supported configuration format is known.
Config file · macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Use Settings → Developer → Edit Config when available. Do not assume a Linux configuration path; check the client documentation for your platform. Remote servers use the app’s connector flow when supported, not the local stdio file shown here. Merge this example with existing settings; do not overwrite unrelated servers.
{
"mcpServers": {
"test_django_mcp": {
"command": "/path/to/interpreter/python",
"args": [
"/path/to/your/project/manage.py",
"stdio_server"
]
}
}
}Config file · Project: .cursor/mcp.json
User: ~/.cursor/mcp.json
The project path is relative to the workspace root. The tilde denotes your user home directory. Use Cursor’s MCP settings to confirm which configuration and scope your installed version is reading. Merge this example with existing settings; do not overwrite unrelated servers.
{
"mcpServers": {
"test_django_mcp": {
"command": "/path/to/interpreter/python",
"args": [
"/path/to/your/project/manage.py",
"stdio_server"
]
}
}
}Config file · Workspace: .vscode/mcp.json
For user scope, use the “MCP: Open User Configuration” command if available. Do not guess a user configuration path across operating systems, profiles, containers, or remote workspaces; check the client documentation. Merge this example with existing settings; do not overwrite unrelated servers.
{
"servers": {
"test_django_mcp": {
"type": "stdio",
"command": "/path/to/interpreter/python",
"args": [
"/path/to/your/project/manage.py",
"stdio_server"
]
}
}
}Config file · macOS/Linux: ~/.codeium/windsurf/mcp_config.json
Windows: %USERPROFILE%\.codeium\windsurf\mcp_config.json
Open the MCP configuration through Windsurf’s settings when possible to confirm the active file. Paths can differ in managed or future releases; check the client documentation if this location is not present. Merge this example with existing settings; do not overwrite unrelated servers.
{
"mcpServers": {
"test_django_mcp": {
"command": "/path/to/interpreter/python",
"args": [
"/path/to/your/project/manage.py",
"stdio_server"
]
}
}
}Config file · Project scope: .mcp.json at the repository root
The project file uses mcpServers. For user scope, use claude mcp add --scope user rather than assuming .mcp.json in your home directory is the user configuration. Check the client documentation for managed settings and storage details. Merge this example with existing settings; do not overwrite unrelated servers.
{
"mcpServers": {
"test_django_mcp": {
"type": "stdio",
"command": "/path/to/interpreter/python",
"args": [
"/path/to/your/project/manage.py",
"stdio_server"
]
}
}
}Examples are translated from the published configuration. Supply your own credentials and verify requirements in the upstream README. Remote connectors are shown only where a supported configuration format is known.
Use cases
- Expose request-scoped Django ORM models safely to AI assistants in 2 lines of Python by overriding `ModelQueryToolset.get_queryset`.
- Convert existing Django REST Framework `CreateAPIView`, update, delete, and list views into schema-typed MCP tools with a single decorator.
- Serve a validated remote Streamable HTTP MCP endpoint for Claude AI or Google ADK directly from a production WSGI or ASGI Django deployment.
- Return DRF-serialized objects or CSV/JSON renderer outputs (inline or as MCP Embedded Resources) from custom `MCPToolset` methods.
Strengths
- Runs natively inside existing Django apps on both WSGI and ASGI with no separate sidecar service or infrastructure rewrite.
- Offers layered ergonomics: 2-line `ModelQueryToolset`, class-based `MCPToolset`, DRF CRUD view decorators, DRF serializer/renderer hooks, and FastMCP `@mcp.tool()`.
- Integrates with DRF authentication classes (`TokenAuthentication`, OAuth2 via `django-oauth-toolkit`) and ships `manage.py mcp_inspect` and `stdio_server`.
- Manages stateful MCP sessions via Django's session backend without cookies, or toggles stateless mode in `DJANGO_MCP_GLOBAL_SERVER_CONFIG`.
Limitations
- DRF view decorators disable built-in DRF authentication, filter backends, permissions, and pagination by default (`self.paginator` becomes `None`), requiring explicit handling.
- Secondary `DjangoMCP` endpoints mounted manually ignore `DJANGO_MCP_AUTHENTICATION_CLASSES` and remain unsecured unless DRF auth/permissions are passed to `MCPServerStreamableHttpView.as_view()`.
- Remote Claude AI OAuth2 requires Dynamic Client Registration via a separate `django-oauth-toolkit-dcr` add-on, and async `@mcp.tool()` definitions must avoid returning unevaluated QuerySets.
django-mcp-server setup notes
- django-mcp-server's example uses stdio, while its catalog transports are streamable-http / stdio; use the example's connection type.