@mastra/connect 0.7.0-alpha.0 → 1.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +2 -2
  2. package/dist/channels.d.ts +4 -2
  3. package/dist/channels.d.ts.map +1 -1
  4. package/dist/client.d.ts +21 -0
  5. package/dist/client.d.ts.map +1 -1
  6. package/dist/environment.d.ts.map +1 -1
  7. package/dist/errors.d.ts +23 -0
  8. package/dist/errors.d.ts.map +1 -1
  9. package/dist/index.cjs +458 -386
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.js +458 -386
  12. package/dist/index.js.map +1 -1
  13. package/dist/multi-connection.d.ts +1 -1
  14. package/dist/multi-connection.d.ts.map +1 -1
  15. package/dist/providers/channels.d.ts +5 -1
  16. package/dist/providers/channels.d.ts.map +1 -1
  17. package/dist/providers/clerk/tools/create-organization-domain.d.ts +9 -9
  18. package/dist/providers/clerk/tools/create-organization-domain.d.ts.map +1 -1
  19. package/dist/providers/clerk/tools/create-organization-invitation.d.ts +3 -3
  20. package/dist/providers/clerk/tools/create-user.d.ts.map +1 -1
  21. package/dist/providers/clerk/tools/delete-email-address.d.ts.map +1 -1
  22. package/dist/providers/clerk/tools/delete-organization-domain.d.ts.map +1 -1
  23. package/dist/providers/clerk/tools/delete-organization-membership.d.ts.map +1 -1
  24. package/dist/providers/clerk/tools/delete-organization-role.d.ts.map +1 -1
  25. package/dist/providers/clerk/tools/delete-phone-number.d.ts.map +1 -1
  26. package/dist/providers/clerk/tools/get-email-address.d.ts.map +1 -1
  27. package/dist/providers/clerk/tools/get-organization-invitation.d.ts +3 -3
  28. package/dist/providers/clerk/tools/get-organization-role.d.ts.map +1 -1
  29. package/dist/providers/clerk/tools/get-phone-number.d.ts.map +1 -1
  30. package/dist/providers/clerk/tools/get-session.d.ts +3 -3
  31. package/dist/providers/clerk/tools/get-session.d.ts.map +1 -1
  32. package/dist/providers/clerk/tools/list-organization-domains.d.ts +9 -9
  33. package/dist/providers/clerk/tools/list-organization-domains.d.ts.map +1 -1
  34. package/dist/providers/clerk/tools/list-organization-invitations.d.ts +3 -3
  35. package/dist/providers/clerk/tools/list-organization-invitations.d.ts.map +1 -1
  36. package/dist/providers/clerk/tools/list-organization-memberships.d.ts.map +1 -1
  37. package/dist/providers/clerk/tools/list-organization-roles.d.ts.map +1 -1
  38. package/dist/providers/clerk/tools/list-organizations.d.ts.map +1 -1
  39. package/dist/providers/clerk/tools/list-sessions.d.ts +3 -5
  40. package/dist/providers/clerk/tools/list-sessions.d.ts.map +1 -1
  41. package/dist/providers/clerk/tools/list-users.d.ts +12 -0
  42. package/dist/providers/clerk/tools/list-users.d.ts.map +1 -1
  43. package/dist/providers/clerk/tools/revoke-organization-invitation.d.ts +3 -3
  44. package/dist/providers/clerk/tools/revoke-session.d.ts +3 -3
  45. package/dist/providers/clerk/tools/revoke-session.d.ts.map +1 -1
  46. package/dist/providers/clerk/tools/update-organization-domain.d.ts +9 -9
  47. package/dist/providers/clerk/tools/update-organization-domain.d.ts.map +1 -1
  48. package/dist/providers/clerk/tools/update-organization-role.d.ts.map +1 -1
  49. package/dist/providers/clerk/tools/update-organization.d.ts +2 -0
  50. package/dist/providers/clerk/tools/update-organization.d.ts.map +1 -1
  51. package/dist/providers/clerk/tools/update-user.d.ts +10 -10
  52. package/dist/providers/clerk/tools/verify-organization-domain.d.ts +12 -7
  53. package/dist/providers/clerk/tools/verify-organization-domain.d.ts.map +1 -1
  54. package/dist/providers/discord/index.d.ts.map +1 -1
  55. package/dist/providers/discord/tools/_bot-token.d.ts +11 -0
  56. package/dist/providers/discord/tools/_bot-token.d.ts.map +1 -0
  57. package/dist/providers/discord/tools/add-guild-member-role.d.ts.map +1 -1
  58. package/dist/providers/discord/tools/create-channel.d.ts.map +1 -1
  59. package/dist/providers/discord/tools/create-message.d.ts.map +1 -1
  60. package/dist/providers/discord/tools/create-reaction.d.ts.map +1 -1
  61. package/dist/providers/discord/tools/create-role.d.ts.map +1 -1
  62. package/dist/providers/discord/tools/create-thread-from-message.d.ts.map +1 -1
  63. package/dist/providers/discord/tools/create-webhook.d.ts.map +1 -1
  64. package/dist/providers/discord/tools/delete-channel.d.ts.map +1 -1
  65. package/dist/providers/discord/tools/delete-guild-member.d.ts.map +1 -1
  66. package/dist/providers/discord/tools/delete-guild.d.ts.map +1 -1
  67. package/dist/providers/discord/tools/delete-message.d.ts.map +1 -1
  68. package/dist/providers/discord/tools/delete-reaction.d.ts.map +1 -1
  69. package/dist/providers/discord/tools/delete-role.d.ts.map +1 -1
  70. package/dist/providers/discord/tools/delete-webhook.d.ts.map +1 -1
  71. package/dist/providers/discord/tools/get-channel.d.ts.map +1 -1
  72. package/dist/providers/discord/tools/get-guild-member.d.ts.map +1 -1
  73. package/dist/providers/discord/tools/get-guild.d.ts.map +1 -1
  74. package/dist/providers/discord/tools/get-message.d.ts.map +1 -1
  75. package/dist/providers/discord/tools/get-role.d.ts.map +1 -1
  76. package/dist/providers/discord/tools/get-webhook.d.ts.map +1 -1
  77. package/dist/providers/discord/tools/list-channels.d.ts +2 -2
  78. package/dist/providers/discord/tools/list-channels.d.ts.map +1 -1
  79. package/dist/providers/discord/tools/list-guild-members.d.ts.map +1 -1
  80. package/dist/providers/discord/tools/list-guilds.d.ts.map +1 -1
  81. package/dist/providers/discord/tools/list-messages.d.ts.map +1 -1
  82. package/dist/providers/discord/tools/list-roles.d.ts.map +1 -1
  83. package/dist/providers/discord/tools/list-webhooks.d.ts.map +1 -1
  84. package/dist/providers/discord/tools/remove-guild-member-role.d.ts.map +1 -1
  85. package/dist/providers/discord/tools/update-channel.d.ts.map +1 -1
  86. package/dist/providers/discord/tools/update-guild-member.d.ts.map +1 -1
  87. package/dist/providers/discord/tools/update-guild.d.ts.map +1 -1
  88. package/dist/providers/discord/tools/update-message.d.ts.map +1 -1
  89. package/dist/providers/discord/tools/update-role.d.ts.map +1 -1
  90. package/dist/providers/discord/tools/update-webhook.d.ts.map +1 -1
  91. package/dist/providers/resend/tools/cancel-email.d.ts +2 -2
  92. package/dist/providers/resend/tools/get-email.d.ts +2 -2
  93. package/dist/providers/resend/tools/get-received-email.d.ts +2 -2
  94. package/dist/providers/resend/tools/get-template.d.ts +2 -2
  95. package/dist/providers/resend/tools/list-emails.d.ts +2 -2
  96. package/dist/providers/resend/tools/list-received-emails.d.ts +2 -2
  97. package/dist/providers/resend/tools/update-contact-topics.d.ts.map +1 -1
  98. package/dist/runtime/platform-proxy.d.ts.map +1 -1
  99. package/dist/tools.d.ts +12 -7
  100. package/dist/tools.d.ts.map +1 -1
  101. package/package.json +11 -7
package/dist/index.js CHANGED
@@ -7,18 +7,56 @@ var MastraConnectError = class extends Error {
7
7
  code;
8
8
  status;
9
9
  detail;
10
+ /**
11
+ * Axios-compatible alias for {@link status}. Generated provider tools come
12
+ * from upstream Nango templates whose error handlers check
13
+ * `error.response.status` (the axios/Nango SDK shape). Exposing the HTTP
14
+ * status under `response.status` as well lets that generated code work
15
+ * unchanged against the errors this package throws. Only set when the error
16
+ * carries an HTTP status.
17
+ */
18
+ response;
10
19
  constructor(code, message, options) {
11
20
  super(message);
12
21
  this.name = "MastraConnectError";
13
22
  this.code = code;
14
23
  this.status = options?.status;
15
24
  this.detail = options?.detail ? truncate(options.detail) : void 0;
25
+ if (typeof options?.status === "number") this.response = { status: options.status };
26
+ }
27
+ };
28
+ /**
29
+ * A caller configuration mistake (for example an unknown tool name in
30
+ * `requireApproval`) that must fail resolution instead of being downgraded
31
+ * to the resolver's warn-and-skip path, which exists for provider-side
32
+ * failures. Internal to the package: callers observe it as a regular
33
+ * `MastraConnectError` with code `invalid_options`.
34
+ *
35
+ * @internal
36
+ */
37
+ var MastraConnectConfigError = class extends MastraConnectError {
38
+ constructor(message) {
39
+ super("invalid_options", message);
16
40
  }
17
41
  };
18
42
  function truncate(text) {
19
43
  return text.length > MAX_DETAIL_LENGTH ? `${text.slice(0, MAX_DETAIL_LENGTH)}…` : text;
20
44
  }
