Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Edison-A-N
Copy link
Contributor

Add WebSocket Dependency to MCP

Issue

core.py uses websocket_client from MCP SDK, but the required websockets dependency is not installed by default.

Changes

Updated pyproject.toml:

  • Changed: mcp>=1.10.1mcp[ws]>=1.10.1

This ensures the websockets>=15.0.1 package is automatically installed, enabling WebSocket transport support in core.py.

Type

Critical Bug Fix - Resolves ImportError and restores WebSocket functionality.

@Edison-A-N
Copy link
Contributor Author

@grll Hi, this fix is required to support #73

@grll
Copy link
Owner

grll commented Oct 12, 2025

@grll Hi, this fix is required to support #73

Thanks for highlighting this and proposing a fix I saw the issue when merging #73 but somehow I didn't have any issue neither in the test env or my local env I thought the websocket package must be included as a dependency somewhere.

Have you observed a specific error related?

Also I am wondering why is it an optional dependency on MCP is it that large of a package to not come with the rest?

@Edison-A-N
Copy link
Contributor Author

Hi, I install smolagents using pip install 'smolagents[mcp]' for testing and i met this error:

Traceback (most recent call last):
  File "/data/smolagents/try.py", line 39, in <module>
    with MCPClient(serverparams, structured_output=True) as tools:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/smolagents/.venv/lib/python3.12/site-packages/smolagents/mcp_client.py", line 107, in __init__
    raise ModuleNotFoundError("Please install 'mcp' extra to use MCPClient: `pip install 'smolagents[mcp]'`")
ModuleNotFoundError: Please install 'mcp' extra to use MCPClient: `pip install 'smolagents[mcp]'

in smolagents/mcp_client.py:

       try:
            from mcpadapt.core import MCPAdapt
            from mcpadapt.smolagents_adapter import SmolAgentsAdapter
        except ModuleNotFoundError:
            raise ModuleNotFoundError("Please install 'mcp' extra to use MCPClient: `pip install 'smolagents[mcp]'`")

As for why websockets is optional, the reference is a suggestion made in that PR: modelcontextprotocol/python-sdk#179 (comment), but no rationale was given (see also issue modelcontextprotocol/python-sdk#302 (comment))

@davidmezzetti
Copy link

@grll Thank you for your contributions in open source! Just as a heads up, #73 broke this package for most people as websockets isn't installed.

@grll
Copy link
Owner

grll commented Oct 14, 2025

@grll Thank you for your contributions in open source! Just as a heads up, #73 broke this package for most people as websockets isn't installed.

Thanks for the heads up I will have a look at it later today!

@grll
Copy link
Owner

grll commented Oct 16, 2025

Ok its a bit of a mess because on mac intel there is no wheel for the latest torch audio. I will merge and release this change for unblocking everyone. Sorry for the delay.
@davidmezzetti
@Edison-A-N

@grll grll merged commit d0404b1 into grll:main Oct 16, 2025
3 checks passed
@chahn
Copy link
Contributor

chahn commented Oct 16, 2025

Thanks a lot for the fix @grll and @Edison-A-N.

@Edison-A-N Edison-A-N deleted the fix/add-mcp-ws-dependency branch October 16, 2025 08:14
@davidmezzetti
Copy link

I appreciate the quick fix on this, thank you!

@Edison-A-N
Copy link
Contributor Author

@grll Hi, I apologize for the oversight in this PR 🙏

While working on PR #76 (fault tolerance feature), I discovered that I only updated pyproject.toml but forgot to sync uv.lock when adding the mcp[ws] dependency.

Impact

  • websockets package won't be installed via uv sync

Fix

I have the corrected uv.lock ready locally. The key changes needed:

+[package.optional-dependencies]
+ws = [
+    { name = "websockets" },
+]

-    { name = "mcp" },
+    { name = "mcp", extra = ["ws"] },

Would you like me to submit a patch PR to fix this, or would you prefer to handle it differently?

Sorry again for not following the proper contribution workflow!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants