-
Notifications
You must be signed in to change notification settings - Fork 33
Description
[my operating environment]
Django version:5.2.4
python version:3.10
dms: 0.5.6
[scene]
I cloned the source code of this project and ran the example with the latest version. However, when I used the cursor to call LocationAPIView_CreateTool in the example, the system reported an error and the return value was as follows:
Error executing tool LocationAPIView_CreateTool: {'name': [ErrorDetail(string='This field is required.', code='required')]}
The complete error message from the server is:
[08/01/25 08:31:08] INFO StreamableHTTP streamable_http_manager.py:112
session manager
started
INFO Processing request of type server.py:619
CallToolRequest
ERROR Error in DRF tool invocation djangomcp.py:529
╭─ Traceback (most recent call l─╮
│ /Users/mika/PycharmProje │
│ cts/django-mcp-server/mcp_serv │
│ er/djangomcp.py:527 in │
│ __call__ │
│ │
│ 524 │ │ │
│ 525 │ │ # Create the vie │
│ 526 │ │ try: │
│ ❱ 527 │ │ │ return self. │
│ 528 │ │ except Exception │
│ 529 │ │ │ logger.excep │
│ 530 │ │ │ raise exp │
│ │
│ /Users/mika/PycharmProje │
│ cts/cov_data_mcp/.venv/lib/pyt │
│ hon3.10/site-packages/django/v │
│ iews/decorators/csrf.py:65 in │
│ _view_wrapper │
│ │
│ 62 │ else: │
│ 63 │ │ │
│ 64 │ │ def _view_wrapper │
│ ❱ 65 │ │ │ return view_f │
│ 66 │ │
│ 67 │ _view_wrapper.csrf_ex │
│ 68 │
│ │
│ /Users/mika/PycharmProje │
│ cts/cov_data_mcp/.venv/lib/pyt │
│ hon3.10/site-packages/django/v │
│ iews/generic/base.py:105 in │
│ view │
│ │
│ 102 │ │ │ │ │ "%s │
│ 103 │ │ │ │ │ "set │
│ 104 │ │ │ │ ) │
│ ❱ 105 │ │ │ return self. │
│ 106 │ │ │
│ 107 │ │ view.view_class │
│ 108 │ │ view.view_initkw │
│ │
│ /Users/mika/PycharmProje │
│ cts/cov_data_mcp/.venv/lib/pyt │
│ hon3.10/site-packages/rest_fra │
│ mework/views.py:515 in │
│ dispatch │
│ │
│ 512 │ │ │ response = h │
│ 513 │ │ │
│ 514 │ │ except Exception │
│ ❱ 515 │ │ │ response = s │
│ 516 │ │ │
│ 517 │ │ self.response = │
│ 518 │ │ return self.resp │
│ │
│ /Users/mika/PycharmProje │
│ cts/django-mcp-server/mcp_serv │
│ er/djangomcp.py:507 in │
│ raise_exception │
│ │
│ 504 │ │ self.view_class │
│ 505 │ │ │
│ 506 │ │ def raise_except │
│ ❱ 507 │ │ │ raise exp │
│ 508 │ │ │
│ 509 │ │ kwargs = dict( │
│ 510 │ │ │ filter_backe │
│ │
│ /Users/mika/PycharmProje │
│ cts/cov_data_mcp/.venv/lib/pyt │
│ hon3.10/site-packages/rest_fra │
│ mework/views.py:512 in │
│ dispatch │
│ │
│ 509 │ │ │ else: │
│ 510 │ │ │ │ handler │
│ 511 │ │ │ │
│ ❱ 512 │ │ │ response = h │
│ 513 │ │ │
│ 514 │ │ except Exception │
│ 515 │ │ │ response = s │
│ │
│ /Users/mika/PycharmProje │
│ cts/cov_data_mcp/.venv/lib/pyt │
│ hon3.10/site-packages/rest_fra │
│ mework/generics.py:194 in post │
│ │
│ 191 │ Concrete view for cr │
│ 192 │ """ │
│ 193 │ def post(self, reque │
│ ❱ 194 │ │ return self.crea │
│ 195 │
│ 196 │
│ 197 class ListAPIView(mixins │
│ │
│ /Users/mika/PycharmProje │
│ cts/cov_data_mcp/.venv/lib/pyt │
│ hon3.10/site-packages/rest_fra │
│ mework/mixins.py:18 in create │
│ │
│ 15 │ """ │
│ 16 │ def create(self, requ │
│ 17 │ │ serializer = self │
│ ❱ 18 │ │ serializer.is_val │
│ 19 │ │ self.perform_crea │
│ 20 │ │ headers = self.ge │
│ 21 │ │ return Response(s │
│ headers=headers) │
│ │
│ /Users/mika/PycharmProje │
│ cts/cov_data_mcp/.venv/lib/pyt │
│ hon3.10/site-packages/rest_fra │
│ mework/serializers.py:233 in │
│ is_valid │
│ │
│ 230 │ │ │ │ self._e │
│ 231 │ │ │
│ 232 │ │ if self._errors │
│ ❱ 233 │ │ │ raise Valid │
│ 234 │ │ │
│ 235 │ │ return not bool │
│ 236 │
╰────────────────────────────────╯
ValidationError: {'name':
[ErrorDetail(string='This field is
required.', code='required')]}
INFO StreamableHTTP streamable_http_manager.py:116
session manager
shutting down
[01/Aug/2025 08:31:09] "POST /mcpunsecured HTTP/1.1" 200 212
[Other information]
I debugged and found that the root cause seemed to be the following exception reported in the create of CreateModelMixin, which caused the data to be unable to be obtained normally:
AssertionError('When a serializer is passed a data keyword argument you must call .is_valid() before attempting to access the serialized .data representation.\nYou should either call .is_valid() first, or access .initial_data instead.')
I used claude to help analyze and found that it might be because BaseAPIViewCallerTool's _patched_initialize_request did not create a DRF Request,If we change to the following implementation, everything seems to work fine:
@staticmethod
def _patched_initialize_request(self, request, *args, **kwargs):
parser_context = self.get_parser_context(request)
return Request(
request,
parsers=self.get_parsers(),
authenticators=self.get_authenticators(),
negotiator=self.get_content_negotiator(),
parser_context=parser_context
)
I'm not sure if there are historical reasons for the original design that I'm not aware of. If not, should I file a pull request to fix it?