AttributeError: 'JSONRPCMessage' object has no attribute 'message' in MCP 1.4.0
Describe the bug
I encountered an AttributeError when running the example code from MCP Quickstart - Client with MCP version 1.4.0. The error suggests that the JSONRPCMessage object is missing the message attribute. This issue does not occur with MCP 1.3.0.
To Reproduce
Steps to reproduce the behavior:
-
Install MCP version 1.4.0:
uv add mcp==1.4.0 -
Run the example client code from the MCP Quickstart.
-
Observe the following error:
Exception Group Traceback (most recent call last): | File "/Users/cesaraugustogoncalves/mcp-client/.venv/lib/python3.11/site-packages/mcp/client/stdio.py", line 153, in stdio_client | yield read_stream, write_stream | File "/Users/cesaraugustogoncalves/.local/share/uv/python/cpython-3.11.11-macos-aarch64-none/lib/python3.11/contextlib.py", line 728, in __aexit__ | cb_suppress = await cb(*exc_details) | ^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/cesaraugustogoncalves/mcp-client/.venv/lib/python3.11/site-packages/mcp/shared/session.py", line 217, in __aexit__ | return await self._task_group.__aexit__(exc_type, exc_val, exc_tb) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/Users/cesaraugustogoncalves/mcp-client/.venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 767, in __aexit__ | raise BaseExceptionGroup( | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception) +-+---------------- 1 ---------------- | Traceback (most recent call last): | File "/Users/cesaraugustogoncalves/mcp-client/.venv/lib/python3.11/site-packages/mcp/shared/session.py", line 324, in _receive_loop | message = raw_message.message | ^^^^^^^^^^^^^^^^^^^ | File "/Users/cesaraugustogoncalves/mcp-client/.venv/lib/python3.11/site-packages/pydantic/main.py", line 891, in __getattr__ | raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}') | AttributeError: 'JSONRPCMessage' object has no attribute 'message'
Expected behavior
The client should run without raising an AttributeError, as it does with MCP 1.3.0.
Desktop (please complete the following information):
- OS: macOS Sequoia 15.3.2 (M1 ARM64)
- Python Version: 3.11.11
- MCP Client Version: 1.4.0
Additional context
- The issue does not occur when using MCP 1.3.0.
- It seems like the
JSONRPCMessageclass no longer has amessageattribute in version 1.4.0, but this is just based on the traceback.
Would appreciate any insights on whether this is an intended change or a regression. Thanks!
I encountered the same issue.
Upon further investigation of the error, I discovered that the type of raw_message is consistently mcp.types.JSONRPCMessage at this location:
https://github.com/modelcontextprotocol/python-sdk/blob/ebb81d3b2b675cf48225047c0f85e6d6296dc970/src/mcp/shared/session.py#L324
This appears to be happening because the server extracts the inner JSONRPCRequest or JSONRPCResponse from MessageFrame and sends it at this point:
https://github.com/modelcontextprotocol/python-sdk/blob/ebb81d3b2b675cf48225047c0f85e6d6296dc970/src/mcp/server/stdio.py#L85-L86
Same here
Same here
Yeah, it seems this line: https://github.com/modelcontextprotocol/python-sdk/blob/ebb81d3b2b675cf48225047c0f85e6d6296dc970/src/mcp/server/stdio.py#L85-L86
Should have been message.message instead.
I would prefer to revert https://github.com/modelcontextprotocol/python-sdk/pull/239 - not really because of this, but because of the type changes.
+1 having this issue
Same here
The fix was released in mcp 1.4.1. FYI
Fixed in v1.4.1.
@Kludex we need to revisit this, but we need to have a way for servers to get access to the raw http request, in order to get access to headers ,etc.