Skip to content

Add optional headers argument to websocket transport #455

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

andrewmjc
Copy link

This is a small PR to expose the additional_headers param on ws_connect through a new 'headers' argument in the websocket transport

Motivation and Context

This enables users to pass through custom headers that the MCP server might require for auth, remote customization, version headers, or otherwise. Currently, the SSE transport supports settings headers, but the WS transport does not.

I am aware that the JS Websocket implementation only allows setting the Sec-WebSocket-Protocol header, so adding headers to all SDKs might be tricky, but I think it's better to expose the ability to set these headers where we can.

How Has This Been Tested?

Will work the exact same as the current WS transport. The receiving server can now view the headers sent in the handshake request.

Breaking Changes

No breaking changes

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

Additional context

Copy link

@mcp-shadow mcp-shadow bot left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution!

Some suggestions:

  1. Add unit tests to verify the headers are correctly passed to the WebSocket connection
  2. Update the function docstring to document the new headers parameter
  3. Consider adding a simple usage example in a comment

@ihrpr ihrpr added this to the r-05-25 milestone May 13, 2025
Copy link
Contributor

@ihrpr ihrpr left a comment

Choose a reason for hiding this comment

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

Thank you!

Please address minor suggestions in the comments.

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.

2 participants