python-sdk icon indicating copy to clipboard operation
python-sdk copied to clipboard

Add optional headers argument to websocket transport

Open andrewmjc opened this issue 10 months ago • 0 comments

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)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [ ] Documentation update

Checklist

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

Additional context

andrewmjc avatar Apr 08 '25 15:04 andrewmjc