Skip to content

Conversation

@avi1mizrahi
Copy link

Add support for custom headers in SSE transport.

Motivation and Context

This change enables forwarding custom HTTP headers with SSE connections, particularly useful for authorization via bearer tokens (our use case).
This brings the Rust SDK in line with Python and TypeScript SDKs which already support this capability (links point to the relevant implementation in each repository).

How Has This Been Tested?

Implemented and tested authentication header forwarding in the example SSE client application against our server.

Breaking Changes

The SseTransport constructor signature has been modified: the env parameter has been removed and replaced with headers. IDK why it was there in the first place, but if it is needed I'll put it back; probably just a copy-paste from the STDIO.

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

This implementation replaces the previous environment variable approach with direct header management, providing a more intuitive API that aligns with standard HTTP client libraries and other SDK implementations.

@4t145
Copy link
Collaborator

4t145 commented Mar 28, 2025

Hello, in the newly merged rmcp, you can add custom headers by using SseTransport::start_with_client. You can set default headers for reqwest::Client. So I will close this pr.

@4t145 4t145 closed this Mar 28, 2025
@avi1mizrahi
Copy link
Author

Hello, in the newly merged rmcp, you can add custom headers by using SseTransport::start_with_client. You can set default headers for reqwest::Client. So I will close this pr.

Nice, thank you. I had the dilemma whether to get the client or just the headers. Anyhow good to see that this SDK is starting to get going 🚀

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

Labels

None yet

2 participants