-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
mediumMedium priorityMedium priority
Description
Description
Two separate code paths implement identical MCP endpoint logic, risking divergence.
Location
- File:
django_admin_mcp/views.py - MCPHTTPView: lines 58-126 (class-based view)
- mcp_endpoint(): lines 136-213 (function-based async view)
Issue
Both implementations:
- Call
authenticate_token() - Parse JSON requests
- Route to handlers
- Format responses
If a bug is fixed in one, the other may be forgotten.
Current Duplication
# MCPHTTPView.post()
token = await authenticate_token(request)
if not token:
return JsonResponse({"error": "..."}, status=401)
# ... parsing and routing ...
# mcp_endpoint()
token = await authenticate_token(request)
if not token:
return JsonResponse({"error": "..."}, status=401)
# ... same parsing and routing ...Recommended Fix
Consolidate into single implementation:
async def _handle_mcp_request(request: HttpRequest) -> JsonResponse:
"""Core MCP request handling logic."""
token = await authenticate_token(request)
if not token:
return JsonResponse({"error": "Invalid or missing token"}, status=401)
# ... shared logic ...
# Class-based wrapper
class MCPHTTPView(View):
async def post(self, request):
return await _handle_mcp_request(request)
# Function-based wrapper
async def mcp_endpoint(request):
if request.method != "POST":
return JsonResponse({"error": "Method not allowed"}, status=405)
return await _handle_mcp_request(request)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
mediumMedium priorityMedium priority