Skip to content

Create Client websocket.py#179

Merged
jerome3o-anthropic merged 11 commits into
modelcontextprotocol:mainfrom
smithery-ai:patch-1
Mar 12, 2025
Merged

Create Client websocket.py#179
jerome3o-anthropic merged 11 commits into
modelcontextprotocol:mainfrom
smithery-ai:patch-1

Conversation

@calclavia

@calclavia calclavia commented Jan 29, 2025

Copy link
Copy Markdown
Member

Adds a WebSocket client.

Motivation and Context

Currently, there's a WebSocket server but no client. Allows Python clients to connect to WS servers.

How Has This Been Tested?

This is a draft PR. If there's interest in this, then we can move on to adding a test.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

@jalleyne

jalleyne commented Feb 6, 2025

Copy link
Copy Markdown

@calclavia thanks for pushing this draft, I'd love to see tests and happy to assist.

@akaashdash

Copy link
Copy Markdown

any update on this?

@calclavia

Copy link
Copy Markdown
Member Author

any update on this?

Hey, sorry I missed this thread. Will run some tests and update!

Comment thread src/mcp/client/websocket.py Outdated
Comment thread src/mcp/client/websocket.py Outdated
Comment thread src/mcp/client/websocket.py Outdated
calclavia and others added 3 commits March 6, 2025 20:12
@calclavia calclavia marked this pull request as ready for review March 7, 2025 14:02
@calclavia

Copy link
Copy Markdown
Member Author

@Kludex I addressed your comments by fixing it. Also added a test and that new test passes.

Comment thread src/mcp/client/websocket.py Outdated
@Kludex

Kludex commented Mar 7, 2025

Copy link
Copy Markdown
Member

Btw, I'm not a maintainer here. I was just passing by.

@calclavia

Copy link
Copy Markdown
Member Author

My bad - notifying @jalleyne

@jerome3o-anthropic jerome3o-anthropic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome - I've had a play with it locally and it works well. Once the requested changes are in I'm happy to merge

Comment thread pyproject.toml Outdated
Comment thread src/mcp/client/websocket.py Outdated
@calclavia

Copy link
Copy Markdown
Member Author

@jerome3o-anthropic Addressed comments!

@jerome3o-anthropic jerome3o-anthropic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm - thanks

@jerome3o-anthropic

Copy link
Copy Markdown
Member

Looks like you have some linting / formating / locking issues, once solved we can merge

Comment on lines +66 to +70
# Convert to a dict, then to JSON
msg_dict = message.model_dump(
by_alias=True, mode="json", exclude_none=True
)
await ws.send(json.dumps(msg_dict))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to use all this, you can just do message.model_dump_json().

@jerome3o-anthropic jerome3o-anthropic merged commit 1691b90 into modelcontextprotocol:main Mar 12, 2025
@calclavia calclavia deleted the patch-1 branch March 13, 2025 20:32
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.

5 participants