Skip to content

Commit 2883f91

Browse files
authored
Merge pull request #7709 from fbricon/fix-mcp-env
fix: use common process.env values to launch MCP
2 parents 9b4224d + d5e8c28 commit 2883f91

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

core/context/mcp/MCPConnection.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ const WINDOWS_BATCH_COMMANDS = [
3838
"bunx",
3939
];
4040

41+
const COMMONS_ENV_VARS = ["HOME", "USER", "USERPROFILE", "LOGNAME", "USERNAME"];
42+
4143
function is401Error(error: unknown) {
4244
return (
4345
(error instanceof SseError && error.code === 401) ||
@@ -464,7 +466,16 @@ class MCPConnection {
464466
private async constructStdioTransport(
465467
options: InternalStdioMcpOptions,
466468
): Promise<StdioClientTransport> {
467-
const env: Record<string, string> = options.env ? { ...options.env } : {};
469+
const commonEnvVars: Record<string, string> = Object.fromEntries(
470+
COMMONS_ENV_VARS.filter((key) => process.env[key] !== undefined).map(
471+
(key) => [key, process.env[key] as string],
472+
),
473+
);
474+
475+
const env = {
476+
...commonEnvVars,
477+
...(options.env ?? {}),
478+
};
468479

469480
if (process.env.PATH !== undefined) {
470481
// Set the initial PATH from process.env

0 commit comments

Comments
 (0)