@google/adk 1.1.0 → 1.2.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 (150) hide show
  1. package/dist/cjs/agents/functions.js +4 -0
  2. package/dist/cjs/auth/oauth2/oauth2_discovery.js +26 -2
  3. package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +305 -0
  4. package/dist/cjs/code_executors/code_execution_utils.js +1 -1
  5. package/dist/cjs/common.js +11 -0
  6. package/dist/cjs/events/event.js +3 -1
  7. package/dist/cjs/index.js +14 -0
  8. package/dist/cjs/integrations/agent_registry/agent_registry.js +362 -0
  9. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +103 -0
  10. package/dist/cjs/integrations/agent_registry/helpers.js +57 -0
  11. package/dist/cjs/integrations/agent_registry/types.js +50 -0
  12. package/dist/cjs/memory/vertex_ai_memory_bank_service.js +496 -0
  13. package/dist/cjs/runner/in_memory_runner.js +10 -5
  14. package/dist/cjs/runner/runner.js +32 -2
  15. package/dist/cjs/sessions/database_session_service.js +49 -3
  16. package/dist/cjs/sessions/in_memory_session_service.js +70 -14
  17. package/dist/cjs/sessions/registry.js +4 -0
  18. package/dist/cjs/sessions/vertex_ai_session_service.js +428 -0
  19. package/dist/cjs/tools/agent_tool.js +10 -5
  20. package/dist/cjs/tools/exit_loop_tool.js +9 -0
  21. package/dist/cjs/tools/function_tool.js +7 -2
  22. package/dist/cjs/tools/google_maps_grounding_tool.js +80 -0
  23. package/dist/cjs/tools/long_running_tool.js +2 -1
  24. package/dist/cjs/tools/mcp/mcp_session_manager.js +11 -0
  25. package/dist/cjs/tools/mcp/mcp_tool.js +10 -6
  26. package/dist/cjs/tools/mcp/mcp_toolset.js +26 -3
  27. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +78 -0
  28. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +84 -0
  29. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +133 -0
  30. package/dist/cjs/tools/skill/load_skill_resource_tool.js +2 -25
  31. package/dist/cjs/tools/vertex_rag_retrieval_tool.js +64 -0
  32. package/dist/cjs/utils/file_utils.js +28 -0
  33. package/dist/cjs/utils/gemini_schema_util.js +18 -0
  34. package/dist/cjs/utils/partial_copy.js +51 -0
  35. package/dist/cjs/utils/streaming_utils.js +167 -121
  36. package/dist/cjs/utils/vertex_ai_utils.js +50 -0
  37. package/dist/cjs/version.js +1 -1
  38. package/dist/esm/agents/functions.js +4 -0
  39. package/dist/esm/auth/oauth2/oauth2_discovery.js +26 -2
  40. package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  41. package/dist/esm/code_executors/code_execution_utils.js +1 -1
  42. package/dist/esm/common.js +10 -0
  43. package/dist/esm/events/event.js +3 -1
  44. package/dist/esm/index.js +11 -0
  45. package/dist/esm/integrations/agent_registry/agent_registry.js +333 -0
  46. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +77 -0
  47. package/dist/esm/integrations/agent_registry/helpers.js +28 -0
  48. package/dist/esm/integrations/agent_registry/types.js +20 -0
  49. package/dist/esm/memory/vertex_ai_memory_bank_service.js +468 -0
  50. package/dist/esm/runner/in_memory_runner.js +10 -5
  51. package/dist/esm/runner/runner.js +32 -2
  52. package/dist/esm/sessions/database_session_service.js +49 -3
  53. package/dist/esm/sessions/in_memory_session_service.js +70 -14
  54. package/dist/esm/sessions/registry.js +7 -0
  55. package/dist/esm/sessions/vertex_ai_session_service.js +403 -0
  56. package/dist/esm/tools/agent_tool.js +10 -5
  57. package/dist/esm/tools/exit_loop_tool.js +9 -0
  58. package/dist/esm/tools/function_tool.js +7 -2
  59. package/dist/esm/tools/google_maps_grounding_tool.js +54 -0
  60. package/dist/esm/tools/long_running_tool.js +2 -1
  61. package/dist/esm/tools/mcp/mcp_session_manager.js +11 -0
  62. package/dist/esm/tools/mcp/mcp_tool.js +10 -6
  63. package/dist/esm/tools/mcp/mcp_toolset.js +26 -3
  64. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +48 -0
  65. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  66. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  67. package/dist/esm/tools/skill/load_skill_resource_tool.js +1 -24
  68. package/dist/esm/tools/vertex_rag_retrieval_tool.js +36 -0
  69. package/dist/esm/utils/file_utils.js +26 -0
  70. package/dist/esm/utils/gemini_schema_util.js +18 -0
  71. package/dist/esm/utils/partial_copy.js +23 -0
  72. package/dist/esm/utils/streaming_utils.js +165 -120
  73. package/dist/esm/utils/vertex_ai_utils.js +22 -0
  74. package/dist/esm/version.js +1 -1
  75. package/dist/types/a2a/a2a_remote_agent.d.ts +14 -0
  76. package/dist/types/agents/processors/base_llm_processor.d.ts +12 -4
  77. package/dist/types/agents/processors/basic_llm_request_processor.d.ts +5 -0
  78. package/dist/types/agents/processors/identity_llm_request_processor.d.ts +4 -0
  79. package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +5 -0
  80. package/dist/types/agents/run_config.d.ts +15 -0
  81. package/dist/types/code_executors/agent_engine_sandbox_code_executor.d.ts +51 -0
  82. package/dist/types/common.d.ts +4 -0
  83. package/dist/types/events/event_actions.d.ts +24 -6
  84. package/dist/types/events/structured_events.d.ts +13 -0
  85. package/dist/types/examples/example_util.d.ts +25 -0
  86. package/dist/types/index.d.ts +6 -0
  87. package/dist/types/integrations/agent_registry/agent_registry.d.ts +94 -0
  88. package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +43 -0
  89. package/dist/types/integrations/agent_registry/helpers.d.ts +7 -0
  90. package/dist/types/integrations/agent_registry/types.d.ts +101 -0
  91. package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +52 -0
  92. package/dist/types/runner/in_memory_runner.d.ts +28 -1
  93. package/dist/types/runner/runner.d.ts +47 -0
  94. package/dist/types/sessions/base_session_service.d.ts +18 -0
  95. package/dist/types/sessions/database_session_service.d.ts +1 -1
  96. package/dist/types/sessions/in_memory_session_service.d.ts +1 -1
  97. package/dist/types/sessions/vertex_ai_session_service.d.ts +37 -0
  98. package/dist/types/tools/exit_loop_tool.d.ts +9 -0
  99. package/dist/types/tools/function_tool.d.ts +22 -2
  100. package/dist/types/tools/google_maps_grounding_tool.d.ts +22 -0
  101. package/dist/types/tools/long_running_tool.d.ts +11 -1
  102. package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
  103. package/dist/types/tools/mcp/mcp_toolset.d.ts +2 -1
  104. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +25 -0
  105. package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +20 -0
  106. package/dist/types/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.d.ts +20 -0
  107. package/dist/types/tools/vertex_rag_retrieval_tool.d.ts +42 -0
  108. package/dist/types/utils/file_utils.d.ts +2 -0
  109. package/dist/types/utils/partial_copy.d.ts +13 -0
  110. package/dist/types/utils/streaming_utils.d.ts +8 -17
  111. package/dist/types/utils/vertex_ai_utils.d.ts +14 -0
  112. package/dist/types/version.d.ts +1 -1
  113. package/dist/web/agents/functions.js +4 -0
  114. package/dist/web/auth/oauth2/oauth2_discovery.js +26 -2
  115. package/dist/web/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  116. package/dist/web/code_executors/code_execution_utils.js +1 -1
  117. package/dist/web/common.js +10 -0
  118. package/dist/web/events/event.js +3 -1
  119. package/dist/web/index.js +11 -0
  120. package/dist/web/integrations/agent_registry/agent_registry.js +333 -0
  121. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +90 -0
  122. package/dist/web/integrations/agent_registry/helpers.js +28 -0
  123. package/dist/web/integrations/agent_registry/types.js +20 -0
  124. package/dist/web/memory/vertex_ai_memory_bank_service.js +475 -0
  125. package/dist/web/runner/in_memory_runner.js +10 -5
  126. package/dist/web/runner/runner.js +32 -2
  127. package/dist/web/sessions/database_session_service.js +49 -3
  128. package/dist/web/sessions/in_memory_session_service.js +70 -14
  129. package/dist/web/sessions/registry.js +7 -0
  130. package/dist/web/sessions/vertex_ai_session_service.js +414 -0
  131. package/dist/web/tools/agent_tool.js +10 -5
  132. package/dist/web/tools/exit_loop_tool.js +9 -0
  133. package/dist/web/tools/function_tool.js +7 -2
  134. package/dist/web/tools/google_maps_grounding_tool.js +54 -0
  135. package/dist/web/tools/long_running_tool.js +2 -1
  136. package/dist/web/tools/mcp/mcp_session_manager.js +11 -0
  137. package/dist/web/tools/mcp/mcp_tool.js +10 -6
  138. package/dist/web/tools/mcp/mcp_toolset.js +26 -3
  139. package/dist/web/tools/openapi_tool/auth/auth_helpers.js +48 -0
  140. package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  141. package/dist/web/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  142. package/dist/web/tools/skill/load_skill_resource_tool.js +1 -24
  143. package/dist/web/tools/vertex_rag_retrieval_tool.js +36 -0
  144. package/dist/web/utils/file_utils.js +26 -0
  145. package/dist/web/utils/gemini_schema_util.js +18 -0
  146. package/dist/web/utils/partial_copy.js +23 -0
  147. package/dist/web/utils/streaming_utils.js +219 -121
  148. package/dist/web/utils/vertex_ai_utils.js +22 -0
  149. package/dist/web/version.js +1 -1
  150. package/package.json +2 -1
@@ -0,0 +1,333 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ /**
4
+ * @license
5
+ * Copyright 2026 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ import { GoogleAuth } from "google-auth-library";
9
+ import { RemoteA2AAgent } from "../../a2a/a2a_remote_agent.js";
10
+ import { logger } from "../../utils/logger.js";
11
+ import { AgentRegistrySingleMCPToolset } from "./agent_registry_mcp_toolset.js";
12
+ import { cleanName, isGoogleApi } from "./helpers.js";
13
+ import {
14
+ AGENT_REGISTRY_BASE_URL,
15
+ ProtocolType
16
+ } from "./types.js";
17
+ export * from "./agent_registry_mcp_toolset.js";
18
+ export * from "./helpers.js";
19
+ export * from "./types.js";
20
+ const TRANSPORT_MAPPING = {
21
+ "HTTP_JSON": "HTTP+JSON",
22
+ "JSONRPC": "JSONRPC",
23
+ "GRPC": "GRPC"
24
+ };
25
+ class AgentRegistry {
26
+ constructor(options) {
27
+ if (!options.projectId || !options.location) {
28
+ throw new Error("project_id and location must be provided");
29
+ }
30
+ this.projectId = options.projectId;
31
+ this.location = options.location;
32
+ this.basePath = `projects/${this.projectId}/locations/${this.location}`;
33
+ this.headerProvider = options.headerProvider;
34
+ this.auth = new GoogleAuth({
35
+ scopes: ["https://www.googleapis.com/auth/cloud-platform"]
36
+ });
37
+ }
38
+ /**
39
+ * Resolves default Google Cloud credentials and returns standard headers.
40
+ * Automatically caches, fetches, and handles refreshing expired OAuth tokens.
41
+ * Injects the billing/quota project identifier `x-goog-user-project` if present.
42
+ */
43
+ async getAuthHeaders() {
44
+ try {
45
+ const client = await this.auth.getClient();
46
+ const headers = await client.getRequestHeaders(
47
+ "https://agentregistry.googleapis.com"
48
+ );
49
+ const authHeaders = {};
50
+ const rawHeaders = headers;
51
+ const authKey = Object.keys(rawHeaders).find(
52
+ (k) => k.toLowerCase() === "authorization"
53
+ );
54
+ let token = authKey ? rawHeaders[authKey] : void 0;
55
+ if (!token && client.credentials && client.credentials.access_token) {
56
+ token = `Bearer ${client.credentials.access_token}`;
57
+ }
58
+ if (token) {
59
+ authHeaders["Authorization"] = token;
60
+ }
61
+ authHeaders["Content-Type"] = "application/json";
62
+ const quotaProjectId = client.quotaProjectId || this.auth.quotaProjectId;
63
+ if (quotaProjectId) {
64
+ authHeaders["x-goog-user-project"] = quotaProjectId;
65
+ }
66
+ return authHeaders;
67
+ } catch (err) {
68
+ const msg = err instanceof Error ? err.message : String(err);
69
+ throw new Error(`Failed to refresh Google Cloud credentials: ${msg}`);
70
+ }
71
+ }
72
+ /**
73
+ * Helper function to execute HTTP GET requests against the Agent Registry API.
74
+ * Handles path resolution, search query params compilation, and auth headers fetching.
75
+ */
76
+ async makeRequest(path, params) {
77
+ let url;
78
+ if (path.startsWith("projects/")) {
79
+ url = `${AGENT_REGISTRY_BASE_URL}/${path}`;
80
+ } else {
81
+ url = `${AGENT_REGISTRY_BASE_URL}/${this.basePath}/${path}`;
82
+ }
83
+ if (params && Object.keys(params).length > 0) {
84
+ const searchParams = new URLSearchParams(params);
85
+ url += `?${searchParams.toString()}`;
86
+ }
87
+ try {
88
+ const headers = await this.getAuthHeaders();
89
+ const res = await fetch(url, {
90
+ method: "GET",
91
+ headers
92
+ });
93
+ if (!res.ok) {
94
+ const text = await res.text();
95
+ throw new Error(
96
+ `API request failed with status ${res.status}: ${text}`
97
+ );
98
+ }
99
+ return await res.json();
100
+ } catch (err) {
101
+ const msg = err instanceof Error ? err.message : String(err);
102
+ if (msg.includes("API request failed")) {
103
+ throw err;
104
+ }
105
+ throw new Error(`API request failed: ${msg}`);
106
+ }
107
+ }
108
+ /**
109
+ * Parses connection interfaces list from registry metadata and returns the first match
110
+ * corresponding to requested protocol types and binding options.
111
+ */
112
+ getConnectionUri(resourceDetails, filters) {
113
+ const protocols = [];
114
+ if (resourceDetails.protocols) {
115
+ protocols.push(...resourceDetails.protocols);
116
+ }
117
+ if (resourceDetails.interfaces) {
118
+ protocols.push({ interfaces: resourceDetails.interfaces });
119
+ }
120
+ for (const p of protocols) {
121
+ if ((filters == null ? void 0 : filters.protocolType) && p.type !== filters.protocolType) {
122
+ continue;
123
+ }
124
+ const protocolVersion = p.protocolVersion;
125
+ const interfaces = p.interfaces || [];
126
+ for (const i of interfaces) {
127
+ const mappedBinding = i.protocolBinding ? TRANSPORT_MAPPING[i.protocolBinding] : void 0;
128
+ if ((filters == null ? void 0 : filters.protocolBinding) && mappedBinding !== filters.protocolBinding) {
129
+ continue;
130
+ }
131
+ if (i.url) {
132
+ return { url: i.url, protocolVersion, protocolBinding: mappedBinding };
133
+ }
134
+ }
135
+ }
136
+ return {};
137
+ }
138
+ // --- MCP Server Methods ---
139
+ async listMcpServers(options) {
140
+ const params = {};
141
+ if (options == null ? void 0 : options.filterStr) {
142
+ params["filter"] = options.filterStr;
143
+ }
144
+ if (options == null ? void 0 : options.pageSize) {
145
+ params["pageSize"] = String(options.pageSize);
146
+ }
147
+ if (options == null ? void 0 : options.pageToken) {
148
+ params["pageToken"] = options.pageToken;
149
+ }
150
+ return this.makeRequest("mcpServers", params);
151
+ }
152
+ async getMcpServer(name) {
153
+ return this.makeRequest(name);
154
+ }
155
+ async getMcpToolset(mcpServerName, options) {
156
+ var _a, _b;
157
+ const serverDetails = await this.getMcpServer(mcpServerName);
158
+ const name = cleanName(serverDetails.displayName || mcpServerName);
159
+ const mcpServerId = serverDetails.mcpServerId;
160
+ let endpointUri = this.getConnectionUri(serverDetails, {
161
+ protocolBinding: "JSONRPC"
162
+ }).url;
163
+ if (!endpointUri) {
164
+ endpointUri = this.getConnectionUri(serverDetails, {
165
+ protocolBinding: "HTTP+JSON"
166
+ }).url;
167
+ }
168
+ if (!endpointUri) {
169
+ throw new Error(
170
+ `MCP Server endpoint URI not found for: ${mcpServerName}`
171
+ );
172
+ }
173
+ let authScheme = options == null ? void 0 : options.authScheme;
174
+ if (mcpServerId && !authScheme) {
175
+ try {
176
+ const bindingsData = await this.makeRequest("bindings");
177
+ const bindings = bindingsData.bindings || [];
178
+ for (const b of bindings) {
179
+ const targetId = ((_a = b.target) == null ? void 0 : _a.identifier) || "";
180
+ if (targetId.endsWith(mcpServerId)) {
181
+ const authProvider = (_b = b.authProviderBinding) == null ? void 0 : _b.authProvider;
182
+ if (authProvider) {
183
+ authScheme = {
184
+ type: "gcpAuthProviderScheme",
185
+ name: authProvider,
186
+ continueUri: options == null ? void 0 : options.continueUri
187
+ };
188
+ break;
189
+ }
190
+ }
191
+ }
192
+ } catch (err) {
193
+ const msg = err instanceof Error ? err.message : String(err);
194
+ logger.warn(
195
+ `Failed to fetch bindings for MCP Server ${mcpServerName}: ${msg}`
196
+ );
197
+ }
198
+ }
199
+ const connectionParams = {
200
+ type: "StreamableHTTPConnectionParams",
201
+ url: endpointUri
202
+ };
203
+ const combinedHeaderProvider = async (context) => {
204
+ const headers = {};
205
+ if (!authScheme && !(options == null ? void 0 : options.authCredential) && isGoogleApi(endpointUri)) {
206
+ Object.assign(headers, await this.getAuthHeaders());
207
+ }
208
+ if (this.headerProvider && context) {
209
+ Object.assign(headers, this.headerProvider(context));
210
+ }
211
+ return headers;
212
+ };
213
+ return new AgentRegistrySingleMCPToolset({
214
+ destinationResourceId: mcpServerId,
215
+ connectionParams,
216
+ prefix: name,
217
+ headerProvider: combinedHeaderProvider,
218
+ authScheme,
219
+ authCredential: options == null ? void 0 : options.authCredential
220
+ });
221
+ }
222
+ // --- Endpoint Methods ---
223
+ async listEndpoints(options) {
224
+ const params = {};
225
+ if (options == null ? void 0 : options.filterStr) {
226
+ params["filter"] = options.filterStr;
227
+ }
228
+ if (options == null ? void 0 : options.pageSize) {
229
+ params["pageSize"] = String(options.pageSize);
230
+ }
231
+ if (options == null ? void 0 : options.pageToken) {
232
+ params["pageToken"] = options.pageToken;
233
+ }
234
+ return this.makeRequest("endpoints", params);
235
+ }
236
+ async getEndpoint(name) {
237
+ return this.makeRequest(name);
238
+ }
239
+ async getModelName(endpointName) {
240
+ const endpointDetails = await this.getEndpoint(endpointName);
241
+ const { url } = this.getConnectionUri(endpointDetails);
242
+ if (!url) {
243
+ throw new Error(`Connection URI not found for endpoint: ${endpointName}`);
244
+ }
245
+ const uri = url.replace(/:\w+$/, "");
246
+ if (uri.startsWith("projects/")) {
247
+ return uri;
248
+ }
249
+ const match = uri.match(/(projects\/.+)/);
250
+ if (match) {
251
+ return match[1];
252
+ }
253
+ return uri;
254
+ }
255
+ // --- Agent Methods ---
256
+ async listAgents(options) {
257
+ const params = {};
258
+ if (options == null ? void 0 : options.filterStr) {
259
+ params["filter"] = options.filterStr;
260
+ }
261
+ if (options == null ? void 0 : options.pageSize) {
262
+ params["pageSize"] = String(options.pageSize);
263
+ }
264
+ if (options == null ? void 0 : options.pageToken) {
265
+ params["pageToken"] = options.pageToken;
266
+ }
267
+ return this.makeRequest("agents", params);
268
+ }
269
+ async getAgentInfo(name) {
270
+ return this.makeRequest(name);
271
+ }
272
+ async getRemoteA2AAgent(agentName, options) {
273
+ const agentInfo = await this.getAgentInfo(agentName);
274
+ const card = agentInfo.card || {};
275
+ const cardContent = card.content;
276
+ if (card.type === "A2A_AGENT_CARD" && cardContent) {
277
+ const agentCard2 = cardContent;
278
+ const name2 = cleanName(agentCard2.name);
279
+ return new RemoteA2AAgent({
280
+ name: name2,
281
+ agentCard: agentCard2,
282
+ description: agentCard2.description,
283
+ client: options == null ? void 0 : options.client,
284
+ clientFactory: options == null ? void 0 : options.clientFactory
285
+ });
286
+ }
287
+ const name = cleanName(agentInfo.displayName || agentName);
288
+ const description = agentInfo.description || "";
289
+ const version = agentInfo.version || "";
290
+ const { url, protocolVersion, protocolBinding } = this.getConnectionUri(
291
+ agentInfo,
292
+ {
293
+ protocolType: ProtocolType.A2A_AGENT
294
+ }
295
+ );
296
+ if (!url) {
297
+ throw new Error(`A2A connection URI not found for Agent: ${agentName}`);
298
+ }
299
+ const skills = (agentInfo.skills || []).map(
300
+ (s) => ({
301
+ id: s.id,
302
+ name: s.name,
303
+ description: s.description || "",
304
+ tags: s.tags || [],
305
+ examples: s.examples || []
306
+ })
307
+ );
308
+ const agentCard = {
309
+ name,
310
+ description,
311
+ version,
312
+ preferredTransport: protocolBinding || "HTTP+JSON",
313
+ protocolVersion: protocolVersion || "0.3.0",
314
+ url,
315
+ skills,
316
+ capabilities: {
317
+ streaming: false
318
+ },
319
+ defaultInputModes: ["text"],
320
+ defaultOutputModes: ["text"]
321
+ };
322
+ return new RemoteA2AAgent({
323
+ name,
324
+ agentCard,
325
+ description,
326
+ client: options == null ? void 0 : options.client,
327
+ clientFactory: options == null ? void 0 : options.clientFactory
328
+ });
329
+ }
330
+ }
331
+ export {
332
+ AgentRegistry
333
+ };
@@ -0,0 +1,77 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ /**
4
+ * @license
5
+ * Copyright 2026 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ import { BaseToolset } from "../../tools/base_toolset.js";
9
+ import {
10
+ MCPSessionManager
11
+ } from "../../tools/mcp/mcp_session_manager.js";
12
+ import { MCPTool } from "../../tools/mcp/mcp_tool.js";
13
+ import { GCP_MCP_SERVER_DESTINATION_ID } from "./types.js";
14
+ class AgentRegistrySingleMCPToolset extends BaseToolset {
15
+ constructor(options) {
16
+ super(options.toolFilter || [], options.prefix);
17
+ this.destinationResourceId = options.destinationResourceId;
18
+ this.connectionParams = options.connectionParams;
19
+ this.headerProvider = options.headerProvider;
20
+ this.authScheme = options.authScheme;
21
+ this.authCredential = options.authCredential;
22
+ }
23
+ /**
24
+ * Connects to the underlying MCP server, retrieves tool definitions, prefixes tool names,
25
+ * and injects destination telemetry metadata.
26
+ */
27
+ async getTools(context) {
28
+ var _a, _b, _c;
29
+ const headers = {};
30
+ if (this.headerProvider) {
31
+ const providerHeaders = await this.headerProvider(context);
32
+ Object.assign(headers, providerHeaders);
33
+ }
34
+ const connectionParamsCopy = {
35
+ ...this.connectionParams,
36
+ transportOptions: {
37
+ ...this.connectionParams.transportOptions,
38
+ requestInit: {
39
+ ...(_a = this.connectionParams.transportOptions) == null ? void 0 : _a.requestInit,
40
+ headers: {
41
+ ...(_c = (_b = this.connectionParams.transportOptions) == null ? void 0 : _b.requestInit) == null ? void 0 : _c.headers,
42
+ ...headers
43
+ }
44
+ }
45
+ }
46
+ };
47
+ const sessionManager = new MCPSessionManager(connectionParamsCopy);
48
+ const session = await sessionManager.createSession();
49
+ const listResult = await session.listTools();
50
+ const tools = listResult.tools.map((tool) => {
51
+ const prefixedName = this.prefix ? `${this.prefix}_${tool.name}` : tool.name;
52
+ const mcpTool = new MCPTool(
53
+ { ...tool, name: prefixedName },
54
+ sessionManager,
55
+ tool.name
56
+ );
57
+ const toolWithMetadata = mcpTool;
58
+ if (this.destinationResourceId) {
59
+ if (!toolWithMetadata.customMetadata) {
60
+ toolWithMetadata.customMetadata = {};
61
+ }
62
+ toolWithMetadata.customMetadata[GCP_MCP_SERVER_DESTINATION_ID] = this.destinationResourceId;
63
+ }
64
+ return mcpTool;
65
+ });
66
+ const filter = this.toolFilter;
67
+ if (!filter || Array.isArray(filter) && filter.length === 0) {
68
+ return tools;
69
+ }
70
+ return tools.filter((t) => this.isToolSelected(t, context));
71
+ }
72
+ async close() {
73
+ }
74
+ }
75
+ export {
76
+ AgentRegistrySingleMCPToolset
77
+ };
@@ -0,0 +1,28 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ /**
4
+ * @license
5
+ * Copyright 2026 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ function isGoogleApi(url) {
9
+ try {
10
+ const parsed = new URL(url);
11
+ return parsed.hostname === "googleapis.com" || parsed.hostname.endsWith(".googleapis.com");
12
+ } catch {
13
+ return false;
14
+ }
15
+ }
16
+ function cleanName(name) {
17
+ let clean = name.replace(/[^a-zA-Z0-9_]/g, "_");
18
+ clean = clean.replace(/_+/g, "_");
19
+ clean = clean.replace(/^_+|_+$/g, "");
20
+ if (clean && !/^[a-zA-Z_]/.test(clean)) {
21
+ clean = "_" + clean;
22
+ }
23
+ return clean;
24
+ }
25
+ export {
26
+ cleanName,
27
+ isGoogleApi
28
+ };
@@ -0,0 +1,20 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ /**
4
+ * @license
5
+ * Copyright 2026 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ const AGENT_REGISTRY_BASE_URL = "https://agentregistry.googleapis.com/v1alpha";
9
+ const GCP_MCP_SERVER_DESTINATION_ID = "gcp.mcp.server.destination.id";
10
+ var ProtocolType = /* @__PURE__ */ ((ProtocolType2) => {
11
+ ProtocolType2["TYPE_UNSPECIFIED"] = "TYPE_UNSPECIFIED";
12
+ ProtocolType2["A2A_AGENT"] = "A2A_AGENT";
13
+ ProtocolType2["CUSTOM"] = "CUSTOM";
14
+ return ProtocolType2;
15
+ })(ProtocolType || {});
16
+ export {
17
+ AGENT_REGISTRY_BASE_URL,
18
+ GCP_MCP_SERVER_DESTINATION_ID,
19
+ ProtocolType
20
+ };