Skip to content

Commit f276e68

Browse files
committed
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
1 parent db095b7 commit f276e68

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/services/mcp/McpHub.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ const createServerTypeSchema = () => {
8686
type: z.enum(["stdio"]).optional(),
8787
command: z.string().min(1, "Command cannot be empty"),
8888
args: z.array(z.string()).optional(),
89-
cwd: z.string().default(() => vscode.workspace.workspaceFolders?.at(0)?.uri.fsPath ?? process.cwd()),
89+
cwd: z.string().default(() => {
90+
const workspaceFolders = vscode.workspace.workspaceFolders
91+
return workspaceFolders && workspaceFolders.length > 0 ? workspaceFolders[0].uri.fsPath : process.cwd()
92+
}),
9093
env: z.record(z.string()).optional(),
9194
// Ensure no SSE fields are present
9295
url: z.undefined().optional(),

0 commit comments

Comments
 (0)