21
45
  /**
46
+ * Pulls the first human-readable message from an array of error entries. Many
47
+ * providers (Clerk, Linear's GraphQL envelope, Nango v2) return
48
+ * `{ errors: [{ message, long_message, code }] }`; surfacing the first message
49
+ * is the most useful detail without echoing the whole payload.
50
+ */
51
+ function extractFirstArrayMessage(errors) {
52
+ for (const entry of errors) {
53
+ if (!entry || typeof entry !== "object") continue;
54
+ const record = entry;
55
+ const message = typeof record.long_message === "string" ? record.long_message : record.message;
56
+ if (typeof message === "string" && message) return message;
57
+ }
58
+ }
59
+ /**
22
60
  * Extracts a human-readable detail string from an RFC-7807 problem JSON body
23
61
  * (or a plain `{ error }` body) without echoing anything else from the response.
24
62
  * Returns undefined when the body is not parseable JSON.
@@ -49,6 +87,14 @@ async function extractProblemDetail(response) {
49
87
  };
50
88
  }
51
89
  }
90
+ if (Array.isArray(data.errors)) {
91
+ const message = extractFirstArrayMessage(data.errors);
92
+ if (message) return {
93
+ detail: truncate(message),
94
+ code,
95
+ isProblemJson
96
+ };
97
+ }
52
98
  return {
53
99
  code,
54
100
  isProblemJson
@@ -188,14 +234,35 @@ const integrationCatalogEntrySchema = z.object({
188
234
  capabilities: z.object({ mcp: z.boolean().optional() })
189
235
  });
190
236
  const integrationCatalogResponseSchema = z.object({ integrations: z.array(integrationCatalogEntrySchema) });
191
- const credentialSchema = z.discriminatedUnion("type", [z.object({
192
- type: z.literal("oauth2"),
237
+ /**
238
+ * Secondary access token minted by the vendor alongside the primary oauth2
239
+ * credential (e.g. `devPortalAccessToken` on Microsoft Teams connections).
240
+ * Keyed by the vendor's connection-config field name. Treat this like any
241
+ * other bearer credential — it authenticates second-audience API calls
242
+ * (Teams Dev Portal, etc.) and must not be logged or forwarded to code that
243
+ * shouldn't hold connection secrets.
244
+ */
245
+ const secondaryAccessTokenSchema = z.object({
193
246
  accessToken: z.string(),
194
247
  expiresAt: z.string().nullable()
195
- }), z.object({
196
- type: z.literal("api_key"),
197
- apiKey: z.string()
198
- })]);
248
+ });
249
+ const credentialSchema = z.discriminatedUnion("type", [
250
+ z.object({
251
+ type: z.literal("oauth2"),
252
+ accessToken: z.string(),
253
+ expiresAt: z.string().nullable(),
254
+ secondaryAccessTokens: z.record(z.string(), secondaryAccessTokenSchema).optional()
255
+ }),
256
+ z.object({
257
+ type: z.literal("api_key"),
258
+ apiKey: z.string()
259
+ }),
260
+ z.object({
261
+ type: z.literal("two_step"),
262
+ token: z.string(),
263
+ expiresAt: z.string().nullable()
264
+ })
265
+ ]);
199
266
  const connectionContextSchema = z.object({
200
267
  connection_config: z.record(z.string(), z.unknown()).nullable(),
201
268
  metadata: z.record(z.string(), z.unknown()).nullable()
@@ -286,7 +353,12 @@ async function proxyRequestWithResponse(client, connectionId, options) {
286
353
  }
287
354
  const queryString = search.size > 0 ? `?${search.toString()}` : "";
288
355
  const url = `/v2/connections/${encodeURIComponent(connectionId)}/proxy/${cleanPath}${queryString}`;
289
- const headers = { ...options.headers };
356
+ const headers = {};
357
+ for (const [name, value] of Object.entries(options.headers ?? {})) {
358
+ const lower = name.toLowerCase();
359
+ if (lower === "authorization" || lower === "proxy-authorization") continue;
360
+ headers[name] = value;
361
+ }
290
362
  if (options.baseUrlOverride !== void 0) {
291
363
  assertValidBaseUrlOverride(options.baseUrlOverride);
292
364
  headers["base-url-override"] = options.baseUrlOverride;
@@ -636,8 +708,8 @@ function buildProxyMultiConnectionTools(input) {
636
708
  * client cache so stale clients can be reaped elsewhere.
637
709
  */
638
710
  async function buildMcpMultiConnectionTools(input) {
639
- const { registration, connections, allowTools, disallowTools, autoApproveTools, client, mcpClients, resolverId } = input;
640
- const autoApproved = new Set(autoApproveTools ?? []);
711
+ const { registration, connections, allowTools, disallowTools, requireApproval, client, mcpClients, resolverId } = input;
712
+ const requireApprovalFor = Array.isArray(requireApproval) ? new Set(requireApproval) : void 0;
641
713
  const listToolKey = listConnectionsToolKey(registration.integrationId);
642
714
  const innerAllowTools = allowTools?.filter((name) => name !== listToolKey);
643
715
  const innerDisallowTools = disallowTools?.filter((name) => name !== listToolKey);
@@ -661,7 +733,7 @@ async function buildMcpMultiConnectionTools(input) {
661
733
  id: `mastra-connect-${resolverId}-${registration.integrationId}-${connection.id}`,
662
734
  servers: { [registration.integrationId]: {
663
735
  ...transport,
664
- requireToolApproval: ({ toolName }) => !autoApproved.has(`${registration.integrationId}_${String(toolName)}`)
736
+ ...requireApproval === true ? { requireToolApproval: true } : requireApprovalFor ? { requireToolApproval: ({ toolName }) => requireApprovalFor.has(`${registration.integrationId}_${String(toolName)}`) } : {}
665
737
  } }
666
738
  })
667
739
  };
@@ -678,8 +750,10 @@ async function buildMcpMultiConnectionTools(input) {
678
750
  }
679
751
  const catalogUnion = /* @__PURE__ */ new Set();
680
752
  for (const catalog of rawInnerCatalogs.values()) for (const key of Object.keys(catalog)) catalogUnion.add(key);
681
- const unknownAutoApprove = [...autoApproved].filter((name) => !catalogUnion.has(name));
682
- if (unknownAutoApprove.length > 0) throw new MastraConnectError("invalid_options", `Unknown tool name(s) in autoApproveTools for '${registration.integrationId}': ${unknownAutoApprove.join(", ")}. Known tools: ${[...catalogUnion].join(", ")}.`);
753
+ if (requireApprovalFor) {
754
+ const unknown = [...requireApprovalFor].filter((name) => !catalogUnion.has(name));
755
+ if (unknown.length > 0) throw new MastraConnectConfigError(`Unknown tool name(s) in requireApproval for '${registration.integrationId}': ${unknown.join(", ")}. Known tools: ${[...catalogUnion].join(", ")}.`);
756
+ }
683
757
  innerToolsByConnectionId = /* @__PURE__ */ new Map();
684
758
  for (const [connectionId, catalog] of rawInnerCatalogs) {
685
759
  const filtered = applyToolFilter(catalog, {
@@ -708,10 +782,14 @@ async function buildMcpMultiConnectionTools(input) {
708
782
  //#endregion
709
783
  //#region src/providers/channels.ts
710
784
  function credentialToken$1(credential) {
711
- return credential.type === "oauth2" ? credential.accessToken : credential.apiKey;
785
+ switch (credential.type) {
786
+ case "oauth2": return credential.accessToken;
787
+ case "two_step": return credential.token;
788
+ default: return credential.apiKey;
789
+ }
712
790
  }
713
791
  const RESERVED_OPTION_KEYS = {
714
- slack: [
792
+ "slack-channels": [
715
793
  "baseUrl",
716
794
  "refreshToken",
717
795
  "token",
@@ -725,7 +803,14 @@ const RESERVED_OPTION_KEYS = {
725
803
  "tokenResolver",
726
804
  "encryptionKey"
727
805
  ],
728
- discord: ["baseUrl", "encryptionKey"]
806
+ discord: ["baseUrl", "encryptionKey"],
807
+ "microsoft-teams": [
808
+ "baseUrl",
809
+ "appId",
810
+ "appPassword",
811
+ "tokenResolver",
812
+ "encryptionKey"
813
+ ]
729
814
  };
730
815
  function stripReservedOptions(integrationId, options) {
731
816
  if (!options) return options;
@@ -745,10 +830,10 @@ function stripReservedOptions(integrationId, options) {
745
830
  }
746
831
  const CHANNELS$1 = [
747
832
  {
748
- integrationId: "slack",
833
+ integrationId: "slack-channels",
749
834
  async create(options, runtime) {
750
835
  const mod = await import("@mastra/slack");
751
- const safeOptions = stripReservedOptions("slack", options);
836
+ const safeOptions = stripReservedOptions("slack-channels", options);
752
837
  const tokenResolver = async () => {
753
838
  return credentialToken$1(await runtime.getCredential());
754
839
  };
@@ -782,9 +867,11 @@ const CHANNELS$1 = [
782
867
  return {
783
868
  provider,
784
869
  async sync() {
870
+ const credential = await runtime.getCredential();
871
+ if (credential.type !== "api_key") throw new MastraConnectError("unsupported_credential_type", `Discord connection ${runtime.getConnectionId()} returned a '${credential.type}' credential, but the Discord channel requires the bot token as an API-key credential (the 'discord' integration). OAuth Discord connections yield user Bearer tokens, which Discord rejects for bot auth.`);
872
+ const botToken = credential.apiKey;
873
+ if (typeof botToken !== "string" || botToken.length === 0) throw new MastraConnectError("no_active_connection", `Discord connection ${runtime.getConnectionId()} has no bot token on its credential.`);
785
874
  const metadata = (await runtime.getConnectionContext())?.metadata ?? {};
786
- const botToken = typeof metadata.botToken === "string" && metadata.botToken || typeof metadata.bot_token === "string" && metadata.bot_token || void 0;
787
- if (!botToken) throw new MastraConnectError("no_active_connection", `Discord connection ${runtime.getConnectionId()} has no botToken in its metadata. Store the bot token on the connection (Nango setMetadata) to activate the Discord channel.`);
788
875
  const applicationId = optionsAppId ?? (typeof metadata.applicationId === "string" ? metadata.applicationId : void 0) ?? (typeof metadata.application_id === "string" ? metadata.application_id : void 0);
789
876
  const publicKey = optionsPublicKey ?? (typeof metadata.publicKey === "string" ? metadata.publicKey : void 0) ?? (typeof metadata.public_key === "string" ? metadata.public_key : void 0);
790
877
  const credentials = { botToken };
@@ -794,17 +881,42 @@ const CHANNELS$1 = [
794
881
  }
795
882
  };
796
883
  }
884
+ },
885
+ {
886
+ integrationId: "microsoft-teams",
887
+ async create(options, runtime) {
888
+ const mod = await import("@mastra/teams");
889
+ if (!process.env.MASTRA_ENCRYPTION_KEY) throw new MastraConnectError("invalid_options", "Microsoft Teams channel: MASTRA_ENCRYPTION_KEY is not set. The Teams install store persists per-agent bot secrets and requires an at-rest encryption key (a 32-byte value, base64-encoded).");
890
+ const safeOptions = stripReservedOptions("microsoft-teams", options);
891
+ const tokenResolver = async (scope) => {
892
+ const fresh = await runtime.getCredential();
893
+ if (!(Array.isArray(scope) ? scope : [scope]).includes(mod.TEAMS_DEV_PORTAL_SCOPE)) return credentialToken$1(fresh);
894
+ const token = fresh.type === "oauth2" ? fresh.secondaryAccessTokens?.devPortalAccessToken?.accessToken : void 0;
895
+ if (!token) throw new MastraConnectError("no_active_connection", `Teams connection ${runtime.getConnectionId()} has no Dev Portal token on its credential. Reconnect with an integration that requests the ${mod.TEAMS_DEV_PORTAL_SCOPE} scope.`);
896
+ return token;
897
+ };
898
+ return { provider: new mod.TeamsProvider({
899
+ tokenResolver,
900
+ ...safeOptions ?? {}
901
+ }) };
902
+ }
797
903
  }
798
904
  ];
799
905
  //#endregion
800
906
  //#region src/runtime/platform-proxy.ts
801
907
  /** Maps the platform credential to the field names templates are written against. */
802
908
  function toTemplateCredentials(credential) {
803
- return credential.type === "oauth2" ? {
909
+ if (credential.type === "oauth2") return {
804
910
  type: "OAUTH2",
805
911
  access_token: credential.accessToken,
806
912
  expires_at: credential.expiresAt
807
- } : {
913
+ };
914
+ if (credential.type === "two_step") return {
915
+ type: "TWO_STEP",
916
+ token: credential.token,
917
+ expires_at: credential.expiresAt
918
+ };
919
+ return {
808
920
  type: "API_KEY",
809
921
  apiKey: credential.apiKey
810
922
  };
@@ -1732,8 +1844,8 @@ const anthropicProvider = {
1732
1844
  //#endregion
1733
1845
  //#region src/providers/clerk/tools/assign-organization-role-permission.ts
1734
1846
  const assignOrganizationRolePermissionInputSchema = z.object({
1735
- organization_role_id: z.string(),
1736
- permission_id: z.string()
1847
+ organization_role_id: z.string().min(1),
1848
+ permission_id: z.string().min(1)
1737
1849
  });
1738
1850
  const ResourceSchema$49 = z.object({
1739
1851
  id: z.string(),
@@ -1769,8 +1881,8 @@ function assignOrganizationRolePermissionTool(proxy) {
1769
1881
  //#endregion
1770
1882
  //#region src/providers/clerk/tools/create-email-address.ts
1771
1883
  const createEmailAddressInputSchema = z.object({
1772
- user_id: z.string(),
1773
- email_address: z.string(),
1884
+ user_id: z.string().min(1),
1885
+ email_address: z.string().email(),
1774
1886
  verified: z.boolean().optional(),
1775
1887
  primary: z.boolean().optional(),
1776
1888
  notify_primary_email_address_changed: z.boolean().optional()
@@ -1815,16 +1927,22 @@ function createEmailAddressTool(proxy) {
1815
1927
  }
1816
1928
  //#endregion
1817
1929
  //#region src/providers/clerk/tools/create-organization-domain.ts
1818
- const EnrollmentModeSchema$2 = z.enum([
1930
+ const EnrollmentModeSchema$3 = z.enum([
1819
1931
  "manual_invitation",
1820
1932
  "automatic_invitation",
1821
1933
  "automatic_suggestion",
1822
1934
  "enterprise_sso"
1823
1935
  ]);
1936
+ const EnrollmentModeSchemaWidened$2 = z.enum([
1937
+ "manual_invitation",
1938
+ "automatic_invitation",
1939
+ "automatic_suggestion",
1940
+ "enterprise_sso"
1941
+ ]).or(z.string());
1824
1942
  const createOrganizationDomainInputSchema$1 = z.object({
1825
- organization_id: z.string(),
1943
+ organization_id: z.string().min(1),
1826
1944
  name: z.string(),
1827
- enrollment_mode: EnrollmentModeSchema$2,
1945
+ enrollment_mode: EnrollmentModeSchema$3,
1828
1946
  verified: z.boolean().optional()
1829
1947
  });
1830
1948
  const ResourceSchema$47 = z.object({
@@ -1832,15 +1950,15 @@ const ResourceSchema$47 = z.object({
1832
1950
  object: z.string().optional(),
1833
1951
  organization_id: z.string().optional(),
1834
1952
  name: z.string(),
1835
- enrollment_mode: EnrollmentModeSchema$2.optional(),
1953
+ enrollment_mode: EnrollmentModeSchemaWidened$2.optional(),
1836
1954
  affiliation_verification: z.object({
1837
1955
  attempts: z.number().optional(),
1838
1956
  status: z.string().optional()
1839
- }).passthrough().optional(),
1957
+ }).passthrough().nullable().optional(),
1840
1958
  verification: z.object({
1841
1959
  attempts: z.number().optional(),
1842
1960
  status: z.string().optional()
1843
- }).passthrough().optional(),
1961
+ }).passthrough().nullable().optional(),
1844
1962
  verified: z.boolean().optional(),
1845
1963
  created_at: z.number().optional(),
1846
1964
  updated_at: z.number().optional()
@@ -1869,7 +1987,7 @@ function createOrganizationDomainTool$1(proxy) {
1869
1987
  //#endregion
1870
1988
  //#region src/providers/clerk/tools/create-organization-invitation.ts
1871
1989
  const createOrganizationInvitationInputSchema = z.object({
1872
- organization_id: z.string(),
1990
+ organization_id: z.string().min(1),
1873
1991
  email_address: z.string().email(),
1874
1992
  role: z.string(),
1875
1993
  inviter_user_id: z.string().optional(),
@@ -1890,7 +2008,7 @@ const ResourceSchema$46 = z.object({
1890
2008
  "accepted",
1891
2009
  "revoked",
1892
2010
  "expired"
1893
- ]).optional(),
2011
+ ]).or(z.string()).optional(),
1894
2012
  created_at: z.number().optional(),
1895
2013
  updated_at: z.number().optional()
1896
2014
  }).passthrough();
@@ -1923,8 +2041,8 @@ function createOrganizationInvitationTool(proxy) {
1923
2041
  //#endregion
1924
2042
  //#region src/providers/clerk/tools/create-organization-membership.ts
1925
2043
  const createOrganizationMembershipInputSchema$1 = z.object({
1926
- organization_id: z.string(),
1927
- user_id: z.string(),
2044
+ organization_id: z.string().min(1),
2045
+ user_id: z.string().min(1),
1928
2046
  role: z.string(),
1929
2047
  public_metadata: z.record(z.string(), z.unknown()).optional(),
1930
2048
  private_metadata: z.record(z.string(), z.unknown()).optional()
@@ -2060,7 +2178,7 @@ function createOrganizationTool$1(proxy) {
2060
2178
  //#endregion
2061
2179
  //#region src/providers/clerk/tools/create-phone-number.ts
2062
2180
  const createPhoneNumberInputSchema = z.object({
2063
- user_id: z.string(),
2181
+ user_id: z.string().min(1),
2064
2182
  phone_number: z.string(),
2065
2183
  verified: z.boolean().optional(),
2066
2184
  primary: z.boolean().optional(),
@@ -2123,7 +2241,7 @@ const createUserInputSchema$2 = z.object({
2123
2241
  public_metadata: z.record(z.string(), z.unknown()).optional(),
2124
2242
  private_metadata: z.record(z.string(), z.unknown()).optional(),
2125
2243
  unsafe_metadata: z.record(z.string(), z.unknown()).optional()
2126
- });
2244
+ }).refine((value) => (value.email_address?.length ?? 0) > 0 || (value.phone_number?.length ?? 0) > 0 || value.username !== void 0 || value.password !== void 0, { message: "Provide at least one of email_address, phone_number, username, or password." });
2127
2245
  const UserSchema$27 = z.object({
2128
2246
  id: z.string(),
2129
2247
  object: z.string().optional(),
@@ -2175,7 +2293,7 @@ function createUserTool$2(proxy) {
2175
2293
  }
2176
2294
  //#endregion
2177
2295
  //#region src/providers/clerk/tools/delete-email-address.ts
2178
- const deleteEmailAddressInputSchema = z.object({ email_address_id: z.string() });
2296
+ const deleteEmailAddressInputSchema = z.object({ email_address_id: z.string().min(1) });
2179
2297
  const deleteEmailAddressOutputSchema = z.object({
2180
2298
  id: z.string(),
2181
2299
  success: z.boolean()
@@ -2201,8 +2319,8 @@ function deleteEmailAddressTool(proxy) {
2201
2319
  //#endregion
2202
2320
  //#region src/providers/clerk/tools/delete-organization-domain.ts
2203
2321
  const deleteOrganizationDomainInputSchema$1 = z.object({
2204
- organization_id: z.string(),
2205
- domain_id: z.string()
2322
+ organization_id: z.string().min(1),
2323
+ domain_id: z.string().min(1)
2206
2324
  });
2207
2325
  const deleteOrganizationDomainOutputSchema$1 = z.object({
2208
2326
  id: z.string(),
@@ -2229,8 +2347,8 @@ function deleteOrganizationDomainTool$1(proxy) {
2229
2347
  //#endregion
2230
2348
  //#region src/providers/clerk/tools/delete-organization-membership.ts
2231
2349
  const deleteOrganizationMembershipInputSchema$1 = z.object({
2232
- organization_id: z.string(),
2233
- user_id: z.string()
2350
+ organization_id: z.string().min(1),
2351
+ user_id: z.string().min(1)
2234
2352
  });
2235
2353
  const deleteOrganizationMembershipOutputSchema$1 = z.object({
2236
2354
  id: z.string(),
@@ -2256,7 +2374,7 @@ function deleteOrganizationMembershipTool$1(proxy) {
2256
2374
  }
2257
2375
  //#endregion
2258
2376
  //#region src/providers/clerk/tools/delete-organization-role.ts
2259
- const deleteOrganizationRoleInputSchema = z.object({ organization_role_id: z.string() });
2377
+ const deleteOrganizationRoleInputSchema = z.object({ organization_role_id: z.string().min(1) });
2260
2378
  const deleteOrganizationRoleOutputSchema = z.object({
2261
2379
  id: z.string(),
2262
2380
  success: z.boolean()
@@ -2306,7 +2424,7 @@ function deleteOrganizationTool$1(proxy) {
2306
2424
  }
2307
2425
  //#endregion
2308
2426
  //#region src/providers/clerk/tools/delete-phone-number.ts
2309
- const deletePhoneNumberInputSchema = z.object({ phone_number_id: z.string() });
2427
+ const deletePhoneNumberInputSchema = z.object({ phone_number_id: z.string().min(1) });
2310
2428
  const deletePhoneNumberOutputSchema = z.object({
2311
2429
  id: z.string(),
2312
2430
  success: z.boolean()
@@ -2356,7 +2474,7 @@ function deleteUserTool$2(proxy) {
2356
2474
  }
2357
2475
  //#endregion
2358
2476
  //#region src/providers/clerk/tools/get-email-address.ts
2359
- const getEmailAddressInputSchema = z.object({ email_address_id: z.string() });
2477
+ const getEmailAddressInputSchema = z.object({ email_address_id: z.string().min(1) });
2360
2478
  const ResourceSchema$42 = z.object({
2361
2479
  id: z.string(),
2362
2480
  object: z.string().optional(),
@@ -2391,8 +2509,8 @@ function getEmailAddressTool(proxy) {
2391
2509
  //#endregion
2392
2510
  //#region src/providers/clerk/tools/get-organization-invitation.ts
2393
2511
  const getOrganizationInvitationInputSchema = z.object({
2394
- organization_id: z.string(),
2395
- invitation_id: z.string()
2512
+ organization_id: z.string().min(1),
2513
+ invitation_id: z.string().min(1)
2396
2514
  });
2397
2515
  const ResourceSchema$41 = z.object({
2398
2516
  id: z.string(),
@@ -2405,7 +2523,7 @@ const ResourceSchema$41 = z.object({
2405
2523
  "accepted",
2406
2524
  "revoked",
2407
2525
  "expired"
2408
- ]).optional(),
2526
+ ]).or(z.string()).optional(),
2409
2527
  created_at: z.number().optional(),
2410
2528
  updated_at: z.number().optional()
2411
2529
  }).passthrough();
@@ -2427,7 +2545,7 @@ function getOrganizationInvitationTool(proxy) {
2427
2545
  }
2428
2546
  //#endregion
2429
2547
  //#region src/providers/clerk/tools/get-organization-role.ts
2430
- const getOrganizationRoleInputSchema = z.object({ organization_role_id: z.string() });
2548
+ const getOrganizationRoleInputSchema = z.object({ organization_role_id: z.string().min(1) });
2431
2549
  const ResourceSchema$40 = z.object({
2432
2550
  id: z.string(),
2433
2551
  object: z.string().optional(),
@@ -2499,7 +2617,7 @@ function getOrganizationTool$1(proxy) {
2499
2617
  }
2500
2618
  //#endregion
2501
2619
  //#region src/providers/clerk/tools/get-phone-number.ts
2502
- const getPhoneNumberInputSchema = z.object({ phone_number_id: z.string() });
2620
+ const getPhoneNumberInputSchema = z.object({ phone_number_id: z.string().min(1) });
2503
2621
  const ResourceSchema$39 = z.object({
2504
2622
  id: z.string(),
2505
2623
  object: z.string().optional(),
@@ -2534,7 +2652,7 @@ function getPhoneNumberTool(proxy) {
2534
2652
  }
2535
2653
  //#endregion
2536
2654
  //#region src/providers/clerk/tools/get-session.ts
2537
- const getSessionInputSchema = z.object({ session_id: z.string() });
2655
+ const getSessionInputSchema = z.object({ session_id: z.string().min(1) });
2538
2656
  const ResourceSchema$38 = z.object({
2539
2657
  id: z.string(),
2540
2658
  object: z.string().optional(),
@@ -2548,7 +2666,7 @@ const ResourceSchema$38 = z.object({
2548
2666
  "removed",
2549
2667
  "replaced",
2550
2668
  "revoked"
2551
- ]).optional(),
2669
+ ]).or(z.string()).optional(),
2552
2670
  last_active_at: z.number().optional(),
2553
2671
  expire_at: z.number().optional(),
2554
2672
  abandon_at: z.number().optional(),
@@ -2608,33 +2726,39 @@ function getUserTool$7(proxy) {
2608
2726
  }
2609
2727
  //#endregion
2610
2728
  //#region src/providers/clerk/tools/list-organization-domains.ts
2611
- const EnrollmentModeSchema$1 = z.enum([
2729
+ const EnrollmentModeSchema$2 = z.enum([
2612
2730
  "manual_invitation",
2613
2731
  "automatic_invitation",
2614
2732
  "automatic_suggestion",
2615
2733
  "enterprise_sso"
2616
2734
  ]);
2735
+ const EnrollmentModeSchemaWidened$1 = z.enum([
2736
+ "manual_invitation",
2737
+ "automatic_invitation",
2738
+ "automatic_suggestion",
2739
+ "enterprise_sso"
2740
+ ]).or(z.string());
2617
2741
  const listOrganizationDomainsInputSchema = z.object({
2618
- cursor: z.string().optional().describe("Pagination cursor returned by a previous request. Omit for the first page."),
2742
+ cursor: z.string().regex(/^\d+$/, "Cursor must be a non-negative integer.").refine((value) => Number.isSafeInteger(Number(value)), "Cursor must be a non-negative integer.").optional().describe("Pagination cursor returned by a previous request. Omit for the first page."),
2619
2743
  limit: z.number().int().min(1).max(500).optional(),
2620
- organization_id: z.string(),
2744
+ organization_id: z.string().min(1),
2621
2745
  verified: z.boolean().optional(),
2622
- enrollment_mode: EnrollmentModeSchema$1.optional()
2746
+ enrollment_mode: EnrollmentModeSchema$2.optional()
2623
2747
  });
2624
2748
  const ResourceSchema$37 = z.object({
2625
2749
  id: z.string(),
2626
2750
  object: z.string().optional(),
2627
2751
  organization_id: z.string().optional(),
2628
2752
  name: z.string(),
2629
- enrollment_mode: EnrollmentModeSchema$1.optional(),
2753
+ enrollment_mode: EnrollmentModeSchemaWidened$1.optional(),
2630
2754
  affiliation_verification: z.object({
2631
2755
  attempts: z.number().optional(),
2632
2756
  status: z.string().optional()
2633
- }).passthrough().optional(),
2757
+ }).passthrough().nullable().optional(),
2634
2758
  verification: z.object({
2635
2759
  attempts: z.number().optional(),
2636
2760
  status: z.string().optional()
2637
- }).passthrough().optional(),
2761
+ }).passthrough().nullable().optional(),
2638
2762
  verified: z.boolean().optional(),
2639
2763
  created_at: z.number().optional(),
2640
2764
  updated_at: z.number().optional()
@@ -2645,7 +2769,7 @@ const ProviderResponseSchema$244 = z.object({
2645
2769
  });
2646
2770
  const listOrganizationDomainsOutputSchema = z.object({
2647
2771
  items: z.array(ResourceSchema$37),
2648
- next_cursor: z.string().optional(),
2772
+ next_cursor: z.string().regex(/^\d+$/, "Cursor must be a non-negative integer.").refine((value) => Number.isSafeInteger(Number(value)), "Cursor must be a non-negative integer.").optional().describe("Pagination cursor returned by a previous request. Omit for the first page."),
2649
2773
  total: z.number()
2650
2774
  });
2651
2775
  function listOrganizationDomainsTool(proxy) {
@@ -2656,11 +2780,7 @@ function listOrganizationDomainsTool(proxy) {
2656
2780
  outputSchema: listOrganizationDomainsOutputSchema,
2657
2781
  execute: async (input, { requestContext }) => {
2658
2782
  const platformProxy = proxy.withRequestContext(requestContext);
2659
- const offset = input.cursor === void 0 ? 0 : Number.parseInt(input.cursor, 10);
2660
- if (!Number.isInteger(offset) || offset < 0) throw new platformProxy.ActionError({
2661
- type: "invalid_cursor",
2662
- message: "Cursor must be a non-negative integer."
2663
- });
2783
+ const offset = input.cursor === void 0 ? 0 : Number(input.cursor);
2664
2784
  const response = await platformProxy.get({
2665
2785
  endpoint: `/v1/organizations/${encodeURIComponent(input.organization_id)}/domains`,
2666
2786
  params: {
@@ -2684,9 +2804,9 @@ function listOrganizationDomainsTool(proxy) {
2684
2804
  //#endregion
2685
2805
  //#region src/providers/clerk/tools/list-organization-invitations.ts
2686
2806
  const listOrganizationInvitationsInputSchema = z.object({
2687
- cursor: z.string().optional().describe("Pagination cursor returned by a previous request. Omit for the first page."),
2807
+ cursor: z.string().regex(/^\d+$/, "Cursor must be a non-negative integer.").refine((value) => Number.isSafeInteger(Number(value)), "Cursor must be a non-negative integer.").optional().describe("Pagination cursor returned by a previous request. Omit for the first page."),
2688
2808
  limit: z.number().int().min(1).max(500).optional(),
2689
- organization_id: z.string(),
2809
+ organization_id: z.string().min(1),
2690
2810
  status: z.enum([
2691
2811
  "pending",
2692
2812
  "accepted",
@@ -2707,7 +2827,7 @@ const ResourceSchema$36 = z.object({
2707
2827
  "accepted",
2708
2828
  "revoked",
2709
2829
  "expired"
2710
- ]).optional(),
2830
+ ]).or(z.string()).optional(),
2711
2831
  created_at: z.number().optional(),
2712
2832
  updated_at: z.number().optional()
2713
2833
  }).passthrough();
@@ -2717,7 +2837,7 @@ const ProviderResponseSchema$243 = z.object({
2717
2837
  });
2718
2838
  const listOrganizationInvitationsOutputSchema = z.object({
2719
2839
  items: z.array(ResourceSchema$36),
2720
- next_cursor: z.string().optional(),
2840
+ next_cursor: z.string().regex(/^\d+$/, "Cursor must be a non-negative integer.").refine((value) => Number.isSafeInteger(Number(value)), "Cursor must be a non-negative integer.").optional().describe("Pagination cursor returned by a previous request. Omit for the first page."),
2721
2841
  total: z.number()
2722
2842
  });
2723
2843
  function listOrganizationInvitationsTool(proxy) {
@@ -2728,11 +2848,7 @@ function listOrganizationInvitationsTool(proxy) {
2728
2848
  outputSchema: listOrganizationInvitationsOutputSchema,
2729
2849
  execute: async (input, { requestContext }) => {
2730
2850
  const platformProxy = proxy.withRequestContext(requestContext);
2731
- const offset = input.cursor === void 0 ? 0 : Number.parseInt(input.cursor, 10);
2732
- if (!Number.isInteger(offset) || offset < 0) throw new platformProxy.ActionError({
2733
- type: "invalid_cursor",
2734
- message: "Cursor must be a non-negative integer."
2735
- });
2851
+ const offset = input.cursor === void 0 ? 0 : Number(input.cursor);
2736
2852
  const response = await platformProxy.get({
2737
2853
  endpoint: `/v1/organizations/${encodeURIComponent(input.organization_id)}/invitations`,
2738
2854
  params: {
@@ -2757,9 +2873,9 @@ function listOrganizationInvitationsTool(proxy) {
2757
2873
  //#endregion
2758
2874
  //#region src/providers/clerk/tools/list-organization-memberships.ts
2759
2875
  const listOrganizationMembershipsInputSchema$1 = z.object({
2760
- cursor: z.string().optional().describe("Pagination cursor returned by a previous request. Omit for the first page."),
2876
+ cursor: z.string().regex(/^\d+$/, "Cursor must be a non-negative integer.").refine((value) => Number.isSafeInteger(Number(value)), "Cursor must be a non-negative integer.").optional().describe("Pagination cursor returned by a previous request. Omit for the first page."),
2761
2877
  limit: z.number().int().min(1).max(500).optional(),
2762
- organization_id: z.string(),
2878
+ organization_id: z.string().min(1),
2763
2879
  user_id: z.array(z.string()).optional(),
2764
2880
  email_address: z.array(z.string()).optional(),
2765
2881
  phone_number: z.array(z.string()).optional(),
@@ -2793,7 +2909,7 @@ const ProviderResponseSchema$242 = z.object({
2793
2909
  });
2794
2910
  const listOrganizationMembershipsOutputSchema$1 = z.object({
2795
2911
  items: z.array(ResourceSchema$35),
2796
- next_cursor: z.string().optional(),
2912
+ next_cursor: z.string().regex(/^\d+$/, "Cursor must be a non-negative integer.").refine((value) => Number.isSafeInteger(Number(value)), "Cursor must be a non-negative integer.").optional().describe("Pagination cursor returned by a previous request. Omit for the first page."),
2797
2913
  total: z.number()
2798
2914
  });
2799
2915
  function listOrganizationMembershipsTool$1(proxy) {
@@ -2804,11 +2920,7 @@ function listOrganizationMembershipsTool$1(proxy) {
2804
2920
  outputSchema: listOrganizationMembershipsOutputSchema$1,
2805
2921
  execute: async (input, { requestContext }) => {
2806
2922
  const platformProxy = proxy.withRequestContext(requestContext);
2807
- const offset = input.cursor === void 0 ? 0 : Number.parseInt(input.cursor, 10);
2808
- if (!Number.isInteger(offset) || offset < 0) throw new platformProxy.ActionError({
2809
- type: "invalid_cursor",
2810
- message: "Cursor must be a non-negative integer."
2811
- });
2923
+ const offset = input.cursor === void 0 ? 0 : Number(input.cursor);
2812
2924
  const response = await platformProxy.get({
2813
2925
  endpoint: `/v1/organizations/${encodeURIComponent(input.organization_id)}/memberships`,
2814
2926
  params: {
@@ -2846,7 +2958,7 @@ function listOrganizationMembershipsTool$1(proxy) {
2846
2958
  //#endregion
2847
2959
  //#region src/providers/clerk/tools/list-organization-roles.ts
2848
2960
  const listOrganizationRolesInputSchema = z.object({
2849
- cursor: z.string().optional().describe("Pagination cursor returned by a previous request. Omit for the first page."),
2961
+ cursor: z.string().regex(/^\d+$/, "Cursor must be a non-negative integer.").refine((value) => Number.isSafeInteger(Number(value)), "Cursor must be a non-negative integer.").optional().describe("Pagination cursor returned by a previous request. Omit for the first page."),
2850
2962
  limit: z.number().int().min(1).max(500).optional(),
2851
2963
  query: z.string().optional(),
2852
2964
  order_by: z.string().optional()
@@ -2871,7 +2983,7 @@ const ProviderResponseSchema$241 = z.object({
2871
2983
  });
2872
2984
  const listOrganizationRolesOutputSchema = z.object({
2873
2985
  items: z.array(ResourceSchema$34),
2874
- next_cursor: z.string().optional(),
2986
+ next_cursor: z.string().regex(/^\d+$/, "Cursor must be a non-negative integer.").refine((value) => Number.isSafeInteger(Number(value)), "Cursor must be a non-negative integer.").optional().describe("Pagination cursor returned by a previous request. Omit for the first page."),
2875
2987
  total: z.number()
2876
2988
  });
2877
2989
  function listOrganizationRolesTool(proxy) {
@@ -2882,11 +2994,7 @@ function listOrganizationRolesTool(proxy) {
2882
2994
  outputSchema: listOrganizationRolesOutputSchema,
2883
2995
  execute: async (input, { requestContext }) => {
2884
2996
  const platformProxy = proxy.withRequestContext(requestContext);
2885
- const offset = input.cursor === void 0 ? 0 : Number.parseInt(input.cursor, 10);
2886
- if (!Number.isInteger(offset) || offset < 0) throw new platformProxy.ActionError({
2887
- type: "invalid_cursor",
2888
- message: "Cursor must be a non-negative integer."
2889
- });
2997
+ const offset = input.cursor === void 0 ? 0 : Number(input.cursor);
2890
2998
  const response = await platformProxy.get({
2891
2999
  endpoint: "/v1/organization_roles",
2892
3000
  params: {
@@ -2910,7 +3018,7 @@ function listOrganizationRolesTool(proxy) {
2910
3018
  //#endregion
2911
3019
  //#region src/providers/clerk/tools/list-organizations.ts
2912
3020
  const listOrganizationsInputSchema$1 = z.object({
2913
- cursor: z.string().optional(),
3021
+ cursor: z.string().regex(/^\d+$/, "Cursor must be a non-negative integer.").refine((value) => Number.isSafeInteger(Number(value)), "Cursor must be a non-negative integer.").optional().describe("Pagination cursor returned by a previous request. Omit for the first page."),
2914
3022
  limit: z.number().int().min(1).max(500).optional(),
2915
3023
  query: z.string().optional(),
2916
3024
  order_by: z.string().optional().describe("Sort by name, created_at, or members_count, prefixed with + or -."),
@@ -2950,11 +3058,7 @@ function listOrganizationsTool$1(proxy) {
2950
3058
  outputSchema: listOrganizationsOutputSchema$1,
2951
3059
  execute: async (input, { requestContext }) => {
2952
3060
  const platformProxy = proxy.withRequestContext(requestContext);
2953
- const offset = input.cursor === void 0 ? 0 : Number.parseInt(input.cursor, 10);
2954
- if (!Number.isInteger(offset) || offset < 0) throw new platformProxy.ActionError({
2955
- type: "invalid_cursor",
2956
- message: "Cursor must be a non-negative integer."
2957
- });
3061
+ const offset = input.cursor === void 0 ? 0 : Number(input.cursor);
2958
3062
  const response = await platformProxy.get({
2959
3063
  endpoint: "/v1/organizations",
2960
3064
  params: {
@@ -2980,10 +3084,10 @@ function listOrganizationsTool$1(proxy) {
2980
3084
  //#endregion
2981
3085
  //#region src/providers/clerk/tools/list-sessions.ts
2982
3086
  const listSessionsInputSchema = z.object({
2983
- cursor: z.string().optional().describe("Pagination cursor returned by a previous request. Omit for the first page."),
3087
+ cursor: z.string().regex(/^\d+$/, "Cursor must be a non-negative integer.").refine((value) => Number.isSafeInteger(Number(value)), "Cursor must be a non-negative integer.").optional().describe("Pagination cursor returned by a previous request. Omit for the first page."),
2984
3088
  limit: z.number().int().min(1).max(500).optional(),
2985
- client_id: z.string().optional(),
2986
- user_id: z.string().optional(),
3089
+ client_id: z.string().min(1).optional(),
3090
+ user_id: z.string().min(1).optional(),
2987
3091
  status: z.enum([
2988
3092
  "abandoned",
2989
3093
  "active",
@@ -2993,7 +3097,7 @@ const listSessionsInputSchema = z.object({
2993
3097
  "replaced",
2994
3098
  "revoked"
2995
3099
  ]).optional()
2996
- });
3100
+ }).refine((value) => value.client_id !== void 0 || value.user_id !== void 0, { message: "Provide at least one of client_id or user_id." });
2997
3101
  const ResourceSchema$33 = z.object({
2998
3102
  id: z.string(),
2999
3103
  object: z.string().optional(),
@@ -3007,21 +3111,17 @@ const ResourceSchema$33 = z.object({
3007
3111
  "removed",
3008
3112
  "replaced",
3009
3113
  "revoked"
3010
- ]).optional(),
3114
+ ]).or(z.string()).optional(),
3011
3115
  last_active_at: z.number().optional(),
3012
3116
  expire_at: z.number().optional(),
3013
3117
  abandon_at: z.number().optional(),
3014
3118
  created_at: z.number().optional(),
3015
3119
  updated_at: z.number().optional()
3016
3120
  }).passthrough();
3017
- const ProviderResponseSchema$239 = z.object({
3018
- data: z.array(ResourceSchema$33),
3019
- total_count: z.number()
3020
- });
3121
+ const ProviderResponseSchema$239 = z.array(ResourceSchema$33);
3021
3122
  const listSessionsOutputSchema = z.object({
3022
3123
  items: z.array(ResourceSchema$33),
3023
- next_cursor: z.string().optional(),
3024
- total: z.number()
3124
+ next_cursor: z.string().regex(/^\d+$/, "Cursor must be a non-negative integer.").refine((value) => Number.isSafeInteger(Number(value)), "Cursor must be a non-negative integer.").optional().describe("Pagination cursor returned by a previous request. Omit for the first page.")
3025
3125
  });
3026
3126
  function listSessionsTool(proxy) {
3027
3127
  return createTool({
@@ -3031,28 +3131,23 @@ function listSessionsTool(proxy) {
3031
3131
  outputSchema: listSessionsOutputSchema,
3032
3132
  execute: async (input, { requestContext }) => {
3033
3133
  const platformProxy = proxy.withRequestContext(requestContext);
3034
- const offset = input.cursor === void 0 ? 0 : Number.parseInt(input.cursor, 10);
3035
- if (!Number.isInteger(offset) || offset < 0) throw new platformProxy.ActionError({
3036
- type: "invalid_cursor",
3037
- message: "Cursor must be a non-negative integer."
3038
- });
3134
+ const offset = input.cursor === void 0 ? 0 : Number(input.cursor);
3135
+ const limit = input.limit ?? 10;
3039
3136
  const response = await platformProxy.get({
3040
3137
  endpoint: "/v1/sessions",
3041
3138
  params: {
3042
3139
  offset: String(offset),
3043
- ...input.limit !== void 0 && { limit: String(input.limit) },
3140
+ limit: String(limit),
3044
3141
  ...input.client_id !== void 0 && { client_id: input.client_id },
3045
3142
  ...input.user_id !== void 0 && { user_id: input.user_id },
3046
3143
  ...input.status !== void 0 && { status: input.status }
3047
3144
  },
3048
3145
  retries: 3
3049
3146
  });
3050
- const provider = ProviderResponseSchema$239.parse(response.data);
3051
- const nextOffset = offset + provider.data.length;
3147
+ const sessions = ProviderResponseSchema$239.parse(response.data);
3052
3148
  return {
3053
- items: provider.data,
3054
- ...nextOffset < provider.total_count && { next_cursor: String(nextOffset) },
3055
- total: provider.total_count
3149
+ items: sessions,
3150
+ ...sessions.length === limit && { next_cursor: String(offset + sessions.length) }
3056
3151
  };
3057
3152
  }
3058
3153
  });
@@ -3060,13 +3155,19 @@ function listSessionsTool(proxy) {
3060
3155
  //#endregion
3061
3156
  //#region src/providers/clerk/tools/list-users.ts
3062
3157
  const listUsersInputSchema$9 = z.object({
3063
- cursor: z.string().optional().describe("Pagination cursor returned by a previous request. Omit for the first page."),
3158
+ cursor: z.string().regex(/^\d+$/, "Cursor must be a non-negative integer.").refine((value) => Number.isSafeInteger(Number(value)), "Cursor must be a non-negative integer.").optional().describe("Pagination cursor returned by a previous request. Omit for the first page."),
3064
3159
  limit: z.number().int().min(1).max(500).optional().describe("Maximum number of users to return. Maximum 500."),
3065
3160
  query: z.string().optional().describe("Search across names, identifiers, email addresses, phone numbers, and usernames."),
3066
3161
  email_address: z.array(z.string()).max(100).optional().describe("Filter by email addresses."),
3162
+ phone_number: z.array(z.string()).max(100).optional().describe("Filter by phone numbers."),
3163
+ username: z.array(z.string()).max(100).optional().describe("Filter by usernames."),
3067
3164
  user_id: z.array(z.string()).max(100).optional().describe("Filter by Clerk user IDs."),
3068
3165
  external_id: z.array(z.string()).max(100).optional().describe("Filter by external user IDs."),
3069
3166
  organization_id: z.array(z.string()).max(100).optional().describe("Filter by organization IDs."),
3167
+ last_active_at_before: z.number().int().optional().describe("Filter users last active before this Unix timestamp in milliseconds."),
3168
+ last_active_at_after: z.number().int().optional().describe("Filter users last active after this Unix timestamp in milliseconds."),
3169
+ created_at_before: z.number().int().optional().describe("Filter users created before this Unix timestamp in milliseconds."),
3170
+ created_at_after: z.number().int().optional().describe("Filter users created after this Unix timestamp in milliseconds."),
3070
3171
  order_by: z.string().optional().describe("Sort field prefixed with + for ascending or - for descending. Example: \"-created_at\"")
3071
3172
  });
3072
3173
  const UserSchema$25 = z.object({
@@ -3085,13 +3186,11 @@ const UserSchema$25 = z.object({
3085
3186
  updated_at: z.number().optional(),
3086
3187
  locale: z.string().nullable().optional()
3087
3188
  }).passthrough();
3088
- const ProviderResponseSchema$238 = z.object({
3089
- data: z.array(UserSchema$25),
3090
- total_count: z.number()
3091
- });
3189
+ const ProviderResponseSchema$238 = z.array(UserSchema$25);
3190
+ const ProviderCountSchema = z.object({ total_count: z.number() }).passthrough();
3092
3191
  const listUsersOutputSchema$9 = z.object({
3093
3192
  items: z.array(UserSchema$25),
3094
- next_cursor: z.string().optional(),
3193
+ next_cursor: z.string().regex(/^\d+$/, "Cursor must be a non-negative integer.").refine((value) => Number.isSafeInteger(Number(value)), "Cursor must be a non-negative integer.").optional().describe("Pagination cursor returned by a previous request. Omit for the first page."),
3095
3194
  total: z.number()
3096
3195
  });
3097
3196
  function listUsersTool$9(proxy) {
@@ -3102,31 +3201,42 @@ function listUsersTool$9(proxy) {
3102
3201
  outputSchema: listUsersOutputSchema$9,
3103
3202
  execute: async (input, { requestContext }) => {
3104
3203
  const platformProxy = proxy.withRequestContext(requestContext);
3105
- const offset = input.cursor === void 0 ? 0 : Number.parseInt(input.cursor, 10);
3106
- if (!Number.isInteger(offset) || offset < 0) throw new platformProxy.ActionError({
3107
- type: "invalid_cursor",
3108
- message: "Cursor must be a non-negative integer."
3109
- });
3204
+ const offset = input.cursor === void 0 ? 0 : Number(input.cursor);
3205
+ const filterParams = {
3206
+ ...input.query !== void 0 && { query: input.query },
3207
+ ...input.email_address !== void 0 && { email_address: input.email_address },
3208
+ ...input.phone_number !== void 0 && { phone_number: input.phone_number },
3209
+ ...input.username !== void 0 && { username: input.username },
3210
+ ...input.user_id !== void 0 && { user_id: input.user_id },
3211
+ ...input.external_id !== void 0 && { external_id: input.external_id },
3212
+ ...input.organization_id !== void 0 && { organization_id: input.organization_id },
3213
+ ...input.last_active_at_before !== void 0 && { last_active_at_before: String(input.last_active_at_before) },
3214
+ ...input.last_active_at_after !== void 0 && { last_active_at_after: String(input.last_active_at_after) },
3215
+ ...input.created_at_before !== void 0 && { created_at_before: String(input.created_at_before) },
3216
+ ...input.created_at_after !== void 0 && { created_at_after: String(input.created_at_after) }
3217
+ };
3110
3218
  const response = await platformProxy.get({
3111
3219
  endpoint: "/v1/users",
3112
3220
  params: {
3113
3221
  offset: String(offset),
3114
3222
  ...input.limit !== void 0 && { limit: String(input.limit) },
3115
- ...input.query !== void 0 && { query: input.query },
3116
- ...input.email_address !== void 0 && { email_address: input.email_address },
3117
- ...input.user_id !== void 0 && { user_id: input.user_id },
3118
- ...input.external_id !== void 0 && { external_id: input.external_id },
3119
- ...input.organization_id !== void 0 && { organization_id: input.organization_id },
3120
- ...input.order_by !== void 0 && { order_by: input.order_by }
3223
+ ...input.order_by !== void 0 && { order_by: input.order_by },
3224
+ ...filterParams
3121
3225
  },
3122
3226
  retries: 3
3123
3227
  });
3124
- const provider = ProviderResponseSchema$238.parse(response.data);
3125
- const nextOffset = offset + provider.data.length;
3228
+ const users = ProviderResponseSchema$238.parse(response.data);
3229
+ const countResponse = await platformProxy.get({
3230
+ endpoint: "/v1/users/count",
3231
+ params: filterParams,
3232
+ retries: 3
3233
+ });
3234
+ const total = ProviderCountSchema.parse(countResponse.data).total_count;
3235
+ const nextOffset = offset + users.length;
3126
3236
  return {
3127
- items: provider.data,
3128
- ...nextOffset < provider.total_count && { next_cursor: String(nextOffset) },
3129
- total: provider.total_count
3237
+ items: users,
3238
+ ...users.length > 0 && nextOffset < total && { next_cursor: String(nextOffset) },
3239
+ total
3130
3240
  };
3131
3241
  }
3132
3242
  });
@@ -3134,8 +3244,8 @@ function listUsersTool$9(proxy) {
3134
3244
  //#endregion
3135
3245
  //#region src/providers/clerk/tools/remove-organization-role-permission.ts
3136
3246
  const removeOrganizationRolePermissionInputSchema = z.object({
3137
- organization_role_id: z.string(),
3138
- permission_id: z.string()
3247
+ organization_role_id: z.string().min(1),
3248
+ permission_id: z.string().min(1)
3139
3249
  });
3140
3250
  const removeOrganizationRolePermissionOutputSchema = z.object({
3141
3251
  id: z.string(),
@@ -3162,8 +3272,8 @@ function removeOrganizationRolePermissionTool(proxy) {
3162
3272
  //#endregion
3163
3273
  //#region src/providers/clerk/tools/revoke-organization-invitation.ts
3164
3274
  const revokeOrganizationInvitationInputSchema = z.object({
3165
- organization_id: z.string(),
3166
- invitation_id: z.string(),
3275
+ organization_id: z.string().min(1),
3276
+ invitation_id: z.string().min(1),
3167
3277
  requesting_user_id: z.string().optional()
3168
3278
  });
3169
3279
  const ResourceSchema$32 = z.object({
@@ -3177,7 +3287,7 @@ const ResourceSchema$32 = z.object({
3177
3287
  "accepted",
3178
3288
  "revoked",
3179
3289
  "expired"
3180
- ]).optional(),
3290
+ ]).or(z.string()).optional(),
3181
3291
  created_at: z.number().optional(),
3182
3292
  updated_at: z.number().optional()
3183
3293
  }).passthrough();
@@ -3200,7 +3310,7 @@ function revokeOrganizationInvitationTool(proxy) {
3200
3310
  }
3201
3311
  //#endregion
3202
3312
  //#region src/providers/clerk/tools/revoke-session.ts
3203
- const revokeSessionInputSchema = z.object({ session_id: z.string() });
3313
+ const revokeSessionInputSchema = z.object({ session_id: z.string().min(1) });
3204
3314
  const ResourceSchema$31 = z.object({
3205
3315
  id: z.string(),
3206
3316
  object: z.string().optional(),
@@ -3214,7 +3324,7 @@ const ResourceSchema$31 = z.object({
3214
3324
  "removed",
3215
3325
  "replaced",
3216
3326
  "revoked"
3217
- ]).optional(),
3327
+ ]).or(z.string()).optional(),
3218
3328
  last_active_at: z.number().optional(),
3219
3329
  expire_at: z.number().optional(),
3220
3330
  abandon_at: z.number().optional(),
@@ -3241,7 +3351,7 @@ function revokeSessionTool(proxy) {
3241
3351
  //#endregion
3242
3352
  //#region src/providers/clerk/tools/update-email-address.ts
3243
3353
  const updateEmailAddressInputSchema = z.object({
3244
- email_address_id: z.string(),
3354
+ email_address_id: z.string().min(1),
3245
3355
  verified: z.boolean().optional(),
3246
3356
  primary: z.boolean().optional(),
3247
3357
  notify_primary_email_address_changed: z.boolean().optional()
@@ -3284,16 +3394,22 @@ function updateEmailAddressTool(proxy) {
3284
3394
  }
3285
3395
  //#endregion
3286
3396
  //#region src/providers/clerk/tools/update-organization-domain.ts
3287
- const EnrollmentModeSchema = z.enum([
3397
+ const EnrollmentModeSchema$1 = z.enum([
3288
3398
  "manual_invitation",
3289
3399
  "automatic_invitation",
3290
3400
  "automatic_suggestion",
3291
3401
  "enterprise_sso"
3292
3402
  ]);
3403
+ const EnrollmentModeSchemaWidened = z.enum([
3404
+ "manual_invitation",
3405
+ "automatic_invitation",
3406
+ "automatic_suggestion",
3407
+ "enterprise_sso"
3408
+ ]).or(z.string());
3293
3409
  const updateOrganizationDomainInputSchema = z.object({
3294
- organization_id: z.string(),
3295
- domain_id: z.string(),
3296
- enrollment_mode: EnrollmentModeSchema.optional(),
3410
+ organization_id: z.string().min(1),
3411
+ domain_id: z.string().min(1),
3412
+ enrollment_mode: EnrollmentModeSchema$1.optional(),
3297
3413
  verified: z.boolean().optional()
3298
3414
  });
3299
3415
  const ResourceSchema$29 = z.object({
@@ -3301,15 +3417,15 @@ const ResourceSchema$29 = z.object({
3301
3417
  object: z.string().optional(),
3302
3418
  organization_id: z.string().optional(),
3303
3419
  name: z.string(),
3304
- enrollment_mode: EnrollmentModeSchema.optional(),
3420
+ enrollment_mode: EnrollmentModeSchemaWidened.optional(),
3305
3421
  affiliation_verification: z.object({
3306
3422
  attempts: z.number().optional(),
3307
3423
  status: z.string().optional()
3308
- }).passthrough().optional(),
3424
+ }).passthrough().nullable().optional(),
3309
3425
  verification: z.object({
3310
3426
  attempts: z.number().optional(),
3311
3427
  status: z.string().optional()
3312
- }).passthrough().optional(),
3428
+ }).passthrough().nullable().optional(),
3313
3429
  verified: z.boolean().optional(),
3314
3430
  created_at: z.number().optional(),
3315
3431
  updated_at: z.number().optional()
@@ -3337,8 +3453,8 @@ function updateOrganizationDomainTool(proxy) {
3337
3453
  //#endregion
3338
3454
  //#region src/providers/clerk/tools/update-organization-membership-metadata.ts
3339
3455
  const updateOrganizationMembershipMetadataInputSchema = z.object({
3340
- organization_id: z.string(),
3341
- user_id: z.string(),
3456
+ organization_id: z.string().min(1),
3457
+ user_id: z.string().min(1),
3342
3458
  public_metadata: z.record(z.string(), z.unknown()).optional(),
3343
3459
  private_metadata: z.record(z.string(), z.unknown()).optional()
3344
3460
  });
@@ -3375,8 +3491,8 @@ function updateOrganizationMembershipMetadataTool(proxy) {
3375
3491
  //#endregion
3376
3492
  //#region src/providers/clerk/tools/update-organization-membership.ts
3377
3493
  const updateOrganizationMembershipInputSchema$1 = z.object({
3378
- organization_id: z.string(),
3379
- user_id: z.string(),
3494
+ organization_id: z.string().min(1),
3495
+ user_id: z.string().min(1),
3380
3496
  role: z.string()
3381
3497
  });
3382
3498
  const ResourceSchema$27 = z.object({
@@ -3409,12 +3525,12 @@ function updateOrganizationMembershipTool$1(proxy) {
3409
3525
  //#endregion
3410
3526
  //#region src/providers/clerk/tools/update-organization-role.ts
3411
3527
  const updateOrganizationRoleInputSchema = z.object({
3412
- organization_role_id: z.string(),
3528
+ organization_role_id: z.string().min(1),
3413
3529
  name: z.string().optional(),
3414
3530
  key: z.string().optional(),
3415
3531
  description: z.string().optional(),
3416
3532
  permissions: z.array(z.string()).optional()
3417
- });
3533
+ }).refine((value) => value.name !== void 0 || value.key !== void 0 || value.description !== void 0 || value.permissions !== void 0, { message: "Provide at least one of name, key, description, or permissions." });
3418
3534
  const ResourceSchema$26 = z.object({
3419
3535
  id: z.string(),
3420
3536
  object: z.string().optional(),
@@ -3458,7 +3574,8 @@ const updateOrganizationInputSchema$1 = z.object({
3458
3574
  name: z.string().min(1).optional(),
3459
3575
  slug: z.string().optional(),
3460
3576
  admin_delete_enabled: z.boolean().optional(),
3461
- max_allowed_memberships: z.number().int().min(0).optional()
3577
+ max_allowed_memberships: z.number().int().min(0).optional(),
3578
+ public_metadata: z.record(z.string(), z.unknown()).optional()
3462
3579
  });
3463
3580
  const OrganizationSchema$1 = z.object({
3464
3581
  id: z.string(),
@@ -3490,7 +3607,8 @@ function updateOrganizationTool$1(proxy) {
3490
3607
  ...input.name !== void 0 && { name: input.name },
3491
3608
  ...input.slug !== void 0 && { slug: input.slug },
3492
3609
  ...input.admin_delete_enabled !== void 0 && { admin_delete_enabled: input.admin_delete_enabled },
3493
- ...input.max_allowed_memberships !== void 0 && { max_allowed_memberships: input.max_allowed_memberships }
3610
+ ...input.max_allowed_memberships !== void 0 && { max_allowed_memberships: input.max_allowed_memberships },
3611
+ ...input.public_metadata !== void 0 && { public_metadata: input.public_metadata }
3494
3612
  },
3495
3613
  retries: 3
3496
3614
  });
@@ -3501,7 +3619,7 @@ function updateOrganizationTool$1(proxy) {
3501
3619
  //#endregion
3502
3620
  //#region src/providers/clerk/tools/update-phone-number.ts
3503
3621
  const updatePhoneNumberInputSchema = z.object({
3504
- phone_number_id: z.string(),
3622
+ phone_number_id: z.string().min(1),
3505
3623
  verified: z.boolean().optional(),
3506
3624
  primary: z.boolean().optional(),
3507
3625
  reserved_for_second_factor: z.boolean().optional()
@@ -3547,14 +3665,14 @@ function updatePhoneNumberTool(proxy) {
3547
3665
  //#region src/providers/clerk/tools/update-user.ts
3548
3666
  const updateUserInputSchema$1 = z.object({
3549
3667
  user_id: z.string().min(1),
3550
- first_name: z.string().optional(),
3551
- last_name: z.string().optional(),
3552
- username: z.string().optional(),
3668
+ first_name: z.string().nullable().optional().describe("Pass null to clear the first name."),
3669
+ last_name: z.string().nullable().optional().describe("Pass null to clear the last name."),
3670
+ username: z.string().nullable().optional().describe("Pass null to clear the username."),
3553
3671
  password: z.string().min(8).optional(),
3554
3672
  skip_password_checks: z.boolean().optional(),
3555
3673
  sign_out_of_other_sessions: z.boolean().optional(),
3556
- external_id: z.string().optional(),
3557
- locale: z.string().optional()
3674
+ external_id: z.string().nullable().optional().describe("Pass null to clear the external ID."),
3675
+ locale: z.string().nullable().optional().describe("Pass null to clear the locale.")
3558
3676
  });
3559
3677
  const UserSchema$24 = z.object({
3560
3678
  id: z.string(),
@@ -3600,24 +3718,30 @@ function updateUserTool$1(proxy) {
3600
3718
  }
3601
3719
  //#endregion
3602
3720
  //#region src/providers/clerk/tools/verify-organization-domain.ts
3721
+ const EnrollmentModeSchema = z.enum([
3722
+ "manual_invitation",
3723
+ "automatic_invitation",
3724
+ "automatic_suggestion",
3725
+ "enterprise_sso"
3726
+ ]).or(z.string());
3603
3727
  const verifyOrganizationDomainInputSchema$1 = z.object({
3604
- organization_id: z.string(),
3605
- domain_id: z.string()
3728
+ organization_id: z.string().min(1),
3729
+ domain_id: z.string().min(1)
3606
3730
  });
3607
3731
  const ResourceSchema$24 = z.object({
3608
3732
  id: z.string(),
3609
3733
  object: z.string().optional(),
3610
3734
  organization_id: z.string().optional(),
3611
3735
  name: z.string(),
3612
- enrollment_mode: z.string().optional(),
3736
+ enrollment_mode: EnrollmentModeSchema.optional(),
3613
3737
  affiliation_verification: z.object({
3614
3738
  attempts: z.number().optional(),
3615
3739
  status: z.string().optional()
3616
- }).passthrough().optional(),
3740
+ }).passthrough().nullable().optional(),
3617
3741
  verification: z.object({
3618
3742
  attempts: z.number().optional(),
3619
3743
  status: z.string().optional()
3620
- }).passthrough().optional(),
3744
+ }).passthrough().nullable().optional(),
3621
3745
  verified: z.boolean().optional(),
3622
3746
  created_at: z.number().optional(),
3623
3747
  updated_at: z.number().optional()
@@ -3702,8 +3826,25 @@ const clerkProvider = {
3702
3826
  createTools: createClerkTools
3703
3827
  };
3704
3828
  //#endregion
3829
+ //#region src/providers/discord/tools/_bot-token.ts
3830
+ /**
3831
+ * Resolves the Discord bot token from the connection's credentials. Nango's
3832
+ * `discord` provider is API_KEY-typed and stores the bot token as its
3833
+ * secret, so the platform serves it back as `credentials.apiKey` (the wire
3834
+ * shape templates are written against). Throws a ToolActionError with a
3835
+ * consistent `missing_credentials` payload so exec bodies don't need to repeat
3836
+ * the guard.
3837
+ */
3838
+ async function resolveDiscordBotToken(platformProxy) {
3839
+ const credentials = (await platformProxy.getConnectionWithCredentials()).credentials;
3840
+ if (credentials && typeof credentials.apiKey === "string" && credentials.apiKey) return credentials.apiKey;
3841
+ throw new platformProxy.ActionError({
3842
+ type: "missing_credentials",
3843
+ message: "Discord bot token is missing from the connection credentials. Reconnect the discord integration with a valid bot token."
3844
+ });
3845
+ }
3846
+ //#endregion
3705
3847
  //#region src/providers/discord/tools/add-guild-member-role.ts
3706
- const MetadataSchema$7 = z.object({ botToken: z.string() });
3707
3848
  const addGuildMemberRoleInputSchema = z.object({
3708
3849
  guildId: z.string().describe("Guild ID. Example: \"123456789012345678\""),
3709
3850
  userId: z.string().describe("User ID. Example: \"987654321098765432\""),
@@ -3718,12 +3859,7 @@ function addGuildMemberRoleTool(proxy) {
3718
3859
  outputSchema: addGuildMemberRoleOutputSchema,
3719
3860
  execute: async (input, { requestContext }) => {
3720
3861
  const platformProxy = proxy.withRequestContext(requestContext);
3721
- const metadataResult = MetadataSchema$7.safeParse(await platformProxy.getMetadata());
3722
- if (!metadataResult.success) throw new platformProxy.ActionError({
3723
- type: "invalid_metadata",
3724
- message: "botToken is required in metadata."
3725
- });
3726
- const { botToken } = metadataResult.data;
3862
+ const botToken = await resolveDiscordBotToken(platformProxy);
3727
3863
  const response = await platformProxy.put({
3728
3864
  endpoint: `/api/v10/guilds/${input.guildId}/members/${input.userId}/roles/${input.roleId}`,
3729
3865
  headers: { Authorization: `Bot ${botToken}` },
@@ -3739,7 +3875,6 @@ function addGuildMemberRoleTool(proxy) {
3739
3875
  }
3740
3876
  //#endregion
3741
3877
  //#region src/providers/discord/tools/create-channel.ts
3742
- z.object({ botToken: z.string().describe("Discord bot token from the Discord Developer Portal") });
3743
3878
  const createChannelInputSchema$2 = z.object({
3744
3879
  guildId: z.string().describe("The ID of the guild to create the channel in. Example: \"41771983423143937\""),
3745
3880
  name: z.string().min(1).max(100).describe("Channel name (1-100 characters). Example: \"general\""),
@@ -3809,11 +3944,7 @@ function createChannelTool$2(proxy) {
3809
3944
  outputSchema: createChannelOutputSchema$2,
3810
3945
  execute: async (input, { requestContext }) => {
3811
3946
  const platformProxy = proxy.withRequestContext(requestContext);
3812
- const metadata = await platformProxy.getMetadata();
3813
- if (!metadata.botToken) throw new platformProxy.ActionError({
3814
- type: "invalid_metadata",
3815
- message: "botToken is required in metadata. Please provide a Discord bot token."
3816
- });
3947
+ const botToken = await resolveDiscordBotToken(platformProxy);
3817
3948
  if (!input.guildId) throw new platformProxy.ActionError({
3818
3949
  type: "invalid_input",
3819
3950
  message: "guildId is required to create a channel."
@@ -3839,7 +3970,7 @@ function createChannelTool$2(proxy) {
3839
3970
  const response = await platformProxy.post({
3840
3971
  endpoint: `/api/v10/guilds/${input.guildId}/channels`,
3841
3972
  data: requestBody,
3842
- headers: { Authorization: `Bot ${metadata.botToken}` },
3973
+ headers: { Authorization: `Bot ${botToken}` },
3843
3974
  retries: 3
3844
3975
  });
3845
3976
  const providerChannel = ProviderChannelSchema$10.parse(response.data);
@@ -3933,11 +4064,7 @@ function createMessageTool(proxy) {
3933
4064
  outputSchema: createMessageOutputSchema,
3934
4065
  execute: async (input, { requestContext }) => {
3935
4066
  const platformProxy = proxy.withRequestContext(requestContext);
3936
- const botToken = (await platformProxy.getMetadata())?.botToken;
3937
- if (!botToken) throw new platformProxy.ActionError({
3938
- type: "invalid_metadata",
3939
- message: "botToken is required in connection metadata."
3940
- });
4067
+ const botToken = await resolveDiscordBotToken(platformProxy);
3941
4068
  const requestBody = {};
3942
4069
  if (input.content !== void 0) requestBody["content"] = input.content;
3943
4070
  if (input.embeds !== void 0) requestBody["embeds"] = input.embeds;
@@ -3989,11 +4116,7 @@ function createReactionTool(proxy) {
3989
4116
  outputSchema: createReactionOutputSchema,
3990
4117
  execute: async (input, { requestContext }) => {
3991
4118
  const platformProxy = proxy.withRequestContext(requestContext);
3992
- const botToken = (await platformProxy.getMetadata())?.botToken;
3993
- if (!botToken) throw new platformProxy.ActionError({
3994
- type: "invalid_metadata",
3995
- message: "botToken is required in metadata. Please configure the Discord bot token."
3996
- });
4119
+ const botToken = await resolveDiscordBotToken(platformProxy);
3997
4120
  await platformProxy.put({
3998
4121
  endpoint: `/api/v10/channels/${input.channel_id}/messages/${input.message_id}/reactions/${encodeURIComponent(input.emoji)}/@me`,
3999
4122
  headers: { Authorization: `Bot ${botToken}` },
@@ -4068,7 +4191,6 @@ const createRoleOutputSchema = z.object({
4068
4191
  tags: RoleTagsSchema$3.optional(),
4069
4192
  flags: z.number().int()
4070
4193
  });
4071
- z.object({ botToken: z.string() });
4072
4194
  function createRoleTool(proxy) {
4073
4195
  return createTool({
4074
4196
  id: "discord_create_role",
@@ -4077,11 +4199,7 @@ function createRoleTool(proxy) {
4077
4199
  outputSchema: createRoleOutputSchema,
4078
4200
  execute: async (input, { requestContext }) => {
4079
4201
  const platformProxy = proxy.withRequestContext(requestContext);
4080
- const botToken = (await platformProxy.getMetadata())?.botToken;
4081
- if (!botToken) throw new platformProxy.ActionError({
4082
- type: "invalid_metadata",
4083
- message: "botToken is required in metadata."
4084
- });
4202
+ const botToken = await resolveDiscordBotToken(platformProxy);
4085
4203
  const response = await platformProxy.post({
4086
4204
  endpoint: `/api/v10/guilds/${input.guildId}/roles`,
4087
4205
  headers: { Authorization: `Bot ${botToken}` },
@@ -4182,7 +4300,7 @@ function createThreadFromMessageTool(proxy) {
4182
4300
  outputSchema: createThreadFromMessageOutputSchema,
4183
4301
  execute: async (input, { requestContext }) => {
4184
4302
  const platformProxy = proxy.withRequestContext(requestContext);
4185
- const botToken = (await platformProxy.getMetadata())?.botToken || "";
4303
+ const botToken = await resolveDiscordBotToken(platformProxy);
4186
4304
  const requestData = { name: input.name };
4187
4305
  if (input.auto_archive_duration !== void 0) requestData["auto_archive_duration"] = input.auto_archive_duration;
4188
4306
  if (input.rate_limit_per_user !== void 0) requestData["rate_limit_per_user"] = input.rate_limit_per_user;
@@ -4256,10 +4374,6 @@ const createWebhookOutputSchema$1 = z.object({
4256
4374
  token: z.string().optional().describe("Webhook token (only for Incoming webhooks)"),
4257
4375
  applicationId: z.string().optional()
4258
4376
  });
4259
- z.object({
4260
- botToken: z.string().describe("Discord bot token for authentication"),
4261
- channelId: z.string().optional().describe("Optional default channel ID for creating webhooks")
4262
- });
4263
4377
  function createWebhookTool$1(proxy) {
4264
4378
  return createTool({
4265
4379
  id: "discord_create_webhook",
@@ -4268,13 +4382,9 @@ function createWebhookTool$1(proxy) {
4268
4382
  outputSchema: createWebhookOutputSchema$1,
4269
4383
  execute: async (input, { requestContext }) => {
4270
4384
  const platformProxy = proxy.withRequestContext(requestContext);
4385
+ const botToken = await resolveDiscordBotToken(platformProxy);
4271
4386
  const metadata = await platformProxy.getMetadata();
4272
- const botToken = metadata?.botToken;
4273
4387
  const channelId = input.channelId ?? metadata?.channelId;
4274
- if (!botToken) throw new platformProxy.ActionError({
4275
- type: "missing_metadata",
4276
- message: "botToken is required in connection metadata."
4277
- });
4278
4388
  if (!channelId) throw new platformProxy.ActionError({
4279
4389
  type: "missing_channel",
4280
4390
  message: "channelId is required in input or metadata."
@@ -4359,11 +4469,7 @@ function deleteChannelTool$1(proxy) {
4359
4469
  outputSchema: deleteChannelOutputSchema$1,
4360
4470
  execute: async (input, { requestContext }) => {
4361
4471
  const platformProxy = proxy.withRequestContext(requestContext);
4362
- const botToken = (await platformProxy.getMetadata())?.botToken;
4363
- if (!botToken) throw new platformProxy.ActionError({
4364
- type: "invalid_metadata",
4365
- message: "botToken is required in metadata. Please provide a Discord bot token."
4366
- });
4472
+ const botToken = await resolveDiscordBotToken(platformProxy);
4367
4473
  const response = await platformProxy.delete({
4368
4474
  endpoint: `/api/v10/channels/${input.channelId}`,
4369
4475
  headers: { Authorization: `Bot ${botToken}` },
@@ -4387,7 +4493,6 @@ function deleteChannelTool$1(proxy) {
4387
4493
  }
4388
4494
  //#endregion
4389
4495
  //#region src/providers/discord/tools/delete-guild-member.ts
4390
- z.object({ botToken: z.string().describe("Discord bot token for authentication") });
4391
4496
  const deleteGuildMemberInputSchema = z.object({
4392
4497
  guild_id: z.string().describe("Guild ID. Example: \"123456789012345678\""),
4393
4498
  user_id: z.string().describe("User ID of the member to delete. Example: \"987654321098765432\"")
@@ -4404,16 +4509,12 @@ function deleteGuildMemberTool(proxy) {
4404
4509
  outputSchema: deleteGuildMemberOutputSchema,
4405
4510
  execute: async (input, { requestContext }) => {
4406
4511
  const platformProxy = proxy.withRequestContext(requestContext);
4407
- const metadata = await platformProxy.getMetadata();
4408
- if (!metadata?.botToken) throw new platformProxy.ActionError({
4409
- type: "invalid_metadata",
4410
- message: "botToken is required in connection metadata"
4411
- });
4512
+ const botToken = await resolveDiscordBotToken(platformProxy);
4412
4513
  let response;
4413
4514
  try {
4414
4515
  response = await platformProxy.delete({
4415
4516
  endpoint: `/api/v10/guilds/${input.guild_id}/members/${input.user_id}`,
4416
- headers: { Authorization: `Bot ${metadata.botToken}` },
4517
+ headers: { Authorization: `Bot ${botToken}` },
4417
4518
  retries: 1
4418
4519
  });
4419
4520
  } catch (err) {
@@ -4436,7 +4537,6 @@ function deleteGuildMemberTool(proxy) {
4436
4537
  }
4437
4538
  //#endregion
4438
4539
  //#region src/providers/discord/tools/delete-guild.ts
4439
- const MetadataSchema$6 = z.object({ botToken: z.string().describe("Discord bot token from the Discord Developer Portal") });
4440
4540
  const deleteGuildInputSchema = z.object({ guild_id: z.string().describe("The ID of the guild for the bot to leave.") });
4441
4541
  const deleteGuildOutputSchema = z.object({
4442
4542
  success: z.boolean().describe("Whether the bot successfully left the guild"),
@@ -4450,13 +4550,7 @@ function deleteGuildTool(proxy) {
4450
4550
  outputSchema: deleteGuildOutputSchema,
4451
4551
  execute: async (input, { requestContext }) => {
4452
4552
  const platformProxy = proxy.withRequestContext(requestContext);
4453
- const metadata = await platformProxy.getMetadata();
4454
- const parsedMetadata = MetadataSchema$6.safeParse(metadata);
4455
- if (!parsedMetadata.success) throw new platformProxy.ActionError({
4456
- type: "invalid_metadata",
4457
- message: "botToken is required in metadata. Please configure the bot token in the connection metadata."
4458
- });
4459
- const botToken = parsedMetadata.data.botToken;
4553
+ const botToken = await resolveDiscordBotToken(platformProxy);
4460
4554
  const response = await platformProxy.delete({
4461
4555
  endpoint: `/api/v10/users/@me/guilds/${input.guild_id}`,
4462
4556
  headers: { Authorization: `Bot ${botToken}` },
@@ -4476,7 +4570,6 @@ function deleteGuildTool(proxy) {
4476
4570
  }
4477
4571
  //#endregion
4478
4572
  //#region src/providers/discord/tools/delete-message.ts
4479
- const MetadataSchema$5 = z.object({ botToken: z.string().describe("Discord bot token") });
4480
4573
  const deleteMessageInputSchema$2 = z.object({
4481
4574
  channelId: z.string().describe("Channel ID where the message exists. Example: \"1234567890123456789\""),
4482
4575
  messageId: z.string().describe("Message ID to delete. Example: \"9876543210987654321\"")
@@ -4494,12 +4587,7 @@ function deleteMessageTool$2(proxy) {
4494
4587
  outputSchema: deleteMessageOutputSchema$2,
4495
4588
  execute: async (input, { requestContext }) => {
4496
4589
  const platformProxy = proxy.withRequestContext(requestContext);
4497
- const metadata = MetadataSchema$5.safeParse(await platformProxy.getMetadata());
4498
- if (!metadata.success) throw new platformProxy.ActionError({
4499
- type: "invalid_metadata",
4500
- message: "Invalid metadata: botToken is required."
4501
- });
4502
- const botToken = metadata.data.botToken;
4590
+ const botToken = await resolveDiscordBotToken(platformProxy);
4503
4591
  await platformProxy.delete({
4504
4592
  endpoint: `/api/v10/channels/${input.channelId}/messages/${input.messageId}`,
4505
4593
  headers: { Authorization: `Bot ${botToken}` },
@@ -4529,11 +4617,7 @@ function deleteReactionTool(proxy) {
4529
4617
  outputSchema: deleteReactionOutputSchema,
4530
4618
  execute: async (input, { requestContext }) => {
4531
4619
  const platformProxy = proxy.withRequestContext(requestContext);
4532
- const botToken = (await platformProxy.getMetadata())?.botToken;
4533
- if (!botToken) throw new platformProxy.ActionError({
4534
- type: "invalid_metadata",
4535
- message: "botToken is required in metadata. Please configure the bot token from Discord Developer Portal."
4536
- });
4620
+ const botToken = await resolveDiscordBotToken(platformProxy);
4537
4621
  await platformProxy.delete({
4538
4622
  endpoint: `/api/v10/channels/${input.channel_id}/messages/${input.message_id}/reactions/${encodeURIComponent(input.emoji)}/@me`,
4539
4623
  headers: { Authorization: `Bot ${botToken}` },
@@ -4575,7 +4659,7 @@ function deleteRoleTool(proxy) {
4575
4659
  outputSchema: deleteRoleOutputSchema,
4576
4660
  execute: async (input, { requestContext }) => {
4577
4661
  const platformProxy = proxy.withRequestContext(requestContext);
4578
- const botToken = (await platformProxy.getMetadata())?.botToken;
4662
+ const botToken = await resolveDiscordBotToken(platformProxy);
4579
4663
  if (!botToken) throw new platformProxy.ActionError({
4580
4664
  type: "invalid_metadata",
4581
4665
  message: "botToken is required in metadata. Please provide the Discord bot token from your Discord application settings."
@@ -4609,11 +4693,7 @@ function deleteWebhookTool$1(proxy) {
4609
4693
  outputSchema: deleteWebhookOutputSchema$1,
4610
4694
  execute: async (input, { requestContext }) => {
4611
4695
  const platformProxy = proxy.withRequestContext(requestContext);
4612
- const botToken = (await platformProxy.getMetadata())?.botToken;
4613
- if (!botToken) throw new platformProxy.ActionError({
4614
- type: "invalid_metadata",
4615
- message: "botToken is required in metadata. Please ensure the Discord connection has a botToken configured."
4616
- });
4696
+ const botToken = await resolveDiscordBotToken(platformProxy);
4617
4697
  const response = await platformProxy.delete({
4618
4698
  endpoint: `/api/v10/webhooks/${input.webhookId}`,
4619
4699
  headers: { Authorization: `Bot ${botToken}` },
@@ -4717,14 +4797,10 @@ function getChannelTool$2(proxy) {
4717
4797
  outputSchema: getChannelOutputSchema$2,
4718
4798
  execute: async (input, { requestContext }) => {
4719
4799
  const platformProxy = proxy.withRequestContext(requestContext);
4720
- const metadata = await platformProxy.getMetadata();
4721
- if (!metadata?.botToken) throw new platformProxy.ActionError({
4722
- type: "invalid_metadata",
4723
- message: "botToken is required in metadata. Please set up the connection with botToken in metadata."
4724
- });
4800
+ const botToken = await resolveDiscordBotToken(platformProxy);
4725
4801
  const response = await platformProxy.get({
4726
4802
  endpoint: `/api/v10/channels/${input.channelId}`,
4727
- headers: { Authorization: `Bot ${metadata.botToken}` },
4803
+ headers: { Authorization: `Bot ${botToken}` },
4728
4804
  retries: 3
4729
4805
  });
4730
4806
  if (!response.data) throw new platformProxy.ActionError({
@@ -4823,14 +4899,10 @@ function getGuildMemberTool(proxy) {
4823
4899
  outputSchema: getGuildMemberOutputSchema,
4824
4900
  execute: async (input, { requestContext }) => {
4825
4901
  const platformProxy = proxy.withRequestContext(requestContext);
4826
- const metadata = await platformProxy.getMetadata();
4827
- if (!metadata?.botToken) throw new platformProxy.ActionError({
4828
- type: "invalid_metadata",
4829
- message: "botToken is required in metadata."
4830
- });
4902
+ const botToken = await resolveDiscordBotToken(platformProxy);
4831
4903
  const response = await platformProxy.get({
4832
4904
  endpoint: `/api/v10/guilds/${input.guild_id}/members/${input.user_id}`,
4833
- headers: { Authorization: `Bot ${metadata.botToken}` },
4905
+ headers: { Authorization: `Bot ${botToken}` },
4834
4906
  retries: 3
4835
4907
  });
4836
4908
  if (response.status === 404) throw new platformProxy.ActionError({
@@ -4873,11 +4945,7 @@ function getGuildTool(proxy) {
4873
4945
  outputSchema: getGuildOutputSchema,
4874
4946
  execute: async (input, { requestContext }) => {
4875
4947
  const platformProxy = proxy.withRequestContext(requestContext);
4876
- const botToken = (await platformProxy.getMetadata())?.botToken;
4877
- if (!botToken) throw new platformProxy.ActionError({
4878
- type: "invalid_metadata",
4879
- message: "botToken is required in metadata. Please configure the bot token from Discord Developer Portal."
4880
- });
4948
+ const botToken = await resolveDiscordBotToken(platformProxy);
4881
4949
  const response = await platformProxy.get({
4882
4950
  endpoint: `/api/v10/guilds/${input.guildId}`,
4883
4951
  headers: { Authorization: `Bot ${botToken}` },
@@ -4988,14 +5056,10 @@ function getMessageTool$1(proxy) {
4988
5056
  outputSchema: getMessageOutputSchema$1,
4989
5057
  execute: async (input, { requestContext }) => {
4990
5058
  const platformProxy = proxy.withRequestContext(requestContext);
4991
- const metadata = await platformProxy.getMetadata();
4992
- if (!metadata?.botToken) throw new platformProxy.ActionError({
4993
- type: "invalid_metadata",
4994
- message: "botToken is required in metadata."
4995
- });
5059
+ const botToken = await resolveDiscordBotToken(platformProxy);
4996
5060
  const response = await platformProxy.get({
4997
5061
  endpoint: `/api/v10/channels/${input.channelId}/messages/${input.messageId}`,
4998
- headers: { Authorization: `Bot ${metadata.botToken}` },
5062
+ headers: { Authorization: `Bot ${botToken}` },
4999
5063
  retries: 3
5000
5064
  });
5001
5065
  if (!response.data) throw new platformProxy.ActionError({
@@ -5106,14 +5170,10 @@ function getRoleTool(proxy) {
5106
5170
  outputSchema: getRoleOutputSchema,
5107
5171
  execute: async (input, { requestContext }) => {
5108
5172
  const platformProxy = proxy.withRequestContext(requestContext);
5109
- const metadata = await platformProxy.getMetadata();
5110
- if (!metadata?.botToken) throw new platformProxy.ActionError({
5111
- type: "invalid_metadata",
5112
- message: "botToken is required in metadata."
5113
- });
5173
+ const botToken = await resolveDiscordBotToken(platformProxy);
5114
5174
  const response = await platformProxy.get({
5115
5175
  endpoint: `/api/v10/guilds/${input.guild_id}/roles/${input.role_id}`,
5116
- headers: { Authorization: `Bot ${metadata.botToken}` },
5176
+ headers: { Authorization: `Bot ${botToken}` },
5117
5177
  retries: 3
5118
5178
  });
5119
5179
  if (!response.data) throw new platformProxy.ActionError({
@@ -5188,14 +5248,10 @@ function getWebhookTool$1(proxy) {
5188
5248
  outputSchema: getWebhookOutputSchema$1,
5189
5249
  execute: async (input, { requestContext }) => {
5190
5250
  const platformProxy = proxy.withRequestContext(requestContext);
5191
- const metadata = await platformProxy.getMetadata();
5192
- if (!metadata?.botToken) throw new platformProxy.ActionError({
5193
- type: "invalid_metadata",
5194
- message: "botToken is required in connection metadata."
5195
- });
5251
+ const botToken = await resolveDiscordBotToken(platformProxy);
5196
5252
  const response = await platformProxy.get({
5197
5253
  endpoint: `/api/v10/webhooks/${input.webhookId}`,
5198
- headers: { Authorization: `Bot ${metadata.botToken}` },
5254
+ headers: { Authorization: `Bot ${botToken}` },
5199
5255
  retries: 3
5200
5256
  });
5201
5257
  if (!response.data) throw new platformProxy.ActionError({
@@ -5243,7 +5299,7 @@ const ChannelSchema$2 = z.object({
5243
5299
  recipients: z.array(z.unknown()).optional(),
5244
5300
  icon: z.string().nullable().optional(),
5245
5301
  owner_id: z.string().optional(),
5246
- application_id: z.string().optional(),
5302
+ application_id: z.string().nullable().optional(),
5247
5303
  managed: z.boolean().optional(),
5248
5304
  parent_id: z.string().nullable().optional(),
5249
5305
  last_pin_timestamp: z.string().nullable().optional(),
@@ -5266,7 +5322,7 @@ function listChannelsTool$2(proxy) {
5266
5322
  outputSchema: listChannelsOutputSchema$2,
5267
5323
  execute: async (input, { requestContext }) => {
5268
5324
  const platformProxy = proxy.withRequestContext(requestContext);
5269
- const botToken = (await platformProxy.getMetadata())?.botToken;
5325
+ const botToken = await resolveDiscordBotToken(platformProxy);
5270
5326
  if (!botToken) throw new platformProxy.ActionError({
5271
5327
  type: "invalid_metadata",
5272
5328
  message: "botToken is required in metadata. Please configure the Discord connection with a bot token from your Discord application settings."
@@ -5359,12 +5415,7 @@ function listGuildMembersTool(proxy) {
5359
5415
  outputSchema: listGuildMembersOutputSchema,
5360
5416
  execute: async (input, { requestContext }) => {
5361
5417
  const platformProxy = proxy.withRequestContext(requestContext);
5362
- const metadata = await platformProxy.getMetadata();
5363
- const parsedMetadata = z.object({ botToken: z.string() }).safeParse(metadata);
5364
- if (!parsedMetadata.success) throw new platformProxy.ActionError({
5365
- type: "missing_bot_token",
5366
- message: "botToken is required in connection metadata."
5367
- });
5418
+ const botToken = await resolveDiscordBotToken(platformProxy);
5368
5419
  const limit = input.limit ?? 100;
5369
5420
  const response = await platformProxy.get({
5370
5421
  endpoint: `/api/v10/guilds/${input.guild_id}/members`,
@@ -5372,7 +5423,7 @@ function listGuildMembersTool(proxy) {
5372
5423
  limit: String(limit),
5373
5424
  ...input.after !== void 0 && { after: input.after }
5374
5425
  },
5375
- headers: { Authorization: `Bot ${parsedMetadata.data.botToken}` },
5426
+ headers: { Authorization: `Bot ${botToken}` },
5376
5427
  retries: 3
5377
5428
  });
5378
5429
  const rawMembers = z.array(z.unknown()).parse(response.data);
@@ -5442,11 +5493,7 @@ function listGuildsTool(proxy) {
5442
5493
  outputSchema: listGuildsOutputSchema,
5443
5494
  execute: async (input, { requestContext }) => {
5444
5495
  const platformProxy = proxy.withRequestContext(requestContext);
5445
- const botToken = (await platformProxy.getMetadata())?.botToken;
5446
- if (!botToken) throw new platformProxy.ActionError({
5447
- type: "invalid_metadata",
5448
- message: "botToken is required in metadata."
5449
- });
5496
+ const botToken = await resolveDiscordBotToken(platformProxy);
5450
5497
  const limit = input.limit ?? 200;
5451
5498
  const response = await platformProxy.get({
5452
5499
  endpoint: "/api/v10/users/@me/guilds",
@@ -5565,7 +5612,7 @@ function listMessagesTool$1(proxy) {
5565
5612
  outputSchema: listMessagesOutputSchema$1,
5566
5613
  execute: async (input, { requestContext }) => {
5567
5614
  const platformProxy = proxy.withRequestContext(requestContext);
5568
- const botToken = (await platformProxy.getMetadata())?.botToken;
5615
+ const botToken = await resolveDiscordBotToken(platformProxy);
5569
5616
  if (!botToken) throw new platformProxy.ActionError({
5570
5617
  type: "missing_bot_token",
5571
5618
  message: "Bot token is required in connection metadata. Please configure the bot token in your Nango connection."
@@ -5680,11 +5727,7 @@ function listRolesTool$1(proxy) {
5680
5727
  outputSchema: listRolesOutputSchema$1,
5681
5728
  execute: async (input, { requestContext }) => {
5682
5729
  const platformProxy = proxy.withRequestContext(requestContext);
5683
- const botToken = (await platformProxy.getMetadata())?.botToken;
5684
- if (!botToken) throw new platformProxy.ActionError({
5685
- type: "invalid_metadata",
5686
- message: "botToken is required in metadata."
5687
- });
5730
+ const botToken = await resolveDiscordBotToken(platformProxy);
5688
5731
  const response = await platformProxy.get({
5689
5732
  endpoint: `/api/v10/guilds/${input.guild_id}/roles`,
5690
5733
  headers: { Authorization: `Bot ${botToken}` },
@@ -5744,7 +5787,6 @@ const WebhookSchema = z.object({
5744
5787
  url: z.string().optional()
5745
5788
  });
5746
5789
  const listWebhooksOutputSchema$1 = z.object({ webhooks: z.array(WebhookSchema) });
5747
- z.object({ botToken: z.string() });
5748
5790
  function listWebhooksTool$1(proxy) {
5749
5791
  return createTool({
5750
5792
  id: "discord_list_webhooks",
@@ -5753,14 +5795,10 @@ function listWebhooksTool$1(proxy) {
5753
5795
  outputSchema: listWebhooksOutputSchema$1,
5754
5796
  execute: async (input, { requestContext }) => {
5755
5797
  const platformProxy = proxy.withRequestContext(requestContext);
5756
- const metadata = await platformProxy.getMetadata();
5757
- if (!metadata?.botToken) throw new platformProxy.ActionError({
5758
- type: "missing_bot_token",
5759
- message: "Bot token is required in connection metadata."
5760
- });
5798
+ const botToken = await resolveDiscordBotToken(platformProxy);
5761
5799
  const response = await platformProxy.get({
5762
5800
  endpoint: `/api/v10/channels/${input.channelId}/webhooks`,
5763
- headers: { Authorization: `Bot ${metadata.botToken}` },
5801
+ headers: { Authorization: `Bot ${botToken}` },
5764
5802
  retries: 3
5765
5803
  });
5766
5804
  return { webhooks: z.array(WebhookSchema).parse(response.data) };
@@ -5788,11 +5826,7 @@ function removeGuildMemberRoleTool(proxy) {
5788
5826
  outputSchema: removeGuildMemberRoleOutputSchema,
5789
5827
  execute: async (input, { requestContext }) => {
5790
5828
  const platformProxy = proxy.withRequestContext(requestContext);
5791
- const botToken = (await platformProxy.getMetadata())?.botToken;
5792
- if (!botToken) throw new platformProxy.ActionError({
5793
- type: "missing_bot_token",
5794
- message: "Bot token is required in metadata. Please configure the botToken in your connection metadata."
5795
- });
5829
+ const botToken = await resolveDiscordBotToken(platformProxy);
5796
5830
  const response = await platformProxy.delete({
5797
5831
  endpoint: `/api/v10/guilds/${input.guild_id}/members/${input.user_id}/roles/${input.role_id}`,
5798
5832
  headers: { Authorization: `Bot ${botToken}` },
@@ -5858,7 +5892,6 @@ const ProviderChannelSchema$7 = z.object({
5858
5892
  default_auto_archive_duration: z.number().int().optional(),
5859
5893
  flags: z.number().int().optional()
5860
5894
  });
5861
- const MetadataSchema$4 = z.object({ botToken: z.string() });
5862
5895
  const updateChannelOutputSchema$1 = z.object({
5863
5896
  id: z.string(),
5864
5897
  type: z.number().int(),
@@ -5889,12 +5922,7 @@ function updateChannelTool$1(proxy) {
5889
5922
  outputSchema: updateChannelOutputSchema$1,
5890
5923
  execute: async (input, { requestContext }) => {
5891
5924
  const platformProxy = proxy.withRequestContext(requestContext);
5892
- const rawMetadata = await platformProxy.getMetadata();
5893
- const metadata = MetadataSchema$4.safeParse(rawMetadata);
5894
- if (!metadata.success || !metadata.data.botToken) throw new platformProxy.ActionError({
5895
- type: "invalid_metadata",
5896
- message: "botToken is required in metadata. Please set the Discord bot token in the connection metadata."
5897
- });
5925
+ const botToken = await resolveDiscordBotToken(platformProxy);
5898
5926
  const updateData = {};
5899
5927
  if (input["name"] !== void 0) updateData["name"] = input["name"];
5900
5928
  if (input["type"] !== void 0) updateData["type"] = input["type"];
@@ -5910,7 +5938,7 @@ function updateChannelTool$1(proxy) {
5910
5938
  if (input["flags"] !== void 0) updateData["flags"] = input["flags"];
5911
5939
  const response = await platformProxy.patch({
5912
5940
  endpoint: `/api/v10/channels/${input.channel_id}`,
5913
- headers: { Authorization: `Bot ${metadata.data.botToken}` },
5941
+ headers: { Authorization: `Bot ${botToken}` },
5914
5942
  data: updateData,
5915
5943
  retries: 10
5916
5944
  });
@@ -6018,11 +6046,7 @@ function updateGuildMemberTool(proxy) {
6018
6046
  outputSchema: updateGuildMemberOutputSchema,
6019
6047
  execute: async (input, { requestContext }) => {
6020
6048
  const platformProxy = proxy.withRequestContext(requestContext);
6021
- const metadata = await platformProxy.getMetadata();
6022
- if (!metadata?.botToken) throw new platformProxy.ActionError({
6023
- type: "invalid_metadata",
6024
- message: "botToken is required in metadata. Please provide the bot token from your Discord application."
6025
- });
6049
+ const botToken = await resolveDiscordBotToken(platformProxy);
6026
6050
  const body = {};
6027
6051
  if (input["nick"] !== void 0) body["nick"] = input["nick"];
6028
6052
  if (input["roles"] !== void 0) body["roles"] = input["roles"];
@@ -6031,7 +6055,7 @@ function updateGuildMemberTool(proxy) {
6031
6055
  if (input["channel_id"] !== void 0) body["channel_id"] = input["channel_id"];
6032
6056
  if (input["communication_disabled_until"] !== void 0) body["communication_disabled_until"] = input["communication_disabled_until"];
6033
6057
  if (input["flags"] !== void 0) body["flags"] = input["flags"];
6034
- const headers = { Authorization: `Bot ${metadata.botToken}` };
6058
+ const headers = { Authorization: `Bot ${botToken}` };
6035
6059
  if (input.reason) headers["X-Audit-Log-Reason"] = input.reason;
6036
6060
  if (input["user_id"] === "@me") {
6037
6061
  const currentMemberBody = {};
@@ -6082,7 +6106,6 @@ function updateGuildMemberTool(proxy) {
6082
6106
  }
6083
6107
  //#endregion
6084
6108
  //#region src/providers/discord/tools/update-guild.ts
6085
- z.object({ botToken: z.string() });
6086
6109
  const updateGuildInputSchema = z.object({
6087
6110
  guild_id: z.string().describe("Guild ID to update. Example: \"197038439483310086\""),
6088
6111
  name: z.string().min(2).max(100).optional().describe("Guild name (2-100 characters)"),
@@ -6138,11 +6161,7 @@ function updateGuildTool(proxy) {
6138
6161
  outputSchema: updateGuildOutputSchema,
6139
6162
  execute: async (input, { requestContext }) => {
6140
6163
  const platformProxy = proxy.withRequestContext(requestContext);
6141
- const metadata = await platformProxy.getMetadata();
6142
- if (!metadata?.botToken) throw new platformProxy.ActionError({
6143
- type: "invalid_metadata",
6144
- message: "botToken is required in metadata."
6145
- });
6164
+ const botToken = await resolveDiscordBotToken(platformProxy);
6146
6165
  const payload = {};
6147
6166
  if (input.name !== void 0) payload["name"] = input.name;
6148
6167
  if (input.region !== void 0) payload["region"] = input.region;
@@ -6167,7 +6186,7 @@ function updateGuildTool(proxy) {
6167
6186
  if (input.safety_alerts_channel_id !== void 0) payload["safety_alerts_channel_id"] = input.safety_alerts_channel_id;
6168
6187
  const response = await platformProxy.patch({
6169
6188
  endpoint: `/api/v10/guilds/${input.guild_id}`,
6170
- headers: { Authorization: `Bot ${metadata.botToken}` },
6189
+ headers: { Authorization: `Bot ${botToken}` },
6171
6190
  data: payload,
6172
6191
  retries: 3
6173
6192
  });
@@ -6276,13 +6295,7 @@ function updateMessageTool$1(proxy) {
6276
6295
  outputSchema: updateMessageOutputSchema$1,
6277
6296
  execute: async (input, { requestContext }) => {
6278
6297
  const platformProxy = proxy.withRequestContext(requestContext);
6279
- const metadata = await platformProxy.getMetadata();
6280
- const parsedMetadata = z.object({ botToken: z.string() }).safeParse(metadata);
6281
- if (!parsedMetadata.success) throw new platformProxy.ActionError({
6282
- type: "invalid_metadata",
6283
- message: "botToken is required in metadata."
6284
- });
6285
- const botToken = parsedMetadata.data.botToken;
6298
+ const botToken = await resolveDiscordBotToken(platformProxy);
6286
6299
  const response = await platformProxy.patch({
6287
6300
  endpoint: `/api/v10/channels/${input.channel_id}/messages/${input.message_id}`,
6288
6301
  headers: { Authorization: `Bot ${botToken}` },
@@ -6368,11 +6381,7 @@ function updateRoleTool(proxy) {
6368
6381
  outputSchema: updateRoleOutputSchema,
6369
6382
  execute: async (input, { requestContext }) => {
6370
6383
  const platformProxy = proxy.withRequestContext(requestContext);
6371
- const botToken = (await platformProxy.getMetadata())?.botToken;
6372
- if (!botToken) throw new platformProxy.ActionError({
6373
- type: "invalid_metadata",
6374
- message: "botToken is required in metadata."
6375
- });
6384
+ const botToken = await resolveDiscordBotToken(platformProxy);
6376
6385
  if (input.icon !== void 0 && input.icon !== null && input.unicodeEmoji !== void 0 && input.unicodeEmoji !== null) throw new platformProxy.ActionError({
6377
6386
  type: "invalid_input",
6378
6387
  message: "icon and unicodeEmoji are mutually exclusive; provide at most one."
@@ -6455,12 +6464,7 @@ function updateWebhookTool$1(proxy) {
6455
6464
  outputSchema: updateWebhookOutputSchema$1,
6456
6465
  execute: async (input, { requestContext }) => {
6457
6466
  const platformProxy = proxy.withRequestContext(requestContext);
6458
- const metadata = await platformProxy.getMetadata();
6459
- const botToken = metadata && typeof metadata === "object" && "botToken" in metadata && typeof metadata.botToken === "string" ? metadata.botToken : void 0;
6460
- if (!botToken) throw new platformProxy.ActionError({
6461
- type: "invalid_metadata",
6462
- message: "botToken is required in metadata."
6463
- });
6467
+ const botToken = await resolveDiscordBotToken(platformProxy);
6464
6468
  const requestBody = {};
6465
6469
  if (input.name !== void 0) requestBody["name"] = input.name;
6466
6470
  if (input.avatar !== void 0) requestBody["avatar"] = input.avatar;
@@ -55360,7 +55364,7 @@ const cancelEmailInputSchema = z.object({ email_id: z.string() });
55360
55364
  const ProviderResponseSchema$107 = z.object({
55361
55365
  object: z.string().optional(),
55362
55366
  id: z.string().optional(),
55363
- message_id: z.string().optional(),
55367
+ message_id: z.string().nullable().optional(),
55364
55368
  to: z.array(z.string()).optional(),
55365
55369
  from: z.string().optional(),
55366
55370
  created_at: z.string().optional(),
@@ -56610,7 +56614,7 @@ const getEmailInputSchema = z.object({ email_id: z.string() });
56610
56614
  const ProviderResponseSchema$76 = z.object({
56611
56615
  object: z.string().optional(),
56612
56616
  id: z.string().optional(),
56613
- message_id: z.string().optional(),
56617
+ message_id: z.string().nullable().optional(),
56614
56618
  to: z.array(z.string()).optional(),
56615
56619
  from: z.string().optional(),
56616
56620
  created_at: z.string().optional(),
@@ -56697,7 +56701,7 @@ const ProviderResponseSchema$74 = z.object({
56697
56701
  to: z.array(z.string()).optional(),
56698
56702
  from: z.string().optional(),
56699
56703
  subject: z.string().optional(),
56700
- message_id: z.string().optional(),
56704
+ message_id: z.string().nullable().optional(),
56701
56705
  bcc: z.array(z.string()).nullable().optional(),
56702
56706
  cc: z.array(z.string()).nullable().optional(),
56703
56707
  reply_to: z.array(z.string()).nullable().optional(),
@@ -56771,7 +56775,7 @@ const ProviderResponseSchema$72 = z.object({
56771
56775
  current_version_id: z.string().optional(),
56772
56776
  name: z.string().optional(),
56773
56777
  alias: z.string().optional(),
56774
- from: z.string().optional(),
56778
+ from: z.string().nullable().optional(),
56775
56779
  subject: z.string().optional(),
56776
56780
  reply_to: z.array(z.string()).nullable().optional(),
56777
56781
  html: z.string().optional(),
@@ -57494,7 +57498,7 @@ const ProviderResponseSchema$57 = z.object({
57494
57498
  data: z.array(z.object({
57495
57499
  object: z.string().optional(),
57496
57500
  id: z.string().optional(),
57497
- message_id: z.string().optional(),
57501
+ message_id: z.string().nullable().optional(),
57498
57502
  to: z.array(z.string()).optional(),
57499
57503
  from: z.string().optional(),
57500
57504
  created_at: z.string().optional(),
@@ -57613,7 +57617,7 @@ const ProviderResponseSchema$55 = z.object({
57613
57617
  to: z.array(z.string()).optional(),
57614
57618
  from: z.string().optional(),
57615
57619
  subject: z.string().nullable().optional(),
57616
- message_id: z.string().optional(),
57620
+ message_id: z.string().nullable().optional(),
57617
57621
  bcc: z.array(z.string()).nullable().optional(),
57618
57622
  cc: z.array(z.string()).nullable().optional(),
57619
57623
  reply_to: z.array(z.string()).nullable().optional(),
@@ -58301,7 +58305,7 @@ function updateContactTopicsTool(proxy) {
58301
58305
  const config = {
58302
58306
  endpoint: `/contacts/${encodeURIComponent(input["contact_id"])}/topics`,
58303
58307
  retries: 3,
58304
- data: input.body
58308
+ data: input.body.topics
58305
58309
  };
58306
58310
  const response = await platformProxy.patch(config);
58307
58311
  return ProviderResponseSchema$39.parse(response.data);
@@ -74253,8 +74257,10 @@ let nextResolverId = 0;
74253
74257
  * to (or detached from) the project are picked up (or dropped) without a
74254
74258
  * restart.
74255
74259
  *
74256
- * Configuration errors (missing project id, bad ttlMs, malformed integration id)
74257
- * throw here — at call time — so they surface at startup.
74260
+ * Configuration errors (missing project id, bad ttlMs, malformed integration id,
74261
+ * the removed `autoApproveTools` key) throw here — at call time — so they
74262
+ * surface at startup. Configuration errors that need discovery to detect
74263
+ * (an unknown tool name in `requireApproval`) fail the resolution instead.
74258
74264
  * Expected provider absence is silently skipped. Actionable per-integration
74259
74265
  * problems during resolution (needs re-auth or ambiguity) are downgraded to
74260
74266
  * warn-and-skip so one bad integration never takes down the whole toolset.
@@ -74270,6 +74276,8 @@ function tools(options = {}) {
74270
74276
  const integrationOverrides = normalizeIntegrationOverrides(options.integrations);
74271
74277
  validateIntegrationOverrides(integrationOverrides);
74272
74278
  validateIntegrationXor(integrationOverrides);
74279
+ validateRequireApproval(integrationOverrides);
74280
+ rejectRemovedAutoApproveTools(integrationOverrides);
74273
74281
  let cache;
74274
74282
  let inflight;
74275
74283
  let closing;
@@ -74388,6 +74396,30 @@ function validateIntegrationXor(integrations) {
74388
74396
  if (filters.allowTools !== void 0 && filters.disallowTools !== void 0) throw new MastraConnectError("invalid_options", `Invalid options for '${integrationId}': allowTools and disallowTools are mutually exclusive; set at most one.`);
74389
74397
  }
74390
74398
  }
74399
+ /**
74400
+ * Rejects a `requireApproval` value that is not a boolean or an array of
74401
+ * string tool keys. The approval branches check for literal `true` or an
74402
+ * array, so a loosely typed value like `'true'` would otherwise disable
74403
+ * approval on MCP providers silently (and crash the HTTP path into
74404
+ * warn-and-skip) instead of gating tools as the author intended.
74405
+ */
74406
+ function validateRequireApproval(integrations) {
74407
+ for (const [integrationId, providerOptions] of Object.entries(integrations)) {
74408
+ const requireApproval = providerOptions.requireApproval;
74409
+ if (requireApproval === void 0 || typeof requireApproval === "boolean") continue;
74410
+ if (Array.isArray(requireApproval) && requireApproval.every((name) => typeof name === "string")) continue;
74411
+ throw new MastraConnectError("invalid_options", `Invalid options for '${integrationId}': requireApproval must be a boolean or an array of tool keys.`);
74412
+ }
74413
+ }
74414
+ /**
74415
+ * Rejects the removed `autoApproveTools` option by name. Discovered MCP tools
74416
+ * no longer require approval by default, so a loosely typed config still
74417
+ * carrying this key would otherwise be ignored silently and its tools would
74418
+ * run without the prompts the author expected.
74419
+ */
74420
+ function rejectRemovedAutoApproveTools(integrations) {
74421
+ for (const [integrationId, providerOptions] of Object.entries(integrations)) if ("autoApproveTools" in providerOptions) throw new MastraConnectError("invalid_options", `Invalid options for '${integrationId}': autoApproveTools was removed. Tools no longer require approval by default; opt in with requireApproval: true or a list of tool keys to gate.`);
74422
+ }
74391
74423
  function buildRequests(integrations, catalog) {
74392
74424
  const overrides = integrations;
74393
74425
  const registrations = new Map(TOOLS.map((registration) => [registration.integrationId, registration]));
@@ -74437,16 +74469,19 @@ async function mapTools(connections, requests, options, client, mcpClients, reso
74437
74469
  connectionId: resolution.connectionId,
74438
74470
  allowTools: request.options.allowTools,
74439
74471
  disallowTools: request.options.disallowTools,
74440
- autoApproveTools: request.options.autoApproveTools,
74472
+ requireApproval: request.options.requireApproval,
74441
74473
  client,
74442
74474
  mcpClients,
74443
74475
  resolverId
74444
74476
  });
74445
- } else providerTools = request.registration.createTools({
74446
- connectionId: resolution.connectionId,
74447
- client: options.client,
74448
- ...providerFilterOptions(request.options)
74449
- });
74477
+ } else {
74478
+ providerTools = request.registration.createTools({
74479
+ connectionId: resolution.connectionId,
74480
+ client: options.client,
74481
+ ...providerFilterOptions(request.options)
74482
+ });
74483
+ applyProxyRequireApproval(providerTools, integrationId, request.options.requireApproval);
74484
+ }
74450
74485
  else if (request.registration.transport === "mcp") {
74451
74486
  for (const connection of resolution.connections) activeMcpKeys.add(`${integrationId}::${connection.id}`);
74452
74487
  providerTools = await buildMcpMultiConnectionTools({
@@ -74454,19 +74489,23 @@ async function mapTools(connections, requests, options, client, mcpClients, reso
74454
74489
  connections: resolution.connections,
74455
74490
  allowTools: request.options.allowTools,
74456
74491
  disallowTools: request.options.disallowTools,
74457
- autoApproveTools: request.options.autoApproveTools,
74492
+ requireApproval: request.options.requireApproval,
74458
74493
  client,
74459
74494
  mcpClients,
74460
74495
  resolverId
74461
74496
  });
74462
- } else providerTools = buildProxyMultiConnectionTools({
74463
- registration: request.registration,
74464
- connections: resolution.connections,
74465
- allowTools: request.options.allowTools,
74466
- disallowTools: request.options.disallowTools,
74467
- client: options.client
74468
- });
74497
+ } else {
74498
+ providerTools = buildProxyMultiConnectionTools({
74499
+ registration: request.registration,
74500
+ connections: resolution.connections,
74501
+ allowTools: request.options.allowTools,
74502
+ disallowTools: request.options.disallowTools,
74503
+ client: options.client
74504
+ });
74505
+ applyProxyRequireApproval(providerTools, integrationId, request.options.requireApproval, [listConnectionsToolKey(integrationId)]);
74506
+ }
74469
74507
  } catch (error) {
74508
+ if (error instanceof MastraConnectConfigError) throw error;
74470
74509
  console.warn(`[@mastra/connect] Skipping ${integrationId}: ${error instanceof Error ? error.message : String(error)}`);
74471
74510
  continue;
74472
74511
  }
@@ -74490,9 +74529,33 @@ async function mapTools(connections, requests, options, client, mcpClients, reso
74490
74529
  function providerFilterOptions(options) {
74491
74530
  return options.allowTools !== void 0 ? { allowTools: options.allowTools } : options.disallowTools !== void 0 ? { disallowTools: options.disallowTools } : {};
74492
74531
  }
74532
+ /**
74533
+ * Applies a per-provider `requireApproval` policy to a checked-in HTTP
74534
+ * toolset by marking the selected tools. `true` gates every provider tool
74535
+ * (but never the synthetic `<provider>__list_connections` wrapper tool,
74536
+ * matching the MCP paths, where only server-discovered tools are gated);
74537
+ * an array gates the listed keys and rejects unknown names with the same
74538
+ * `invalid_options` error MCP discovery raises, so a typo never silently
74539
+ * widens access.
74540
+ */
74541
+ function applyProxyRequireApproval(providerTools, integrationId, requireApproval, excludeKeys = []) {
74542
+ if (!requireApproval) return;
74543
+ if (requireApproval === true) {
74544
+ const excluded = new Set(excludeKeys);
74545
+ for (const [toolKey, tool] of Object.entries(providerTools)) {
74546
+ if (excluded.has(toolKey)) continue;
74547
+ tool.requireApproval = true;
74548
+ }
74549
+ return;
74550
+ }
74551
+ const known = Object.keys(providerTools);
74552
+ const unknown = requireApproval.filter((name) => !known.includes(name));
74553
+ if (unknown.length > 0) throw new MastraConnectConfigError(`Unknown tool name(s) in requireApproval for '${integrationId}': ${unknown.join(", ")}. Known tools: ${known.join(", ")}.`);
74554
+ for (const name of requireApproval) providerTools[name].requireApproval = true;
74555
+ }
74493
74556
  async function discoverMcpTools(input) {
74494
- const { registration, connectionId, allowTools, disallowTools, autoApproveTools, client, mcpClients, resolverId } = input;
74495
- const autoApproved = new Set(autoApproveTools ?? []);
74557
+ const { registration, connectionId, allowTools, disallowTools, requireApproval, client, mcpClients, resolverId } = input;
74558
+ const requireApprovalFor = Array.isArray(requireApproval) ? new Set(requireApproval) : void 0;
74496
74559
  const cacheKey = `${registration.integrationId}::${connectionId}`;
74497
74560
  let entry = mcpClients.get(cacheKey);
74498
74561
  if (!entry) {
@@ -74504,7 +74567,7 @@ async function discoverMcpTools(input) {
74504
74567
  id: `mastra-connect-${resolverId}-${registration.integrationId}-${connectionId}`,
74505
74568
  servers: { [registration.integrationId]: {
74506
74569
  ...transport,
74507
- requireToolApproval: ({ toolName }) => !autoApproved.has(`${registration.integrationId}_${String(toolName)}`)
74570
+ ...requireApproval === true ? { requireToolApproval: true } : requireApprovalFor ? { requireToolApproval: ({ toolName }) => requireApprovalFor.has(`${registration.integrationId}_${String(toolName)}`) } : {}
74508
74571
  } }
74509
74572
  })
74510
74573
  };
@@ -74513,8 +74576,10 @@ async function discoverMcpTools(input) {
74513
74576
  const discovery = await entry.client.listToolsWithErrors();
74514
74577
  const error = discovery.errors[registration.integrationId];
74515
74578
  if (error) throw new Error(`MCP tool discovery failed: ${error}`);
74516
- const unknown = [...autoApproved].filter((name) => !(name in discovery.tools));
74517
- if (unknown.length > 0) throw new MastraConnectError("invalid_options", `Unknown tool name(s) in autoApproveTools for '${registration.integrationId}': ${unknown.join(", ")}. Known tools: ${Object.keys(discovery.tools).join(", ")}.`);
74579
+ if (requireApprovalFor) {
74580
+ const unknown = [...requireApprovalFor].filter((name) => !(name in discovery.tools));
74581
+ if (unknown.length > 0) throw new MastraConnectConfigError(`Unknown tool name(s) in requireApproval for '${registration.integrationId}': ${unknown.join(", ")}. Known tools: ${Object.keys(discovery.tools).join(", ")}.`);
74582
+ }
74518
74583
  return applyToolFilter(discovery.tools, {
74519
74584
  allowTools,
74520
74585
  disallowTools
@@ -74616,6 +74681,7 @@ async function channels(options = {}) {
74616
74681
  let cache;
74617
74682
  let inflight;
74618
74683
  let lastFailureAt;
74684
+ let warnedStaleSlackConnection = false;
74619
74685
  const buildSnapshot = async () => {
74620
74686
  let connections;
74621
74687
  try {
@@ -74626,6 +74692,10 @@ async function channels(options = {}) {
74626
74692
  }
74627
74693
  const byIntegrationId = groupByIntegrationId(connections);
74628
74694
  const providers = {};
74695
+ if (!warnedStaleSlackConnection && states.some((state) => state.registration.integrationId === "slack-channels") && (byIntegrationId.get("slack")?.length ?? 0) > 0 && (byIntegrationId.get("slack-channels")?.length ?? 0) === 0) {
74696
+ warnedStaleSlackConnection = true;
74697
+ console.warn(`[@mastra/connect] Project ${projectId} has an active 'slack' connection but no 'slack-channels' connection: the Slack channel is now keyed off 'slack-channels'. Connect Slack again as 'slack-channels' to restore it; the existing 'slack' connection still powers the generated Slack tools.`);
74698
+ }
74629
74699
  for (const state of states) {
74630
74700
  const integrationId = state.registration.integrationId;
74631
74701
  const overrides = options.integrations?.[integrationId] ?? {};
@@ -74737,7 +74807,9 @@ async function credential(connectionId, options) {
74737
74807
  //#endregion
74738
74808
  //#region src/environment.ts
74739
74809
  function credentialToken(credential) {
74740
- return credential.type === "oauth2" ? credential.accessToken : credential.apiKey;
74810
+ if (credential.type === "oauth2") return credential.accessToken;
74811
+ if (credential.type === "two_step") return credential.token;
74812
+ return credential.apiKey;
74741
74813
  }
74742
74814
  /**
74743
74815
  * Wires git's credential helper to read the token from the environment at use