Skip to content

Commit 326e67b

Browse files
committed
remove clients from session id map when disconnecting
1 parent 2406e90 commit 326e67b

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/mcp-handler.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { Options, CoreConfig } from "storybook/internal/types";
1010
import type { IncomingMessage, ServerResponse } from "node:http";
1111
import {
1212
collectTelemetry,
13-
setClientForSession,
13+
mcpSessionIdToClientMap,
1414
setDisableTelemetry,
1515
} from "./telemetry";
1616

@@ -26,7 +26,7 @@ async function createMcpServer(options: Options, client: string) {
2626
{},
2727
);
2828
setDisableTelemetry(disableTelemetry);
29-
setClientForSession(sessionId, client);
29+
mcpSessionIdToClientMap[sessionId] = client;
3030

3131
await collectTelemetry({
3232
event: "session:initialized",
@@ -36,8 +36,13 @@ async function createMcpServer(options: Options, client: string) {
3636
});
3737

3838
transport.onclose = () => {
39-
if (transport.sessionId) {
40-
delete transports[transport.sessionId];
39+
if (!transport.sessionId) {
40+
return;
41+
}
42+
43+
delete transports[transport.sessionId];
44+
if (mcpSessionIdToClientMap[transport.sessionId]) {
45+
delete mcpSessionIdToClientMap[transport.sessionId];
4146
}
4247
};
4348

src/telemetry.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ export async function collectTelemetry({
2626
}
2727
}
2828

29-
const mcpSessionIdToClientMap: Record<string, string> = {};
30-
31-
export const setClientForSession = (sessionId: string, client: string) => {
32-
mcpSessionIdToClientMap[sessionId] = client;
33-
};
29+
export const mcpSessionIdToClientMap: Record<string, string> = {};
3430

3531
let disableTelemetry = false;
3632
export const setDisableTelemetry = (value = false) => {

0 commit comments

Comments
 (0)