From ff07bd4e39b7efde1033161dfa69ca55fc6649e2 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Tue, 29 Jul 2025 14:19:18 +0530 Subject: [PATCH] do not start server is already listening --- core/context/mcp/MCPOauth.ts | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/core/context/mcp/MCPOauth.ts b/core/context/mcp/MCPOauth.ts index 7455fb246..0b711082f 100644 --- a/core/context/mcp/MCPOauth.ts +++ b/core/context/mcp/MCPOauth.ts @@ -62,10 +62,6 @@ class MCPConnectionOauthProvider implements OAuthClientProvider { private ide: IDE, ) { this.globalContext = new GlobalContext(); - console.log( - "debug1 mcp oauth storage", - this.globalContext.get("mcpOauthStorage"), - ); } get redirectUrl() { @@ -152,18 +148,16 @@ class MCPConnectionOauthProvider implements OAuthClientProvider { clear() { this._clearOauthStorage(); - console.log( - "debug1 after clearing mcp oauth storage", - this.globalContext.get("mcpOauthStorage"), - ); } async redirectToAuthorization(authorizationUrl: URL) { - server.listen(PORT, () => { - console.debug( - `Server started for MCP Oauth process at http://localhost:${PORT}/`, - ); - }); + if (!server.listening) { + server.listen(PORT, () => { + console.debug( + `Server started for MCP Oauth process at http://localhost:${PORT}/`, + ); + }); + } void this.ide.openUrl(authorizationUrl.toString()); } } @@ -193,7 +187,7 @@ export async function performAuth(mcpServer: MCPServerStatus, ide: IDE) { /** * handle the authentication code received from the oauth redirect */ -export async function handleMCPOauthCode(authorizationCode: string) { +async function handleMCPOauthCode(authorizationCode: string) { if (!authenticatingMCPContext) { return; }