ai-sdk-provider-codex-cli 2.1.1 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -900,7 +900,21 @@ declare class ExecLanguageModel implements LanguageModelV4 {
900
900
  private mergeSettings;
901
901
  private getItemType;
902
902
  private buildArgs;
903
+ /**
904
+ * Apply MCP server settings as `-c` config overrides.
905
+ *
906
+ * Returns environment variables that must be set on the spawned codex
907
+ * process. Inline HTTP `bearerToken` secrets are routed through the child
908
+ * environment (via `bearer_token_env_var`) instead of argv, because command
909
+ * lines are readable by any local process (`ps`, /proc/<pid>/cmdline).
910
+ */
903
911
  private applyMcpSettings;
912
+ /**
913
+ * Pick a child-env variable name to carry an inline MCP bearer token,
914
+ * avoiding collisions between server names that normalize identically
915
+ * (e.g. 'foo-bar' and 'foo_bar').
916
+ */
917
+ private allocateBearerTokenEnvVar;
904
918
  private addConfigOverride;
905
919
  /**
906
920
  * Serialize a config override value into a CLI-safe string.
package/dist/index.js CHANGED
@@ -1443,7 +1443,7 @@ var ExecLanguageModel = class {
1443
1443
  if (settings.webSearch) {
1444
1444
  args.push("-c", "tools.web_search=true");
1445
1445
  }
1446
- this.applyMcpSettings(args, settings);
1446
+ const mcpSecretEnv = this.applyMcpSettings(args, settings);
1447
1447
  if (settings.color) {
1448
1448
  args.push("--color", settings.color);
1449
1449
  }
@@ -1491,6 +1491,7 @@ var ExecLanguageModel = class {
1491
1491
  const env = {
1492
1492
  ...process.env,
1493
1493
  ...settings.env || {},
1494
+ ...mcpSecretEnv,
1494
1495
  RUST_LOG: process.env.RUST_LOG || "error"
1495
1496
  };
1496
1497
  let lastMessagePath = settings.outputLastMessageFile;
@@ -1516,11 +1517,20 @@ var ExecLanguageModel = class {
1516
1517
  tempImagePaths: tempImagePaths.length > 0 ? tempImagePaths : void 0
1517
1518
  };
1518
1519
  }
1520
+ /**
1521
+ * Apply MCP server settings as `-c` config overrides.
1522
+ *
1523
+ * Returns environment variables that must be set on the spawned codex
1524
+ * process. Inline HTTP `bearerToken` secrets are routed through the child
1525
+ * environment (via `bearer_token_env_var`) instead of argv, because command
1526
+ * lines are readable by any local process (`ps`, /proc/<pid>/cmdline).
1527
+ */
1519
1528
  applyMcpSettings(args, settings) {
1520
1529
  if (settings.rmcpClient) {
1521
1530
  this.addConfigOverride(args, "features.rmcp_client", true);
1522
1531
  }
1523
- if (!settings.mcpServers) return;
1532
+ if (!settings.mcpServers) return void 0;
1533
+ const secretEnv = {};
1524
1534
  for (const [rawName, server] of Object.entries(settings.mcpServers)) {
1525
1535
  const name = assertValidMcpServerName(rawName);
1526
1536
  const prefix = `mcp_servers.${name}`;
@@ -1546,15 +1556,43 @@ var ExecLanguageModel = class {
1546
1556
  if (server.cwd) this.addConfigOverride(args, `${prefix}.cwd`, server.cwd);
1547
1557
  } else {
1548
1558
  this.addConfigOverride(args, `${prefix}.url`, server.url);
1549
- if (server.bearerTokenEnvVar)
1559
+ const hasExplicitAuthorizationHeader = Object.keys(server.httpHeaders ?? {}).some(
1560
+ (key) => key.toLowerCase() === "authorization"
1561
+ );
1562
+ if (server.bearerTokenEnvVar) {
1550
1563
  this.addConfigOverride(args, `${prefix}.bearer_token_env_var`, server.bearerTokenEnvVar);
1551
- const httpHeaders = mcpHttpHeadersWithBearerToken(server);
1552
- if (httpHeaders !== void 0)
1553
- this.addConfigOverride(args, `${prefix}.http_headers`, httpHeaders);
1564
+ if (server.bearerToken !== void 0) {
1565
+ this.logger.warn(
1566
+ `[codex-cli] MCP server '${name}': both bearerToken and bearerTokenEnvVar are set; using bearerTokenEnvVar and ignoring the inline token.`
1567
+ );
1568
+ }
1569
+ } else if (server.bearerToken !== void 0 && !hasExplicitAuthorizationHeader) {
1570
+ const envVarName = this.allocateBearerTokenEnvVar(name, secretEnv);
1571
+ secretEnv[envVarName] = server.bearerToken;
1572
+ this.addConfigOverride(args, `${prefix}.bearer_token_env_var`, envVarName);
1573
+ }
1574
+ if (server.httpHeaders !== void 0)
1575
+ this.addConfigOverride(args, `${prefix}.http_headers`, server.httpHeaders);
1554
1576
  if (server.envHttpHeaders !== void 0)
1555
1577
  this.addConfigOverride(args, `${prefix}.env_http_headers`, server.envHttpHeaders);
1556
1578
  }
1557
1579
  }
1580
+ return Object.keys(secretEnv).length > 0 ? secretEnv : void 0;
1581
+ }
1582
+ /**
1583
+ * Pick a child-env variable name to carry an inline MCP bearer token,
1584
+ * avoiding collisions between server names that normalize identically
1585
+ * (e.g. 'foo-bar' and 'foo_bar').
1586
+ */
1587
+ allocateBearerTokenEnvVar(serverName, secretEnv) {
1588
+ const base = `CODEX_MCP_${serverName.toUpperCase().replace(/-/g, "_")}_BEARER_TOKEN`;
1589
+ let candidate = base;
1590
+ let suffix = 2;
1591
+ while (candidate in secretEnv) {
1592
+ candidate = `${base}_${suffix}`;
1593
+ suffix += 1;
1594
+ }
1595
+ return candidate;
1558
1596
  }
1559
1597
  addConfigOverride(args, key, value) {
1560
1598
  assertValidConfigOverrideKey(key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-sdk-provider-codex-cli",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "AI SDK v7 provider for OpenAI Codex CLI (use ChatGPT Plus/Pro subscription)",
5
5
  "keywords": [
6
6
  "ai-sdk",