Exposes Django models, querysets, and REST Framework APIs as MCP tools and resources, allowing AI agents to perform complex queries and interact with a Django application's logic and data.
Enables integration with Google's Agent Development Kit (ADK), allowing Google's AI agents and tools to interact with Django application logic through the Model Context Protocol.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Django MCP Serverlist all bird sightings in the database"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Django MCP Server
Django MCP Server is an implementation of the Model Context Protocol (MCP) extension for Django. This module allows MCP Clients and AI agents to interact with any Django application seamlessly.
π Django-Style declarative style tools to allow AI Agents and MCP clients tool to interact with Django. π Expose Django models for AI Agents and MCP Tools to query in 2 lines of code in a safe way. π Convert Django Rest Framework APIs to MCP tools with one annotation. β Working on both WSGI and ASGI without infrastructure change. β Validated as a Remote Integration with Claude AI. π€ Any MCP Client or AI Agent supporting MCP , (Google Agent Developement Kit, Claude AI, Claude Desktop ...) can interact with your application.
Many thanks π to all the contributor community
Maintained β¨ with care by Smart GTS software engineering.
Licensed under the MIT License.
Features
Expose Django models and logic as MCP tools.
Serve an MCP endpoint inside your Django app.
Easily integrate with AI agents, MCP Clients, or tools like Google ADK.
Quick Start
1οΈβ£ Install
Or directly from GitHub:
2οΈβ£ Configure Django
β
Add mcp_server to your INSTALLED_APPS:
β
Add the MCP endpoint to your urls.py:
By default, the MCP endpoint will be available at /mcp.
3οΈβ£ Define MCP Tools
In mcp.py create a subclass of ModelQueryToolset to give access to a model :
Or create a sub class of MCPToolset to publish generic methods (private _ methods are not published)
Example:
Verify with MCP Inspect
Use the management commande mcp_inspect to ensure your tools are correctly declared :
Use the MCP with any MCP Client
The mcp tool is now published on your Django App at /mcp endpoint.
IMPORTANT For production setup, on non-public data, consider enabling authorization through : DJANGO_MCP_AUTHENTICATION_CLASSES
Test with MCP Python SDK
You can test it with the python mcp SDK :
Replace http://localhost:8000/mcp by the acutal Django host and run this cript.
Use from Claude AI
As of June 2025 Claude AI support now MCPs through streamable HTTP protocol with preè-requisites : *
Setup OAuth2, for example :
Install Django Oauth Toolkit)
Include
'oauth2_provider.contrib.rest_framework.OAuth2Authentication'inDJANGO_MCP_AUTHENTICATION_CLASSESinsettings.py
Claude AI requires Dynamic Client Registration. as of today it is not supported by django oauth toolkit but you can use This Django Oauth Toolkit DCR Add-On
Unless you implement OAuth server Metadata RFC correctly, you need to keep OAuth2 URLS (
/register,/tokenand/authorizeat their default location).
Test in Claude Desktop
You can test MCP servers in Claude Desktop. As for now claude desktop only supports local MCP Servers. So you need to have your app installed on the same machine, in a dev setting probably.
For this you need :
To install Claude Desktop from claude.ai
Open File > Settings > Developer and click Edit Config
Open
claude_desktop_config.jsonand setup your MCP server :{ "mcpServers": { "test_django_mcp": { "command": "/path/to/interpreter/python", "args": [ "/path/to/your/project/manage.py", "stdio_server" ] } }
NOTE /path/to/interpreter/ should point to a python interpreter you use (can be in your venv for example)
and /path/to/your/project/ is the path to your django project.
Advanced topics
Publish Django Rest Framework APIs as MCP Tools
You can use drf_publish_create_mcp_tool / drf_publish_update_mcp_tool / drf_publish_delete_mcp_tool /
drf_publish_list_mcp_tool as annotations or method calls to register DRF CreateModelMixin / UpdateModelMixin
/ DestroyModelMixin / ListModelMixin based views to MCP tools seamlessly. Django MCP Server will generate the schemas
to allow MCP Clients to use them.
NOTE in some older DRF versions schema generation is not supported out of the box, you should then provide to the registration annotation the
notice that the docstring of the view is used as instructions for the model. You can better tune this like :
Finally, you can register after hand in mcp.py for example with:
IMPORTANT
Notice that builti-in authentication classes are disabled by default along with filter_backends, permission_classes and pagination_class, that's because the MCP authentication is used.
Since the pagination_class is also disabled, you will need to account for that if you're using an existing paginated DRF view (self.paginator will be None).
Django Rest Framework Serializer integration
You can annotate a tool with drf_serialize_output(...) to serialize its output using
django rest framework, like :
Use low level mcp server annotation
You can import the DjangoMCP server instance and use FastMCP annotations to declare mcp tools and resources :
β οΈ Important:
Always use Django's async ORM API when you define async tools.
Be careful not to return a QuerySet as it will be evaluated asynchroniously which would create errors.
Customize the default MCP server settings
In settings.py you can initialize the DJANGO_MCP_GLOBAL_SERVER_CONFIG parameter. These will be
passed to the MCPServer server during initialization
Session management
By default the server is statefull, and state is managed as Django session
request.session object, so the session backend must thus be set up correctly. The
request object is available in self.request for class based toolsets.
NOTE The session middleware is not required to be set up as MCP sessions are managed
independently and without cookies.
.
You can make the server stateless by defining : DJANGO_MCP_GLOBAL_SERVER_CONFIG
IMPORTANT state is managed by django sessions, if you use low level @mcp_server.tool() annotation for example
the behaviour of preserving the server instance accross calls of the base python API is not preserved due to architecture
of django in WSGI deployments where requests can be served by different threads !
Authorization
The MCP endpoint supports Django Rest Framework authorization classes
You can set them using DJANGO_MCP_AUTHENTICATION_CLASSES in settings.py ex. :
IMPORTANT Now the MCP Specification version 2025-03-26
advices to use an OAuth2 workflow, so you should integrate
django-oauth-toolkit with djangorestframework integration
setup, and use 'oauth2_provider.contrib.rest_framework.OAuth2Authentication' in
DJANGO_MCP_AUTHENTICATION_CLASSES. Refer to the official documentation of django-oauth-toolkit
Advanced / customized setup of the view
You can in your urls.py mount the MCPServerStreamableHttpView.as_view() view and customize it with any extra parameters.
Custom output format (renderers) for ModelQueryToolset
You can define any DRF rendrer to produce output, for this it must be declared in your settings:
Then in your ModelQueryToolset declaration you can add
further you can instruct the tool to attach the result as an [MCP Embedded Resource] rather than direct return with
NOTE some renderers like drf-excel are designed in a way that does not allow using them outside of DRF View, they will not
work here..
Secondary MCP endpoint
in mcp.py
in urls.py
IMPORTANT When you do this the DJANGO_MCP_AUTHENTICATION_CLASSES settings is ignored and your view is unsecure. You SHOULD Setup DRF Authentication for your view, for exemple :
Testing
The server
You can setup you own app or use the mcpexample django app app.
The client
By default, your MCP Server will be available as a stateless streamable http transport endpoint at <your_django_server>/mcp (ex. http://localhost:8000/mcp) (*without / at the end !).
There are many ways to test :
Using the test MCP Client script : test/test_mcp_client.py
You can test using MCP Inspector tool
or any compatible MCP Client like google agent developement kit.
Integration with Agentic Frameworks and MCP Clients
Google Agent Developement Kit Example
NOTE as of today the official google adk does not support StreamableHTTP Transport but you could use this fork
Then you can use the test agent in test/test_agent with by
starting adk web in the test folder. Make sure first :
Install adk with streamablehttp support :
pip install git+https://github.com/omarbenhamid/google-adk-python.gitStart a django app with an MCP endpoint :
python manage.py runserverin theexamples/mcpexamplefolder.If you use TokenAuthorization create an access token, for example in Django Admin of your app.
Setup in
test/test_agent/agent.pythe right endpoint location and authentication headerEnter the
testfolder.Run
adk webIn the shell you can for example use this prompt : "I saw woody woodpecker, add it to my inventory"
Other clients
You can easily plug your MCP server endpoint into any agentic framework supporting MCP streamable http servers. Refer to this list of clients
Settings
DJANGO_MCP_GLOBAL_SERVER_CONFIG a configuration dictionnary for the global MCP server default to empty. It can include the following parmaters
name: a name for the server
instructions: global instructions
stateless : when set to 'True' the server will not manage sessions
DJANGO_MCP_AUTHENTICATION_CLASSES (default to no authentication) a list of reference to Django Rest Framework authentication classes to enfors in the main MCP view.
DJANGO_MCP_GET_SERVER_INSTRUCTIONS_TOOL (default=True) if true a tool will be offered to obtain global instruction and tools will instruct the agent to use it, as agents do not always have the MCP server global instructions included in their system prompt.
DJANGO_MCP_ENDPOINT (default="mcp") a string indicating the url endpoint used by the server. If you want it to have a trailing slash, for example, set it to "mcp/"
Roadmap
β Stateless streamable HTTP transport (implemented)
π STDIO transport integration for dev configuration (ex. Claude Desktop)
π ****
π Stateful streamable HTTP transport using Django sessions
π SSE endpoint integration (requires ASGI)
π Improved error management and logging
Issues
If you encounter bugs or have feature requests, please open an issue on GitHub Issues.
License
MIT License.