Skip to content

Commit 32f2432

Browse files
author
Gustavo Bicalho
committed
for single-root workspaces, use that folder as CWD for MCP servers
1 parent 3f2321b commit 32f2432

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/services/mcp/McpHub.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export class McpHub {
172172
// ...(process.env.NODE_PATH ? { NODE_PATH: process.env.NODE_PATH } : {}),
173173
},
174174
stderr: "pipe", // necessary for stderr to be available
175+
cwd: config.cwd ?? this.getDefaultCwd(),
175176
})
176177

177178
transport.onerror = async (error) => {
@@ -266,6 +267,14 @@ export class McpHub {
266267
}
267268
}
268269

270+
private getDefaultCwd() {
271+
const paths = vscode.workspace.workspaceFolders
272+
if (paths?.length === 1) {
273+
return paths[0].uri.fsPath
274+
}
275+
return undefined
276+
}
277+
269278
private appendErrorMessage(connection: McpConnection, error: string) {
270279
const newError = connection.server.error ? `${connection.server.error}\n${error}` : error
271280
connection.server.error = newError //.slice(0, 800)

0 commit comments

Comments
 (0)