File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"
99import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js" ;
1010import { WebSocketClientTransport } from "@modelcontextprotocol/sdk/client/websocket.js" ;
1111
12+ import { fileURLToPath } from "node:url" ;
1213import {
1314 IDE ,
1415 MCPConnectionStatus ,
@@ -343,6 +344,26 @@ class MCPConnection {
343344 } ;
344345 }
345346
347+ /**
348+ * Resolves the current working directory of the current workspace.
349+ * @param cwd The cwd parameter provided by user.
350+ * @returns Current working directory (user-provided cwd or workspace root).
351+ */
352+ private async resolveCwd ( cwd ?: string ) {
353+ // Return cwd if it has been explicitly set.
354+ if ( cwd ) {
355+ return cwd ;
356+ }
357+ // Otherwise use workspace folder.
358+ const workspaceDirs = await this . extras ?. ide . getWorkspaceDirs ( ) ;
359+ if ( workspaceDirs ) {
360+ if ( workspaceDirs . length > 0 ) {
361+ cwd = fileURLToPath ( workspaceDirs [ 0 ] ) ;
362+ }
363+ }
364+ return cwd ;
365+ }
366+
346367 private async constructTransportAsync (
347368 options : MCPOptions ,
348369 ) : Promise < Transport > {
@@ -379,7 +400,7 @@ class MCPConnection {
379400 command,
380401 args,
381402 env,
382- cwd : options . transport . cwd ,
403+ cwd : await this . resolveCwd ( options . transport . cwd ) ,
383404 stderr : "pipe" ,
384405 } ) ;
385406
You can’t perform that action at this time.
0 commit comments