From f276e681335dc6eb94d3a41eecfddd850d9a0cae Mon Sep 17 00:00:00 2001 From: Roo Code Date: Fri, 5 Sep 2025 07:13:10 +0000 Subject: [PATCH] fix: handle empty workspace folders array to prevent path type errors - Replace .at(0) with safe array access using length checks - Fixes "path argument must be of type string" error when workspace is empty - Addresses regression introduced between v3.25.17 and v3.26.7 Fixes #7695 --- src/services/mcp/McpHub.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/services/mcp/McpHub.ts b/src/services/mcp/McpHub.ts index 6ec5b839e8..07264637b2 100644 --- a/src/services/mcp/McpHub.ts +++ b/src/services/mcp/McpHub.ts @@ -86,7 +86,10 @@ const createServerTypeSchema = () => { type: z.enum(["stdio"]).optional(), command: z.string().min(1, "Command cannot be empty"), args: z.array(z.string()).optional(), - cwd: z.string().default(() => vscode.workspace.workspaceFolders?.at(0)?.uri.fsPath ?? process.cwd()), + cwd: z.string().default(() => { + const workspaceFolders = vscode.workspace.workspaceFolders + return workspaceFolders && workspaceFolders.length > 0 ? workspaceFolders[0].uri.fsPath : process.cwd() + }), env: z.record(z.string()).optional(), // Ensure no SSE fields are present url: z.undefined().optional(),