Skip to content

Commit 7aeb679

Browse files
committed
improve comments
1 parent c21b9a0 commit 7aeb679

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

src/client/streamableHttp.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ describe("StreamableHTTPClientTransport", () => {
164164
// We expect the 405 error to be caught and handled gracefully
165165
// This should not throw an error that breaks the transport
166166
await transport.start();
167-
await expect(transport["_startOrAuthStandaloneSSE"]()).resolves.not.toThrow("Failed to open SSE stream: Method Not Allowed");
167+
await expect(transport["_startOrAuthSse"]()).resolves.not.toThrow("Failed to open SSE stream: Method Not Allowed");
168168
// Check that GET was attempted
169169
expect(global.fetch).toHaveBeenCalledWith(
170170
expect.anything(),
@@ -208,7 +208,7 @@ describe("StreamableHTTPClientTransport", () => {
208208
transport.onmessage = messageSpy;
209209

210210
await transport.start();
211-
await transport["_startOrAuthStandaloneSSE"]();
211+
await transport["_startOrAuthSse"]();
212212

213213
// Give time for the SSE event to be processed
214214
await new Promise(resolve => setTimeout(resolve, 50));
@@ -313,9 +313,9 @@ describe("StreamableHTTPClientTransport", () => {
313313
await transport.start();
314314
// Type assertion to access private method
315315
const transportWithPrivateMethods = transport as unknown as {
316-
_startOrAuthStandaloneSSE: (lastEventId?: string) => Promise<void>
316+
_startOrAuthSse: (lastEventId?: string) => Promise<void>
317317
};
318-
await transportWithPrivateMethods._startOrAuthStandaloneSSE("test-event-id");
318+
await transportWithPrivateMethods._startOrAuthSse("test-event-id");
319319

320320
// Verify fetch was called with the lastEventId header
321321
expect(fetchSpy).toHaveBeenCalled();
@@ -382,7 +382,7 @@ describe("StreamableHTTPClientTransport", () => {
382382

383383
await transport.start();
384384

385-
await transport["_startOrAuthStandaloneSSE"]();
385+
await transport["_startOrAuthSse"]();
386386
expect((actualReqInit.headers as Headers).get("x-custom-header")).toBe("CustomValue");
387387

388388
requestInit.headers["X-Custom-Header"] = "SecondCustomValue";

src/client/streamableHttp.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class StreamableHTTPClientTransport implements Transport {
123123
throw new UnauthorizedError();
124124
}
125125

126-
return await this._startOrAuthStandaloneSSE();
126+
return await this._startOrAuthSse();
127127
}
128128

129129
private async _commonHeaders(): Promise<Headers> {
@@ -144,7 +144,7 @@ export class StreamableHTTPClientTransport implements Transport {
144144
);
145145
}
146146

147-
private async _startOrAuthStandaloneSSE(lastEventId?: string): Promise<void> {
147+
private async _startOrAuthSse(lastEventId?: string): Promise<void> {
148148
try {
149149
// Try to open an initial SSE stream with GET to listen for server messages
150150
// This is optional according to the spec - server may not support it
@@ -238,7 +238,7 @@ export class StreamableHTTPClientTransport implements Transport {
238238
// Schedule the reconnection
239239
setTimeout(() => {
240240
// Use the last event ID to resume where we left off
241-
this._startOrAuthStandaloneSSE(lastEventId).catch(error => {
241+
this._startOrAuthSse(lastEventId).catch(error => {
242242
this.onerror?.(new Error(`Failed to reconnect SSE stream: ${error instanceof Error ? error.message : String(error)}`));
243243
// Schedule another attempt if this one failed, incrementing the attempt counter
244244
this._scheduleReconnection(lastEventId, attemptCount + 1);
@@ -343,7 +343,7 @@ export class StreamableHTTPClientTransport implements Transport {
343343
const { lastEventId, onLastEventIdUpdate } = options ?? {};
344344
if (lastEventId) {
345345
// If we have at last event ID, we need to reconnect the SSE stream
346-
this._startOrAuthStandaloneSSE(lastEventId).catch(err => this.onerror?.(err));
346+
this._startOrAuthSse(lastEventId).catch(err => this.onerror?.(err));
347347
return;
348348
}
349349

@@ -390,7 +390,7 @@ export class StreamableHTTPClientTransport implements Transport {
390390
// if it's supported by the server
391391
if (isJSONRPCNotification(message) && message.method === "notifications/initialized") {
392392
// Start without a lastEventId since this is a fresh connection
393-
this._startOrAuthStandaloneSSE().catch(err => this.onerror?.(err));
393+
this._startOrAuthSse().catch(err => this.onerror?.(err));
394394
}
395395
return;
396396
}

src/server/streamableHttp.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ export class StreamableHTTPServerTransport implements Transport {
346346
);
347347
const mcpSessionId = req.headers["mcp-session-id"] as string | undefined;
348348
if (isInitializationRequest) {
349-
// if generateSessionId is not set, the server does not support session management
349+
// If it's a server with session management and the session ID is already set we should reject the request
350+
// to avoid re-initialization.
350351
if (this._initialized && this.sessionId !== undefined && mcpSessionId !== this.sessionId) {
351352
res.writeHead(400).end(JSON.stringify({
352353
jsonrpc: "2.0",

src/shared/protocol.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,15 @@ export type RequestOptions = {
8787
* May be used to indicate to the transport which incoming request to associate this outgoing request with.
8888
*/
8989
relatedRequestId?: RequestId;
90-
9190
/**
92-
* May be used to indicate to the transport which last event ID to associate this outgoing request with.
93-
* This is used to resume a long-running requests that may have been interrupted and a new instance of a client is being created.
91+
* The last event ID to associate with the request.
92+
* Used to resume long-running requests that were interrupted when creating a new client instance.
9493
*/
9594
lastEventId?: string;
9695

9796
/**
9897
* A callback that is invoked when the last event ID is updated.
99-
* This is used to notidy the client that the last event ID has changed, so that client can update its state accordingly.
98+
* This is used to notify the client that the last event ID has changed, so the client can update its state accordingly.
10099
*/
101100
onLastEventIdUpdate?: (event: string) => void;
102101
};

0 commit comments

Comments
 (0)