Django admin MCP integration - expose Django admin models to MCP clients
Project description
django-admin-mcp
Expose Django admin models to MCP (Model Context Protocol) clients via HTTP. Add a mixin to your ModelAdmin classes and get instant access to CRUD operations, admin actions, model history, and more.
โจ Features
- ๐ฆ Zero dependencies โ only Django and Pydantic required
- ๐ Token authentication โ secure Bearer token auth with configurable expiry
- ๐ก๏ธ Django admin permissions โ respects existing view/add/change/delete permissions
- ๐ Field filtering โ control which fields are exposed via
mcp_fieldsandmcp_exclude_fields - ๐ Full CRUD โ list, get, create, update, delete operations
- โก Admin actions โ execute registered Django admin actions
- ๐ฆ Bulk operations โ create, update, or delete multiple records at once
- ๐ Model introspection โ describe model fields and relationships
- ๐ Related objects โ traverse foreign keys and reverse relations
- ๐ Change history โ access Django admin's history log
- ๐ Autocomplete โ search suggestions for foreign key fields
๐ฅ Installation
pip install django-admin-mcp
Add to your Django project:
# settings.py
INSTALLED_APPS = [
'django_admin_mcp',
# ...
]
# urls.py
from django.urls import path, include
urlpatterns = [
path('mcp/', include('django_admin_mcp.urls')),
# ...
]
Run migrations to create the token model:
python manage.py migrate django_admin_mcp
๐ Quick Start
1๏ธโฃ Expose Your Models
Add the mixin to any ModelAdmin. Set mcp_expose = True to expose direct tools:
from django.contrib import admin
from django_admin_mcp import MCPAdminMixin
from .models import Article, Author
@admin.register(Article)
class ArticleAdmin(MCPAdminMixin, admin.ModelAdmin):
mcp_expose = True # Exposes list_article, get_article, etc.
list_display = ['title', 'author', 'published']
@admin.register(Author)
class AuthorAdmin(MCPAdminMixin, admin.ModelAdmin):
pass # Discoverable via find_models, no direct tools
๐ Protecting Sensitive Fields
Use mcp_exclude_fields to prevent sensitive data exposure:
@admin.register(User)
class UserAdmin(MCPAdminMixin, admin.ModelAdmin):
mcp_expose = True
# Never expose sensitive fields via MCP
mcp_exclude_fields = ['password', 'security_token']
2๏ธโฃ Create an API Token
Go to Django admin at /admin/django_admin_mcp/mcptoken/ and create a token. Tokens can optionally be tied to users, groups, or have direct permissions assigned.
3๏ธโฃ Configure Your MCP Client
Add to your MCP client settings (~/.claude/claude_desktop_config.json or project .mcp.json):
{
"mcpServers": {
"django-admin": {
"url": "http://localhost:8000/mcp/",
"headers": {
"Authorization": "Bearer YOUR_TOKEN"
}
}
}
}
4๏ธโฃ Use with Your Agent
Once configured, the agent can use the tools directly:
User: What models are available in Django admin?
Agent: [calls find_models tool]
User: Show me the latest 10 articles
Agent: [calls list_article with limit=10]
User: Get article #42 and update its title to "New Title"
Agent: [calls get_article with id=42, then update_article]
๐ ๏ธ Available Tools
For each exposed model (e.g., Article), the following tools are generated:
๐ CRUD Operations
| Tool | Description |
|---|---|
list_article |
List all articles with pagination (limit, offset) and filtering |
get_article |
Get a single article by id |
create_article |
Create a new article with field values |
update_article |
Update an existing article by id |
delete_article |
Delete an article by id |
๐ Model Introspection
| Tool | Description |
|---|---|
find_models |
Discover all exposed models and their available tools |
describe_article |
Get field definitions, types, and constraints |
โก Admin Actions
| Tool | Description |
|---|---|
actions_article |
List available admin actions for the model |
action_article |
Execute an admin action on selected records |
bulk_article |
Bulk create, update, or delete multiple records |
๐ Relationships
| Tool | Description |
|---|---|
related_article |
Get related objects via foreign keys |
history_article |
View Django admin change history |
autocomplete_article |
Search suggestions for autocomplete fields |
๐ HTTP Protocol Reference
For custom integrations, the MCP endpoint accepts POST requests:
# List available tools
curl -X POST http://localhost:8000/mcp/ \
-H "Authorization: Bearer TOKEN" \
-H "Content-Type: application/json" \
-d '{"method": "tools/list"}'
# Call a tool
curl -X POST http://localhost:8000/mcp/ \
-H "Authorization: Bearer TOKEN" \
-H "Content-Type: application/json" \
-d '{"method": "tools/call", "name": "list_article", "arguments": {"limit": 10}}'
๐ฌ Example Conversations
๐ CRUD Operations
User: Create a new article titled "Getting Started with Django"
Agent: I'll create that article for you.
[calls create_article with title="Getting Started with Django"]
Created article #15: "Getting Started with Django"
User: Update article 15 to add content
Agent: [calls update_article with id=15, content="..."]
Updated article #15 successfully.
User: Delete article 15
Agent: [calls delete_article with id=15]
Deleted article #15.
โก Admin Actions
User: Mark articles 1, 2, and 3 as published
Agent: [calls action_article with action="mark_as_published", ids=[1,2,3]]
Marked 3 articles as published.
๐ฆ Bulk Operations
User: Set status to "archived" for articles 10-15
Agent: [calls bulk_article with operation="update", ids=[10,11,12,13,14,15], data={"status": "archived"}]
Updated 6 articles.
User: Delete all draft articles from last month
Agent: [calls list_article to find drafts, then bulk_article with operation="delete"]
Deleted 12 draft articles.
๐ Exploring Relationships
User: Show me all comments on article 42
Agent: [calls related_article with id=42, relation="comments"]
Found 8 comments on article #42...
User: What changes were made to article 42?
Agent: [calls history_article with id=42]
Change history for article #42:
- 2024-01-15: Changed title (admin)
- 2024-01-10: Created (admin)
๐ Model Discovery
User: What can I manage through MCP?
Agent: [calls find_models]
Available models:
- article (5 tools: list, get, create, update, delete)
- author (5 tools: list, get, create, update, delete)
- category (5 tools: list, get, create, update, delete)
User: What fields does article have?
Agent: [calls describe_article]
Article fields:
- id (AutoField, read-only)
- title (CharField, max_length=200, required)
- content (TextField, optional)
- author (ForeignKey to Author, required)
- published (BooleanField, default=False)
- created_at (DateTimeField, auto)
๐ Security
๐๏ธ Two-Level Exposure
Models with MCPAdminMixin are automatically discoverable via the find_models tool, allowing the agent to see what's available. To expose full CRUD tools directly, set mcp_expose = True:
# Discoverable via find_models only
class AuthorAdmin(MCPAdminMixin, admin.ModelAdmin):
pass
# Full tools exposed (list_article, get_article, etc.)
class ArticleAdmin(MCPAdminMixin, admin.ModelAdmin):
mcp_expose = True
๐ Token Authentication
- ๐ซ Tokens are created in Django admin
- ๐ค Tokens can be associated with a user, groups, or have direct permissions
- ๐ซ Tokens without any permissions have no access (principle of least privilege)
- โฐ Token expiry is configurable (default: 90 days)
- ๐๏ธ Revoke tokens by deleting them in admin
๐ก๏ธ Permission Checking
All operations respect Django admin permissions:
| Operation | Required Permission |
|---|---|
list_* / get_* |
๐๏ธ view |
create_* |
โ add |
update_* |
โ๏ธ change |
delete_* |
๐๏ธ delete |
If a token lacks permission, the operation returns an error.
๐ Requirements
| Dependency | Version |
|---|---|
| ๐ Python | >= 3.10 |
| ๐ Django | >= 3.2 |
| ๐ Pydantic | >= 2.0 |
โ Supported Django Versions
Django 3.2 ยท 4.0 ยท 4.1 ยท 4.2 ยท 5.0
๐ License
GPL-3.0-or-later
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_admin_mcp-0.3.1.tar.gz.
File metadata
- Download URL: django_admin_mcp-0.3.1.tar.gz
- Upload date:
- Size: 56.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f83644e1f21c7e0395f2bbb7e31b98ccf00b30315e99276d480acf79fb7bb49
|
|
| MD5 |
5910a08826c22f172493187ff3664256
|
|
| BLAKE2b-256 |
ec24de14423d8eab2b61b69220db86dd17412ba357626766d259ff42ac7f343b
|
Provenance
The following attestation bundles were made for django_admin_mcp-0.3.1.tar.gz:
Publisher:
publish.yml on 7tg/django-admin-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_admin_mcp-0.3.1.tar.gz -
Subject digest:
8f83644e1f21c7e0395f2bbb7e31b98ccf00b30315e99276d480acf79fb7bb49 - Sigstore transparency entry: 1091209950
- Sigstore integration time:
-
Permalink:
7tg/django-admin-mcp@ae79623544d55240d8e08b66d95498824d1c128f -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/7tg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ae79623544d55240d8e08b66d95498824d1c128f -
Trigger Event:
release
-
Statement type:
File details
Details for the file django_admin_mcp-0.3.1-py3-none-any.whl.
File metadata
- Download URL: django_admin_mcp-0.3.1-py3-none-any.whl
- Upload date:
- Size: 58.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
549a0f3a74a554e387d335b3fce0703d8954106d4bfe851494ac324adc79c99b
|
|
| MD5 |
b59eb144fa196c8f74109bd3f834ce71
|
|
| BLAKE2b-256 |
aed0526c0b00e1416514249662cf8af6dc26c92cd3f7233cf8c926cc23d7c45c
|
Provenance
The following attestation bundles were made for django_admin_mcp-0.3.1-py3-none-any.whl:
Publisher:
publish.yml on 7tg/django-admin-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_admin_mcp-0.3.1-py3-none-any.whl -
Subject digest:
549a0f3a74a554e387d335b3fce0703d8954106d4bfe851494ac324adc79c99b - Sigstore transparency entry: 1091209953
- Sigstore integration time:
-
Permalink:
7tg/django-admin-mcp@ae79623544d55240d8e08b66d95498824d1c128f -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/7tg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ae79623544d55240d8e08b66d95498824d1c128f -
Trigger Event:
release
-
Statement type: