Changesets · Branches · Tags · Compare
| Changeset | 08608c2155bf4bfb9fb0e9bb5250f255a671424068672718d2b08ec04dddb9be |
|---|---|
| Author | Nate <sestinj@gmail.com> · 2025-07-03 23:07 -07:00 |
| Committer | Nate <sestinj@gmail.com> · 2025-07-03 23:07 -07:00 |
| Parents | d26a03bcbf7f |
2 files changed
modified core/context/mcp/MCPConnection.ts +8 −4
| @@ -47,7 +47,8 @@ | ||
| 47 | 47 | }; |
| 48 | 48 | |
| 49 | 49 | constructor(public options: MCPOptions) { |
| 50 | - this.transport = this.constructTransport(options); | |
| 50 | + // Don't construct transport in constructor to avoid blocking | |
| 51 | + this.transport = {} as Transport; // Will be set in connectClient | |
| 51 | 52 | |
| 52 | 53 | this.client = new Client( |
| 53 | 54 | { |
| @@ -132,7 +133,8 @@ | ||
| 132 | 133 | }); |
| 133 | 134 | }), |
| 134 | 135 | (async () => { |
| 135 | - this.transport = this.constructTransport(this.options); | |
| 136 | + this.transport = await this.constructTransportAsync(this.options); | |
| 137 | + | |
| 136 | 138 | try { |
| 137 | 139 | await this.client.connect(this.transport); |
| 138 | 140 | } catch (error) { |
| @@ -295,7 +297,9 @@ | ||
| 295 | 297 | }; |
| 296 | 298 | } |
| 297 | 299 | |
| 298 | - private constructTransport(options: MCPOptions): Transport { | |
| 300 | + private async constructTransportAsync( | |
| 301 | + options: MCPOptions, | |
| 302 | + ): Promise<Transport> { | |
| 299 | 303 | switch (options.transport.type) { |
| 300 | 304 | case "stdio": |
| 301 | 305 | const env: Record<string, string> = options.transport.env |
| @@ -309,7 +313,7 @@ | ||
| 309 | 313 | // For non-Windows platforms, try to get the PATH from user shell |
| 310 | 314 | if (process.platform !== "win32") { |
| 311 | 315 | try { |
| 312 | - const shellEnvPath = getEnvPathFromUserShell(); | |
| 316 | + const shellEnvPath = await getEnvPathFromUserShell(); | |
| 313 | 317 | if (shellEnvPath && shellEnvPath !== process.env.PATH) { |
| 314 | 318 | env.PATH = shellEnvPath; |
| 315 | 319 | } |
modified core/util/shellPath.ts +6 −5
| @@ -1,7 +1,8 @@ | ||
| 1 | -import { execSync } from "child_process"; | |
| 2 | -import { homedir } from "os"; | |
| 3 | - | |
| 4 | -export function getEnvPathFromUserShell(): string | undefined { | |
| 1 | +import { exec } from "child_process"; | |
| 2 | +import { promisify } from "util"; | |
| 3 | + | |
| 4 | +const execAsync = promisify(exec); | |
| 5 | +export async function getEnvPathFromUserShell(): Promise<string | undefined> { | |
| 5 | 6 | if (process.platform === "win32") { |
| 6 | 7 | console.warn(`${getEnvPathFromUserShell.name} not implemented for Windows`); |
| 7 | 8 | return undefined; |
| @@ -15,7 +16,7 @@ | ||
| 15 | 16 | // Source common profile files |
| 16 | 17 | const command = `${process.env.SHELL} -l -c 'for f in ~/.zprofile ~/.zshrc ~/.bash_profile ~/.bashrc; do [ -f "$f" ] && source "$f" 2>/dev/null; done; echo $PATH'`; |
| 17 | 18 | |
| 18 | - const stdout = execSync(command, { | |
| 19 | + const { stdout } = await execAsync(command, { | |
| 19 | 20 | encoding: "utf8", |
| 20 | 21 | }); |
| 21 | 22 |