|
|
@@ -71,6 +71,13 @@ function cleanupStateIndex(oauthState: string) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+function stopIfIdle() {
|
|
|
+ if (pendingAuths.size > 0 || !server) return
|
|
|
+
|
|
|
+ server.close()
|
|
|
+ server = undefined
|
|
|
+}
|
|
|
+
|
|
|
function handleRequest(req: import("http").IncomingMessage, res: import("http").ServerResponse) {
|
|
|
const url = new URL(req.url || "/", `http://localhost:${currentPort}`)
|
|
|
|
|
|
@@ -104,6 +111,7 @@ function handleRequest(req: import("http").IncomingMessage, res: import("http").
|
|
|
}
|
|
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" })
|
|
|
res.end(HTML_ERROR(errorMsg))
|
|
|
+ stopIfIdle()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -130,6 +138,7 @@ function handleRequest(req: import("http").IncomingMessage, res: import("http").
|
|
|
|
|
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" })
|
|
|
res.end(HTML_SUCCESS)
|
|
|
+ stopIfIdle()
|
|
|
}
|
|
|
|
|
|
export async function ensureRunning(redirectUri?: string): Promise<void> {
|
|
|
@@ -168,6 +177,7 @@ export function waitForCallback(oauthState: string, mcpName?: string): Promise<s
|
|
|
pendingAuths.delete(oauthState)
|
|
|
if (mcpName) mcpNameToState.delete(mcpName)
|
|
|
reject(new Error("OAuth callback timeout - authorization took too long"))
|
|
|
+ stopIfIdle()
|
|
|
}
|
|
|
}, CALLBACK_TIMEOUT_MS)
|
|
|
|
|
|
@@ -185,6 +195,7 @@ export function cancelPending(mcpName: string): void {
|
|
|
pendingAuths.delete(key)
|
|
|
mcpNameToState.delete(mcpName)
|
|
|
pending.reject(new Error("Authorization cancelled"))
|
|
|
+ stopIfIdle()
|
|
|
}
|
|
|
}
|
|
|
|