Skip to content

Commit 8961614

Browse files
committed
feat(McpHub): inject env variable on whole mcp config
1 parent 57b8378 commit 8961614

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/services/mcp/McpHub.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,16 @@ export class McpHub {
443443

444444
let transport: StdioClientTransport | SSEClientTransport
445445

446-
if (config.type === "stdio") {
446+
// Inject environment variables to the config
447+
const configInjected = (await injectEnv(config)) as typeof config
448+
449+
if (configInjected.type === "stdio") {
447450
transport = new StdioClientTransport({
448-
command: config.command,
449-
args: config.args,
450-
cwd: config.cwd,
451+
command: configInjected.command,
452+
args: configInjected.args,
453+
cwd: configInjected.cwd,
451454
env: {
452-
...(config.env ? await injectEnv(config.env) : {}),
455+
...configInjected.env,
453456
...(process.env.PATH ? { PATH: process.env.PATH } : {}),
454457
...(process.env.HOME ? { HOME: process.env.HOME } : {}),
455458
},
@@ -508,16 +511,16 @@ export class McpHub {
508511
// SSE connection
509512
const sseOptions = {
510513
requestInit: {
511-
headers: config.headers,
514+
headers: configInjected.headers,
512515
},
513516
}
514517
// Configure ReconnectingEventSource options
515518
const reconnectingEventSourceOptions = {
516519
max_retry_time: 5000, // Maximum retry time in milliseconds
517-
withCredentials: config.headers?.["Authorization"] ? true : false, // Enable credentials if Authorization header exists
520+
withCredentials: configInjected.headers?.["Authorization"] ? true : false, // Enable credentials if Authorization header exists
518521
}
519522
global.EventSource = ReconnectingEventSource
520-
transport = new SSEClientTransport(new URL(config.url), {
523+
transport = new SSEClientTransport(new URL(configInjected.url), {
521524
...sseOptions,
522525
eventSourceInit: reconnectingEventSourceOptions,
523526
})
@@ -537,9 +540,9 @@ export class McpHub {
537540
const connection: McpConnection = {
538541
server: {
539542
name,
540-
config: JSON.stringify(config),
543+
config: JSON.stringify(configInjected),
541544
status: "connecting",
542-
disabled: config.disabled,
545+
disabled: configInjected.disabled,
543546
source,
544547
projectPath: source === "project" ? vscode.workspace.workspaceFolders?.[0]?.uri.fsPath : undefined,
545548
errorHistory: [],

0 commit comments

Comments
 (0)