django-admin-api-mcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django_admin_api_mcp-0.1.0/.gitignore +12 -0
- django_admin_api_mcp-0.1.0/CHANGELOG.md +345 -0
- django_admin_api_mcp-0.1.0/LICENSE +21 -0
- django_admin_api_mcp-0.1.0/PKG-INFO +280 -0
- django_admin_api_mcp-0.1.0/README.md +249 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/__init__.py +9 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/actions.py +197 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/admin.py +131 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/apps.py +10 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/auth.py +62 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/changelist.py +261 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/checks.py +35 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/confirm.py +97 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/contrib/__init__.py +1 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/contrib/search/__init__.py +0 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/contrib/search/apps.py +21 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/contrib/search/backend.py +121 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/contrib/search/checks.py +12 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/contrib/search/conf.py +42 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/contrib/search/engines/__init__.py +0 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/contrib/search/engines/base.py +99 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/contrib/search/engines/db.py +265 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/contrib/search/fold.py +41 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/contrib/search/indexer.py +364 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/contrib/search/management/__init__.py +0 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/contrib/search/management/commands/__init__.py +0 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/contrib/search/management/commands/rebuild_search_index.py +29 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/contrib/search/management/commands/search_index.py +25 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/contrib/search/migrations/0001_initial.py +83 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/contrib/search/migrations/__init__.py +0 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/contrib/search/models.py +43 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/contrib/subadmin.py +37 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/custom_views.py +471 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/decorators.py +26 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/deletion.py +58 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/detail.py +115 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/encoders.py +72 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/errors.py +82 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/jsonschema.py +225 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/management/__init__.py +0 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/management/commands/__init__.py +0 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/management/commands/create_api_token.py +40 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/management/commands/mcp_serve.py +86 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/management/commands/migrate_from_admin_api.py +153 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/mcp/__init__.py +7 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/mcp/bridge.py +71 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/mcp/handlers.py +771 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/mcp/resolve.py +410 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/mcp/server.py +76 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/mcp/sites.py +284 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/mcp/stdio.py +53 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/mcp/tools.py +84 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/mcp/views.py +74 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/middleware.py +18 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/migrations/0001_initial.py +40 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/migrations/0002_mcp_confirmation.py +27 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/migrations/0003_mcp_user_instructions.py +28 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/migrations/__init__.py +0 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/mixins.py +173 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/models.py +145 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/nested.py +122 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/resolver.py +95 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/scopes.py +142 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/sensitive.py +67 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/services.py +652 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/sites.py +242 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/templates/admin_api_mcp/token_created.html +17 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/views/__init__.py +0 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/views/changelist.py +70 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/views/custom.py +33 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/views/detail.py +50 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/views/nested.py +73 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/views/registry.py +15 -0
- django_admin_api_mcp-0.1.0/admin_api_mcp/writes.py +530 -0
- django_admin_api_mcp-0.1.0/docs/DESIGN.md +1155 -0
- django_admin_api_mcp-0.1.0/docs/architecture.md +124 -0
- django_admin_api_mcp-0.1.0/docs/confirmation.md +171 -0
- django_admin_api_mcp-0.1.0/docs/connect-claude-code.md +210 -0
- django_admin_api_mcp-0.1.0/docs/custom-views.md +61 -0
- django_admin_api_mcp-0.1.0/docs/mcp.md +189 -0
- django_admin_api_mcp-0.1.0/docs/nested-admins.md +19 -0
- django_admin_api_mcp-0.1.0/docs/oauth.md +297 -0
- django_admin_api_mcp-0.1.0/docs/rest-api.md +155 -0
- django_admin_api_mcp-0.1.0/docs/roadmap.md +33 -0
- django_admin_api_mcp-0.1.0/docs/validation.md +76 -0
- django_admin_api_mcp-0.1.0/pyproject.toml +83 -0
- django_admin_api_mcp-0.1.0/tests/__init__.py +0 -0
- django_admin_api_mcp-0.1.0/tests/conftest.py +88 -0
- django_admin_api_mcp-0.1.0/tests/search_site.py +30 -0
- django_admin_api_mcp-0.1.0/tests/settings.py +40 -0
- django_admin_api_mcp-0.1.0/tests/settings_bigautofield.py +5 -0
- django_admin_api_mcp-0.1.0/tests/settings_file_db.py +7 -0
- django_admin_api_mcp-0.1.0/tests/settings_postgres.py +16 -0
- django_admin_api_mcp-0.1.0/tests/subadmin_site.py +48 -0
- django_admin_api_mcp-0.1.0/tests/subadmin_urls.py +8 -0
- django_admin_api_mcp-0.1.0/tests/test_actions.py +199 -0
- django_admin_api_mcp-0.1.0/tests/test_changelist.py +215 -0
- django_admin_api_mcp-0.1.0/tests/test_contracts.py +211 -0
- django_admin_api_mcp-0.1.0/tests/test_custom_views.py +485 -0
- django_admin_api_mcp-0.1.0/tests/test_detail.py +149 -0
- django_admin_api_mcp-0.1.0/tests/test_files.py +318 -0
- django_admin_api_mcp-0.1.0/tests/test_history.py +225 -0
- django_admin_api_mcp-0.1.0/tests/test_jsonschema.py +165 -0
- django_admin_api_mcp-0.1.0/tests/test_mcp_conformance.py +210 -0
- django_admin_api_mcp-0.1.0/tests/test_mcp_http.py +184 -0
- django_admin_api_mcp-0.1.0/tests/test_mcp_instructions.py +117 -0
- django_admin_api_mcp-0.1.0/tests/test_mcp_resolve.py +643 -0
- django_admin_api_mcp-0.1.0/tests/test_mcp_stdio.py +145 -0
- django_admin_api_mcp-0.1.0/tests/test_mcp_tools.py +588 -0
- django_admin_api_mcp-0.1.0/tests/test_mcp_wording.py +493 -0
- django_admin_api_mcp-0.1.0/tests/test_mcp_write_safety.py +784 -0
- django_admin_api_mcp-0.1.0/tests/test_migrate_from_admin_api.py +187 -0
- django_admin_api_mcp-0.1.0/tests/test_migrations.py +17 -0
- django_admin_api_mcp-0.1.0/tests/test_nested.py +48 -0
- django_admin_api_mcp-0.1.0/tests/test_one_flow.py +372 -0
- django_admin_api_mcp-0.1.0/tests/test_resolver.py +107 -0
- django_admin_api_mcp-0.1.0/tests/test_routes.py +74 -0
- django_admin_api_mcp-0.1.0/tests/test_scopes.py +287 -0
- django_admin_api_mcp-0.1.0/tests/test_search_engines.py +282 -0
- django_admin_api_mcp-0.1.0/tests/test_search_fold.py +41 -0
- django_admin_api_mcp-0.1.0/tests/test_search_index.py +580 -0
- django_admin_api_mcp-0.1.0/tests/test_search_postgres.py +83 -0
- django_admin_api_mcp-0.1.0/tests/test_search_resolve.py +329 -0
- django_admin_api_mcp-0.1.0/tests/test_sensitive.py +273 -0
- django_admin_api_mcp-0.1.0/tests/test_services.py +94 -0
- django_admin_api_mcp-0.1.0/tests/test_site.py +183 -0
- django_admin_api_mcp-0.1.0/tests/test_subadmin.py +372 -0
- django_admin_api_mcp-0.1.0/tests/test_tokens.py +155 -0
- django_admin_api_mcp-0.1.0/tests/test_user_admin.py +146 -0
- django_admin_api_mcp-0.1.0/tests/test_writes.py +380 -0
- django_admin_api_mcp-0.1.0/tests/testapp/__init__.py +0 -0
- django_admin_api_mcp-0.1.0/tests/testapp/admin.py +226 -0
- django_admin_api_mcp-0.1.0/tests/testapp/files_admin.py +24 -0
- django_admin_api_mcp-0.1.0/tests/testapp/migrations/0001_initial.py +63 -0
- django_admin_api_mcp-0.1.0/tests/testapp/migrations/0002_payment.py +30 -0
- django_admin_api_mcp-0.1.0/tests/testapp/migrations/0003_party.py +35 -0
- django_admin_api_mcp-0.1.0/tests/testapp/migrations/0004_search_pk_types.py +35 -0
- django_admin_api_mcp-0.1.0/tests/testapp/migrations/0005_document.py +33 -0
- django_admin_api_mcp-0.1.0/tests/testapp/migrations/__init__.py +0 -0
- django_admin_api_mcp-0.1.0/tests/testapp/models.py +128 -0
- django_admin_api_mcp-0.1.0/tests/testapp/totals_admin.py +36 -0
- django_admin_api_mcp-0.1.0/tests/urls.py +16 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (2026-11-30)
|
|
4
|
+
|
|
5
|
+
First release outside the alpha series. Changes since 0.1.0a3:
|
|
6
|
+
|
|
7
|
+
### Breaking changes
|
|
8
|
+
|
|
9
|
+
- **The package and its app labels are renamed `admin_api` -> `admin_api_mcp`.** The
|
|
10
|
+
unrelated `django-admin-api` package on PyPI installs `admin_api`; both now install together.
|
|
11
|
+
- Code and settings: `admin_api` becomes `admin_api_mcp` in `INSTALLED_APPS`, `MIDDLEWARE`,
|
|
12
|
+
dotted paths (`ADMIN_API_SEARCH` engine `BACKEND`s), imports and `@admin_api_mcp.view` /
|
|
13
|
+
`@admin_api_mcp.display`. Loggers: `admin_api_mcp.mcp`, `admin_api_mcp.mcp.audit`,
|
|
14
|
+
`admin_api_mcp.search`. A project that sets `ADMIN_API_TOKEN_MODEL = "admin_api.ApiToken"`
|
|
15
|
+
sets `"admin_api_mcp.ApiToken"` or drops the setting.
|
|
16
|
+
- Labels: `admin_api` -> `admin_api_mcp`, `admin_api_search` -> `admin_api_mcp_search`. Tables,
|
|
17
|
+
migration history, content types, permissions, admin URLs (`/admin/admin_api_mcp/...`),
|
|
18
|
+
`app_label.model` names in REST and MCP, and check ids (`admin_api_mcp.E001`,
|
|
19
|
+
`admin_api_mcp_search.W001`) follow. Unchanged: the `ADMIN_API_*` settings names and the
|
|
20
|
+
default URL namespace `admin_api`.
|
|
21
|
+
- Upgrade an existing database: after the code and settings change (including project
|
|
22
|
+
migrations that name `admin_api`, such as `("admin_api", "0002_mcp_confirmation")` or
|
|
23
|
+
`to="admin_api.apitoken"`), run
|
|
24
|
+
`manage.py migrate_from_admin_api --dry-run`, then `manage.py migrate_from_admin_api`, then
|
|
25
|
+
`manage.py migrate`. The command migrates the new apps as far as the old ones were, copies
|
|
26
|
+
the rows of the `admin_api` tables (same primary keys), copies content types and permissions with their
|
|
27
|
+
user and group grants, and moves admin `LogEntry` rows to the new content types. The search
|
|
28
|
+
index is not copied: run `manage.py search_index ensure` after `migrate`. Old tables and rows
|
|
29
|
+
stay in place; a second run copies only what is missing.
|
|
30
|
+
- **`require_dry_run` moves to `AdminApiSite` and gates REST and MCP alike.**
|
|
31
|
+
`AdminApiSite(admin_site, require_dry_run=True)` replaces `AdminMcpSite(api_site, require_dry_run=True)`;
|
|
32
|
+
`confirm_token_max_age` and `requires_dry_run()` move with it, and `mcp_require_dry_run` and
|
|
33
|
+
`get_mcp_confirm_state` keep their names and govern both surfaces. A gated REST create, update, write view,
|
|
34
|
+
action or delete now answers 409 `dry_run_required` without the confirm token of a dry run or preview, as MCP
|
|
35
|
+
does, for the same API token. REST sends the token in the `Confirm-Token` header; a dry run, a delete preview
|
|
36
|
+
(`GET <pk>/delete-preview/`) and an action preview return it. Tokens are bound to the
|
|
37
|
+
`AdminApiSite` (signing salt `admin_api_mcp.confirm.<name>`): MCP sites over one API site share them, and the
|
|
38
|
+
token of an MCP dry run unlocks the same REST write. The token module is `admin_api_mcp.confirm` (was
|
|
39
|
+
`admin_api_mcp.mcp.confirm`).
|
|
40
|
+
- **`require_dry_run` gates deletes.** The delete preview returns a `confirm_token` bound to the record, its row
|
|
41
|
+
and its deletion summary; a delete without it answers 409 `dry_run_required`. A one-call delete is refused on
|
|
42
|
+
gated sites.
|
|
43
|
+
- **Admin actions preview first.** REST `POST .../actions/<name>/` and MCP `run_action` run nothing without
|
|
44
|
+
`"confirm": true` / `confirm=true` and return a preview: `action`, `description`, `count`, the first 20
|
|
45
|
+
`objects` (`more` counts the rest), `confirm_required`, and for `delete_selected` without an API twin the
|
|
46
|
+
admin's delete confirmation data as `preview` (`to_delete`, `model_count`, `perms_needed`, `protected`,
|
|
47
|
+
`can_delete`). With `require_dry_run`, the preview carries a `confirm_token` and the run needs it: single use,
|
|
48
|
+
bound to the user, API token, action, `ids` or `all` + `filters`, and the records the selection holds (a record
|
|
49
|
+
joining or leaving it voids the token). A failed run leaves the token unspent. MCP `run_action` takes
|
|
50
|
+
`confirm_token`, REST the `Confirm-Token` header.
|
|
51
|
+
- **Admin actions that declare no permissions need `change`** (see Security). An action that only reads
|
|
52
|
+
declares `permissions=["view"]`.
|
|
53
|
+
- **MCP keys are `id` and `label`** (REST unchanged): object heads, inline rows, related records
|
|
54
|
+
(`{"id", "label"}`), `list_objects` `columns[0]`, write results, delete previews, view results;
|
|
55
|
+
`describe_model` `pk_field` is now `id_field`. `list_models` items start with `name`. The tool
|
|
56
|
+
arguments are `id` and `ids`; `pk` and `pks` stay accepted as aliases for one release. An inline
|
|
57
|
+
row sent with `id` updates that row, and `describe_model`'s update schema names that key `id`.
|
|
58
|
+
- MCP `list_models` and `describe_model` return `can` (the allowed operations of `view`, `add`, `change`,
|
|
59
|
+
`delete`) in place of the `perms` object; read-only sites give `["view"]`. REST keeps `perms`.
|
|
60
|
+
- File values read as `{"name", "url"}` (were the name alone).
|
|
61
|
+
- Direct callers of `admin_api_mcp.services`: `services.create` and `services.update` with `dry_run=True` return
|
|
62
|
+
the dry-run body (they returned `{}` or raised `ValidationFailed`); `services.update` and `services.run_view`
|
|
63
|
+
lost `obj=`; `services.run_action` lost `delete_preview`, reads `confirm` from the payload and takes
|
|
64
|
+
`confirm_token`; `actions.run_action` is gone; `custom_views.run_view(model_admin, request, spec, obj, data)`
|
|
65
|
+
runs a view whose permissions the caller checked.
|
|
66
|
+
- A nested child admin can no longer be named `history`.
|
|
67
|
+
|
|
68
|
+
### Security
|
|
69
|
+
|
|
70
|
+
- **Fix for 0.1.0a3 and earlier: the API no longer returns password hashes.** REST
|
|
71
|
+
detail, MCP `get_object`, write responses and changelist columns returned the full stored hash
|
|
72
|
+
of the user model's `password`, also to a view-only user. They now return `"[redacted]"` (the
|
|
73
|
+
sensitive-field list below); with `password` excluded from it, the masked summary the admin shows
|
|
74
|
+
(`{"algorithm", "iterations", "salt", "hash"}` with salt and hash cut to their first characters),
|
|
75
|
+
or `null` for an unusable password. Upgrade if the stock `UserAdmin` (or any admin of the user
|
|
76
|
+
model) is registered on a site the API wraps.
|
|
77
|
+
- **Fix: a view-only user or `:view` token no longer runs admin actions that declare no permissions.** REST and
|
|
78
|
+
MCP require `change` (permission and token scope) for such an action, and `list_models`, `describe_model` and
|
|
79
|
+
`/schema/` stop listing it.
|
|
80
|
+
- **Sensitive fields are redacted** in REST and MCP output: detail, list (both shapes), inline
|
|
81
|
+
rows, `totals` and write results return `"[redacted]"` and keep the key. Default list
|
|
82
|
+
(`admin_api_mcp.sensitive.DEFAULT_SENSITIVE_FIELDS`): `password`, `passwd`, `secret`, `token`,
|
|
83
|
+
`api_key`, `apikey`, `private_key`, `access_key`, `credential`, `credentials`, matched against
|
|
84
|
+
whole `_`-separated parts of the name. `settings.ADMIN_API_SENSITIVE_FIELDS` replaces the list;
|
|
85
|
+
an admin or inline adds exact keys with `api_sensitive_fields` and shows keys with
|
|
86
|
+
`api_sensitive_exclude` (or `get_api_sensitive_fields(request)` / `get_api_sensitive_exclude(request)`).
|
|
87
|
+
A free-form filter through a sensitive field answers `400 bad_lookup`, and a write that sends
|
|
88
|
+
`"[redacted]"` as a sensitive field's value answers `400 validation_failed`.
|
|
89
|
+
- Redaction covers sensitive keys at every level of a JSON value. The REST reference lists what it does not
|
|
90
|
+
cover.
|
|
91
|
+
- The search index leaves sensitive fields out (run `manage.py search_index ensure` after upgrading), and
|
|
92
|
+
`resolve_entities` without the index skips the search fields the API redacts.
|
|
93
|
+
- A sensitive column cannot be sorted on (`?o=`, MCP `ordering`).
|
|
94
|
+
- Filter errors other than a refused lookup answer a fixed detail without field names.
|
|
95
|
+
- `McpUserInstructions` is superuser-only in the admin.
|
|
96
|
+
- A new API token is shown on the admin's add response, not in a message.
|
|
97
|
+
|
|
98
|
+
### Added
|
|
99
|
+
|
|
100
|
+
- **REST dry run.** `?dry_run=1` (or `true`) on `POST`, `PATCH`, `PUT` and on a `POST` to a custom view runs the
|
|
101
|
+
admin's validation, saves nothing and answers 200 with the body of MCP's dry run: `{"dry_run", "valid", "note"}`,
|
|
102
|
+
or `"valid": false` with `"errors"`. `DELETE <pk>/?dry_run=1` answers the delete preview. A value other than
|
|
103
|
+
`1`, `true`, `0` or `false` answers 400 `invalid_arguments`. Before, the parameter was ignored and the write ran.
|
|
104
|
+
- **New MCP tool `resolve_entities`** (read-only, §14.9): names the user typed become object ids and model
|
|
105
|
+
labels across every model the user can see. Each term returns an `objects` and a `models` list,
|
|
106
|
+
each with `status` `unique`, `ambiguous` or `none` and ranked candidates (`match`, `confidence`,
|
|
107
|
+
`matched_field`, `label` as `str(obj)`). Terms take `kind` (`any`, `objects`, `models`),
|
|
108
|
+
`models` (a top-level `models` is the default for terms without their own), and `for_field` (a create/update
|
|
109
|
+
relation field or `inlines.<prefix>.<field>`, with the field's `limit_choices_to`). Candidates come from each
|
|
110
|
+
admin's `get_search_results` over its `get_queryset(request)`, with its permissions, token scopes and live
|
|
111
|
+
search fields. The `objects` list names `searched_models` only when its status is `none` or with
|
|
112
|
+
`verbose=true`. Model labels are read in any case (`store.Client` is `store.client`); an unknown or hidden
|
|
113
|
+
label is an `invalid_arguments` error naming it (was `status: none` with `searched_models: []`), and a `for_field` that is not a relation field adds `help`.
|
|
114
|
+
- `AdminMcpSite.excluded_models` (and the `excluded_models=` argument): app labels or
|
|
115
|
+
`app_label.model_name` that `resolve_entities` never searches. Default: `auth`, `sessions`,
|
|
116
|
+
`contenttypes`, `admin`, `admin_api_mcp`.
|
|
117
|
+
- `AdminMcpSite.get_entity_backend()` / `entity_backend_class`: the backend that finds
|
|
118
|
+
candidates. The default `LiveEntityBackend` uses the admin's own search on any database.
|
|
119
|
+
Backends receive `limit=` in `search_objects` and `search_models`.
|
|
120
|
+
- **New opt-in app `admin_api_mcp.contrib.search`** (§14.10): a search index behind `resolve_entities`.
|
|
121
|
+
One row per (object, search field) and per (model, label, language), text folded by `fold()`
|
|
122
|
+
(accents, case, Arabic letter variants, digits, the Arabic article). Rows follow the MCP-exposed
|
|
123
|
+
admins' local `search_fields` / `api_search_fields` and `Meta` labels under every `LANGUAGES` code.
|
|
124
|
+
Saves update rows on commit; `post_migrate` refreshes the label rows. Hits are scoped like the live
|
|
125
|
+
backend (exposure, permissions, token scopes, `excluded_models`, live search fields) and checked
|
|
126
|
+
against the admin's `get_queryset(request)` inside the query. Run `migrate`, then
|
|
127
|
+
`search_index ensure` on every deploy. Installing the app sets `AdminMcpSite.entity_backend_class` to
|
|
128
|
+
`SearchEntityBackend`; sites that set their own keep it.
|
|
129
|
+
- Deleting an object removes its search index rows on commit, including `QuerySet.delete()` and bulk deletes
|
|
130
|
+
through the admin, REST and MCP. The `post_delete` receiver turns off Django's fast delete project-wide.
|
|
131
|
+
- Pluggable search engines through `ADMIN_API_SEARCH` (`DEFAULT_ENGINE`, `ENGINES`), interface
|
|
132
|
+
`engines.base.SearchEngine`. The built-in `db` engine (`admin_api_mcp_search_entry` table) runs on every
|
|
133
|
+
database; on Postgres the migration installs `pg_trgm` and a GIN index, and a trigram pass adds
|
|
134
|
+
`fuzzy` matches.
|
|
135
|
+
- Commands `rebuild_search_index [--model] [--models-only] [--batch-size]` and `search_index ensure`
|
|
136
|
+
(fingerprint-gated rebuild; exits non-zero on a `C` / `POSIX` database ctype). System check
|
|
137
|
+
`admin_api_mcp_search.W001` warns about that ctype.
|
|
138
|
+
- `admin_api_mcp.contrib.search.indexer.indexing_suspended()`: a context manager for bulk loads; saves
|
|
139
|
+
inside it (this thread or task) skip the index until `rebuild_search_index` runs.
|
|
140
|
+
- Admin hooks `get_search_index_fields()`, `search_index_code_fields`, `search_aliases`.
|
|
141
|
+
- **New MCP tool `get_history`** (read-only) and REST `GET <pk>/history/`: one record's admin
|
|
142
|
+
history from `LogEntry`, newest first, each entry with `when`, `user`, `action` (`added`,
|
|
143
|
+
`changed`, `deleted`) and `message` in the admin's own wording. `limit` defaults to 20, at most
|
|
144
|
+
100; a `hint` says when older entries exist. Same permission as the admin's history page
|
|
145
|
+
(`has_view_or_change_permission(obj)` on an object from `get_queryset`).
|
|
146
|
+
- **Per-user MCP instructions.** New model `admin_api_mcp.McpUserInstructions` (migration `0003`):
|
|
147
|
+
one instructions text per user, set in the Django admin (`McpUserInstructionsAdmin`). The default
|
|
148
|
+
`AdminMcpSite.get_instructions(request)` appends it to the site's instructions, cut at
|
|
149
|
+
`instructions_max_length` (4,096) with a note.
|
|
150
|
+
- `AdminMcpSite.get_instructions(request)` (sent at `initialize`; the HTTP view builds one SDK
|
|
151
|
+
`Server` per request) and `AdminMcpSite.get_language(request)` (default `None`: keep the active
|
|
152
|
+
language), which wraps `call_tool` and `get_tools` in `translation.override`.
|
|
153
|
+
- **File and image fields are writable** (REST and MCP, main form and inline rows):
|
|
154
|
+
`{"filename", "content_base64"}` becomes an `UploadedFile` before the admin form runs, and the
|
|
155
|
+
admin's own validation applies. `null` clears an optional file; leaving the field out keeps it.
|
|
156
|
+
`AdminApiSite.max_upload_size` caps each file (default 5 MiB); bad base64, a bad file name or a
|
|
157
|
+
file over the cap is a field error. `input_schema` describes file fields as `{filename, content_base64}`,
|
|
158
|
+
and an MCP dry run validates uploads and stores no file. Before, any write to an admin with a file field
|
|
159
|
+
failed.
|
|
160
|
+
- **MCP `list_models` lists the admin actions** each model allows the user (`actions`, from
|
|
161
|
+
`get_actions(request)`), next to `can` and `views`. Read-only sites list no actions.
|
|
162
|
+
- **Permission errors point to that list.** A 403 `permission_denied` (or `read_only`) and the 404
|
|
163
|
+
for an action the user may not run add `help`: on MCP "Call list_models to see what you may do
|
|
164
|
+
on each model.", on REST "GET /api/v1/ to see what you may do on each model." Denials before any
|
|
165
|
+
model (site access, CSRF, origin) carry no `help`.
|
|
166
|
+
- `AdminMcpSite.excluded_tools` (and `excluded_tools=`): tool names left out of `tools/list`. With
|
|
167
|
+
`read_only=True, excluded_tools=["get_history"]` a question-answering client gets 6 generic tools.
|
|
168
|
+
- MCP `list_objects` pages through at most `AdminMcpSite.list_max_rows` records of a query (default
|
|
169
|
+
1000, `None` for no cap). A larger query reports only the reachable `pages` and adds a `hint`
|
|
170
|
+
pointing at reports, filters and search; a page past the cap answers `invalid_arguments`.
|
|
171
|
+
- MCP `list_objects` with a `search` that finds nothing adds `searched_fields` (the admin's search
|
|
172
|
+
fields), `id_filters` (the `list_filter` parameters that take a related record's ID, e.g.
|
|
173
|
+
`client__id__exact`) and a `hint`.
|
|
174
|
+
- **`get_mcp_confirm_state(request, obj)`** on the admin (default on `ApiAdminMixin`: `None`)
|
|
175
|
+
adds state stored outside the object's row, such as the last row of a status log, to the
|
|
176
|
+
`require_dry_run` confirm-token fingerprint. A concurrent change to that state gets 409
|
|
177
|
+
`invalid_confirm_token`.
|
|
178
|
+
- **Write views log a change.** `@admin_api_mcp.view(writes=True)` run on one record (REST and MCP)
|
|
179
|
+
creates a `LogEntry` like create and update do: `Ran <view title>.` (plus `Via MCP.`), without
|
|
180
|
+
parameter values. A dry run rolls it back; write views on no single record log nothing.
|
|
181
|
+
- `server.json` for the MCP Registry and the `mcp-name` line in the README. The release workflow
|
|
182
|
+
checks that its versions equal the tag.
|
|
183
|
+
- `LICENSE` file (MIT), shipped in the wheel and the sdist.
|
|
184
|
+
|
|
185
|
+
### Changed
|
|
186
|
+
|
|
187
|
+
- **One flow for REST and MCP.** MCP deletes, delete previews and actions call `services.delete`,
|
|
188
|
+
`services.delete_preview` and `services.run_action`; REST custom views call `services.run_view`;
|
|
189
|
+
`describe_model` builds the input schema once through `services.schema(instance=, row_id=)`.
|
|
190
|
+
- MCP deletes write "Via MCP." in their `LogEntry`, as adds and changes do (`delete_object` and
|
|
191
|
+
`delete_selected`).
|
|
192
|
+
- **MCP dry runs validate only.** `dry_run=true` on `create_object` / `update_object` runs the
|
|
193
|
+
permission checks, the admin's queryset and its form and inline validation, and saves nothing:
|
|
194
|
+
no `save_model`, signal, `LogEntry` or e-mail. The validation runs in a transaction that is
|
|
195
|
+
always rolled back: rows a form `clean()` writes are undone. A write view's dry run checks
|
|
196
|
+
permissions and params without calling the view. The result is `dry_run`, `valid`
|
|
197
|
+
and `errors` or `note`; `object` and `totals` come with the real write only.
|
|
198
|
+
`writes.validate_changeform` is the validation half of `default_process_changeform`; an admin
|
|
199
|
+
replaces it for dry runs with its own `validate_changeform(request, obj, change)`.
|
|
200
|
+
- **MCP answers in business wording.** The default instructions open with "This server gives you
|
|
201
|
+
the user's business records and documents" and ask the agent to name kinds of records by `name` /
|
|
202
|
+
`name_plural`, records by their label, and to say "ID" only when needed. They say `delete_object` and
|
|
203
|
+
`run_action` preview unless `confirm=true`, and that a required `confirm_token` comes with `run_action`'s
|
|
204
|
+
preview. They are 2,072 characters.
|
|
205
|
+
- The default instructions gain a line on `resolve_entities`: resolve names first; reads use any `unique`
|
|
206
|
+
result, writes only an `exact` or `exact_code` one. On `ambiguous`, list each candidate's label and kind of
|
|
207
|
+
record and ask which one before running anything; on `none`, say nothing matched and ask whether to run it
|
|
208
|
+
for everyone. Resolved IDs go in as describe_model's filter for that kind of record (e.g. `client`), not as
|
|
209
|
+
`search` text.
|
|
210
|
+
- Messages use verbose names and "ID", wrapped in `gettext`: `"No sales with ID 9."`,
|
|
211
|
+
`"This connection may not change sales."`, `"No view 'x' on sales."`. Unknown, hidden and excluded models
|
|
212
|
+
all answer `"This kind of record is not available here."` (was `No API for app.model` /
|
|
213
|
+
`No MCP access to app.model`).
|
|
214
|
+
- `PermissionDeniedError` has a default detail ("You do not have permission to do this."); the
|
|
215
|
+
services pass one per operation (`"You may not change this sales."`). Promoted view tools say
|
|
216
|
+
"(Same as run_view 'post' on sales.)" and "ID of the sales.".
|
|
217
|
+
- Action descriptions are formatted like the admin's action menu: `delete_selected` reads
|
|
218
|
+
"Delete selected sales", not "Delete selected %(verbose_name_plural)s".
|
|
219
|
+
- MCP `list_objects` names the argument for a reserved filter key (`q` is `search`, `o` is `ordering`, `p` is
|
|
220
|
+
`page`, `_per_page` is `per_page`); `all` points to `page` and `per_page`.
|
|
221
|
+
- REST answers an unhandled exception with `500 {"error": "server_error"}` (it was Django's HTML 500) and logs
|
|
222
|
+
it to the new `admin_api_mcp.api` logger. Django's `Http404`, `PermissionDenied`, `MultiPartParserError`,
|
|
223
|
+
`BadRequest` and `SuspiciousOperation` keep Django's answer. REST and MCP share `errors.server_error`: both
|
|
224
|
+
roll back an `ATOMIC_REQUESTS` transaction, and the MCP payload gains `"status": 500` and reads "The request
|
|
225
|
+
failed; see the server log."
|
|
226
|
+
- REST authenticates before it checks the method: an anonymous call with a method the route does not take
|
|
227
|
+
answers `401 not_authenticated`, not `405 method_not_allowed`.
|
|
228
|
+
- A body over `DATA_UPLOAD_MAX_MEMORY_SIZE` answers `413 payload_too_large` as JSON (REST and MCP
|
|
229
|
+
HTTP), not Django's HTML 400.
|
|
230
|
+
- `import admin_api_mcp` works without Django settings: the scope verbs and error default details are
|
|
231
|
+
`gettext_lazy` strings.
|
|
232
|
+
- `InvalidArguments` moved to `admin_api_mcp.errors`; `admin_api_mcp.mcp.handlers` still imports it.
|
|
233
|
+
- The MCP server reads the SDK's wire types as `mcp.types` (no direct import of the `mcp-types` distribution).
|
|
234
|
+
- The GitHub repository is renamed to `RamezIssac/django-admin-api-mcp`; project URLs point to it
|
|
235
|
+
(old URLs redirect).
|
|
236
|
+
- The sdist holds the package, `tests/`, `docs/`, README, LICENSE and CHANGELOG; `examples/` is left out.
|
|
237
|
+
|
|
238
|
+
### Fixed
|
|
239
|
+
|
|
240
|
+
- The README quick start builds `api_site` before `admin.site.urls` and has its imports: the token
|
|
241
|
+
admin registered after the admin URLs made `GET /admin/` answer 500 (`NoReverseMatch` for
|
|
242
|
+
`app_list`).
|
|
243
|
+
|
|
244
|
+
### Docs
|
|
245
|
+
|
|
246
|
+
- The README is the front door (quick start, tool table, security model, a comparison with
|
|
247
|
+
the other admin-to-MCP packages, how the library is verified). The reference moved to
|
|
248
|
+
`docs/rest-api.md`, `docs/mcp.md`, `docs/custom-views.md` and `docs/nested-admins.md`. README
|
|
249
|
+
links are absolute GitHub URLs and work on PyPI.
|
|
250
|
+
- `docs/confirmation.md` (dry runs, the confirm token and what voids it, delete and action previews, REST and
|
|
251
|
+
MCP, the settings) and `docs/architecture.md` (the layers from `ModelAdmin` through `admin_api_mcp.services`
|
|
252
|
+
to the REST views and MCP tools, what each tool calls, where permissions and validation run), both linked
|
|
253
|
+
from the README.
|
|
254
|
+
- The README comparison puts django-admin-fastmcp second, adds a lines-of-code row (cloc, latest PyPI
|
|
255
|
+
wheels) and states that the code is written by coding agents and the design decisions by the author.
|
|
256
|
+
- The README and `docs/DECISIONS.md` state what the write tests check (an API update runs the
|
|
257
|
+
admin's own `process_changeform` and save hooks).
|
|
258
|
+
- [docs/oauth.md](docs/oauth.md): OAuth in front of the MCP endpoint. django-oauth-toolkit is the
|
|
259
|
+
authorization server (DCR, CIMD, PKCE, RFC 9728 and RFC 8414 discovery). A project-side
|
|
260
|
+
`OAuthAuthenticator` in `AdminMcpSite.authenticators` maps the access token to its user and its
|
|
261
|
+
scopes to library scopes. A 401 points clients at the resource metadata. A Note covers open client
|
|
262
|
+
registration.
|
|
263
|
+
|
|
264
|
+
### Development
|
|
265
|
+
|
|
266
|
+
- CI runs mutation testing on the lines a PR changes (report only, mutmut). Each run starts fresh (no
|
|
267
|
+
`mutants/` cache), names the
|
|
268
|
+
PR head commit, and its PR comment adds the coverage of the changed lines and a survivor table capped at
|
|
269
|
+
40 rows.
|
|
270
|
+
- CI posts a per-PR report of public API changes (`scripts/api_surface.py`); one fork-safe workflow posts
|
|
271
|
+
the PR comments.
|
|
272
|
+
- The suite turns `DeprecationWarning`, `PendingDeprecationWarning`, `ResourceWarning`,
|
|
273
|
+
`PytestUnraisableExceptionWarning` and `RuntimeWarning` into errors (`RuntimeWarning` also in the stdio
|
|
274
|
+
subprocess).
|
|
275
|
+
- Query counts are pinned for REST changelist and detail and MCP `list_objects`, `get_object`,
|
|
276
|
+
`list_models`, `describe_model`, `create_object` and `update_object`.
|
|
277
|
+
- ruff and zizmor are pinned in a `lint` dependency group; the lint session also checks `scripts/` and
|
|
278
|
+
the workflows (actions pinned to commit SHAs, checkouts without persisted credentials).
|
|
279
|
+
- The nox matrix runs Python 3.11 (Django 5.2, latest MCP SDK), matching the 3.11 classifier. CI runs the
|
|
280
|
+
search tests on Postgres 17 (nox session `tests_postgres`).
|
|
281
|
+
- Tests hash passwords with MD5 (suite 13.7 s, was 94.7 s).
|
|
282
|
+
- The package is 166 code lines shorter with behaviour unchanged.
|
|
283
|
+
- The smoke example is `examples/erp_smoke/`, run against django-erp-framework's public `api_tests` app.
|
|
284
|
+
|
|
285
|
+
## 0.1.0a3 (2026-11-19)
|
|
286
|
+
|
|
287
|
+
- **The MCP `confirm_token` is single-use and bound to the object's state.** It was a stateless
|
|
288
|
+
signature, valid 15 minutes for any number of writes: one dry run allowed repeated writes, from
|
|
289
|
+
any API token of the same user, after the object changed. Now the dry run stores a random `jti`
|
|
290
|
+
in the new `McpConfirmation` model (migration `admin_api.0002`) with a fingerprint of the user,
|
|
291
|
+
the API token, the operation, the exact arguments and the object's stored row. The real write
|
|
292
|
+
spends it in one conditional `UPDATE`, in the same transaction as the write (row read
|
|
293
|
+
`FOR UPDATE`): a failed write leaves the token unspent. A replay, another API token, other
|
|
294
|
+
arguments or a changed object get 409 `invalid_confirm_token`; a call that does not match leaves
|
|
295
|
+
the token unspent. The dry run then confirm flow and the error codes are unchanged. Run
|
|
296
|
+
`migrate`.
|
|
297
|
+
- MCP writes check permissions and token scopes before the confirm token: a user who may not
|
|
298
|
+
write gets 403 `permission_denied`, not 409 `dry_run_required` / `invalid_confirm_token`.
|
|
299
|
+
- Free-form changelist lookups (REST `?field__lookup=` and MCP `filters`) must start at a field
|
|
300
|
+
the API shows: the pk, `list_display` field columns, `list_filter` fields, `date_hierarchy` and
|
|
301
|
+
the API detail fields (add and change form). Other local fields answer 400 `bad_lookup`.
|
|
302
|
+
`api_lookup_fields` / `get_api_lookup_fields(request)` sets the list explicitly.
|
|
303
|
+
- MCP `tools/list` no longer crashes for a non-superuser: tool permissions are checked in the
|
|
304
|
+
sync thread (they query the database).
|
|
305
|
+
- Every MCP tool call is logged at INFO to the `admin_api.mcp.audit` logger (tool, user pk, token
|
|
306
|
+
prefix, IP, model, pk, view, action, pks, `all`, `dry_run`, `confirm`, outcome), without `data`,
|
|
307
|
+
`params` or `confirm_token`.
|
|
308
|
+
- `AdminApiConfig.default_auto_field = "django.db.models.AutoField"`, matching migration 0001: a
|
|
309
|
+
project with `DEFAULT_AUTO_FIELD = BigAutoField` no longer sees a pending `admin_api` migration.
|
|
310
|
+
|
|
311
|
+
## 0.1.0a2 (2026-11-19)
|
|
312
|
+
|
|
313
|
+
- The project is renamed to `django-admin-api-mcp` on PyPI from this release. The import name
|
|
314
|
+
`admin_api` is unchanged.
|
|
315
|
+
- The official `mcp` SDK is a core dependency and the `[mcp]` extra is gone: install with
|
|
316
|
+
`pip install --pre django-admin-api-mcp`.
|
|
317
|
+
- `ADMIN_API_MCP_ENABLED` setting (default `True`): when `False`, the MCP HTTP view answers 404
|
|
318
|
+
`mcp_disabled` and `manage.py mcp_serve` exits with an error.
|
|
319
|
+
- MCP `create_object` / `update_object` (and their dry runs) return the saved document's
|
|
320
|
+
`totals`, declared per admin with `api_totals`. The object is reloaded after the save, so
|
|
321
|
+
values written by signals are included (REST writes get the same reload and a `totals` entry).
|
|
322
|
+
- `AdminMcpSite(require_dry_run=True)` and `mcp_require_dry_run` on an admin: a real write
|
|
323
|
+
(create, update, write views) is refused unless it carries the `confirm_token` returned by a
|
|
324
|
+
matching, valid dry run. New error codes `dry_run_required` and `invalid_confirm_token`.
|
|
325
|
+
- LogEntry messages of MCP creates and updates end in `Via MCP.`.
|
|
326
|
+
- `get_mcp_description(request)` hook on `ApiAdminMixin`: override it to return another attribute
|
|
327
|
+
(e.g. the admin's `description`) as the MCP description. `mcp_description` keeps working.
|
|
328
|
+
- `confirm_token` is a reserved view parameter name, next to `pk` and `dry_run`.
|
|
329
|
+
|
|
330
|
+
## 0.1.0a1 (published)
|
|
331
|
+
|
|
332
|
+
First alpha. Published as `django-admin-api2` (the `django-admin-api` name on PyPI is taken
|
|
333
|
+
by an unrelated package); the import package is `admin_api`.
|
|
334
|
+
|
|
335
|
+
- REST API from existing `ModelAdmin`s: changelist with admin filters/search/ordering,
|
|
336
|
+
detail, `/schema/`, writes through the admin's own change-form pipeline with inline
|
|
337
|
+
formsets, actions, delete with preview (decisions 8, 10, R4, 11a, 12, 13, R5).
|
|
338
|
+
- `api_` twins and `request.is_api` for API-specific behaviour; mixin-less admins are wrapped
|
|
339
|
+
at runtime (§3, R3.4).
|
|
340
|
+
- Session + personal-access-token auth, tokens narrowed by scopes (15, R6, R7, §9.3).
|
|
341
|
+
- MCP server: Streamable HTTP and stdio transports, generic tools with
|
|
342
|
+
`dry_run`, JSON Schema write payloads, official-client conformance tests (§14).
|
|
343
|
+
- Nested admins via django-subadmin; custom admin views via `@admin_api.view` (§15, §16).
|
|
344
|
+
|
|
345
|
+
Decision ids and section numbers refer to [docs/DESIGN.md](docs/DESIGN.md).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ramez Ashraf Issac
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|