{"id":27696,"library":"django-mcp-server","title":"Django MCP Server","description":"Django MCP Server is a Django extension that enables AI Agents to interact with Django Apps through the Model Context Protocol (MCP). It works on both WSGI and ASGI, providing a simple way to expose Django models and views as tools for AI agents. Current version 0.5.7, release cadence is irregular as the library is still in early development.","status":"active","version":"0.5.7","language":"python","source_language":"en","source_url":"https://github.com/Intuit/django-mcp-server","tags":["django","mcp","model-context-protocol","ai","agents","llm"],"install":[{"cmd":"pip install django-mcp-server","lang":"bash","label":"Install via pip"},{"cmd":"pip install django-mcp-server[uvicorn]","lang":"bash","label":"Install with ASGI (recommended for production)"}],"dependencies":[{"reason":"Required, Django >=3.2","package":"django","optional":false},{"reason":"Used for data validation in MCP schema","package":"pydantic","optional":false},{"reason":"Optional, required for ASGI mode","package":"uvicorn","optional":true}],"imports":[{"note":"Incorrect module name; the package is 'django_mcp_server'","wrong":"from django_mcp import MCPServer","symbol":"MCPServer","correct":"from django_mcp_server import MCPServer"},{"note":"tools is a decorator in the decorators module","wrong":"from django_mcp_server import tools","symbol":"tools","correct":"from django_mcp_server.decorators import tools"},{"note":"","wrong":null,"symbol":"mcp_tool","correct":"from django_mcp_server.decorators import mcp_tool"}],"quickstart":{"code":"# In your Django app's models.py or mcp.py\nfrom django_mcp_server import MCPServer\nfrom django_mcp_server.decorators import tools\n\nmcp_server = MCPServer()\n\n@tools.register\ndef get_product_count(request) -> int:\n    \"\"\"Return the number of products in the database.\"\"\"\n    from myapp.models import Product\n    return Product.objects.count()\n\n# In urls.py\nfrom django.urls import path\nfrom . import mcp\n\nurlpatterns = [\n    path('mcp/', mcp.mcp_server.urls),\n]\n\n# Then run with ASGI (uvicorn) or WSGI\n# uvicorn myproject.asgi:application --reload","lang":"python","description":"Create an MCP endpoint at /mcp/ exposing Django ORM tools."},"warnings":[{"fix":"Change imports to 'from django_mcp_server import MCPServer'","message":"In version 0.5.x, the MCPServer class moved from django_mcp_server.server to django_mcp_server directly. If you import from the old path, it will break.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"Remove name argument; if you need a custom name, use the @mcp_tool decorator instead","message":"The @tools.register decorator signature changed in v0.5.4: the 'name' parameter is deprecated. Use the function name directly.","severity":"deprecated","affected_versions":">=0.5.4"},{"fix":"Ensure the tool function signature is 'def my_tool(request, ...)'","message":"When using the @tools.register decorator, the first argument must be a request object (HttpRequest), not a plain dictionary. Many users mistakenly pass a dict from an external API call.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use a tool like curl with -X POST -H 'Content-Type: application/json'","message":"The MCP endpoint expects POST requests with Content-Type application/json. Some users try to access the endpoint via GET, resulting in a 405 Method Not Allowed error.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Run 'pip install django-mcp-server' and ensure you imported 'django_mcp_server' (underscore, not hyphen).","cause":"Package not installed or wrong import path.","error":"ModuleNotFoundError: No module named 'django_mcp_server'"},{"fix":"Change import to 'from django_mcp_server.decorators import tools'","cause":"tools is a decorator in the decorators submodule, not directly on the package.","error":"AttributeError: module 'django_mcp_server' has no attribute 'tools'"},{"fix":"Use '@tools.register' without parentheses if no arguments, or '@tools.register(name=\"...\")' with parentheses if needed.","cause":"The @tools.register decorator was used without parentheses, but the syntax requires parentheses when passing arguments (e.g., name).","error":"TypeError: register() missing 1 required positional argument: 'func'"},{"fix":"Ensure the MCP server is mounted inside Django's URLconf so that request objects are properly constructed.","cause":"The tool function received a non-request object, likely from an external HTTP call that bypassed Django middleware.","error":"RuntimeError: MCP endpoint requires a Django HttpRequest object."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}