Skip to content
Open
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
22 changes: 20 additions & 2 deletions src/vs/workbench/api/common/extHostMcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ export class McpHTTPHandle extends Disposable {
private readonly _abortCtrl = new AbortController();
private _authMetadata?: AuthMetadata;
private _didSendClose = false;
private _didSendInitialized = false;

constructor(
private readonly _id: number,
Expand All @@ -384,8 +385,17 @@ export class McpHTTPHandle extends Disposable {

async send(message: string) {
try {
if (this._mode.value === HttpMode.Unknown) {
await this._requestSequencer.queue(() => this._send(message));
// Keep sends serialized until `notifications/initialized` has been
// delivered. Each message is a separate HTTP POST, so otherwise the
// notification and the first request that follows it race, and servers
// that track session state can reject the request as uninitialized.
if (this._mode.value === HttpMode.Unknown || !this._didSendInitialized) {
await this._requestSequencer.queue(async () => {
await this._send(message);
if (isInitializedNotification(message)) {
this._didSendInitialized = true;
}
});
Comment on lines +392 to +398
} else {
await this._send(message);
}
Expand Down Expand Up @@ -956,6 +966,14 @@ function isJSON(str: string): boolean {
}
}

function isInitializedNotification(message: string): boolean {
try {
return JSON.parse(message)?.method === 'notifications/initialized';
} catch (e) {
return false;
}
}

function isAuthStatusCode(status: number): boolean {
return status === 401 || status === 403;
}
Expand Down