Merge pull request #7709 from fbricon/fix-mcp-env

fix: use common process.env values to launch MCP
This commit is contained in:
Dallin Romney 2025-10-06 11:00:59 -07:00 • committed by GitHub
commit 2883f91ca0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -38,6 +38,8 @@ const WINDOWS_BATCH_COMMANDS = [
"bunx",
];
const COMMONS_ENV_VARS = ["HOME", "USER", "USERPROFILE", "LOGNAME", "USERNAME"];
function is401Error(error: unknown) {
return (
(error instanceof SseError && error.code === 401) ||
@ -464,7 +466,16 @@ class MCPConnection {
private async constructStdioTransport(
options: InternalStdioMcpOptions,
): Promise<StdioClientTransport> {
const env: Record<string, string> = options.env ? { ...options.env } : {};
const commonEnvVars: Record<string, string> = Object.fromEntries(
COMMONS_ENV_VARS.filter((key) => process.env[key] !== undefined).map(
(key) => [key, process.env[key] as string],
),
);
const env = {
...commonEnvVars,
...(options.env ?? {}),
};
if (process.env.PATH !== undefined) {
// Set the initial PATH from process.env