Skip to content

apply requestInit to SSE GET in StreamableHTTP transport 895 problem #897

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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@
"resolutions": {
"strip-ansi": "6.0.1"
}
}
}
4 changes: 4 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ async function runServer(port: number | null) {
version: "0.1.0",
},
{

capabilities: {},
},
);
Expand Down Expand Up @@ -142,6 +143,7 @@ switch (command) {
}

runClient(args[1], args.slice(2)).catch((error) => {
console.log("hi")
console.error(error);
process.exit(1);
});
Expand All @@ -150,7 +152,9 @@ switch (command) {

case "server": {
const port = args[1] ? parseInt(args[1]) : null;

runServer(port).catch((error) => {

console.error(error);
process.exit(1);
});
Expand Down
1 change: 1 addition & 0 deletions src/client/streamableHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export class StreamableHTTPClientTransport implements Transport {
}

const response = await (this._fetch ?? fetch)(this._url, {
...this._requestInit,
method: "GET",
headers,
signal: this._abortController?.signal,
Expand Down
6 changes: 5 additions & 1 deletion src/examples/client/multipleClientsParallel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ async function createAndRunClient(config: ClientConfig): Promise<{ id: string; r
version: '1.0.0'
});

const transport = new StreamableHTTPClientTransport(new URL(serverUrl));
const transport = new StreamableHTTPClientTransport(new URL(serverUrl), {
requestInit: {
credentials: "include", // ensures cookies/auth headers are sent
},
});

// Set up client-specific error handler
client.onerror = (error) => {
Expand Down
1 change: 1 addition & 0 deletions src/server/streamableHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export class StreamableHTTPServerTransport implements Transport {
private async handleGetRequest(req: IncomingMessage, res: ServerResponse): Promise<void> {
// The client MUST include an Accept header, listing text/event-stream as a supported content type.
const acceptHeader = req.headers.accept;
console.log('GET cookies:', req.headers.cookie);
if (!acceptHeader?.includes("text/event-stream")) {
res.writeHead(406).end(JSON.stringify({
jsonrpc: "2.0",
Expand Down