-
Notifications
You must be signed in to change notification settings - Fork 989
add custom headers on initial _startOrAuth call #318
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
base: main
Are you sure you want to change the base?
add custom headers on initial _startOrAuth call #318
Conversation
This fix for |
@ihrpr Could you please help with the merge? Thanks! |
Update README requirement node js version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @anthonjn, a much needed update indeed! Suggested a slight refactor :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should update the commonHeaders method & align it w/ the streamableHttp version. Something like:
private async _commonHeaders(): Promise<Headers> {
const headers: HeadersInit = {};
if (this._authProvider) {
const tokens = await this._authProvider.tokens();
if (tokens) {
headers["Authorization"] = `Bearer ${tokens.access_token}`;
}
}
return new Headers(
{ ...headers, ...this._requestInit?.headers }
);
}
Could you please also update the header usage in the send method?
const headers = await this._commonHeaders();
headers.set("content-type", "application/json");
const commonHeaders = await this._commonHeaders(); | ||
const allHeaders = { ...commonHeaders, ...this._requestInit?.headers}; | ||
return fetch(url, { | ||
...init, | ||
headers: { | ||
...allHeaders, | ||
Accept: "text/event-stream" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const commonHeaders = await this._commonHeaders(); | |
const allHeaders = { ...commonHeaders, ...this._requestInit?.headers}; | |
return fetch(url, { | |
...init, | |
headers: { | |
...allHeaders, | |
Accept: "text/event-stream" | |
} | |
const headers = await this._commonHeaders(); | |
headers.set("Accept", "text/event-stream"); | |
return fetch(url, { | |
...init, | |
headers, | |
}) |
Ensure that custom headers provided in
this._requestInit?.headers
are included in the initial call to the/sse
endpoint.Motivation and Context
Fixes #317, where custom headers (e.g.
Host
,X-*
) were not sent in the initial/sse
request, but were correctly sent in/messages
. This is needed for MCP servers behind proxies that rely on these headers.This PR aligns the behavior of the
/sse
request withsend()
by ensuring that all custom headers (when provided) are forwarded appropriately.How Has This Been Tested?
/sse
request.Breaking Changes
No
Types of changes
Checklist
Additional context
N/a