Skip to content

Add request init headers defined on the sse transport on the start phase #538

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

Conversation

danielgek
Copy link
Contributor

This pr adds the headers from the transport instantiation into the start procedure to on sse(this already happens on the httpstream transport)

Motivation and Context

If i want to use sse transport and send a token for the authentication i need to have the token on the start phase

How Has This Been Tested?

This has been tested in a real application

Breaking Changes

I don't think there is 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

@ihrpr ihrpr added this to the HPR milestone May 23, 2025
if (this._authProvider) {
const tokens = await this._authProvider.tokens();
if (tokens) {
headers["Authorization"] = `Bearer ${tokens.access_token}`;
(headers as Record<string, string>)["Authorization"] = `Bearer ${tokens.access_token}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

with this change, like 217 can be simplified as well:

      const headers = new Headers({ ...commonHeaders, ...this._requestInit?.headers });

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!

Minor suggestion can be addressed later.

@ihrpr ihrpr merged commit df0d9c4 into modelcontextprotocol:main May 27, 2025
2 checks passed
@manucorporat
Copy link

hope we release this soon

@steve8708
Copy link

likewise, eager to get this into production!

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