@google/gemini-cli 0.33.0-preview.3 → 0.33.0-preview.5

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/bundle/gemini.js CHANGED
@@ -105392,10 +105392,36 @@ var init_tools = __esm({
105392
105392
 
105393
105393
  // packages/core/dist/src/tools/mcp-tool.js
105394
105394
  function isMcpToolName(name4) {
105395
- if (!name4.includes(MCP_QUALIFIED_NAME_SEPARATOR))
105396
- return false;
105397
- const parts2 = name4.split(MCP_QUALIFIED_NAME_SEPARATOR);
105398
- return parts2.length === 2 && parts2[0].length > 0 && parts2[1].length > 0;
105395
+ return name4.startsWith(MCP_TOOL_PREFIX);
105396
+ }
105397
+ function parseMcpToolName(name4) {
105398
+ if (!isMcpToolName(name4)) {
105399
+ return {};
105400
+ }
105401
+ const withoutPrefix = name4.slice(MCP_TOOL_PREFIX.length);
105402
+ const match2 = withoutPrefix.match(/^([^_]+)_(.+)$/);
105403
+ if (match2) {
105404
+ return {
105405
+ serverName: match2[1],
105406
+ toolName: match2[2]
105407
+ };
105408
+ }
105409
+ return {};
105410
+ }
105411
+ function formatMcpToolName(serverName, toolName) {
105412
+ if (serverName === "*" && !toolName) {
105413
+ return `${MCP_TOOL_PREFIX}*`;
105414
+ } else if (serverName === "*") {
105415
+ return `${MCP_TOOL_PREFIX}*_${toolName}`;
105416
+ } else if (!toolName) {
105417
+ return `${MCP_TOOL_PREFIX}${serverName}_*`;
105418
+ } else {
105419
+ return `${MCP_TOOL_PREFIX}${serverName}_${toolName}`;
105420
+ }
105421
+ }
105422
+ function isMcpToolAnnotation(annotation) {
105423
+ return typeof annotation === "object" && annotation !== null && // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
105424
+ typeof annotation["_serverName"] === "string";
105399
105425
  }
105400
105426
  function transformTextBlock(block) {
105401
105427
  return { text: block.text };
@@ -105490,24 +105516,28 @@ function getStringifiedResultForDisplay(rawResponse) {
105490
105516
  return displayParts.join("\n");
105491
105517
  }
105492
105518
  function generateValidName(name4) {
105493
- let validToolname = name4.replace(/[^a-zA-Z0-9_.:-]/g, "_");
105519
+ let validToolname = name4.startsWith("mcp_") ? name4 : `mcp_${name4}`;
105520
+ validToolname = validToolname.replace(/[^a-zA-Z0-9_\-.:]/g, "_");
105494
105521
  if (/^[^a-zA-Z_]/.test(validToolname)) {
105495
105522
  validToolname = `_${validToolname}`;
105496
105523
  }
105497
105524
  const safeLimit = MAX_FUNCTION_NAME_LENGTH - 1;
105498
105525
  if (validToolname.length > safeLimit) {
105526
+ debugLogger.warn(`Truncating MCP tool name "${validToolname}" to fit within the 64 character limit. This tool may require user approval.`);
105499
105527
  validToolname = validToolname.slice(0, 30) + "..." + validToolname.slice(-30);
105500
105528
  }
105501
105529
  return validToolname;
105502
105530
  }
105503
- var MCP_QUALIFIED_NAME_SEPARATOR, DiscoveredMCPToolInvocation, DiscoveredMCPTool, MAX_FUNCTION_NAME_LENGTH;
105531
+ var MCP_QUALIFIED_NAME_SEPARATOR, MCP_TOOL_PREFIX, DiscoveredMCPToolInvocation, DiscoveredMCPTool, MAX_FUNCTION_NAME_LENGTH;
105504
105532
  var init_mcp_tool = __esm({
105505
105533
  "packages/core/dist/src/tools/mcp-tool.js"() {
105506
105534
  "use strict";
105507
105535
  init_safeJsonStringify();
105536
+ init_debugLogger();
105508
105537
  init_tools();
105509
105538
  init_tool_error();
105510
- MCP_QUALIFIED_NAME_SEPARATOR = "__";
105539
+ MCP_QUALIFIED_NAME_SEPARATOR = "_";
105540
+ MCP_TOOL_PREFIX = "mcp_";
105511
105541
  DiscoveredMCPToolInvocation = class _DiscoveredMCPToolInvocation extends BaseToolInvocation {
105512
105542
  mcpTool;
105513
105543
  serverName;
@@ -105649,7 +105679,7 @@ var init_mcp_tool = __esm({
105649
105679
  _toolAnnotations;
105650
105680
  constructor(mcpTool, serverName, serverToolName, description, parameterSchema, messageBus, trust, isReadOnly, nameOverride, cliConfig, extensionName, extensionId, _toolAnnotations) {
105651
105681
  super(
105652
- generateValidName(nameOverride ?? serverToolName),
105682
+ nameOverride ?? generateValidName(`${serverName}${MCP_QUALIFIED_NAME_SEPARATOR}${serverToolName}`),
105653
105683
  `${serverToolName} (${serverName} MCP Server)`,
105654
105684
  description,
105655
105685
  Kind.Other,
@@ -105684,7 +105714,7 @@ var init_mcp_tool = __esm({
105684
105714
  return this._toolAnnotations;
105685
105715
  }
105686
105716
  getFullyQualifiedPrefix() {
105687
- return `${this.serverName}${MCP_QUALIFIED_NAME_SEPARATOR}`;
105717
+ return generateValidName(`${this.serverName}${MCP_QUALIFIED_NAME_SEPARATOR}`);
105688
105718
  }
105689
105719
  getFullyQualifiedName() {
105690
105720
  return generateValidName(`${this.serverName}${MCP_QUALIFIED_NAME_SEPARATOR}${this.serverToolName}`);
@@ -196293,8 +196323,8 @@ var GIT_COMMIT_INFO, CLI_VERSION;
196293
196323
  var init_git_commit = __esm({
196294
196324
  "packages/core/dist/src/generated/git-commit.js"() {
196295
196325
  "use strict";
196296
- GIT_COMMIT_INFO = "03a8fc311";
196297
- CLI_VERSION = "0.33.0-preview.3";
196326
+ GIT_COMMIT_INFO = "a6256cdab";
196327
+ CLI_VERSION = "0.33.0-preview.5";
196298
196328
  }
196299
196329
  });
196300
196330
 
@@ -292762,7 +292792,7 @@ function getVersion() {
292762
292792
  }
292763
292793
  versionPromise = (async () => {
292764
292794
  const pkgJson = await getPackageJson(__dirname3);
292765
- return "0.33.0-preview.3";
292795
+ return "0.33.0-preview.5";
292766
292796
  })();
292767
292797
  return versionPromise;
292768
292798
  }
@@ -294201,14 +294231,16 @@ function getAuthTypeFromEnv() {
294201
294231
  }
294202
294232
  return void 0;
294203
294233
  }
294204
- async function createContentGeneratorConfig(config2, authType, apiKey) {
294234
+ async function createContentGeneratorConfig(config2, authType, apiKey, baseUrl, customHeaders) {
294205
294235
  const geminiApiKey = apiKey || process.env["GEMINI_API_KEY"] || await loadApiKey() || void 0;
294206
294236
  const googleApiKey = process.env["GOOGLE_API_KEY"] || void 0;
294207
294237
  const googleCloudProject = process.env["GOOGLE_CLOUD_PROJECT"] || process.env["GOOGLE_CLOUD_PROJECT_ID"] || void 0;
294208
294238
  const googleCloudLocation = process.env["GOOGLE_CLOUD_LOCATION"] || void 0;
294209
294239
  const contentGeneratorConfig = {
294210
294240
  authType,
294211
- proxy: config2?.getProxy()
294241
+ proxy: config2?.getProxy(),
294242
+ baseUrl,
294243
+ customHeaders
294212
294244
  };
294213
294245
  if (authType === AuthType2.LOGIN_WITH_GOOGLE || authType === AuthType2.COMPUTE_ADC) {
294214
294246
  return contentGeneratorConfig;
@@ -294249,8 +294281,11 @@ async function createContentGenerator(config2, gcConfig, sessionId2) {
294249
294281
  const httpOptions = { headers: baseHeaders };
294250
294282
  return new LoggingContentGenerator(await createCodeAssistContentGenerator(httpOptions, config2.authType, gcConfig, sessionId2), gcConfig);
294251
294283
  }
294252
- if (config2.authType === AuthType2.USE_GEMINI || config2.authType === AuthType2.USE_VERTEX_AI) {
294284
+ if (config2.authType === AuthType2.USE_GEMINI || config2.authType === AuthType2.USE_VERTEX_AI || config2.authType === AuthType2.GATEWAY) {
294253
294285
  let headers = { ...baseHeaders };
294286
+ if (config2.customHeaders) {
294287
+ headers = { ...headers, ...config2.customHeaders };
294288
+ }
294254
294289
  if (gcConfig?.getUsageStatisticsEnabled()) {
294255
294290
  const installationManager2 = new InstallationManager();
294256
294291
  const installationId = installationManager2.getInstallationId();
@@ -294260,6 +294295,9 @@ async function createContentGenerator(config2, gcConfig, sessionId2) {
294260
294295
  };
294261
294296
  }
294262
294297
  const httpOptions = { headers };
294298
+ if (config2.baseUrl) {
294299
+ httpOptions.baseUrl = config2.baseUrl;
294300
+ }
294263
294301
  const googleGenAI = new GoogleGenAI({
294264
294302
  apiKey: config2.apiKey === "" ? void 0 : config2.apiKey,
294265
294303
  vertexai: config2.vertexai,
@@ -294294,6 +294332,7 @@ var init_contentGenerator = __esm({
294294
294332
  AuthType3["USE_VERTEX_AI"] = "vertex-ai";
294295
294333
  AuthType3["LEGACY_CLOUD_SHELL"] = "cloud-shell";
294296
294334
  AuthType3["COMPUTE_ADC"] = "compute-default-credentials";
294335
+ AuthType3["GATEWAY"] = "gateway";
294297
294336
  })(AuthType2 || (AuthType2 = {}));
294298
294337
  }
294299
294338
  });
@@ -294976,11 +295015,11 @@ Signal: Signal number or \`(none)\` if no signal was received.
294976
295015
  buildToolMetadata() {
294977
295016
  const toolMetadata = /* @__PURE__ */ new Map();
294978
295017
  for (const [name4, tool] of this.allKnownTools) {
294979
- if (tool.toolAnnotations) {
294980
- const metadata2 = { ...tool.toolAnnotations };
294981
- if (tool instanceof DiscoveredMCPTool) {
294982
- metadata2["_serverName"] = tool.serverName;
294983
- }
295018
+ const metadata2 = tool.toolAnnotations ? { ...tool.toolAnnotations } : {};
295019
+ if (tool instanceof DiscoveredMCPTool) {
295020
+ metadata2["_serverName"] = tool.serverName;
295021
+ }
295022
+ if (Object.keys(metadata2).length > 0) {
294984
295023
  toolMetadata.set(name4, metadata2);
294985
295024
  }
294986
295025
  }
@@ -411943,34 +411982,17 @@ function matchesWildcard(pattern, toolName, serverName) {
411943
411982
  if (pattern === "*") {
411944
411983
  return true;
411945
411984
  }
411946
- if (pattern.includes("__")) {
411947
- return matchesCompositePattern(pattern, toolName, serverName);
411948
- }
411949
- return toolName === pattern;
411950
- }
411951
- function matchesCompositePattern(pattern, toolName, serverName) {
411952
- const parts2 = pattern.split("__");
411953
- if (parts2.length !== 2)
411954
- return false;
411955
- const [patternServer, patternTool] = parts2;
411956
- const { actualServer, actualTool } = getToolMetadata(toolName, serverName);
411957
- if (actualServer === void 0) {
411958
- return false;
411985
+ if (pattern === `${MCP_TOOL_PREFIX}*`) {
411986
+ return serverName !== void 0;
411959
411987
  }
411960
- if (serverName !== void 0 && !toolName.startsWith(serverName + "__")) {
411961
- return false;
411988
+ if (pattern.startsWith(MCP_TOOL_PREFIX) && pattern.endsWith("_*")) {
411989
+ const expectedServerName = pattern.slice(MCP_TOOL_PREFIX.length, -2);
411990
+ if (serverName === void 0 || serverName !== expectedServerName) {
411991
+ return false;
411992
+ }
411993
+ return toolName.startsWith(`${MCP_TOOL_PREFIX}${expectedServerName}_`);
411962
411994
  }
411963
- const serverMatch = patternServer === "*" || patternServer === actualServer;
411964
- const toolMatch = patternTool === "*" || patternTool === actualTool;
411965
- return serverMatch && toolMatch;
411966
- }
411967
- function getToolMetadata(toolName, serverName) {
411968
- const sepIndex = toolName.indexOf("__");
411969
- const isQualified = sepIndex !== -1;
411970
- return {
411971
- actualServer: serverName ?? (isQualified ? toolName.substring(0, sepIndex) : void 0),
411972
- actualTool: isQualified ? toolName.substring(sepIndex + 2) : toolName
411973
- };
411995
+ return toolName === pattern;
411974
411996
  }
411975
411997
  function ruleMatches(rule, toolCall, stringifiedArgs, serverName, currentApprovalMode, toolAnnotations) {
411976
411998
  if (rule.modes && rule.modes.length > 0) {
@@ -411978,6 +412000,15 @@ function ruleMatches(rule, toolCall, stringifiedArgs, serverName, currentApprova
411978
412000
  return false;
411979
412001
  }
411980
412002
  }
412003
+ if (rule.mcpName) {
412004
+ if (rule.mcpName === "*") {
412005
+ if (serverName === void 0)
412006
+ return false;
412007
+ } else {
412008
+ if (serverName !== rule.mcpName)
412009
+ return false;
412010
+ }
412011
+ }
411981
412012
  if (rule.toolName) {
411982
412013
  if (rule.toolName === "*") {
411983
412014
  } else if (isWildcardPattern(rule.toolName)) {
@@ -412019,6 +412050,7 @@ var init_policy_engine = __esm({
412019
412050
  init_protocol2();
412020
412051
  init_shell_utils();
412021
412052
  init_tool_names();
412053
+ init_mcp_tool();
412022
412054
  PolicyEngine = class {
412023
412055
  rules;
412024
412056
  checkers;
@@ -412147,6 +412179,15 @@ var init_policy_engine = __esm({
412147
412179
  * Returns the decision and the matching rule (if any).
412148
412180
  */
412149
412181
  async check(toolCall, serverName, toolAnnotations) {
412182
+ if (!serverName && isMcpToolAnnotation(toolAnnotations)) {
412183
+ serverName = toolAnnotations._serverName;
412184
+ }
412185
+ if (!serverName && toolCall.name) {
412186
+ const parsed = parseMcpToolName(toolCall.name);
412187
+ if (parsed.serverName) {
412188
+ serverName = parsed.serverName;
412189
+ }
412190
+ }
412150
412191
  let stringifiedArgs;
412151
412192
  if (toolCall.args && (this.rules.some((rule) => rule.argsPattern) || this.checkers.some((checker) => checker.argsPattern))) {
412152
412193
  stringifiedArgs = stableStringify(toolCall.args);
@@ -412168,12 +412209,6 @@ var init_policy_engine = __esm({
412168
412209
  const toolCallsToTry = [];
412169
412210
  for (const name4 of toolNamesToTry) {
412170
412211
  toolCallsToTry.push({ ...toolCall, name: name4 });
412171
- if (serverName && !name4.includes("__")) {
412172
- toolCallsToTry.push({
412173
- ...toolCall,
412174
- name: `${serverName}__${name4}`
412175
- });
412176
- }
412177
412212
  }
412178
412213
  for (const rule of this.rules) {
412179
412214
  const match2 = toolCallsToTry.some((tc) => ruleMatches(rule, tc, stringifiedArgs, serverName, this.approvalMode, toolAnnotations));
@@ -412319,107 +412354,52 @@ var init_policy_engine = __esm({
412319
412354
  */
412320
412355
  getExcludedTools(toolMetadata, allToolNames) {
412321
412356
  const excludedTools = /* @__PURE__ */ new Set();
412322
- const processedTools = /* @__PURE__ */ new Set();
412323
- let globalVerdict;
412324
- for (const rule of this.rules) {
412325
- if (rule.argsPattern) {
412326
- if (rule.toolName && rule.decision !== PolicyDecision.DENY) {
412327
- processedTools.add(rule.toolName);
412328
- }
412329
- continue;
412330
- }
412331
- if (rule.modes && rule.modes.length > 0) {
412332
- if (!rule.modes.includes(this.approvalMode)) {
412333
- continue;
412334
- }
412335
- }
412336
- if (rule.toolAnnotations) {
412337
- if (!toolMetadata) {
412338
- continue;
412339
- }
412340
- for (const [toolName2, annotations] of toolMetadata) {
412341
- if (processedTools.has(toolName2)) {
412342
- continue;
412343
- }
412344
- let annotationsMatch = true;
412345
- for (const [key, value] of Object.entries(rule.toolAnnotations)) {
412346
- if (annotations[key] !== value) {
412347
- annotationsMatch = false;
412357
+ if (!allToolNames) {
412358
+ return excludedTools;
412359
+ }
412360
+ for (const toolName of allToolNames) {
412361
+ const annotations = toolMetadata?.get(toolName);
412362
+ const serverName = isMcpToolAnnotation(annotations) ? annotations._serverName : void 0;
412363
+ let staticallyExcluded = false;
412364
+ let matchFound = false;
412365
+ for (const rule of this.rules) {
412366
+ const ruleWithoutArgs = { ...rule, argsPattern: void 0 };
412367
+ const toolCall = { name: toolName, args: {} };
412368
+ const appliesToTool = ruleMatches(
412369
+ ruleWithoutArgs,
412370
+ toolCall,
412371
+ void 0,
412372
+ // stringifiedArgs
412373
+ serverName,
412374
+ this.approvalMode,
412375
+ annotations
412376
+ );
412377
+ if (appliesToTool) {
412378
+ if (rule.argsPattern) {
412379
+ if (rule.decision !== PolicyDecision.DENY) {
412380
+ staticallyExcluded = false;
412381
+ matchFound = true;
412348
412382
  break;
412349
412383
  }
412350
- }
412351
- if (!annotationsMatch) {
412352
412384
  continue;
412353
- }
412354
- if (rule.toolName) {
412355
- if (isWildcardPattern(rule.toolName)) {
412356
- const rawServerName = annotations["_serverName"];
412357
- const serverName = typeof rawServerName === "string" ? rawServerName : void 0;
412358
- const qualifiedName = serverName && !toolName2.includes("__") ? `${serverName}__${toolName2}` : toolName2;
412359
- if (!matchesWildcard(rule.toolName, qualifiedName, void 0)) {
412360
- continue;
412361
- }
412362
- } else if (toolName2 !== rule.toolName) {
412363
- continue;
412364
- }
412365
- }
412366
- let decision2;
412367
- if (globalVerdict !== void 0) {
412368
- decision2 = globalVerdict;
412369
412385
  } else {
412370
- decision2 = rule.decision;
412371
- }
412372
- if (decision2 === PolicyDecision.DENY) {
412373
- excludedTools.add(toolName2);
412374
- }
412375
- processedTools.add(toolName2);
412376
- }
412377
- continue;
412378
- }
412379
- if (!rule.toolName) {
412380
- if (globalVerdict === void 0) {
412381
- globalVerdict = rule.decision;
412382
- if (globalVerdict !== PolicyDecision.DENY) {
412386
+ const decision = this.applyNonInteractiveMode(rule.decision);
412387
+ staticallyExcluded = decision === PolicyDecision.DENY;
412388
+ matchFound = true;
412383
412389
  break;
412384
412390
  }
412385
412391
  }
412386
- continue;
412387
- }
412388
- const toolName = rule.toolName;
412389
- if (processedTools.has(toolName)) {
412390
- continue;
412391
412392
  }
412392
- let coveredByWildcard = false;
412393
- for (const processed of processedTools) {
412394
- if (isWildcardPattern(processed) && matchesWildcard(processed, toolName, void 0)) {
412395
- if (excludedTools.has(processed)) {
412396
- excludedTools.add(toolName);
412397
- }
412398
- coveredByWildcard = true;
412399
- break;
412393
+ if (!matchFound) {
412394
+ const defaultDec = this.applyNonInteractiveMode(this.defaultDecision);
412395
+ if (defaultDec === PolicyDecision.DENY) {
412396
+ staticallyExcluded = true;
412400
412397
  }
412401
412398
  }
412402
- if (coveredByWildcard) {
412403
- continue;
412404
- }
412405
- processedTools.add(toolName);
412406
- let decision;
412407
- if (globalVerdict !== void 0) {
412408
- decision = globalVerdict;
412409
- } else {
412410
- decision = rule.decision;
412411
- }
412412
- if (decision === PolicyDecision.DENY) {
412399
+ if (staticallyExcluded) {
412413
412400
  excludedTools.add(toolName);
412414
412401
  }
412415
412402
  }
412416
- if (globalVerdict === PolicyDecision.DENY && allToolNames) {
412417
- for (const name4 of allToolNames) {
412418
- if (!processedTools.has(name4)) {
412419
- excludedTools.add(name4);
412420
- }
412421
- }
412422
- }
412423
412403
  return excludedTools;
412424
412404
  }
412425
412405
  applyNonInteractiveMode(decision) {
@@ -427972,7 +427952,10 @@ function validateShellCommandSyntax(rule, ruleIndex) {
427972
427952
  return null;
427973
427953
  }
427974
427954
  function validateToolName(name4, ruleIndex) {
427975
- if (isValidToolName(name4, { allowWildcards: true }) && !name4.includes("__")) {
427955
+ if (name4.includes("__")) {
427956
+ return `Rule #${ruleIndex + 1}: The "__" syntax for MCP tools is strictly deprecated. Please use the 'mcpName = "..."' property or the 'mcp_server_tool' format instead.`;
427957
+ }
427958
+ if (isValidToolName(name4, { allowWildcards: true })) {
427976
427959
  return null;
427977
427960
  }
427978
427961
  const allNames = [...ALL_BUILTIN_TOOL_NAMES];
@@ -428057,8 +428040,6 @@ async function loadPoliciesFromToml(policyPaths, getPolicyTier2) {
428057
428040
  }
428058
428041
  for (let i4 = 0; i4 < tomlRules.length; i4++) {
428059
428042
  const rule = tomlRules[i4];
428060
- if (rule.mcpName)
428061
- continue;
428062
428043
  const toolNames = rule.toolName ? Array.isArray(rule.toolName) ? rule.toolName : [rule.toolName] : [];
428063
428044
  for (const name4 of toolNames) {
428064
428045
  const warning = validateToolName(name4, i4);
@@ -428081,16 +428062,14 @@ async function loadPoliciesFromToml(policyPaths, getPolicyTier2) {
428081
428062
  return argsPatterns.flatMap((argsPattern) => {
428082
428063
  const toolNames = rule.toolName ? Array.isArray(rule.toolName) ? rule.toolName : [rule.toolName] : [void 0];
428083
428064
  return toolNames.map((toolName) => {
428084
- let effectiveToolName;
428085
- if (rule.mcpName && toolName) {
428086
- effectiveToolName = `${rule.mcpName}__${toolName}`;
428087
- } else if (rule.mcpName) {
428088
- effectiveToolName = `${rule.mcpName}__*`;
428089
- } else {
428090
- effectiveToolName = toolName;
428065
+ let effectiveToolName = toolName;
428066
+ const mcpName = rule.mcpName;
428067
+ if (mcpName) {
428068
+ effectiveToolName = formatMcpToolName(mcpName, effectiveToolName);
428091
428069
  }
428092
428070
  const policyRule = {
428093
428071
  toolName: effectiveToolName,
428072
+ mcpName: rule.mcpName,
428094
428073
  decision: rule.decision,
428095
428074
  priority: transformPriority(rule.priority, tier),
428096
428075
  modes: rule.modes,
@@ -428164,14 +428143,15 @@ Error: ${error40.message}`,
428164
428143
  return toolNames.map((toolName) => {
428165
428144
  let effectiveToolName;
428166
428145
  if (checker.mcpName && toolName) {
428167
- effectiveToolName = `${checker.mcpName}__${toolName}`;
428146
+ effectiveToolName = `${MCP_TOOL_PREFIX}${checker.mcpName}_${toolName}`;
428168
428147
  } else if (checker.mcpName) {
428169
- effectiveToolName = `${checker.mcpName}__*`;
428148
+ effectiveToolName = `${MCP_TOOL_PREFIX}${checker.mcpName}_*`;
428170
428149
  } else {
428171
428150
  effectiveToolName = toolName;
428172
428151
  }
428173
428152
  const safetyCheckerRule = {
428174
428153
  toolName: effectiveToolName,
428154
+ mcpName: checker.mcpName,
428175
428155
  priority: transformPriority(checker.priority, tier),
428176
428156
  // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
428177
428157
  checker: checker.checker,
@@ -428230,14 +428210,19 @@ Error: ${error40.message}`
428230
428210
  return { rules, checkers, errors };
428231
428211
  }
428232
428212
  function validateMcpPolicyToolNames(serverName, discoveredToolNames, policyRules) {
428233
- const prefix = `${serverName}__`;
428213
+ const prefix = `${MCP_TOOL_PREFIX}${serverName}_`;
428234
428214
  const warnings = [];
428235
428215
  for (const rule of policyRules) {
428236
428216
  if (!rule.toolName)
428237
428217
  continue;
428238
- if (!rule.toolName.startsWith(prefix))
428218
+ let toolPart;
428219
+ if (rule.mcpName === serverName && rule.toolName.startsWith(prefix)) {
428220
+ toolPart = rule.toolName.slice(prefix.length);
428221
+ } else if (rule.toolName.startsWith(prefix)) {
428222
+ toolPart = rule.toolName.slice(prefix.length);
428223
+ } else {
428239
428224
  continue;
428240
- const toolPart = rule.toolName.slice(prefix.length);
428225
+ }
428241
428226
  if (toolPart === "*")
428242
428227
  continue;
428243
428228
  if (discoveredToolNames.includes(toolPart))
@@ -428265,6 +428250,7 @@ var init_toml_loader = __esm({
428265
428250
  import_toml = __toESM(require_toml(), 1);
428266
428251
  init_zod();
428267
428252
  init_errors();
428253
+ init_mcp_tool();
428268
428254
  MAX_TYPO_DISTANCE = 3;
428269
428255
  PolicyRuleSchema = external_exports.object({
428270
428256
  toolName: external_exports.union([external_exports.string(), external_exports.array(external_exports.string())]).optional(),
@@ -428520,7 +428506,8 @@ async function createPolicyEngineConfig(settings, approvalMode, defaultPoliciesD
428520
428506
  if (settings.mcp?.excluded) {
428521
428507
  for (const serverName of settings.mcp.excluded) {
428522
428508
  rules.push({
428523
- toolName: `${serverName}__*`,
428509
+ toolName: serverName === "*" ? `${MCP_TOOL_PREFIX}*` : `${MCP_TOOL_PREFIX}${serverName}_*`,
428510
+ mcpName: serverName,
428524
428511
  decision: PolicyDecision.DENY,
428525
428512
  priority: MCP_EXCLUDED_PRIORITY,
428526
428513
  source: "Settings (MCP Excluded)"
@@ -428579,7 +428566,8 @@ async function createPolicyEngineConfig(settings, approvalMode, defaultPoliciesD
428579
428566
  for (const [serverName, serverConfig] of Object.entries(settings.mcpServers)) {
428580
428567
  if (serverConfig.trust) {
428581
428568
  rules.push({
428582
- toolName: `${serverName}__*`,
428569
+ toolName: `${MCP_TOOL_PREFIX}${serverName}_*`,
428570
+ mcpName: serverName,
428583
428571
  decision: PolicyDecision.ALLOW,
428584
428572
  priority: TRUSTED_MCP_SERVER_PRIORITY,
428585
428573
  source: "Settings (MCP Trusted)"
@@ -428590,7 +428578,8 @@ async function createPolicyEngineConfig(settings, approvalMode, defaultPoliciesD
428590
428578
  if (settings.mcp?.allowed) {
428591
428579
  for (const serverName of settings.mcp.allowed) {
428592
428580
  rules.push({
428593
- toolName: `${serverName}__*`,
428581
+ toolName: serverName === "*" ? `${MCP_TOOL_PREFIX}*` : `${MCP_TOOL_PREFIX}${serverName}_*`,
428582
+ mcpName: serverName,
428594
428583
  decision: PolicyDecision.ALLOW,
428595
428584
  priority: ALLOWED_MCP_SERVER_PRIORITY,
428596
428585
  source: "Settings (MCP Allowed)"
@@ -428707,6 +428696,7 @@ var init_config3 = __esm({
428707
428696
  init_shell_utils();
428708
428697
  init_tool_names();
428709
428698
  init_errors();
428699
+ init_mcp_tool();
428710
428700
  init_security();
428711
428701
  __filename3 = fileURLToPath15(import.meta.url);
428712
428702
  __dirname7 = path69.dirname(__filename3);
@@ -433764,7 +433754,7 @@ var init_config4 = __esm({
433764
433754
  getContentGenerator() {
433765
433755
  return this.contentGenerator;
433766
433756
  }
433767
- async refreshAuth(authMethod, apiKey) {
433757
+ async refreshAuth(authMethod, apiKey, baseUrl, customHeaders) {
433768
433758
  this.modelAvailabilityService.reset();
433769
433759
  if (this.contentGeneratorConfig?.authType === AuthType2.USE_GEMINI && authMethod !== AuthType2.USE_GEMINI) {
433770
433760
  this.geminiClient.stripThoughtsFromHistory();
@@ -433773,7 +433763,7 @@ var init_config4 = __esm({
433773
433763
  if (this.contentGeneratorConfig) {
433774
433764
  this.contentGeneratorConfig.authType = void 0;
433775
433765
  }
433776
- const newContentGeneratorConfig = await createContentGeneratorConfig(this, authMethod, apiKey);
433766
+ const newContentGeneratorConfig = await createContentGeneratorConfig(this, authMethod, apiKey, baseUrl, customHeaders);
433777
433767
  this.contentGenerator = await createContentGenerator(newContentGeneratorConfig, this, this.getSessionId());
433778
433768
  this.contentGeneratorConfig = newContentGeneratorConfig;
433779
433769
  this.baseLlmClient = new BaseLlmClient(this.contentGenerator, this);
@@ -441105,6 +441095,7 @@ __export(dist_exports, {
441105
441095
  MCP_DEFAULT_TIMEOUT_MSEC: () => MCP_DEFAULT_TIMEOUT_MSEC,
441106
441096
  MCP_EXCLUDED_PRIORITY: () => MCP_EXCLUDED_PRIORITY,
441107
441097
  MCP_QUALIFIED_NAME_SEPARATOR: () => MCP_QUALIFIED_NAME_SEPARATOR,
441098
+ MCP_TOOL_PREFIX: () => MCP_TOOL_PREFIX,
441108
441099
  MEDIA_FILE_PATTERNS: () => MEDIA_FILE_PATTERNS,
441109
441100
  MEMORY_PARAM_FACT: () => MEMORY_PARAM_FACT,
441110
441101
  MEMORY_SECTION_HEADER: () => MEMORY_SECTION_HEADER,
@@ -441334,6 +441325,7 @@ __export(dist_exports, {
441334
441325
  flushTelemetry: () => flushTelemetry,
441335
441326
  formatBytes: () => formatBytes,
441336
441327
  formatCheckpointDisplayList: () => formatCheckpointDisplayList,
441328
+ formatMcpToolName: () => formatMcpToolName,
441337
441329
  formatPolicyError: () => formatPolicyError,
441338
441330
  formatProtoJsonDuration: () => formatProtoJsonDuration,
441339
441331
  formatTruncatedToolOutput: () => formatTruncatedToolOutput,
@@ -441453,6 +441445,7 @@ __export(dist_exports, {
441453
441445
  isHeadlessMode: () => isHeadlessMode,
441454
441446
  isInvalidArgumentError: () => isInvalidArgumentError,
441455
441447
  isJetBrainsTerminal: () => isJetBrainsTerminal,
441448
+ isMcpToolAnnotation: () => isMcpToolAnnotation,
441456
441449
  isMcpToolName: () => isMcpToolName,
441457
441450
  isNightly: () => isNightly,
441458
441451
  isNodeError: () => isNodeError,
@@ -441527,6 +441520,7 @@ __export(dist_exports, {
441527
441520
  parseBooleanEnvFlag: () => parseBooleanEnvFlag,
441528
441521
  parseCommandDetails: () => parseCommandDetails,
441529
441522
  parseGoogleApiError: () => parseGoogleApiError,
441523
+ parseMcpToolName: () => parseMcpToolName,
441530
441524
  parsePrompt: () => parsePrompt,
441531
441525
  parseTelemetryTargetValue: () => parseTelemetryTargetValue,
441532
441526
  parseThought: () => parseThought,
@@ -515083,7 +515077,7 @@ var WarningMessage = ({ text }) => {
515083
515077
  };
515084
515078
 
515085
515079
  // packages/cli/src/generated/git-commit.ts
515086
- var GIT_COMMIT_INFO2 = "b25c8137f";
515080
+ var GIT_COMMIT_INFO2 = "508aaeda8";
515087
515081
 
515088
515082
  // packages/cli/src/ui/components/AboutBox.tsx
515089
515083
  init_dist8();
@@ -563500,7 +563494,7 @@ async function loadSandboxConfig(settings, argv) {
563500
563494
  const sandboxOption = argv.sandbox ?? settings.tools?.sandbox;
563501
563495
  const command2 = getSandboxCommand(sandboxOption);
563502
563496
  const packageJson2 = await getPackageJson(__dirname13);
563503
- const image2 = process.env["GEMINI_SANDBOX_IMAGE"] ?? "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.33.0-preview.3" ?? packageJson2?.config?.sandboxImageUri;
563497
+ const image2 = process.env["GEMINI_SANDBOX_IMAGE"] ?? "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.33.0-preview.5" ?? packageJson2?.config?.sandboxImageUri;
563504
563498
  return command2 && image2 ? { command: command2, image: image2 } : void 0;
563505
563499
  }
563506
563500
 
@@ -567814,6 +567808,8 @@ var GeminiAgent = class {
567814
567808
  sessions = /* @__PURE__ */ new Map();
567815
567809
  clientCapabilities;
567816
567810
  apiKey;
567811
+ baseUrl;
567812
+ customHeaders;
567817
567813
  async initialize(args2) {
567818
567814
  this.clientCapabilities = args2.clientCapabilities;
567819
567815
  const authMethods = [
@@ -567836,6 +567832,17 @@ var GeminiAgent = class {
567836
567832
  id: AuthType2.USE_VERTEX_AI,
567837
567833
  name: "Vertex AI",
567838
567834
  description: "Use an API key with Vertex AI GenAI API"
567835
+ },
567836
+ {
567837
+ id: AuthType2.GATEWAY,
567838
+ name: "AI API Gateway",
567839
+ description: "Use a custom AI API Gateway",
567840
+ _meta: {
567841
+ gateway: {
567842
+ protocol: "google",
567843
+ restartRequired: "false"
567844
+ }
567845
+ }
567839
567846
  }
567840
567847
  ];
567841
567848
  await this.config.initialize();
@@ -567875,7 +567882,32 @@ var GeminiAgent = class {
567875
567882
  if (apiKey) {
567876
567883
  this.apiKey = apiKey;
567877
567884
  }
567878
- await this.config.refreshAuth(method, apiKey ?? this.apiKey);
567885
+ const gatewaySchema = external_exports.object({
567886
+ baseUrl: external_exports.string().optional(),
567887
+ headers: external_exports.record(external_exports.string()).optional()
567888
+ });
567889
+ let baseUrl;
567890
+ let headers;
567891
+ if (meta?.["gateway"]) {
567892
+ const result2 = gatewaySchema.safeParse(meta["gateway"]);
567893
+ if (result2.success) {
567894
+ baseUrl = result2.data.baseUrl;
567895
+ headers = result2.data.headers;
567896
+ } else {
567897
+ throw new RequestError3(
567898
+ -32602,
567899
+ `Malformed gateway payload: ${result2.error.message}`
567900
+ );
567901
+ }
567902
+ }
567903
+ this.baseUrl = baseUrl;
567904
+ this.customHeaders = headers;
567905
+ await this.config.refreshAuth(
567906
+ method,
567907
+ apiKey ?? this.apiKey,
567908
+ baseUrl,
567909
+ headers
567910
+ );
567879
567911
  } catch (e3) {
567880
567912
  throw new RequestError3(-32e3, getAcpErrorMessage(e3));
567881
567913
  }
@@ -567901,7 +567933,12 @@ var GeminiAgent = class {
567901
567933
  let isAuthenticated = false;
567902
567934
  let authErrorMessage = "";
567903
567935
  try {
567904
- await config2.refreshAuth(authType, this.apiKey);
567936
+ await config2.refreshAuth(
567937
+ authType,
567938
+ this.apiKey,
567939
+ this.baseUrl,
567940
+ this.customHeaders
567941
+ );
567905
567942
  isAuthenticated = true;
567906
567943
  const contentGeneratorConfig = config2.getContentGeneratorConfig();
567907
567944
  if (authType === AuthType2.USE_GEMINI && (!contentGeneratorConfig || !contentGeneratorConfig.apiKey)) {
@@ -568025,7 +568062,12 @@ var GeminiAgent = class {
568025
568062
  }
568026
568063
  const config2 = await this.newSessionConfig(sessionId2, cwd7, mcpServers);
568027
568064
  try {
568028
- await config2.refreshAuth(selectedAuthType, this.apiKey);
568065
+ await config2.refreshAuth(
568066
+ selectedAuthType,
568067
+ this.apiKey,
568068
+ this.baseUrl,
568069
+ this.customHeaders
568070
+ );
568029
568071
  } catch (e3) {
568030
568072
  debugLogger.error(`Authentication failed: ${e3}`);
568031
568073
  throw RequestError3.authRequired();
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@google/gemini-cli-devtools",
3
- "version": "0.33.0-preview.3",
3
+ "version": "0.33.0-preview.5",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@google/gemini-cli",
3
- "version": "0.33.0-preview.3",
3
+ "version": "0.33.0-preview.5",
4
4
  "description": "Gemini CLI",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {