← Back to Pull requests

Phase 2: autodiscover per-app mcp.py modules #17

Closed
unknown closed this pull request without merging on Jul 29, 2026 10:54 UTC
View on GitHub
unknown unknown commented on Jul 29, 2026 10:46 UTC
Author

The first Django-ergonomics layer: apps contribute tools the way they contribute admin models. Recorded in ADR-0009.

# settings.py
INSTALLED_APPS = [..., "django_stateless_mcp"]

# myapp/mcp.py
from project.mcp import server

@server.tool()
def lookup_order(order_id: int) -> str: ...

Design: import, don't register

The scope revision against the installed SDK drives this. Registration already exists — @server.tool() is public SDK API — so the only genuine gap was that nothing imports an app's mcp.py. The implementation is therefore one AppConfig.ready() calling Django's own autodiscover_modules("mcp"), the same mechanism django.contrib.admin uses. No package registry, no default server, no new API surface beyond the app config itself.

  • App-relative imports (myapp.mcp) — no collision with the SDK's top-level mcp package.

  • Apps without an mcp.py are skipped; one that fails to import raises at startup rather than being swallowed.

  • The explicit mcp_view(server) contract from ADR-0007 is unchanged — autodiscovery is opt-in sugar via INSTALLED_APPS.

  • The tool registry is populated at import time and read per request: configuration like the URLconf, not the request-spanning mutable state the statelessness invariant forbids.
  • The proof-shaped test

    Nothing in the suite or URLconf imports tests/mcp.py — so its multiply tool can only appear in tools/list if autodiscovery imported it. That assertion plus a call test (multiply(6,7) → 42) are the new coverage; a Phase 1 assertion that the tool list is exactly ["add"] was updated to membership, with the exact-set assertion now owned by the autodiscovery test.

    Test plan

  • 11 tests pass on Django 5.2.16 and 6.0.7 via tox

  • Conformance suite re-run with the second tool present → baseline unchanged, exit 0

  • mypy strict, pre-commit, mkdocs --strict all clean

  • CI green (including the Conformance workflow — waiting for its actual conclusion this time, not just the gate verdict)
  • Diff: 254 lines (+190 / -64) across 3 files Reviewer: BenA-SA Review duration: 7m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 254 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.332
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #17"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.1% (MEDIUM) · Higher = larger blast radius
    39.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.4% · Safe to merge
    15.4%