Skip to content

๐Ÿค 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

git clone https://github.com/7tg/django-admin-mcp.git
cd django-admin-mcp

๐Ÿ“ฆ Install Dependencies

Using uv (recommended):

uv sync --all-extras

Using pip:

pip install -e ".[dev]"

๐Ÿ”ง Set Up Pre-commit Hooks

pre-commit install

This ensures code quality checks run before each commit.


๐Ÿงช Running Tests

โ–ถ๏ธ Run All Tests

pytest

๐Ÿ“Š Run with Coverage

pytest --cov=django_admin_mcp --cov-report=html
open htmlcov/index.html

๐ŸŽฏ 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:

# Install a specific Django version
pip install "django==4.2.*"
pytest

โœ… Code Quality

๐Ÿ” Linting

We use Ruff for linting:

ruff check .

Auto-fix issues:

ruff check --fix .

๐ŸŽจ Formatting

ruff format .

๐Ÿท๏ธ Type Checking

mypy django_admin_mcp

๐Ÿ”„ All Checks

Run all checks at once:

pre-commit run --all-files

๐Ÿ“‚ 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

  1. Fork the repository
  2. Create a feature branch from main:
    git checkout -b feature/my-feature
    
  3. Make your changes
  4. 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

  1. 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))]
  1. Register in tools/registry.py:
HANDLERS = {
    # ...
    "my_operation": handle_my_operation,
}
  1. Add tool schema generation if needed

  2. Write tests in tests/

๐Ÿ› ๏ธ Adding a New Tool

  1. Define the tool schema in tools/registry.py
  2. Implement the handler
  3. Add comprehensive tests
  4. 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:

@pytest.fixture
def article_factory():
    return ArticleFactory

๐Ÿ“– Documentation

๐Ÿ”ง Building Docs Locally

pip install mkdocs mkdocs-material
mkdocs serve

Visit http://localhost:8000 to preview.

๐Ÿ“‚ Documentation Structure

  • docs/getting-started/ โ€” Installation and setup
  • docs/guide/ โ€” User guides
  • docs/tools/ โ€” Tool reference
  • docs/examples/ โ€” Examples and use cases
  • docs/reference/ โ€” API and settings reference

๐Ÿš€ Release Process

Releases are managed by maintainers:

  1. Update version in pyproject.toml
  2. Update CHANGELOG.md
  3. Create release tag
  4. CI publishes to PyPI

๐Ÿ’ฌ Getting Help


๐Ÿค Code of Conduct

Be respectful and constructive. We're all here to build something great together.


Thank you for contributing!