Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'JSONRPCMessage' object has no attribute 'message' in MCP 1.4.0 #280

Closed
cgoncalves94 opened this issue Mar 14, 2025 · 8 comments · Fixed by #282
Closed

Comments

@cgoncalves94
Copy link

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:

  1. Install MCP version 1.4.0:

    uv add mcp==1.4.0
  2. Run the example client code from the MCP Quickstart.

  3. 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 JSONRPCMessage class no longer has a message attribute 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!

@jkawamoto
Copy link

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:

message = raw_message.message

This appears to be happening because the server extracts the inner JSONRPCRequest or JSONRPCResponse from MessageFrame and sends it at this point:

# Extract the inner JSONRPCRequest/JSONRPCResponse from MessageFrame
json = message.model_dump_json(by_alias=True, exclude_none=True)

jkawamoto added a commit to jkawamoto/mcp-youtube-transcript that referenced this issue Mar 14, 2025
Set MCP dependency to <1.4 for compatibility and replaced a custom logging utility with standard `logging` module setup. This improves maintainability and ensures consistent behavior with logging configurations.

See also: modelcontextprotocol/python-sdk#280
@Soulter
Copy link

Soulter commented Mar 14, 2025

Same here

1 similar comment
@Henry-Jessie
Copy link

Same here

@Kludex
Copy link
Member

Kludex commented Mar 14, 2025

Yeah, it seems this line:

# Extract the inner JSONRPCRequest/JSONRPCResponse from MessageFrame
json = message.model_dump_json(by_alias=True, exclude_none=True)

Should have been message.message instead.


I would prefer to revert #239 - not really because of this, but because of the type changes.

@xinyang-zhu
Copy link

+1 having this issue

@Ryaningli
Copy link

Same here

@Kludex
Copy link
Member

Kludex commented Mar 14, 2025

The fix was released in mcp 1.4.1. FYI

@dsp-ant
Copy link
Member

dsp-ant commented Mar 14, 2025

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.

jkawamoto added a commit to jkawamoto/python-sdk that referenced this issue Mar 16, 2025
This commit introduces end-to-end tests to detect potential miscommunication issues between servers and clients (e.g. modelcontextprotocol#280).

The implementation includes:
- Basic end-to-end test suite using an Echo server
- Verification of session initialization
- Testing of tools and prompts listing functionality

Note: Resource listing tests are currently skipped due to modelcontextprotocol#268.
jkawamoto added a commit to jkawamoto/python-sdk that referenced this issue Mar 17, 2025
This commit introduces end-to-end tests to detect potential miscommunication issues between servers and clients (e.g. modelcontextprotocol#280).

The implementation includes:
- Basic end-to-end test suite using an Echo server
- Verification of session initialization
- Testing of resource templates, tools, and prompts listing functionality
jkawamoto added a commit to jkawamoto/python-sdk that referenced this issue Mar 21, 2025
This commit introduces end-to-end tests to detect potential miscommunication issues between servers and clients (e.g. modelcontextprotocol#280).

The implementation includes:
- Basic end-to-end test suite using an Echo server
- Verification of session initialization
- Testing of resource templates, tools, and prompts listing functionality
jkawamoto added a commit to jkawamoto/python-sdk that referenced this issue Mar 21, 2025
This commit introduces end-to-end tests to detect potential miscommunication issues between servers and clients (e.g. modelcontextprotocol#280).

The implementation includes:
- Basic end-to-end test suite using an Echo server
- Verification of session initialization
- Testing of resource templates, tools, and prompts listing functionality
jkawamoto added a commit to jkawamoto/python-sdk that referenced this issue Mar 24, 2025
This commit introduces end-to-end tests to detect potential miscommunication issues between servers and clients (e.g. modelcontextprotocol#280).

The implementation includes:
- Basic end-to-end test suite using an Echo server
- Verification of session initialization
- Testing of resource templates, tools, and prompts listing functionality
jkawamoto added a commit to jkawamoto/python-sdk that referenced this issue Mar 27, 2025
This commit introduces end-to-end tests to detect potential miscommunication issues between servers and clients (e.g. modelcontextprotocol#280).

The implementation includes:
- Basic end-to-end test suite using an Echo server
- Verification of session initialization
- Testing of resource templates, tools, and prompts listing functionality
jkawamoto added a commit to jkawamoto/python-sdk that referenced this issue Apr 3, 2025
This commit introduces end-to-end tests to detect potential miscommunication issues between servers and clients (e.g. modelcontextprotocol#280).

The implementation includes:
- Basic end-to-end test suite using an Echo server
- Verification of session initialization
- Testing of resource templates, tools, and prompts listing functionality
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
8 participants