A Django integration for the Model Context Protocol (MCP) that enables AI-powered assistance for Django applications.
This project integrates Django with the Model Context Protocol (MCP) and Claude AI to create an intelligent assistant that can answer questions about your Django application. The assistant can access model schemas, application documentation, and perform database queries.
- AI-Powered Chat Interface: Web interface for interacting with the assistant
- REST API: API endpoint for programmatic access to the assistant
- Django Model Integration: Access to Django model schemas and data
- Documentation Access: Retrieval of application documentation
The project consists of several components:
- MCP Server: Provides tools and resources for the AI assistant
- MCP Client: Connects to the MCP server and Claude API
- Django Integration: Bridges Django and the MCP service
- Web Interface: User interface for interacting with the assistant
- Clone the repository
- Install dependencies:
pip install -r requirements.txt - Set up environment variables:
ANTHROPIC_API_KEY=your_api_key - Add the URLs to your Django project's urls.py:
urlpatterns = [ # ... your existing URLs path('', include('mcp_service.urls')), ]
Access the chat interface at /chat/ to interact with the assistant through a web interface.
Send POST requests to /api/chat/ with the following JSON payload:
{
"query": "Your question here",
"conversation_history": [] // Optional previous conversation
}Add new tools to the MCP server in mcp_server.py:
@mcp.tool()
def your_tool_function(param1: str, param2: int = 0) -> Dict[str, Any]:
"""
Your tool description
Args:
param1: Description of param1
param2: Description of param2
Returns:
Result of the tool operation
"""
# Your implementation here
return {"result": "value"}Add new resources to the MCP server in mcp_server.py:
@mcp.resource("resource://{param}")
def your_resource_function(param: str) -> Any:
"""
Your resource description
Args:
param: Description of param
Returns:
Resource data
"""
# Your implementation here
return {"data": "value"}For detailed documentation, see docs.md.
MIT
- Python 3.8+
- Django 4.0+
- Anthropic API key