70510a549d
When running in pnpm projects, the .npmrc configuration propagates as NPM_CONFIG_* environment variables to child processes. This can cause MCP servers to fail due to registry/proxy conflicts or case sensitivity issues between uppercase and lowercase variants. This fix adds a createCleanMcpEnvironment function that filters out: - NPM_CONFIG_* and npm_config_* (npm/pnpm config) - YARN_* (yarn config) - PNPM_* (pnpm config) - NO_UPDATE_NOTIFIER Fixes #456 Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
28 lines
693 B
TypeScript
28 lines
693 B
TypeScript
// Filters npm/pnpm/yarn config env vars that break MCP servers in pnpm projects (#456)
|
|
export const EXCLUDED_ENV_PATTERNS: RegExp[] = [
|
|
/^NPM_CONFIG_/i,
|
|
/^npm_config_/,
|
|
/^YARN_/,
|
|
/^PNPM_/,
|
|
/^NO_UPDATE_NOTIFIER$/,
|
|
]
|
|
|
|
export function createCleanMcpEnvironment(
|
|
customEnv: Record<string, string> = {}
|
|
): Record<string, string> {
|
|
const cleanEnv: Record<string, string> = {}
|
|
|
|
for (const [key, value] of Object.entries(process.env)) {
|
|
if (value === undefined) continue
|
|
|
|
const shouldExclude = EXCLUDED_ENV_PATTERNS.some((pattern) => pattern.test(key))
|
|
if (!shouldExclude) {
|
|
cleanEnv[key] = value
|
|
}
|
|
}
|
|
|
|
Object.assign(cleanEnv, customEnv)
|
|
|
|
return cleanEnv
|
|
}
|