Adapt Django¶
Adapt Django — mvp.adapt_django
Cluster: Code Intelligence | Type: component | MCP Tools: 44
Overview¶
Django code-generation block that produces complete project scaffolds, apps, models, views, URLs, admin registrations, templates, forms, serializers, viewsets, migrations, and test files — all as in-memory strings with no runtime Django dependency. Supports natural-language-to-model synthesis via nl_to_models, static code validation, and optional file writing to disk when base_dir is set. Design tokens can be injected as CSS variables to align generated templates with a design system.
Launch readiness
adapt_django is pilot-ready for the launch-plan goal of helping a user scaffold and validate a local Django project through MCP. Generated projects load local .env files, the MCP server uses persistent SQLite state via DJANGO_MCP_DB_PATH, and the component test suite plus a generated-project manage.py check smoke test pass.
Treat it as pilot-ready, not enterprise-ready. Repository-wide dependency pinning and a full clean-machine MCP install test still need to be completed before making stronger production or enterprise support claims.
When to use:
- Scaffolding a Django project or app from a structured model and view specification
- Converting a natural-language description of a data model into Django model code
- Generating REST API viewsets and serializers as part of an automated backend-generation pipeline
- Producing migration files and settings configurations for different databases
Example:
from mvp.adapt_django import AdaptDjangoBlock, DjangoInput, ModelSpec, FieldSpec
block = AdaptDjangoBlock(name="django")
result = block.infer(DjangoInput(
operation="generate_models",
app_name="blog",
models=[ModelSpec(
name="Post",
fields=[FieldSpec(name="title", field_type="CharField", max_length=200),
FieldSpec(name="body", field_type="TextField")],
str_field="title",
)],
))
# result.value.files → list of GeneratedFile with path and content
Works well with: adapt_webpage, meta_programming, adapt_ui_design
Public API¶
DjangoModelRecommendation¶
Validated Django data-model recommendation decision record.
| Field | Type | Default |
|---|---|---|
models | tuple[ModelSpec, ...] | required |
source | str | required |
app_name | str | '' |
rationale | str | '' |
notes | tuple[str, ...] | () |
Methods:
model_count() -> int¶
field_count() -> int¶
to_metadata() -> dict[str, Any]¶
LLMDjangoRuntime¶
Provider-neutral django-model recommendation runtime over G6's LLM caller.
Constructor:
| Parameter | Type | Default |
|---|---|---|
llm | LLMCaller \| None | None |
Methods:
synthesize(nl_description: str) -> Result[list[ModelSpec]]¶
DjangoPlanner¶
Runtime-first facade with the deterministic floor as honest fallback.
Constructor:
| Parameter | Type | Default |
|---|---|---|
runtime | DjangoRuntime \| None | None |
Methods:
recommend_models(nl_description: str, app_name: str = '') -> DjangoModelRecommendation¶
AdaptDjangoBlock(AIBlock[DjangoInput, DjangoOutput, dict])¶
Django project and app code generator.
| Field | Type | Default |
|---|---|---|
name | str | 'adapt_django' |
resource_bounds | ResourceBounds \| None | None |
Methods:
infer(data: DjangoInput) -> Result[DjangoOutput]¶
NLModelSynthesizer¶
Convert a natural-language description into a list of Django ModelSpecs.
Constructor:
| Parameter | Type | Default |
|---|---|---|
claude_block | Any | None |
ollama_fn | Callable[[str], str] \| None | None |
Methods:
synthesize(nl_description: str) -> Result[list[ModelSpec]]¶
RunnerResult¶
Result of a runner operation.
| Field | Type | Default |
|---|---|---|
success | bool | required |
output | str | '' |
error | str | '' |
returncode | int | 0 |
setup_script_path | str | '' |
DjangoProjectRunner¶
Runs subprocess operations against a generated Django project.
Constructor:
| Parameter | Type | Default |
|---|---|---|
base_dir | str | required |
python_path | str | '' |
Methods:
apply_migrations(timeout: int = 120) -> RunnerResult¶
Run
manage.py migrate --no-inputin the project directory.
validate_project(deploy: bool = True, timeout: int = 30) -> RunnerResult¶
Run
manage.py checkand optionallymanage.py check --deploy.
FieldSpec(BaseModel)¶
Specification for a single Django model field.
| Field | Type | Default |
|---|---|---|
name | str | '' |
field_type | str | 'CharField' |
max_length | int | 255 |
null | bool | False |
blank | bool | False |
unique | bool | False |
default | str | '' |
choices | list[tuple[str, str]] | [] |
related_model | str | '' |
help_text | str | '' |
verbose_name | str | '' |
on_delete | str | 'CASCADE' |
ModelSpec(BaseModel)¶
Specification for a Django model class.
| Field | Type | Default |
|---|---|---|
name | str | '' |
fields | list[FieldSpec] | [] |
meta_ordering | list[str] | [] |
str_field | str | '' |
abstract | bool | False |
ViewSpec(BaseModel)¶
Specification for a Django class-based view.
| Field | Type | Default |
|---|---|---|
name | str | '' |
view_type | str | 'list' |
model_name | str | '' |
template_name | str | '' |
fields | list[str] | [] |
login_required | bool | False |
paginate_by | int | 0 |
filter_fields | list[str] | [] |
GeneratedFile(BaseModel)¶
A single generated file with path and content.
| Field | Type | Default |
|---|---|---|
path | str | '' |
content | str | '' |
file_type | str | '' |
DjangoInput(BaseModel)¶
Input to AdaptDjangoBlock.
| Field | Type | Default |
|---|---|---|
operation | Literal['scaffold_project', 'scaffold_app', 'generate_models', 'generate_views', 'generate_urls', 'generate_admin', 'generate_templates', 'generate_forms', 'generate_serializers', 'generate_viewsets', 'generate_settings', 'configure_auth', 'generate_tests', 'nl_to_models', 'validate_code', 'generate_migrations', 'write_project', 'apply_migrations', 'generate_setup_script'] | Field(default='scaffold_project', validation_alias=AliasChoices('operation', 'op')) |
project_name | str | '' |
app_name | str | '' |
models | list[ModelSpec] | [] |
views | list[ViewSpec] | [] |
auth_backend | str | 'django' |
style | str | 'monolith' |
design_tokens_css | str | '' |
nl_description | str | '' |
code | str | '' |
database | str | 'sqlite3' |
base_dir | str | '' |
DjangoOutput(BaseModel)¶
Output from AdaptDjangoBlock.
| Field | Type | Default |
|---|---|---|
operation | str | '' |
files | list[GeneratedFile] | [] |
validation_ok | bool | True |
validation_errors | list[str] | [] |
metadata | dict | {} |
degraded | bool | False |
degradation_reason | str \| None | None |
AdaptDjangoMCPBlock(AIBlock[MCPDjangoInput, MCPDjangoOutput, dict])¶
31-op Django code-generation block with SQLite persistence.
| Field | Type | Default |
|---|---|---|
name | str | 'adapt_django_mcp' |
state | dict \| None | None |
db_path | str \| None | None |
resource_bounds | ResourceBounds \| None | None |
Methods:
infer(data: MCPDjangoInput) -> Result[MCPDjangoOutput]¶
close() -> None¶
Close the underlying store connection.
MCPDjangoInput(BaseModel)¶
Input for the MCP Django block (31-op schema, 27 exposed as MCP tools).
| Field | Type | Default |
|---|---|---|
op | Literal['scaffold_project', 'scaffold_app', 'scaffold_full', 'get_project', 'list_projects', 'write_project', 'generate_setup_script', 'create_model', 'get_model', 'list_models', 'update_model', 'delete_model', 'generate_migrations', 'create_views', 'create_urls', 'create_forms', 'create_admin', 'create_templates', 'create_serializers', 'create_viewsets', 'create_api_urls', 'configure_cors', 'create_api_docs', 'configure_auth', 'generate_tests', 'validate_project', 'nl_to_models', 'generate_settings', 'apply_migrations', 'recommend_models', 'list_patterns', 'discover_capabilities', 'native_django_check', 'native_showmigrations', 'native_inspectdb', 'native_settings_summary', 'native_settings_diff', 'native_app_registry', 'native_model_registry', 'native_url_resolver', 'native_database_check', 'native_migration_state', 'native_makemigrations', 'native_manage_command'] | required |
project_name | str | '' |
app_name | str | '' |
name | str | '' |
model_name | str | '' |
fields_json | str | '[]' |
meta_ordering_json | str | '[]' |
str_field | str | '' |
abstract | bool | False |
view_type | str | 'list' |
views_json | str | '[]' |
template_name | str | '' |
view_fields_json | str | '[]' |
login_required | bool | False |
auth_backend | str | 'django' |
style | str | 'monolith' |
design_tokens_css | str | '' |
nl_description | str | '' |
code | str | '' |
database | str | 'sqlite3' |
base_dir | str | '' |
python_path | str | '' |
settings_module | str | '' |
command_name | str | '' |
command_args_json | str | '[]' |
timeout_seconds | int | 30 |
allow_writes | bool | False |
allow_database_writes | bool | False |
query | str | '' |
top_k | int | 5 |
MCPDjangoOutput(BaseModel)¶
Output from the MCP Django block.
| Field | Type | Default |
|---|---|---|
success | bool | True |
error | Any | '' |
op | str | '' |
key | str | '' |
value | Any | None |
found | bool | False |
count | int | 0 |
files | list[dict[str, str]] | [] |
summary | str | '' |
message | str | '' |
validation_ok | bool | True |
validation_errors | list[str] | [] |
metadata | dict[str, Any] | {} |
degraded | bool | False |
degradation_reason | str \| None | None |
capability_required | str \| None | None |
capability_available | bool \| None | None |
side_effect_level | str | 'read_only' |
data | Any | None |
warnings | list[str] | [] |
error_code | str | '' |
evidence | list[dict[str, Any]] | [] |
request_id | str | '' |
run_id | str | '' |
completion_state | str | 'qualified-draft' |
warning_card | dict[str, Any] | {} |
Methods:
model_post_init(__context: Any) -> None¶
DjangoStore¶
Sync SQLite store with 7 tables.
Constructor:
| Parameter | Type | Default |
|---|---|---|
db_path | str \| None | None |
Methods:
save_project(name: str, style: str = 'monolith', database: str = 'sqlite3', auth_backend: str = 'django', config_json: str = '{}') -> str¶
get_project(name: str) -> dict[str, Any] | None¶
list_projects() -> list[dict[str, Any]]¶
delete_project(name: str) -> bool¶
save_app(project_name: str, name: str, config_json: str = '{}') -> str¶
list_apps(project_name: str = '') -> list[dict[str, Any]]¶
save_model(project_name: str, app_name: str, name: str, fields_json: str = '[]', meta_ordering_json: str = '[]', str_field: str = '', abstract: bool = False) -> str¶
get_model(app_name: str, name: str) -> dict[str, Any] | None¶
list_models(app_name: str = '') -> list[dict[str, Any]]¶
delete_model(app_name: str, name: str) -> bool¶
save_view(project_name: str, app_name: str, model_name: str, view_type: str, name: str, config_json: str = '{}') -> str¶
list_views(app_name: str = '') -> list[dict[str, Any]]¶
save_template(project_name: str, app_name: str, path: str, content: str, file_type: str = 'html') -> str¶
list_templates(app_name: str = '') -> list[dict[str, Any]]¶
save_api(project_name: str, app_name: str, api_type: str, model_name: str, config_json: str = '{}') -> str¶
list_apis(app_name: str = '') -> list[dict[str, Any]]¶
count_all() -> dict[str, int]¶
save_written_project(project_name: str, base_dir: str, manifest: list[str]) -> str¶
get_written_project(project_name: str) -> dict[str, Any] | None¶
list_written_projects() -> list[dict[str, Any]]¶
text_search(query: str, top_k: int = 5) -> list[dict[str, Any]]¶
close() -> None¶
Close the database connection.
Functions¶
agentic_planner_enabled(default_enabled: bool = True) -> bool¶
Decide whether the agentic django-model planner should be used.
recommend_models_floor(nl_description: str, app_name: str = '') -> list[ModelSpec]¶
Deterministic regex/heuristic NL->models selector (the demoted floor).
MCP Tools¶
| Operation | Source |
|---|---|
scaffold_project | django_mcp |
scaffold_app | django_mcp |
scaffold_full | django_mcp |
get_project | django_mcp |
list_projects | django_mcp |
write_project | django_mcp |
generate_setup_script | django_mcp |
create_model | django_mcp |
get_model | django_mcp |
list_models | django_mcp |
update_model | django_mcp |
delete_model | django_mcp |
generate_migrations | django_mcp |
create_views | django_mcp |
create_urls | django_mcp |
create_forms | django_mcp |
create_admin | django_mcp |
create_templates | django_mcp |
create_serializers | django_mcp |
create_viewsets | django_mcp |
create_api_urls | django_mcp |
configure_cors | django_mcp |
create_api_docs | django_mcp |
configure_auth | django_mcp |
generate_tests | django_mcp |
validate_project | django_mcp |
nl_to_models | django_mcp |
generate_settings | django_mcp |
apply_migrations | django_mcp |
recommend_models | django_mcp |
list_patterns | django_mcp |
discover_capabilities | django_mcp |
native_django_check | django_mcp |
native_showmigrations | django_mcp |
native_inspectdb | django_mcp |
native_settings_summary | django_mcp |
native_settings_diff | django_mcp |
native_app_registry | django_mcp |
native_model_registry | django_mcp |
native_url_resolver | django_mcp |
native_database_check | django_mcp |
native_migration_state | django_mcp |
native_makemigrations | django_mcp |
native_manage_command | django_mcp |