diff --git a/backend/src/app/rpc/commands/access_token.clj b/backend/src/app/rpc/commands/access_token.clj index 40a27ee763..eedb119d06 100644 --- a/backend/src/app/rpc/commands/access_token.clj +++ b/backend/src/app/rpc/commands/access_token.clj @@ -100,6 +100,7 @@ :type "mcp"} {:order-by [[:expires-at :asc] [:created-at :asc]] :columns [:token :expires-at]}) - (remove #(ct/is-after? request-at (:expires-at %))) + (remove #(and (some? (:expires-at %)) + (ct/is-after? request-at (:expires-at %)))) (map decode-row) (first))) diff --git a/mcp/packages/plugin/src/main.ts b/mcp/packages/plugin/src/main.ts index 1d6c7edf3b..da87fa025f 100644 --- a/mcp/packages/plugin/src/main.ts +++ b/mcp/packages/plugin/src/main.ts @@ -55,6 +55,8 @@ function connectToMcpServer(baseUrl?: string, token?: string): void { try { let wsUrl = baseUrl || PENPOT_MCP_WEBSOCKET_URL; + let wsError: unknown | undefined; + if (token) { wsUrl += `?userToken=${encodeURIComponent(token)}`; } @@ -79,14 +81,18 @@ function connectToMcpServer(baseUrl?: string, token?: string): void { }; ws.onclose = (event: CloseEvent) => { - console.log("Disconnected from MCP server"); - const message = event.reason || undefined; - updateConnectionStatus("disconnected", "Disconnected", false, message); + // If we've send the error update we don't send the disconnect as well + if (!wsError) { + console.log("Disconnected from MCP server"); + const message = event.reason || undefined; + updateConnectionStatus("disconnected", "Disconnected", false, message); + } ws = null; }; ws.onerror = (error) => { console.error("WebSocket error:", error); + wsError = error; // note: WebSocket error events typically don't contain detailed error messages updateConnectionStatus("error", "Connection error", false); };