๐ค Contributing¶
Thank you for your interest in contributing to Django Admin MCP! This guide will help you get started.
๐ ๏ธ Development Setup¶
๐ Prerequisites¶
- Python 3.10 or higher
- Git
- uv, pip, or another Python package manager
๐ฅ Clone the Repository¶
๐ฆ Install Dependencies¶
Using uv (recommended):
Using pip:
๐ง Set Up Pre-commit Hooks¶
This ensures code quality checks run before each commit.
๐งช Running Tests¶
โถ๏ธ Run All Tests¶
๐ Run with Coverage¶
๐ฏ Run Specific Tests¶
# Run a specific test file
pytest tests/test_crud.py
# Run a specific test
pytest tests/test_crud.py::test_list_articles
# Run tests matching a pattern
pytest -k "test_create"
๐ Test Against Multiple Django Versions¶
The CI runs tests against Django 3.2, 4.0, 4.1, 4.2, and 5.0. To test locally:
โ Code Quality¶
๐ Linting¶
We use Ruff for linting:
Auto-fix issues:
๐จ Formatting¶
๐ท๏ธ Type Checking¶
๐ All Checks¶
Run all checks at once:
๐ Project Structure¶
django-admin-mcp/
โโโ django_admin_mcp/ # Main package
โ โโโ __init__.py # Package exports
โ โโโ mixin.py # MCPAdminMixin
โ โโโ models.py # MCPToken model
โ โโโ views.py # HTTP endpoint
โ โโโ admin.py # Django admin for tokens
โ โโโ urls.py # URL configuration
โ โโโ handlers/ # Tool handlers
โ โ โโโ base.py # Shared utilities
โ โ โโโ crud.py # CRUD operations
โ โ โโโ actions.py # Admin actions
โ โ โโโ meta.py # Model introspection
โ โ โโโ relations.py # Relationships
โ โ โโโ decorators.py # Permission decorators
โ โโโ protocol/ # MCP protocol
โ โ โโโ types.py # Pydantic models
โ โ โโโ jsonrpc.py # JSON-RPC handling
โ โ โโโ errors.py # Error definitions
โ โโโ tools/ # Tool registry
โ โโโ registry.py # Tool generation
โโโ tests/ # Test suite
โโโ docs/ # Documentation
โโโ example/ # Example Django project
โโโ pyproject.toml # Project configuration
๐ Making Changes¶
๐ฟ Branching Strategy¶
- Fork the repository
- Create a feature branch from
main: - Make your changes
- Push and create a pull request
๐ฌ Commit Messages¶
Use clear, descriptive commit messages:
Add support for custom field serializers
- Add FieldSerializer protocol
- Implement JSONFieldSerializer for JSONField
- Update tests for new functionality
๐ Pull Request Guidelines¶
- Include a clear description of changes
- Add tests for new functionality
- Update documentation if needed
- Ensure all checks pass
- Keep changes focused and atomic
โ Adding Features¶
๐ง Adding a New Handler¶
- Create or update handler in
handlers/:
handlers/myhandler.py
async def handle_my_operation(
model_name: str,
arguments: dict[str, Any],
request: HttpRequest
) -> list[TextContent]:
# Implementation
return [TextContent(text=json.dumps(result))]
- Register in
tools/registry.py:
-
Add tool schema generation if needed
-
Write tests in
tests/
๐ ๏ธ Adding a New Tool¶
- Define the tool schema in
tools/registry.py - Implement the handler
- Add comprehensive tests
- Document in
docs/tools/
๐งช Testing Guidelines¶
๐ Test Structure¶
import pytest
from django_admin_mcp.handlers.crud import handle_list
@pytest.mark.django_db
class TestListHandler:
def test_list_returns_results(self, article_factory):
# Arrange
article_factory.create_batch(5)
# Act
result = await handle_list("article", {"limit": 10}, request)
# Assert
data = json.loads(result[0].text)
assert len(data["results"]) == 5
๐ Test Categories¶
- Unit tests โ Test individual functions/methods
- Integration tests โ Test handler + database
- Permission tests โ Test authorization logic
- Edge case tests โ Test error handling
๐ญ Fixtures¶
Use factory_boy for test data:
๐ Documentation¶
๐ง Building Docs Locally¶
Visit http://localhost:8000 to preview.
๐ Documentation Structure¶
docs/getting-started/โ Installation and setupdocs/guide/โ User guidesdocs/tools/โ Tool referencedocs/examples/โ Examples and use casesdocs/reference/โ API and settings reference
๐ Release Process¶
Releases are managed by maintainers:
- Update version in
pyproject.toml - Update
CHANGELOG.md - Create release tag
- CI publishes to PyPI
๐ฌ Getting Help¶
- Issues โ GitHub Issues
- Discussions โ GitHub Discussions
๐ค Code of Conduct¶
Be respectful and constructive. We're all here to build something great together.
Thank you for contributing!