Skip to content

Commit cf63874

Browse files
committed
Fixed env passing
1 parent d536a65 commit cf63874

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/connectors/stdio.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,27 @@ export class StdioConnector extends BaseConnector {
5151
}
5252

5353
logger.debug(`Connecting to MCP implementation via stdio: ${this.command}`)
54-
5554
try {
5655
// 1. Build server parameters for the transport
56+
57+
// Merge env with process.env, filtering out undefined values
58+
let mergedEnv: Record<string, string> | undefined
59+
if (this.env) {
60+
mergedEnv = {}
61+
// First add process.env values (excluding undefined)
62+
for (const [key, value] of Object.entries(process.env)) {
63+
if (value !== undefined) {
64+
mergedEnv[key] = value
65+
}
66+
}
67+
// Then override with provided env
68+
Object.assign(mergedEnv, this.env)
69+
}
70+
5771
const serverParams: StdioServerParameters = {
5872
command: this.command,
5973
args: this.args,
60-
env: this.env,
74+
env: mergedEnv,
6175
}
6276

6377
// 2. Start the connection manager -> returns a live transport

0 commit comments

Comments
 (0)