django-admin-api-mcp 0.1.0__py3-none-any.whl
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.
- admin_api_mcp/__init__.py +9 -0
- admin_api_mcp/actions.py +197 -0
- admin_api_mcp/admin.py +131 -0
- admin_api_mcp/apps.py +10 -0
- admin_api_mcp/auth.py +62 -0
- admin_api_mcp/changelist.py +261 -0
- admin_api_mcp/checks.py +35 -0
- admin_api_mcp/confirm.py +97 -0
- admin_api_mcp/contrib/__init__.py +1 -0
- admin_api_mcp/contrib/search/__init__.py +0 -0
- admin_api_mcp/contrib/search/apps.py +21 -0
- admin_api_mcp/contrib/search/backend.py +121 -0
- admin_api_mcp/contrib/search/checks.py +12 -0
- admin_api_mcp/contrib/search/conf.py +42 -0
- admin_api_mcp/contrib/search/engines/__init__.py +0 -0
- admin_api_mcp/contrib/search/engines/base.py +99 -0
- admin_api_mcp/contrib/search/engines/db.py +265 -0
- admin_api_mcp/contrib/search/fold.py +41 -0
- admin_api_mcp/contrib/search/indexer.py +364 -0
- admin_api_mcp/contrib/search/management/__init__.py +0 -0
- admin_api_mcp/contrib/search/management/commands/__init__.py +0 -0
- admin_api_mcp/contrib/search/management/commands/rebuild_search_index.py +29 -0
- admin_api_mcp/contrib/search/management/commands/search_index.py +25 -0
- admin_api_mcp/contrib/search/migrations/0001_initial.py +83 -0
- admin_api_mcp/contrib/search/migrations/__init__.py +0 -0
- admin_api_mcp/contrib/search/models.py +43 -0
- admin_api_mcp/contrib/subadmin.py +37 -0
- admin_api_mcp/custom_views.py +471 -0
- admin_api_mcp/decorators.py +26 -0
- admin_api_mcp/deletion.py +58 -0
- admin_api_mcp/detail.py +115 -0
- admin_api_mcp/encoders.py +72 -0
- admin_api_mcp/errors.py +82 -0
- admin_api_mcp/jsonschema.py +225 -0
- admin_api_mcp/management/__init__.py +0 -0
- admin_api_mcp/management/commands/__init__.py +0 -0
- admin_api_mcp/management/commands/create_api_token.py +40 -0
- admin_api_mcp/management/commands/mcp_serve.py +86 -0
- admin_api_mcp/management/commands/migrate_from_admin_api.py +153 -0
- admin_api_mcp/mcp/__init__.py +7 -0
- admin_api_mcp/mcp/bridge.py +71 -0
- admin_api_mcp/mcp/handlers.py +771 -0
- admin_api_mcp/mcp/resolve.py +410 -0
- admin_api_mcp/mcp/server.py +76 -0
- admin_api_mcp/mcp/sites.py +284 -0
- admin_api_mcp/mcp/stdio.py +53 -0
- admin_api_mcp/mcp/tools.py +84 -0
- admin_api_mcp/mcp/views.py +74 -0
- admin_api_mcp/middleware.py +18 -0
- admin_api_mcp/migrations/0001_initial.py +40 -0
- admin_api_mcp/migrations/0002_mcp_confirmation.py +27 -0
- admin_api_mcp/migrations/0003_mcp_user_instructions.py +28 -0
- admin_api_mcp/migrations/__init__.py +0 -0
- admin_api_mcp/mixins.py +173 -0
- admin_api_mcp/models.py +145 -0
- admin_api_mcp/nested.py +122 -0
- admin_api_mcp/resolver.py +95 -0
- admin_api_mcp/scopes.py +142 -0
- admin_api_mcp/sensitive.py +67 -0
- admin_api_mcp/services.py +652 -0
- admin_api_mcp/sites.py +242 -0
- admin_api_mcp/templates/admin_api_mcp/token_created.html +17 -0
- admin_api_mcp/views/__init__.py +0 -0
- admin_api_mcp/views/changelist.py +70 -0
- admin_api_mcp/views/custom.py +33 -0
- admin_api_mcp/views/detail.py +50 -0
- admin_api_mcp/views/nested.py +73 -0
- admin_api_mcp/views/registry.py +15 -0
- admin_api_mcp/writes.py +530 -0
- django_admin_api_mcp-0.1.0.dist-info/METADATA +280 -0
- django_admin_api_mcp-0.1.0.dist-info/RECORD +73 -0
- django_admin_api_mcp-0.1.0.dist-info/WHEEL +4 -0
- django_admin_api_mcp-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Run the SDK's Streamable HTTP transport inside a (sync) Django view.
|
|
2
|
+
|
|
3
|
+
A fresh stateless ``StreamableHTTPSessionManager`` handles each request with plain JSON
|
|
4
|
+
responses (no SSE, no sessions). The Django request is translated into an ASGI scope; the
|
|
5
|
+
ASGI response is collected into an ``HttpResponse``.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from django.http import HttpResponse
|
|
11
|
+
from mcp.server.streamable_http_manager import StreamableHTTPSessionManager
|
|
12
|
+
|
|
13
|
+
from .server import current_request
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _scope(request, body: bytes) -> dict:
|
|
17
|
+
host = request.get_host()
|
|
18
|
+
name, _, port = host.rpartition(":") if host.rsplit(":", 1)[-1].isdigit() else (host, "", "")
|
|
19
|
+
headers = [
|
|
20
|
+
(key.lower().encode("latin-1"), value.encode("latin-1"))
|
|
21
|
+
for key, value in request.headers.items()
|
|
22
|
+
if key.lower() != "content-length"
|
|
23
|
+
]
|
|
24
|
+
headers.append((b"content-length", str(len(body)).encode("latin-1")))
|
|
25
|
+
return {
|
|
26
|
+
"type": "http",
|
|
27
|
+
"asgi": {"version": "3.0"},
|
|
28
|
+
"http_version": "1.1",
|
|
29
|
+
"method": request.method,
|
|
30
|
+
"scheme": "https" if request.is_secure() else "http",
|
|
31
|
+
"path": request.path,
|
|
32
|
+
"raw_path": request.path.encode("utf-8"),
|
|
33
|
+
"root_path": "",
|
|
34
|
+
"query_string": request.META.get("QUERY_STRING", "").encode("latin-1"),
|
|
35
|
+
"headers": headers,
|
|
36
|
+
"client": (request.META.get("REMOTE_ADDR") or "", 0),
|
|
37
|
+
"server": (name or host, int(port) if port else (443 if request.is_secure() else 80)),
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
async def handle(server, request) -> HttpResponse:
|
|
42
|
+
"""Serve one Django request with ``server`` (an SDK ``Server``)."""
|
|
43
|
+
current_request.set(request)
|
|
44
|
+
body = request.body
|
|
45
|
+
sent = False
|
|
46
|
+
|
|
47
|
+
async def receive():
|
|
48
|
+
nonlocal sent
|
|
49
|
+
if sent:
|
|
50
|
+
return {"type": "http.disconnect"}
|
|
51
|
+
sent = True
|
|
52
|
+
return {"type": "http.request", "body": body, "more_body": False}
|
|
53
|
+
|
|
54
|
+
status, headers, chunks = 500, [], []
|
|
55
|
+
|
|
56
|
+
async def send(message):
|
|
57
|
+
nonlocal status, headers
|
|
58
|
+
if message["type"] == "http.response.start":
|
|
59
|
+
status, headers = message["status"], message.get("headers", [])
|
|
60
|
+
elif message["type"] == "http.response.body":
|
|
61
|
+
chunks.append(message.get("body", b""))
|
|
62
|
+
|
|
63
|
+
manager = StreamableHTTPSessionManager(app=server, json_response=True, stateless=True)
|
|
64
|
+
async with manager.run():
|
|
65
|
+
await manager.handle_request(_scope(request, body), receive, send)
|
|
66
|
+
|
|
67
|
+
response = HttpResponse(b"".join(chunks), status=status)
|
|
68
|
+
for key, value in headers:
|
|
69
|
+
if key.lower() not in (b"content-length",):
|
|
70
|
+
response[key.decode("latin-1")] = value.decode("latin-1")
|
|
71
|
+
return response
|