Django MCP Server

Local setup required. This server has to be cloned and prepared on your machine before you register it in Claude Code.
1

Set the server up locally

Run this once to clone and prepare the server before adding it to Claude Code.

Run in terminal
pip install django-mcp-server
2

Register it in Claude Code

After the local setup is done, run this command to point Claude Code at the built server.

Run in terminal
claude mcp add django-mcp-server -- python "<FULL_PATH_TO_DJANGO_MCP_SERVER>/dist/index.js" mcp_inspect

Replace <FULL_PATH_TO_DJANGO_MCP_SERVER>/dist/index.js with the actual folder you prepared in step 1.

README.md

An implementation of the Model Context Protocol for Django applications.

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

pip install django-mcp-server

Or directly from GitHub:

pip install git+https://github.com/omarbenhamid/django-mcp-server.git

2️⃣ Configure Django

βœ… Add mcp_server to your INSTALLED_APPS:

INSTALLED_APPS = [
    # your apps...
    'mcp_server',
]

βœ… Add the MCP endpoint to your urls.py:

from django.urls import path, include

urlpatterns = [
    # your urls...
    path("", include('mcp_server.urls')),
]

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 :

from mcp_server import ModelQueryToolset
from .models import *

class BirdQueryTool(ModelQueryToolset):
    model = Bird

    def get_queryset(self):
        """self.request can be used to filter the queryset"""
        return super().get_queryset().filter(location__isnull=False)

class LocationTool(ModelQueryToolset):
    model = Location

class CityTool(ModelQueryToolset):
    model = City

Or create a sub class of MCPToolset to publish generic methods (private _ methods are not published)

Example:

from mcp_server import MCPToolset
from django.core.mail import send_mail

class MyAITools(MCPToolset):
    def add(self, a: int, b: int) -> list[dict]:
        """A service to add two numbers together"""
        return a+b

    def send_email(self, to_email: str, subject: str, body: str):
        """ A tool to send emails"""

        send_mail(
             subject=subject,
             message=body,
             from_email='your_email@example.com',
             recipient_list=[to_email],
             fail_silently=False,
         )

Verify with MCP Inspect

Use the management commande mcp_inspect to ensure your tools are correctly declared :

python manage.py mcp_inspect

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 :

from mcp.client.streamable_http import streamablehttp_client
from mcp import ClientSession

async def main():
    # Connect to a streamable HTTP server
    async with streamablehttp_client("http://localhost:8000/mcp") as (
        read_stream,
        write_stream,
        _,
    ):
        # Create a session using the client streams
        async with ClientSession(read_stream, write_stream) as session:
            # Initialize the connection
            await session.initialize()
            # Call a tool
            tool_result = await session.call_tool("get_alerts", {"state": "NY"})
            print(tool_result)

if __name__ == "__main__":
    import asyncio
    asyncio.run(main())

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 :

Tools (2)

ModelQueryToolsetExposes Django models for AI agents to query data safely.
MCPToolsetPublishes generic Python methods as tools for AI agents.

Environment Variables

DJANGO_MCP_AUTHENTICATION_CLASSESAuthentication classes for securing the MCP endpoint in production.

Configuration

claude_desktop_config.json
{ "mcpServers": { "django": { "command": "python", "args": ["manage.py", "mcp_inspect"] } } }

Try it

β†’Query the Bird model to find all birds located in the current database.
β†’Use the MyAITools to send an email to support@example.com with the subject 'System Update'.
β†’List all available tools exposed by the Django application.
β†’Add the numbers 50 and 25 using the available math tool.

Frequently Asked Questions

What are the key features of Django MCP Server?

Expose Django models as MCP tools with minimal code.. Convert Django Rest Framework APIs to MCP tools via annotations.. Compatible with both WSGI and ASGI deployment environments.. Supports custom toolsets for publishing generic Python logic..

What can I use Django MCP Server for?

Allowing AI agents to perform CRUD operations on internal Django database models.. Enabling Claude to trigger business logic like sending emails directly from a Django app.. Integrating Django-based REST APIs into AI-driven workflows and automation agents.. Providing a secure interface for AI agents to query application-specific data..

How do I install Django MCP Server?

Install Django MCP Server by running: pip install django-mcp-server

What MCP clients work with Django MCP Server?

Django MCP Server works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep Django MCP Server docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare