@google/adk 1.4.0 → 1.6.0

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.
Files changed (213) hide show
  1. package/dist/cjs/a2a/a2a_remote_agent.js +12 -2
  2. package/dist/cjs/a2a/agent_to_a2a.js +18 -3
  3. package/dist/cjs/a2a/auth.js +65 -0
  4. package/dist/cjs/a2a/event_converter_utils.js +47 -18
  5. package/dist/cjs/a2a/metadata_converter_utils.js +1 -1
  6. package/dist/cjs/agents/base_agent.js +39 -0
  7. package/dist/cjs/agents/functions.js +26 -28
  8. package/dist/cjs/agents/llm_agent.js +4 -2
  9. package/dist/cjs/agents/loop_agent.js +15 -3
  10. package/dist/cjs/agents/processors/basic_llm_request_processor.js +3 -2
  11. package/dist/cjs/agents/processors/content_processor_utils.js +2 -1
  12. package/dist/cjs/agents/processors/content_request_processor.js +2 -21
  13. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +3 -1
  14. package/dist/cjs/agents/routed_agent.js +31 -0
  15. package/dist/cjs/agents/run_config.js +3 -2
  16. package/dist/cjs/artifacts/in_memory_artifact_service.js +17 -9
  17. package/dist/cjs/auth/credential_service/in_memory_credential_service.js +14 -3
  18. package/dist/cjs/code_executors/unsafe_local_code_executor.js +23 -12
  19. package/dist/cjs/common.js +35 -0
  20. package/dist/cjs/context/agent_controlled_context_compactor.js +2 -11
  21. package/dist/cjs/context/anchored_context_compactor.js +127 -0
  22. package/dist/cjs/context/compaction_utils.js +64 -0
  23. package/dist/cjs/context/token_based_context_compactor.js +13 -44
  24. package/dist/cjs/events/compacted_event.js +9 -3
  25. package/dist/cjs/events/event.js +28 -0
  26. package/dist/cjs/index.js +7 -0
  27. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
  28. package/dist/cjs/memory/in_memory_memory_service.js +13 -2
  29. package/dist/cjs/memory/vertex_ai_memory_bank_service.js +3 -0
  30. package/dist/cjs/plugins/base_plugin.js +4 -2
  31. package/dist/cjs/plugins/global_instruction_plugin.js +97 -0
  32. package/dist/cjs/runner/runner.js +69 -23
  33. package/dist/cjs/sessions/base_session_service.js +8 -3
  34. package/dist/cjs/sessions/in_memory_session_service.js +8 -8
  35. package/dist/cjs/sessions/vertex_ai_session_service.js +22 -10
  36. package/dist/cjs/skills/loader.js +40 -6
  37. package/dist/cjs/tools/enterprise_web_search_tool.js +81 -0
  38. package/dist/cjs/tools/example_tool.js +68 -0
  39. package/dist/cjs/tools/get_user_choice_tool.js +53 -0
  40. package/dist/cjs/tools/load_web_page.js +250 -0
  41. package/dist/cjs/tools/mcp/load_mcp_resource_tool.js +140 -0
  42. package/dist/cjs/tools/mcp/mcp_session_manager.js +35 -21
  43. package/dist/cjs/tools/mcp/mcp_toolset.js +63 -0
  44. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
  45. package/dist/cjs/tools/request_input_tool.js +54 -0
  46. package/dist/cjs/tools/skill/run_skill_inline_script_tool.js +54 -4
  47. package/dist/cjs/tools/skill/skill_toolset.js +4 -2
  48. package/dist/cjs/utils/branch_trie.js +41 -0
  49. package/dist/cjs/utils/crypto_shim.js +43 -0
  50. package/dist/cjs/utils/env_aware_utils.js +15 -13
  51. package/dist/cjs/utils/error_utils.js +120 -0
  52. package/dist/cjs/utils/file_utils.js +5 -2
  53. package/dist/cjs/utils/output_schema_utils.js +43 -0
  54. package/dist/cjs/utils/streaming_utils.js +5 -5
  55. package/dist/cjs/utils/vertex_ai_utils.js +3 -0
  56. package/dist/cjs/version.js +1 -1
  57. package/dist/esm/a2a/a2a_remote_agent.js +12 -2
  58. package/dist/esm/a2a/agent_to_a2a.js +18 -3
  59. package/dist/esm/a2a/auth.js +37 -0
  60. package/dist/esm/a2a/event_converter_utils.js +47 -18
  61. package/dist/esm/a2a/metadata_converter_utils.js +1 -1
  62. package/dist/esm/agents/base_agent.js +39 -0
  63. package/dist/esm/agents/functions.js +27 -24
  64. package/dist/esm/agents/llm_agent.js +6 -4
  65. package/dist/esm/agents/loop_agent.js +15 -3
  66. package/dist/esm/agents/processors/basic_llm_request_processor.js +3 -2
  67. package/dist/esm/agents/processors/content_processor_utils.js +2 -1
  68. package/dist/esm/agents/processors/content_request_processor.js +2 -21
  69. package/dist/esm/agents/processors/instructions_llm_request_processor.js +3 -1
  70. package/dist/esm/agents/routed_agent.js +31 -0
  71. package/dist/esm/agents/run_config.js +3 -2
  72. package/dist/esm/artifacts/in_memory_artifact_service.js +17 -9
  73. package/dist/esm/auth/credential_service/in_memory_credential_service.js +14 -3
  74. package/dist/esm/code_executors/unsafe_local_code_executor.js +22 -11
  75. package/dist/esm/common.js +29 -1
  76. package/dist/esm/context/agent_controlled_context_compactor.js +2 -11
  77. package/dist/esm/context/anchored_context_compactor.js +99 -0
  78. package/dist/esm/context/compaction_utils.js +38 -0
  79. package/dist/esm/context/token_based_context_compactor.js +16 -44
  80. package/dist/esm/events/compacted_event.js +7 -2
  81. package/dist/esm/events/event.js +24 -0
  82. package/dist/esm/index.js +8 -1
  83. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
  84. package/dist/esm/memory/in_memory_memory_service.js +13 -2
  85. package/dist/esm/memory/vertex_ai_memory_bank_service.js +7 -1
  86. package/dist/esm/plugins/base_plugin.js +4 -2
  87. package/dist/esm/plugins/global_instruction_plugin.js +69 -0
  88. package/dist/esm/runner/runner.js +69 -23
  89. package/dist/esm/sessions/base_session_service.js +8 -3
  90. package/dist/esm/sessions/in_memory_session_service.js +8 -8
  91. package/dist/esm/sessions/vertex_ai_session_service.js +26 -11
  92. package/dist/esm/skills/loader.js +40 -6
  93. package/dist/esm/tools/enterprise_web_search_tool.js +55 -0
  94. package/dist/esm/tools/example_tool.js +42 -0
  95. package/dist/esm/tools/get_user_choice_tool.js +25 -0
  96. package/dist/esm/tools/load_web_page.js +221 -0
  97. package/dist/esm/tools/mcp/load_mcp_resource_tool.js +114 -0
  98. package/dist/esm/tools/mcp/mcp_session_manager.js +35 -21
  99. package/dist/esm/tools/mcp/mcp_toolset.js +63 -0
  100. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
  101. package/dist/esm/tools/request_input_tool.js +26 -0
  102. package/dist/esm/tools/skill/run_skill_inline_script_tool.js +53 -4
  103. package/dist/esm/tools/skill/skill_toolset.js +4 -2
  104. package/dist/esm/utils/branch_trie.js +13 -0
  105. package/dist/esm/utils/crypto_shim.js +15 -0
  106. package/dist/esm/utils/env_aware_utils.js +15 -13
  107. package/dist/esm/utils/error_utils.js +92 -0
  108. package/dist/esm/utils/file_utils.js +5 -2
  109. package/dist/esm/utils/output_schema_utils.js +15 -0
  110. package/dist/esm/utils/streaming_utils.js +1 -1
  111. package/dist/esm/utils/vertex_ai_utils.js +2 -0
  112. package/dist/esm/version.js +1 -1
  113. package/dist/types/a2a/a2a_remote_agent.d.ts +5 -1
  114. package/dist/types/a2a/agent_to_a2a.d.ts +38 -0
  115. package/dist/types/a2a/auth.d.ts +30 -0
  116. package/dist/types/a2a/event_converter_utils.d.ts +4 -1
  117. package/dist/types/agents/base_agent.d.ts +29 -1
  118. package/dist/types/agents/functions.d.ts +1 -9
  119. package/dist/types/agents/llm_agent.d.ts +5 -1
  120. package/dist/types/agents/loop_agent.d.ts +2 -2
  121. package/dist/types/agents/routed_agent.d.ts +24 -1
  122. package/dist/types/agents/run_config.d.ts +1 -1
  123. package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +11 -0
  124. package/dist/types/code_executors/unsafe_local_code_executor.d.ts +5 -1
  125. package/dist/types/common.d.ts +11 -2
  126. package/dist/types/context/agent_controlled_context_compactor.d.ts +0 -1
  127. package/dist/types/context/anchored_context_compactor.d.ts +35 -0
  128. package/dist/types/context/compaction_utils.d.ts +23 -0
  129. package/dist/types/context/token_based_context_compactor.d.ts +0 -1
  130. package/dist/types/events/compacted_event.d.ts +10 -0
  131. package/dist/types/events/event.d.ts +13 -0
  132. package/dist/types/index.d.ts +5 -3
  133. package/dist/types/memory/in_memory_memory_service.d.ts +11 -0
  134. package/dist/types/plugins/base_plugin.d.ts +4 -2
  135. package/dist/types/plugins/global_instruction_plugin.d.ts +38 -0
  136. package/dist/types/runner/runner.d.ts +1 -1
  137. package/dist/types/sessions/base_session_service.d.ts +8 -0
  138. package/dist/types/sessions/in_memory_session_service.d.ts +9 -0
  139. package/dist/types/sessions/vertex_ai_session_service.d.ts +19 -1
  140. package/dist/types/skills/loader.d.ts +5 -0
  141. package/dist/types/tools/enterprise_web_search_tool.d.ts +26 -0
  142. package/dist/types/tools/example_tool.d.ts +21 -0
  143. package/dist/types/tools/get_user_choice_tool.d.ts +14 -0
  144. package/dist/types/tools/load_web_page.d.ts +33 -0
  145. package/dist/types/tools/mcp/load_mcp_resource_tool.d.ts +26 -0
  146. package/dist/types/tools/mcp/mcp_toolset.d.ts +27 -0
  147. package/dist/types/tools/request_input_tool.d.ts +15 -0
  148. package/dist/types/tools/skill/run_skill_inline_script_tool.d.ts +25 -0
  149. package/dist/types/tools/skill/skill_toolset.d.ts +9 -0
  150. package/dist/types/utils/branch_trie.d.ts +14 -0
  151. package/dist/types/utils/crypto_shim.d.ts +16 -0
  152. package/dist/types/utils/env_aware_utils.d.ts +23 -0
  153. package/dist/types/utils/error_utils.d.ts +18 -0
  154. package/dist/types/utils/output_schema_utils.d.ts +18 -0
  155. package/dist/types/utils/vertex_ai_utils.d.ts +1 -0
  156. package/dist/types/version.d.ts +1 -1
  157. package/dist/web/a2a/a2a_remote_agent.js +12 -2
  158. package/dist/web/a2a/agent_to_a2a.js +18 -3
  159. package/dist/web/a2a/auth.js +37 -0
  160. package/dist/web/a2a/event_converter_utils.js +47 -18
  161. package/dist/web/a2a/metadata_converter_utils.js +1 -1
  162. package/dist/web/agents/base_agent.js +39 -0
  163. package/dist/web/agents/functions.js +27 -24
  164. package/dist/web/agents/llm_agent.js +6 -4
  165. package/dist/web/agents/loop_agent.js +27 -3
  166. package/dist/web/agents/processors/basic_llm_request_processor.js +3 -2
  167. package/dist/web/agents/processors/content_processor_utils.js +2 -1
  168. package/dist/web/agents/processors/content_request_processor.js +2 -21
  169. package/dist/web/agents/processors/instructions_llm_request_processor.js +3 -1
  170. package/dist/web/agents/routed_agent.js +31 -0
  171. package/dist/web/agents/run_config.js +8 -3
  172. package/dist/web/artifacts/in_memory_artifact_service.js +17 -9
  173. package/dist/web/auth/credential_service/in_memory_credential_service.js +14 -3
  174. package/dist/web/code_executors/unsafe_local_code_executor.js +22 -11
  175. package/dist/web/common.js +29 -1
  176. package/dist/web/context/agent_controlled_context_compactor.js +2 -11
  177. package/dist/web/context/anchored_context_compactor.js +117 -0
  178. package/dist/web/context/compaction_utils.js +38 -0
  179. package/dist/web/context/token_based_context_compactor.js +16 -44
  180. package/dist/web/events/compacted_event.js +7 -2
  181. package/dist/web/events/event.js +24 -0
  182. package/dist/web/index.js +8 -1
  183. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
  184. package/dist/web/memory/in_memory_memory_service.js +13 -2
  185. package/dist/web/memory/vertex_ai_memory_bank_service.js +7 -1
  186. package/dist/web/plugins/base_plugin.js +4 -2
  187. package/dist/web/plugins/global_instruction_plugin.js +67 -0
  188. package/dist/web/runner/runner.js +65 -22
  189. package/dist/web/sessions/base_session_service.js +8 -3
  190. package/dist/web/sessions/in_memory_session_service.js +8 -8
  191. package/dist/web/sessions/vertex_ai_session_service.js +24 -11
  192. package/dist/web/skills/loader.js +40 -6
  193. package/dist/web/tools/enterprise_web_search_tool.js +55 -0
  194. package/dist/web/tools/example_tool.js +42 -0
  195. package/dist/web/tools/get_user_choice_tool.js +25 -0
  196. package/dist/web/tools/load_web_page.js +221 -0
  197. package/dist/web/tools/mcp/load_mcp_resource_tool.js +107 -0
  198. package/dist/web/tools/mcp/mcp_session_manager.js +35 -21
  199. package/dist/web/tools/mcp/mcp_toolset.js +63 -0
  200. package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
  201. package/dist/web/tools/request_input_tool.js +26 -0
  202. package/dist/web/tools/skill/run_skill_inline_script_tool.js +51 -4
  203. package/dist/web/tools/skill/skill_toolset.js +4 -2
  204. package/dist/web/utils/branch_trie.js +13 -0
  205. package/dist/web/utils/crypto_shim.js +15 -0
  206. package/dist/web/utils/env_aware_utils.js +15 -13
  207. package/dist/web/utils/error_utils.js +92 -0
  208. package/dist/web/utils/file_utils.js +5 -2
  209. package/dist/web/utils/output_schema_utils.js +15 -0
  210. package/dist/web/utils/streaming_utils.js +1 -1
  211. package/dist/web/utils/vertex_ai_utils.js +2 -0
  212. package/dist/web/version.js +1 -1
  213. package/package.json +1 -1
@@ -0,0 +1,140 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ "use strict";
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var load_mcp_resource_tool_exports = {};
26
+ __export(load_mcp_resource_tool_exports, {
27
+ LoadMcpResourceTool: () => LoadMcpResourceTool
28
+ });
29
+ module.exports = __toCommonJS(load_mcp_resource_tool_exports);
30
+ var import_genai = require("@google/genai");
31
+ var import_llm_request = require("../../models/llm_request.js");
32
+ var import_logger = require("../../utils/logger.js");
33
+ var import_base_tool = require("../base_tool.js");
34
+ /**
35
+ * @license
36
+ * Copyright 2026 Google LLC
37
+ * SPDX-License-Identifier: Apache-2.0
38
+ */
39
+ class LoadMcpResourceTool extends import_base_tool.BaseTool {
40
+ constructor(mcpToolset) {
41
+ super({
42
+ name: "load_mcp_resource",
43
+ description: `Loads resources from the MCP server.
44
+
45
+ NOTE: Call when you need access to resources.`
46
+ });
47
+ this.mcpToolset = mcpToolset;
48
+ }
49
+ _getDeclaration() {
50
+ return {
51
+ name: this.name,
52
+ description: this.description,
53
+ parameters: {
54
+ type: import_genai.Type.OBJECT,
55
+ properties: {
56
+ resource_names: {
57
+ type: import_genai.Type.ARRAY,
58
+ items: {
59
+ type: import_genai.Type.STRING
60
+ },
61
+ description: "The names of the MCP resources to load."
62
+ }
63
+ }
64
+ }
65
+ };
66
+ }
67
+ async runAsync({ args }) {
68
+ const resourceNames = args["resource_names"] || [];
69
+ return {
70
+ resource_names: resourceNames,
71
+ status: "resource contents temporarily inserted and removed. to access these resources, call load_mcp_resource tool again."
72
+ };
73
+ }
74
+ async processLlmRequest(request) {
75
+ await super.processLlmRequest(request);
76
+ await this.appendResourcesToLlmRequest(request.llmRequest);
77
+ }
78
+ async appendResourcesToLlmRequest(llmRequest) {
79
+ var _a, _b;
80
+ try {
81
+ const availableResourceNames = await this.mcpToolset.listResources();
82
+ if (availableResourceNames.length > 0) {
83
+ (0, import_llm_request.appendInstructions)(llmRequest, [
84
+ `You have a list of MCP resources:
85
+ ${JSON.stringify(
86
+ availableResourceNames
87
+ )}
88
+
89
+ When the user asks questions about any of the resources, you should call the
90
+ \`load_mcp_resource\` function to load the resource. Always call load_mcp_resource
91
+ before answering questions related to the resources.`
92
+ ]);
93
+ }
94
+ } catch (e) {
95
+ import_logger.logger.warn(`Failed to list MCP resources: ${e}`);
96
+ }
97
+ const lastContent = llmRequest.contents.at(-1);
98
+ const functionResponse = (_b = (_a = lastContent == null ? void 0 : lastContent.parts) == null ? void 0 : _a[0]) == null ? void 0 : _b.functionResponse;
99
+ if (!functionResponse || functionResponse.name !== this.name) {
100
+ return;
101
+ }
102
+ const response = functionResponse.response || {};
103
+ const requestedResourceNames = response["resource_names"] || [];
104
+ for (const resourceName of requestedResourceNames) {
105
+ try {
106
+ const resourceContents = await this.mcpToolset.readResource(resourceName);
107
+ for (const content of resourceContents) {
108
+ llmRequest.contents.push({
109
+ role: "user",
110
+ parts: [
111
+ { text: `Resource ${resourceName} is:` },
112
+ this.mcpContentToPart(content, resourceName)
113
+ ]
114
+ });
115
+ }
116
+ } catch (e) {
117
+ import_logger.logger.warn(`Failed to read MCP resource '${resourceName}': ${e}`);
118
+ }
119
+ }
120
+ }
121
+ mcpContentToPart(content, resourceName) {
122
+ var _a;
123
+ if ("text" in content) {
124
+ return { text: content.text };
125
+ }
126
+ if ("blob" in content) {
127
+ return {
128
+ inlineData: {
129
+ data: content.blob,
130
+ mimeType: (_a = content.mimeType) != null ? _a : "application/octet-stream"
131
+ }
132
+ };
133
+ }
134
+ return { text: `[Unknown content type for ${resourceName}]` };
135
+ }
136
+ }
137
+ // Annotate the CommonJS export names for ESM import in node:
138
+ 0 && (module.exports = {
139
+ LoadMcpResourceTool
140
+ });
@@ -30,11 +30,16 @@ module.exports = __toCommonJS(mcp_session_manager_exports);
30
30
  var import_client = require("@modelcontextprotocol/sdk/client/index.js");
31
31
  var import_stdio = require("@modelcontextprotocol/sdk/client/stdio.js");
32
32
  var import_streamableHttp = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
33
+ var import_error_utils = require("../../utils/error_utils.js");
34
+ var import_logger = require("../../utils/logger.js");
33
35
  /**
34
36
  * @license
35
37
  * Copyright 2025 Google LLC
36
38
  * SPDX-License-Identifier: Apache-2.0
37
39
  */
40
+ function logTransportError(err) {
41
+ import_logger.logger.error("MCP transport error: " + (0, import_error_utils.formatError)(err));
42
+ }
38
43
  class MCPSessionManager {
39
44
  constructor(connectionParams) {
40
45
  this.activeSessions = /* @__PURE__ */ new Set();
@@ -43,31 +48,40 @@ class MCPSessionManager {
43
48
  async createSession() {
44
49
  var _a;
45
50
  const client = new import_client.Client({ name: "MCPClient", version: "1.0.0" });
46
- switch (this.connectionParams.type) {
47
- case "StdioConnectionParams":
48
- await client.connect(
49
- new import_stdio.StdioClientTransport(this.connectionParams.serverParams)
50
- );
51
- break;
52
- case "StreamableHTTPConnectionParams": {
53
- const options = (_a = this.connectionParams.transportOptions) != null ? _a : {};
54
- if (!options.requestInit && this.connectionParams.header !== void 0) {
55
- options.requestInit = {
56
- headers: this.connectionParams.header
57
- };
51
+ try {
52
+ switch (this.connectionParams.type) {
53
+ case "StdioConnectionParams": {
54
+ const transport = new import_stdio.StdioClientTransport(
55
+ this.connectionParams.serverParams
56
+ );
57
+ transport.onerror = logTransportError;
58
+ await client.connect(transport);
59
+ break;
58
60
  }
59
- await client.connect(
60
- new import_streamableHttp.StreamableHTTPClientTransport(
61
+ case "StreamableHTTPConnectionParams": {
62
+ const options = (_a = this.connectionParams.transportOptions) != null ? _a : {};
63
+ if (!options.requestInit && this.connectionParams.header !== void 0) {
64
+ options.requestInit = {
65
+ headers: this.connectionParams.header
66
+ };
67
+ }
68
+ const transport = new import_streamableHttp.StreamableHTTPClientTransport(
61
69
  new URL(this.connectionParams.url),
62
70
  options
63
- )
64
- );
65
- break;
66
- }
67
- default: {
68
- const _exhaustiveCheck = this.connectionParams;
69
- break;
71
+ );
72
+ transport.onerror = logTransportError;
73
+ await client.connect(transport);
74
+ break;
75
+ }
76
+ default: {
77
+ const _exhaustiveCheck = this.connectionParams;
78
+ break;
79
+ }
70
80
  }
81
+ } catch (err) {
82
+ throw new Error("Failed to create MCP session: " + (0, import_error_utils.formatError)(err), {
83
+ cause: err
84
+ });
71
85
  }
72
86
  this.activeSessions.add(client);
73
87
  return client;
@@ -75,6 +75,69 @@ class MCPToolset extends import_base_toolset.BaseToolset {
75
75
  );
76
76
  return tools;
77
77
  }
78
+ /**
79
+ * Lists the names of the resources advertised by the MCP server.
80
+ *
81
+ * @return The resource names available on the server.
82
+ */
83
+ async listResources() {
84
+ const session = await this.mcpSessionManager.createSession();
85
+ try {
86
+ const result = await session.listResources();
87
+ return result.resources.map((resource) => resource.name);
88
+ } finally {
89
+ await this.mcpSessionManager.closeSession(session);
90
+ }
91
+ }
92
+ /**
93
+ * Returns metadata for the resource whose name matches `name`.
94
+ *
95
+ * @param name The advertised name of the resource.
96
+ * @return The matching MCP `Resource`.
97
+ * @throws If no resource with the given name is advertised by the server.
98
+ */
99
+ async getResourceInfo(name) {
100
+ const session = await this.mcpSessionManager.createSession();
101
+ let result;
102
+ try {
103
+ result = await session.listResources();
104
+ } finally {
105
+ await this.mcpSessionManager.closeSession(session);
106
+ }
107
+ const resource = result.resources.find(
108
+ (candidate) => candidate.name === name
109
+ );
110
+ if (!resource) {
111
+ throw new Error(`Resource with name '${name}' not found.`);
112
+ }
113
+ return resource;
114
+ }
115
+ /**
116
+ * Reads the contents of the named resource from the MCP server.
117
+ *
118
+ * The resource name is resolved to a URI via {@link getResourceInfo} before
119
+ * reading. Binary contents are returned base64-encoded, exactly as provided
120
+ * by the server (never decoded and re-encoded).
121
+ *
122
+ * @param name The advertised name of the resource to read.
123
+ * @return The resource contents (text and/or base64-encoded binary).
124
+ * @throws If the resource is unknown or has no URI.
125
+ */
126
+ async readResource(name) {
127
+ const resourceInfo = await this.getResourceInfo(name);
128
+ if (!resourceInfo.uri) {
129
+ throw new Error(`Resource '${name}' has no URI.`);
130
+ }
131
+ const session = await this.mcpSessionManager.createSession();
132
+ try {
133
+ const result = await session.readResource({
134
+ uri: resourceInfo.uri
135
+ });
136
+ return result.contents;
137
+ } finally {
138
+ await this.mcpSessionManager.closeSession(session);
139
+ }
140
+ }
78
141
  async close() {
79
142
  const sessions = this.mcpSessionManager.getActiveSessions();
80
143
  await Promise.allSettled(
@@ -87,19 +87,22 @@ let ToolAuthHandler = class {
87
87
  rawAuthCredential: this.authCredential,
88
88
  credentialKey: this.credentialKey || "default_openapi_key"
89
89
  };
90
- const credential = this.context.getAuthResponse(authConfig);
91
- if (credential) {
92
- const exchanger = new import_auto_auth_credential_exchanger.AutoAuthCredentialExchanger();
93
- const result = await exchanger.exchange({
94
- authScheme: this.authScheme,
95
- authCredential: credential
96
- });
90
+ const authResponseCredential = this.context.getAuthResponse(authConfig);
91
+ const credential = authResponseCredential != null ? authResponseCredential : this.authCredential;
92
+ if (!credential) {
93
+ this.context.requestCredential(authConfig);
94
+ return { state: "pending" };
95
+ }
96
+ const exchanger = new import_auto_auth_credential_exchanger.AutoAuthCredentialExchanger();
97
+ const result = await exchanger.exchange({
98
+ authScheme: this.authScheme,
99
+ authCredential: credential
100
+ });
101
+ if (authResponseCredential || result.wasExchanged) {
97
102
  const key = store.getCredentialKey(this.authScheme);
98
103
  store.storeCredential(key, result.credential);
99
- return { state: "done", authCredential: result.credential };
100
104
  }
101
- this.context.requestCredential(authConfig);
102
- return { state: "pending" };
105
+ return { state: "done", authCredential: result.credential };
103
106
  }
104
107
  };
105
108
  __decorateClass([
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ "use strict";
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var request_input_tool_exports = {};
26
+ __export(request_input_tool_exports, {
27
+ requestInputTool: () => requestInputTool
28
+ });
29
+ module.exports = __toCommonJS(request_input_tool_exports);
30
+ var import_zod = require("zod");
31
+ var import_long_running_tool = require("./long_running_tool.js");
32
+ /**
33
+ * @license
34
+ * Copyright 2026 Google LLC
35
+ * SPDX-License-Identifier: Apache-2.0
36
+ */
37
+ const requestInputTool = new import_long_running_tool.LongRunningFunctionTool({
38
+ name: "adk_request_input",
39
+ description: "Presents a custom message to the user and awaits unstructured or structured input.",
40
+ parameters: import_zod.z.object({
41
+ message: import_zod.z.string().describe("The prompt for the user."),
42
+ responseSchema: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional().describe("Expected schema of the response.")
43
+ }),
44
+ execute: async (input, context) => {
45
+ if (context) {
46
+ context.actions.skipSummarization = true;
47
+ }
48
+ return null;
49
+ }
50
+ });
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ requestInputTool
54
+ });
@@ -32,6 +32,7 @@ var __decorateClass = (decorators, target, key, kind) => {
32
32
  };
33
33
  var run_skill_inline_script_tool_exports = {};
34
34
  __export(run_skill_inline_script_tool_exports, {
35
+ RunSkillInlineScriptErrorCode: () => RunSkillInlineScriptErrorCode,
35
36
  RunSkillInlineScriptTool: () => RunSkillInlineScriptTool
36
37
  });
37
38
  module.exports = __toCommonJS(run_skill_inline_script_tool_exports);
@@ -46,6 +47,15 @@ var import_base_tool = require("../base_tool.js");
46
47
  * Copyright 2026 Google LLC
47
48
  * SPDX-License-Identifier: Apache-2.0
48
49
  */
50
+ var RunSkillInlineScriptErrorCode = /* @__PURE__ */ ((RunSkillInlineScriptErrorCode2) => {
51
+ RunSkillInlineScriptErrorCode2["MISSING_SCRIPT_CONTENT"] = "MISSING_SCRIPT_CONTENT";
52
+ RunSkillInlineScriptErrorCode2["MISSING_LANGUAGE"] = "MISSING_LANGUAGE";
53
+ RunSkillInlineScriptErrorCode2["NO_CODE_EXECUTOR"] = "NO_CODE_EXECUTOR";
54
+ RunSkillInlineScriptErrorCode2["EXECUTION_ERROR"] = "EXECUTION_ERROR";
55
+ RunSkillInlineScriptErrorCode2["CONFIRMATION_REJECTED"] = "CONFIRMATION_REJECTED";
56
+ return RunSkillInlineScriptErrorCode2;
57
+ })(RunSkillInlineScriptErrorCode || {});
58
+ const REQUIRE_CONFIRMATION_MESSAGE = "This tool call needs external confirmation before completion.";
49
59
  let RunSkillInlineScriptTool = class extends import_base_tool.BaseTool {
50
60
  constructor(toolset) {
51
61
  super({
@@ -95,13 +105,13 @@ let RunSkillInlineScriptTool = class extends import_base_tool.BaseTool {
95
105
  if (!inlineScriptContent) {
96
106
  return {
97
107
  error: "Script content is required.",
98
- errorCode: "MISSING_SCRIPT_CONTENT"
108
+ errorCode: "MISSING_SCRIPT_CONTENT" /* MISSING_SCRIPT_CONTENT */
99
109
  };
100
110
  }
101
111
  if (!language) {
102
112
  return {
103
113
  error: "Language is required.",
104
- errorCode: "MISSING_LANGUAGE"
114
+ errorCode: "MISSING_LANGUAGE" /* MISSING_LANGUAGE */
105
115
  };
106
116
  }
107
117
  let codeExecutor = (_a = this.toolset) == null ? void 0 : _a.codeExecutor;
@@ -114,9 +124,17 @@ let RunSkillInlineScriptTool = class extends import_base_tool.BaseTool {
114
124
  if (!codeExecutor) {
115
125
  return {
116
126
  error: "No code executor configured.",
117
- errorCode: "NO_CODE_EXECUTOR"
127
+ errorCode: "NO_CODE_EXECUTOR" /* NO_CODE_EXECUTOR */
118
128
  };
119
129
  }
130
+ const confirmationResult = this.enforceConfirmation(
131
+ toolContext,
132
+ inlineScriptContent,
133
+ language
134
+ );
135
+ if (confirmationResult) {
136
+ return confirmationResult;
137
+ }
120
138
  try {
121
139
  const result = await codeExecutor.executeCode({
122
140
  invocationContext: toolContext.invocationContext,
@@ -132,9 +150,40 @@ let RunSkillInlineScriptTool = class extends import_base_tool.BaseTool {
132
150
  } catch (e) {
133
151
  return {
134
152
  error: `Failed to execute inline script: ${e.message}`,
135
- errorCode: "EXECUTION_ERROR"
153
+ errorCode: "EXECUTION_ERROR" /* EXECUTION_ERROR */
154
+ };
155
+ }
156
+ }
157
+ /**
158
+ * Enforces a human-in-the-loop confirmation gate before executing an inline
159
+ * script, using the repo's standard tool-confirmation mechanism.
160
+ *
161
+ * - When no confirmation has been provided yet, a confirmation is requested
162
+ * (surfacing the language and script that would run) and an intermediate
163
+ * result is returned so the tool call pauses until the client responds.
164
+ * - When a confirmation exists but was not confirmed, a rejection error is
165
+ * returned and execution is refused.
166
+ * - When the confirmation is confirmed, `undefined` is returned to allow the
167
+ * caller to proceed with execution.
168
+ */
169
+ enforceConfirmation(toolContext, scriptContent, language) {
170
+ const confirmation = toolContext.toolConfirmation;
171
+ if (!confirmation) {
172
+ toolContext.requestConfirmation({
173
+ hint: `Confirmation is required before executing an inline skill script. The agent requested to run the following ${language} script in the code executor. Only approve if you trust its contents:
174
+
175
+ ` + scriptContent,
176
+ payload: { language, scriptContent }
177
+ });
178
+ return { partial: REQUIRE_CONFIRMATION_MESSAGE };
179
+ }
180
+ if (!confirmation.confirmed) {
181
+ return {
182
+ error: "Inline script execution was not confirmed and was rejected.",
183
+ errorCode: "CONFIRMATION_REJECTED" /* CONFIRMATION_REJECTED */
136
184
  };
137
185
  }
186
+ return void 0;
138
187
  }
139
188
  };
140
189
  RunSkillInlineScriptTool = __decorateClass([
@@ -142,5 +191,6 @@ RunSkillInlineScriptTool = __decorateClass([
142
191
  ], RunSkillInlineScriptTool);
143
192
  // Annotate the CommonJS export names for ESM import in node:
144
193
  0 && (module.exports = {
194
+ RunSkillInlineScriptErrorCode,
145
195
  RunSkillInlineScriptTool
146
196
  });
@@ -80,9 +80,11 @@ let SkillToolset = class extends import_base_toolset.BaseToolset {
80
80
  new import_list_skills_tool.ListSkillsTool(this),
81
81
  new import_load_skill_tool.LoadSkillTool(this),
82
82
  new import_load_skill_resource_tool.LoadSkillResourceTool(this),
83
- new import_run_skill_script_tool.RunSkillScriptTool(this),
84
- new import_run_skill_inline_script_tool.RunSkillInlineScriptTool(this)
83
+ new import_run_skill_script_tool.RunSkillScriptTool(this)
85
84
  ];
85
+ if (options.allowInlineScripts) {
86
+ this.tools.push(new import_run_skill_inline_script_tool.RunSkillInlineScriptTool(this));
87
+ }
86
88
  if (this.registry) {
87
89
  this.tools.push(new import_search_skills_tool.SearchSkillsTool(this));
88
90
  }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ "use strict";
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var branch_trie_exports = {};
26
+ __export(branch_trie_exports, {
27
+ isSegmentPrefix: () => isSegmentPrefix
28
+ });
29
+ module.exports = __toCommonJS(branch_trie_exports);
30
+ /**
31
+ * @license
32
+ * Copyright 2026 Google LLC
33
+ * SPDX-License-Identifier: Apache-2.0
34
+ */
35
+ function isSegmentPrefix(currentBranch, targetBranch) {
36
+ return !targetBranch || targetBranch === currentBranch || !!currentBranch && currentBranch.startsWith(`${targetBranch}.`);
37
+ }
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ isSegmentPrefix
41
+ });
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ "use strict";
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var crypto_shim_exports = {};
26
+ __export(crypto_shim_exports, {
27
+ randomUUID: () => randomUUID
28
+ });
29
+ module.exports = __toCommonJS(crypto_shim_exports);
30
+ /**
31
+ * @license
32
+ * Copyright 2026 Google LLC
33
+ * SPDX-License-Identifier: Apache-2.0
34
+ */
35
+ function randomUUID() {
36
+ throw new Error(
37
+ "randomUUID: no cryptographically secure source of randomness is available. Neither crypto.randomUUID() nor crypto.getRandomValues() is present in this environment."
38
+ );
39
+ }
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ randomUUID
43
+ });
@@ -32,6 +32,7 @@ __export(env_aware_utils_exports, {
32
32
  randomUUID: () => randomUUID
33
33
  });
34
34
  module.exports = __toCommonJS(env_aware_utils_exports);
35
+ var import_node_crypto = require("node:crypto");
35
36
  /**
36
37
  * @license
37
38
  * Copyright 2025 Google LLC
@@ -40,24 +41,25 @@ module.exports = __toCommonJS(env_aware_utils_exports);
40
41
  function isBrowser() {
41
42
  return typeof window !== "undefined";
42
43
  }
43
- const UUID_MASK = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
44
44
  function randomUUID() {
45
- var _a;
45
+ var _a, _b;
46
46
  if ((_a = globalThis.crypto) == null ? void 0 : _a.randomUUID) {
47
47
  return globalThis.crypto.randomUUID();
48
48
  }
49
- let uuid = "";
50
- for (let i = 0; i < UUID_MASK.length; i++) {
51
- const randomValue = Math.random() * 16 | 0;
52
- if (UUID_MASK[i] === "x") {
53
- uuid += randomValue.toString(16);
54
- } else if (UUID_MASK[i] === "y") {
55
- uuid += (randomValue & 3 | 8).toString(16);
56
- } else {
57
- uuid += UUID_MASK[i];
58
- }
49
+ if ((_b = globalThis.crypto) == null ? void 0 : _b.getRandomValues) {
50
+ const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16));
51
+ bytes[6] = bytes[6] & 15 | 64;
52
+ bytes[8] = bytes[8] & 63 | 128;
53
+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
54
+ return [
55
+ hex.slice(0, 4),
56
+ hex.slice(4, 6),
57
+ hex.slice(6, 8),
58
+ hex.slice(8, 10),
59
+ hex.slice(10, 16)
60
+ ].map((group) => group.join("")).join("-");
59
61
  }
60
- return uuid;
62
+ return (0, import_node_crypto.randomUUID)();
61
63
  }
62
64
  function base64Encode(data) {
63
65
  if (isBrowser()) {