@mastra/connect 0.7.0-alpha.1 → 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 (66) 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 +391 -201
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.js +391 -201
  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/tools/list-channels.d.ts +2 -2
  55. package/dist/providers/discord/tools/list-channels.d.ts.map +1 -1
  56. package/dist/providers/resend/tools/cancel-email.d.ts +2 -2
  57. package/dist/providers/resend/tools/get-email.d.ts +2 -2
  58. package/dist/providers/resend/tools/get-received-email.d.ts +2 -2
  59. package/dist/providers/resend/tools/get-template.d.ts +2 -2
  60. package/dist/providers/resend/tools/list-emails.d.ts +2 -2
  61. package/dist/providers/resend/tools/list-received-emails.d.ts +2 -2
  62. package/dist/providers/resend/tools/update-contact-topics.d.ts.map +1 -1
  63. package/dist/runtime/platform-proxy.d.ts.map +1 -1
  64. package/dist/tools.d.ts +12 -7
  65. package/dist/tools.d.ts.map +1 -1
  66. 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
  };
@@ -796,17 +881,42 @@ const CHANNELS$1 = [
796
881
  }
797
882
  };
798
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
+ }
799
903
  }
800
904
  ];
801
905
  //#endregion
802
906
  //#region src/runtime/platform-proxy.ts
803
907
  /** Maps the platform credential to the field names templates are written against. */
804
908
  function toTemplateCredentials(credential) {
805
- return credential.type === "oauth2" ? {
909
+ if (credential.type === "oauth2") return {
806
910
  type: "OAUTH2",
807
911
  access_token: credential.accessToken,
808
912
  expires_at: credential.expiresAt
809
- } : {
913
+ };
914
+ if (credential.type === "two_step") return {
915
+ type: "TWO_STEP",
916
+ token: credential.token,
917
+ expires_at: credential.expiresAt
918
+ };
919
+ return {
810
920
  type: "API_KEY",
811
921
  apiKey: credential.apiKey
812
922
  };
@@ -1734,8 +1844,8 @@ const anthropicProvider = {
1734
1844
  //#endregion
1735
1845
  //#region src/providers/clerk/tools/assign-organization-role-permission.ts
1736
1846
  const assignOrganizationRolePermissionInputSchema = z.object({
1737
- organization_role_id: z.string(),
1738
- permission_id: z.string()
1847
+ organization_role_id: z.string().min(1),
1848
+ permission_id: z.string().min(1)
1739
1849
  });
1740
1850
  const ResourceSchema$49 = z.object({
1741
1851
  id: z.string(),
@@ -1771,8 +1881,8 @@ function assignOrganizationRolePermissionTool(proxy) {
1771
1881
  //#endregion
1772
1882
  //#region src/providers/clerk/tools/create-email-address.ts
1773
1883
  const createEmailAddressInputSchema = z.object({
1774
- user_id: z.string(),
1775
- email_address: z.string(),
1884
+ user_id: z.string().min(1),
1885
+ email_address: z.string().email(),
1776
1886
  verified: z.boolean().optional(),
1777
1887
  primary: z.boolean().optional(),
1778
1888
  notify_primary_email_address_changed: z.boolean().optional()
@@ -1817,16 +1927,22 @@ function createEmailAddressTool(proxy) {
1817
1927
  }
1818
1928
  //#endregion
1819
1929
  //#region src/providers/clerk/tools/create-organization-domain.ts
1820
- const EnrollmentModeSchema$2 = z.enum([
1930
+ const EnrollmentModeSchema$3 = z.enum([
1821
1931
  "manual_invitation",
1822
1932
  "automatic_invitation",
1823
1933
  "automatic_suggestion",
1824
1934
  "enterprise_sso"
1825
1935
  ]);
1936
+ const EnrollmentModeSchemaWidened$2 = z.enum([
1937
+ "manual_invitation",
1938
+ "automatic_invitation",
1939
+ "automatic_suggestion",
1940
+ "enterprise_sso"
1941
+ ]).or(z.string());
1826
1942
  const createOrganizationDomainInputSchema$1 = z.object({
1827
- organization_id: z.string(),
1943
+ organization_id: z.string().min(1),
1828
1944
  name: z.string(),
1829
- enrollment_mode: EnrollmentModeSchema$2,
1945
+ enrollment_mode: EnrollmentModeSchema$3,
1830
1946
  verified: z.boolean().optional()
1831
1947
  });
1832
1948
  const ResourceSchema$47 = z.object({
@@ -1834,15 +1950,15 @@ const ResourceSchema$47 = z.object({
1834
1950
  object: z.string().optional(),
1835
1951
  organization_id: z.string().optional(),
1836
1952
  name: z.string(),
1837
- enrollment_mode: EnrollmentModeSchema$2.optional(),
1953
+ enrollment_mode: EnrollmentModeSchemaWidened$2.optional(),
1838
1954
  affiliation_verification: z.object({
1839
1955
  attempts: z.number().optional(),
1840
1956
  status: z.string().optional()
1841
- }).passthrough().optional(),
1957
+ }).passthrough().nullable().optional(),
1842
1958
  verification: z.object({
1843
1959
  attempts: z.number().optional(),
1844
1960
  status: z.string().optional()
1845
- }).passthrough().optional(),
1961
+ }).passthrough().nullable().optional(),
1846
1962
  verified: z.boolean().optional(),
1847
1963
  created_at: z.number().optional(),
1848
1964
  updated_at: z.number().optional()
@@ -1871,7 +1987,7 @@ function createOrganizationDomainTool$1(proxy) {
1871
1987
  //#endregion
1872
1988
  //#region src/providers/clerk/tools/create-organization-invitation.ts
1873
1989
  const createOrganizationInvitationInputSchema = z.object({
1874
- organization_id: z.string(),
1990
+ organization_id: z.string().min(1),
1875
1991
  email_address: z.string().email(),
1876
1992
  role: z.string(),
1877
1993
  inviter_user_id: z.string().optional(),
@@ -1892,7 +2008,7 @@ const ResourceSchema$46 = z.object({
1892
2008
  "accepted",
1893
2009
  "revoked",
1894
2010
  "expired"
1895
- ]).optional(),
2011
+ ]).or(z.string()).optional(),
1896
2012
  created_at: z.number().optional(),
1897
2013
  updated_at: z.number().optional()
1898
2014
  }).passthrough();
@@ -1925,8 +2041,8 @@ function createOrganizationInvitationTool(proxy) {
1925
2041
  //#endregion
1926
2042
  //#region src/providers/clerk/tools/create-organization-membership.ts
1927
2043
  const createOrganizationMembershipInputSchema$1 = z.object({
1928
- organization_id: z.string(),
1929
- user_id: z.string(),
2044
+ organization_id: z.string().min(1),
2045
+ user_id: z.string().min(1),
1930
2046
  role: z.string(),
1931
2047
  public_metadata: z.record(z.string(), z.unknown()).optional(),
1932
2048
  private_metadata: z.record(z.string(), z.unknown()).optional()
@@ -2062,7 +2178,7 @@ function createOrganizationTool$1(proxy) {
2062
2178
  //#endregion
2063
2179
  //#region src/providers/clerk/tools/create-phone-number.ts
2064
2180
  const createPhoneNumberInputSchema = z.object({
2065
- user_id: z.string(),
2181
+ user_id: z.string().min(1),
2066
2182
  phone_number: z.string(),
2067
2183
  verified: z.boolean().optional(),
2068
2184
  primary: z.boolean().optional(),
@@ -2125,7 +2241,7 @@ const createUserInputSchema$2 = z.object({
2125
2241
  public_metadata: z.record(z.string(), z.unknown()).optional(),
2126
2242
  private_metadata: z.record(z.string(), z.unknown()).optional(),
2127
2243
  unsafe_metadata: z.record(z.string(), z.unknown()).optional()
2128
- });
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." });
2129
2245
  const UserSchema$27 = z.object({
2130
2246
  id: z.string(),
2131
2247
  object: z.string().optional(),
@@ -2177,7 +2293,7 @@ function createUserTool$2(proxy) {
2177
2293
  }
2178
2294
  //#endregion
2179
2295
  //#region src/providers/clerk/tools/delete-email-address.ts
2180
- const deleteEmailAddressInputSchema = z.object({ email_address_id: z.string() });
2296
+ const deleteEmailAddressInputSchema = z.object({ email_address_id: z.string().min(1) });
2181
2297
  const deleteEmailAddressOutputSchema = z.object({
2182
2298
  id: z.string(),
2183
2299
  success: z.boolean()
@@ -2203,8 +2319,8 @@ function deleteEmailAddressTool(proxy) {
2203
2319
  //#endregion
2204
2320
  //#region src/providers/clerk/tools/delete-organization-domain.ts
2205
2321
  const deleteOrganizationDomainInputSchema$1 = z.object({
2206
- organization_id: z.string(),
2207
- domain_id: z.string()
2322
+ organization_id: z.string().min(1),
2323
+ domain_id: z.string().min(1)
2208
2324
  });
2209
2325
  const deleteOrganizationDomainOutputSchema$1 = z.object({
2210
2326
  id: z.string(),
@@ -2231,8 +2347,8 @@ function deleteOrganizationDomainTool$1(proxy) {
2231
2347
  //#endregion
2232
2348
  //#region src/providers/clerk/tools/delete-organization-membership.ts
2233
2349
  const deleteOrganizationMembershipInputSchema$1 = z.object({
2234
- organization_id: z.string(),
2235
- user_id: z.string()
2350
+ organization_id: z.string().min(1),
2351
+ user_id: z.string().min(1)
2236
2352
  });
2237
2353
  const deleteOrganizationMembershipOutputSchema$1 = z.object({
2238
2354
  id: z.string(),
@@ -2258,7 +2374,7 @@ function deleteOrganizationMembershipTool$1(proxy) {
2258
2374
  }
2259
2375
  //#endregion
2260
2376
  //#region src/providers/clerk/tools/delete-organization-role.ts
2261
- const deleteOrganizationRoleInputSchema = z.object({ organization_role_id: z.string() });
2377
+ const deleteOrganizationRoleInputSchema = z.object({ organization_role_id: z.string().min(1) });
2262
2378
  const deleteOrganizationRoleOutputSchema = z.object({
2263
2379
  id: z.string(),
2264
2380
  success: z.boolean()
@@ -2308,7 +2424,7 @@ function deleteOrganizationTool$1(proxy) {
2308
2424
  }
2309
2425
  //#endregion
2310
2426
  //#region src/providers/clerk/tools/delete-phone-number.ts
2311
- const deletePhoneNumberInputSchema = z.object({ phone_number_id: z.string() });
2427
+ const deletePhoneNumberInputSchema = z.object({ phone_number_id: z.string().min(1) });
2312
2428
  const deletePhoneNumberOutputSchema = z.object({
2313
2429
  id: z.string(),
2314
2430
  success: z.boolean()
@@ -2358,7 +2474,7 @@ function deleteUserTool$2(proxy) {
2358
2474
  }
2359
2475
  //#endregion
2360
2476
  //#region src/providers/clerk/tools/get-email-address.ts
2361
- const getEmailAddressInputSchema = z.object({ email_address_id: z.string() });
2477
+ const getEmailAddressInputSchema = z.object({ email_address_id: z.string().min(1) });
2362
2478
  const ResourceSchema$42 = z.object({
2363
2479
  id: z.string(),
2364
2480
  object: z.string().optional(),
@@ -2393,8 +2509,8 @@ function getEmailAddressTool(proxy) {
2393
2509
  //#endregion
2394
2510
  //#region src/providers/clerk/tools/get-organization-invitation.ts
2395
2511
  const getOrganizationInvitationInputSchema = z.object({
2396
- organization_id: z.string(),
2397
- invitation_id: z.string()
2512
+ organization_id: z.string().min(1),
2513
+ invitation_id: z.string().min(1)
2398
2514
  });
2399
2515
  const ResourceSchema$41 = z.object({
2400
2516
  id: z.string(),
@@ -2407,7 +2523,7 @@ const ResourceSchema$41 = z.object({
2407
2523
  "accepted",
2408
2524
  "revoked",
2409
2525
  "expired"
2410
- ]).optional(),
2526
+ ]).or(z.string()).optional(),
2411
2527
  created_at: z.number().optional(),
2412
2528
  updated_at: z.number().optional()
2413
2529
  }).passthrough();
@@ -2429,7 +2545,7 @@ function getOrganizationInvitationTool(proxy) {
2429
2545
  }
2430
2546
  //#endregion
2431
2547
  //#region src/providers/clerk/tools/get-organization-role.ts
2432
- const getOrganizationRoleInputSchema = z.object({ organization_role_id: z.string() });
2548
+ const getOrganizationRoleInputSchema = z.object({ organization_role_id: z.string().min(1) });
2433
2549
  const ResourceSchema$40 = z.object({
2434
2550
  id: z.string(),
2435
2551
  object: z.string().optional(),
@@ -2501,7 +2617,7 @@ function getOrganizationTool$1(proxy) {
2501
2617
  }
2502
2618
  //#endregion
2503
2619
  //#region src/providers/clerk/tools/get-phone-number.ts
2504
- const getPhoneNumberInputSchema = z.object({ phone_number_id: z.string() });
2620
+ const getPhoneNumberInputSchema = z.object({ phone_number_id: z.string().min(1) });
2505
2621
  const ResourceSchema$39 = z.object({
2506
2622
  id: z.string(),
2507
2623
  object: z.string().optional(),
@@ -2536,7 +2652,7 @@ function getPhoneNumberTool(proxy) {
2536
2652
  }
2537
2653
  //#endregion
2538
2654
  //#region src/providers/clerk/tools/get-session.ts
2539
- const getSessionInputSchema = z.object({ session_id: z.string() });
2655
+ const getSessionInputSchema = z.object({ session_id: z.string().min(1) });
2540
2656
  const ResourceSchema$38 = z.object({
2541
2657
  id: z.string(),
2542
2658
  object: z.string().optional(),
@@ -2550,7 +2666,7 @@ const ResourceSchema$38 = z.object({
2550
2666
  "removed",
2551
2667
  "replaced",
2552
2668
  "revoked"
2553
- ]).optional(),
2669
+ ]).or(z.string()).optional(),
2554
2670
  last_active_at: z.number().optional(),
2555
2671
  expire_at: z.number().optional(),
2556
2672
  abandon_at: z.number().optional(),
@@ -2610,33 +2726,39 @@ function getUserTool$7(proxy) {
2610
2726
  }
2611
2727
  //#endregion
2612
2728
  //#region src/providers/clerk/tools/list-organization-domains.ts
2613
- const EnrollmentModeSchema$1 = z.enum([
2729
+ const EnrollmentModeSchema$2 = z.enum([
2614
2730
  "manual_invitation",
2615
2731
  "automatic_invitation",
2616
2732
  "automatic_suggestion",
2617
2733
  "enterprise_sso"
2618
2734
  ]);
2735
+ const EnrollmentModeSchemaWidened$1 = z.enum([
2736
+ "manual_invitation",
2737
+ "automatic_invitation",
2738
+ "automatic_suggestion",
2739
+ "enterprise_sso"
2740
+ ]).or(z.string());
2619
2741
  const listOrganizationDomainsInputSchema = z.object({
2620
- 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."),
2621
2743
  limit: z.number().int().min(1).max(500).optional(),
2622
- organization_id: z.string(),
2744
+ organization_id: z.string().min(1),
2623
2745
  verified: z.boolean().optional(),
2624
- enrollment_mode: EnrollmentModeSchema$1.optional()
2746
+ enrollment_mode: EnrollmentModeSchema$2.optional()
2625
2747
  });
2626
2748
  const ResourceSchema$37 = z.object({
2627
2749
  id: z.string(),
2628
2750
  object: z.string().optional(),
2629
2751
  organization_id: z.string().optional(),
2630
2752
  name: z.string(),
2631
- enrollment_mode: EnrollmentModeSchema$1.optional(),
2753
+ enrollment_mode: EnrollmentModeSchemaWidened$1.optional(),
2632
2754
  affiliation_verification: z.object({
2633
2755
  attempts: z.number().optional(),
2634
2756
  status: z.string().optional()
2635
- }).passthrough().optional(),
2757
+ }).passthrough().nullable().optional(),
2636
2758
  verification: z.object({
2637
2759
  attempts: z.number().optional(),
2638
2760
  status: z.string().optional()
2639
- }).passthrough().optional(),
2761
+ }).passthrough().nullable().optional(),
2640
2762
  verified: z.boolean().optional(),
2641
2763
  created_at: z.number().optional(),
2642
2764
  updated_at: z.number().optional()
@@ -2647,7 +2769,7 @@ const ProviderResponseSchema$244 = z.object({
2647
2769
  });
2648
2770
  const listOrganizationDomainsOutputSchema = z.object({
2649
2771
  items: z.array(ResourceSchema$37),
2650
- 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."),
2651
2773
  total: z.number()
2652
2774
  });
2653
2775
  function listOrganizationDomainsTool(proxy) {
@@ -2658,11 +2780,7 @@ function listOrganizationDomainsTool(proxy) {
2658
2780
  outputSchema: listOrganizationDomainsOutputSchema,
2659
2781
  execute: async (input, { requestContext }) => {
2660
2782
  const platformProxy = proxy.withRequestContext(requestContext);
2661
- const offset = input.cursor === void 0 ? 0 : Number.parseInt(input.cursor, 10);
2662
- if (!Number.isInteger(offset) || offset < 0) throw new platformProxy.ActionError({
2663
- type: "invalid_cursor",
2664
- message: "Cursor must be a non-negative integer."
2665
- });
2783
+ const offset = input.cursor === void 0 ? 0 : Number(input.cursor);
2666
2784
  const response = await platformProxy.get({
2667
2785
  endpoint: `/v1/organizations/${encodeURIComponent(input.organization_id)}/domains`,
2668
2786
  params: {
@@ -2686,9 +2804,9 @@ function listOrganizationDomainsTool(proxy) {
2686
2804
  //#endregion
2687
2805
  //#region src/providers/clerk/tools/list-organization-invitations.ts
2688
2806
  const listOrganizationInvitationsInputSchema = z.object({
2689
- 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."),
2690
2808
  limit: z.number().int().min(1).max(500).optional(),
2691
- organization_id: z.string(),
2809
+ organization_id: z.string().min(1),
2692
2810
  status: z.enum([
2693
2811
  "pending",
2694
2812
  "accepted",
@@ -2709,7 +2827,7 @@ const ResourceSchema$36 = z.object({
2709
2827
  "accepted",
2710
2828
  "revoked",
2711
2829
  "expired"
2712
- ]).optional(),
2830
+ ]).or(z.string()).optional(),
2713
2831
  created_at: z.number().optional(),
2714
2832
  updated_at: z.number().optional()
2715
2833
  }).passthrough();
@@ -2719,7 +2837,7 @@ const ProviderResponseSchema$243 = z.object({
2719
2837
  });
2720
2838
  const listOrganizationInvitationsOutputSchema = z.object({
2721
2839
  items: z.array(ResourceSchema$36),
2722
- 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."),
2723
2841
  total: z.number()
2724
2842
  });
2725
2843
  function listOrganizationInvitationsTool(proxy) {
@@ -2730,11 +2848,7 @@ function listOrganizationInvitationsTool(proxy) {
2730
2848
  outputSchema: listOrganizationInvitationsOutputSchema,
2731
2849
  execute: async (input, { requestContext }) => {
2732
2850
  const platformProxy = proxy.withRequestContext(requestContext);
2733
- const offset = input.cursor === void 0 ? 0 : Number.parseInt(input.cursor, 10);
2734
- if (!Number.isInteger(offset) || offset < 0) throw new platformProxy.ActionError({
2735
- type: "invalid_cursor",
2736
- message: "Cursor must be a non-negative integer."
2737
- });
2851
+ const offset = input.cursor === void 0 ? 0 : Number(input.cursor);
2738
2852
  const response = await platformProxy.get({
2739
2853
  endpoint: `/v1/organizations/${encodeURIComponent(input.organization_id)}/invitations`,
2740
2854
  params: {
@@ -2759,9 +2873,9 @@ function listOrganizationInvitationsTool(proxy) {
2759
2873
  //#endregion
2760
2874
  //#region src/providers/clerk/tools/list-organization-memberships.ts
2761
2875
  const listOrganizationMembershipsInputSchema$1 = z.object({
2762
- 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."),
2763
2877
  limit: z.number().int().min(1).max(500).optional(),
2764
- organization_id: z.string(),
2878
+ organization_id: z.string().min(1),
2765
2879
  user_id: z.array(z.string()).optional(),
2766
2880
  email_address: z.array(z.string()).optional(),
2767
2881
  phone_number: z.array(z.string()).optional(),
@@ -2795,7 +2909,7 @@ const ProviderResponseSchema$242 = z.object({
2795
2909
  });
2796
2910
  const listOrganizationMembershipsOutputSchema$1 = z.object({
2797
2911
  items: z.array(ResourceSchema$35),
2798
- 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."),
2799
2913
  total: z.number()
2800
2914
  });
2801
2915
  function listOrganizationMembershipsTool$1(proxy) {
@@ -2806,11 +2920,7 @@ function listOrganizationMembershipsTool$1(proxy) {
2806
2920
  outputSchema: listOrganizationMembershipsOutputSchema$1,
2807
2921
  execute: async (input, { requestContext }) => {
2808
2922
  const platformProxy = proxy.withRequestContext(requestContext);
2809
- const offset = input.cursor === void 0 ? 0 : Number.parseInt(input.cursor, 10);
2810
- if (!Number.isInteger(offset) || offset < 0) throw new platformProxy.ActionError({
2811
- type: "invalid_cursor",
2812
- message: "Cursor must be a non-negative integer."
2813
- });
2923
+ const offset = input.cursor === void 0 ? 0 : Number(input.cursor);
2814
2924
  const response = await platformProxy.get({
2815
2925
  endpoint: `/v1/organizations/${encodeURIComponent(input.organization_id)}/memberships`,
2816
2926
  params: {
@@ -2848,7 +2958,7 @@ function listOrganizationMembershipsTool$1(proxy) {
2848
2958
  //#endregion
2849
2959
  //#region src/providers/clerk/tools/list-organization-roles.ts
2850
2960
  const listOrganizationRolesInputSchema = z.object({
2851
- 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."),
2852
2962
  limit: z.number().int().min(1).max(500).optional(),
2853
2963
  query: z.string().optional(),
2854
2964
  order_by: z.string().optional()
@@ -2873,7 +2983,7 @@ const ProviderResponseSchema$241 = z.object({
2873
2983
  });
2874
2984
  const listOrganizationRolesOutputSchema = z.object({
2875
2985
  items: z.array(ResourceSchema$34),
2876
- 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."),
2877
2987
  total: z.number()
2878
2988
  });
2879
2989
  function listOrganizationRolesTool(proxy) {
@@ -2884,11 +2994,7 @@ function listOrganizationRolesTool(proxy) {
2884
2994
  outputSchema: listOrganizationRolesOutputSchema,
2885
2995
  execute: async (input, { requestContext }) => {
2886
2996
  const platformProxy = proxy.withRequestContext(requestContext);
2887
- const offset = input.cursor === void 0 ? 0 : Number.parseInt(input.cursor, 10);
2888
- if (!Number.isInteger(offset) || offset < 0) throw new platformProxy.ActionError({
2889
- type: "invalid_cursor",
2890
- message: "Cursor must be a non-negative integer."
2891
- });
2997
+ const offset = input.cursor === void 0 ? 0 : Number(input.cursor);
2892
2998
  const response = await platformProxy.get({
2893
2999
  endpoint: "/v1/organization_roles",
2894
3000
  params: {
@@ -2912,7 +3018,7 @@ function listOrganizationRolesTool(proxy) {
2912
3018
  //#endregion
2913
3019
  //#region src/providers/clerk/tools/list-organizations.ts
2914
3020
  const listOrganizationsInputSchema$1 = z.object({
2915
- 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."),
2916
3022
  limit: z.number().int().min(1).max(500).optional(),
2917
3023
  query: z.string().optional(),
2918
3024
  order_by: z.string().optional().describe("Sort by name, created_at, or members_count, prefixed with + or -."),
@@ -2952,11 +3058,7 @@ function listOrganizationsTool$1(proxy) {
2952
3058
  outputSchema: listOrganizationsOutputSchema$1,
2953
3059
  execute: async (input, { requestContext }) => {
2954
3060
  const platformProxy = proxy.withRequestContext(requestContext);
2955
- const offset = input.cursor === void 0 ? 0 : Number.parseInt(input.cursor, 10);
2956
- if (!Number.isInteger(offset) || offset < 0) throw new platformProxy.ActionError({
2957
- type: "invalid_cursor",
2958
- message: "Cursor must be a non-negative integer."
2959
- });
3061
+ const offset = input.cursor === void 0 ? 0 : Number(input.cursor);
2960
3062
  const response = await platformProxy.get({
2961
3063
  endpoint: "/v1/organizations",
2962
3064
  params: {
@@ -2982,10 +3084,10 @@ function listOrganizationsTool$1(proxy) {
2982
3084
  //#endregion
2983
3085
  //#region src/providers/clerk/tools/list-sessions.ts
2984
3086
  const listSessionsInputSchema = z.object({
2985
- 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."),
2986
3088
  limit: z.number().int().min(1).max(500).optional(),
2987
- client_id: z.string().optional(),
2988
- user_id: z.string().optional(),
3089
+ client_id: z.string().min(1).optional(),
3090
+ user_id: z.string().min(1).optional(),
2989
3091
  status: z.enum([
2990
3092
  "abandoned",
2991
3093
  "active",
@@ -2995,7 +3097,7 @@ const listSessionsInputSchema = z.object({
2995
3097
  "replaced",
2996
3098
  "revoked"
2997
3099
  ]).optional()
2998
- });
3100
+ }).refine((value) => value.client_id !== void 0 || value.user_id !== void 0, { message: "Provide at least one of client_id or user_id." });
2999
3101
  const ResourceSchema$33 = z.object({
3000
3102
  id: z.string(),
3001
3103
  object: z.string().optional(),
@@ -3009,21 +3111,17 @@ const ResourceSchema$33 = z.object({
3009
3111
  "removed",
3010
3112
  "replaced",
3011
3113
  "revoked"
3012
- ]).optional(),
3114
+ ]).or(z.string()).optional(),
3013
3115
  last_active_at: z.number().optional(),
3014
3116
  expire_at: z.number().optional(),
3015
3117
  abandon_at: z.number().optional(),
3016
3118
  created_at: z.number().optional(),
3017
3119
  updated_at: z.number().optional()
3018
3120
  }).passthrough();
3019
- const ProviderResponseSchema$239 = z.object({
3020
- data: z.array(ResourceSchema$33),
3021
- total_count: z.number()
3022
- });
3121
+ const ProviderResponseSchema$239 = z.array(ResourceSchema$33);
3023
3122
  const listSessionsOutputSchema = z.object({
3024
3123
  items: z.array(ResourceSchema$33),
3025
- next_cursor: z.string().optional(),
3026
- 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.")
3027
3125
  });
3028
3126
  function listSessionsTool(proxy) {
3029
3127
  return createTool({
@@ -3033,28 +3131,23 @@ function listSessionsTool(proxy) {
3033
3131
  outputSchema: listSessionsOutputSchema,
3034
3132
  execute: async (input, { requestContext }) => {
3035
3133
  const platformProxy = proxy.withRequestContext(requestContext);
3036
- const offset = input.cursor === void 0 ? 0 : Number.parseInt(input.cursor, 10);
3037
- if (!Number.isInteger(offset) || offset < 0) throw new platformProxy.ActionError({
3038
- type: "invalid_cursor",
3039
- message: "Cursor must be a non-negative integer."
3040
- });
3134
+ const offset = input.cursor === void 0 ? 0 : Number(input.cursor);
3135
+ const limit = input.limit ?? 10;
3041
3136
  const response = await platformProxy.get({
3042
3137
  endpoint: "/v1/sessions",
3043
3138
  params: {
3044
3139
  offset: String(offset),
3045
- ...input.limit !== void 0 && { limit: String(input.limit) },
3140
+ limit: String(limit),
3046
3141
  ...input.client_id !== void 0 && { client_id: input.client_id },
3047
3142
  ...input.user_id !== void 0 && { user_id: input.user_id },
3048
3143
  ...input.status !== void 0 && { status: input.status }
3049
3144
  },
3050
3145
  retries: 3
3051
3146
  });
3052
- const provider = ProviderResponseSchema$239.parse(response.data);
3053
- const nextOffset = offset + provider.data.length;
3147
+ const sessions = ProviderResponseSchema$239.parse(response.data);
3054
3148
  return {
3055
- items: provider.data,
3056
- ...nextOffset < provider.total_count && { next_cursor: String(nextOffset) },
3057
- total: provider.total_count
3149
+ items: sessions,
3150
+ ...sessions.length === limit && { next_cursor: String(offset + sessions.length) }
3058
3151
  };
3059
3152
  }
3060
3153
  });
@@ -3062,13 +3155,19 @@ function listSessionsTool(proxy) {
3062
3155
  //#endregion
3063
3156
  //#region src/providers/clerk/tools/list-users.ts
3064
3157
  const listUsersInputSchema$9 = z.object({
3065
- 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."),
3066
3159
  limit: z.number().int().min(1).max(500).optional().describe("Maximum number of users to return. Maximum 500."),
3067
3160
  query: z.string().optional().describe("Search across names, identifiers, email addresses, phone numbers, and usernames."),
3068
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."),
3069
3164
  user_id: z.array(z.string()).max(100).optional().describe("Filter by Clerk user IDs."),
3070
3165
  external_id: z.array(z.string()).max(100).optional().describe("Filter by external user IDs."),
3071
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."),
3072
3171
  order_by: z.string().optional().describe("Sort field prefixed with + for ascending or - for descending. Example: \"-created_at\"")
3073
3172
  });
3074
3173
  const UserSchema$25 = z.object({
@@ -3087,13 +3186,11 @@ const UserSchema$25 = z.object({
3087
3186
  updated_at: z.number().optional(),
3088
3187
  locale: z.string().nullable().optional()
3089
3188
  }).passthrough();
3090
- const ProviderResponseSchema$238 = z.object({
3091
- data: z.array(UserSchema$25),
3092
- total_count: z.number()
3093
- });
3189
+ const ProviderResponseSchema$238 = z.array(UserSchema$25);
3190
+ const ProviderCountSchema = z.object({ total_count: z.number() }).passthrough();
3094
3191
  const listUsersOutputSchema$9 = z.object({
3095
3192
  items: z.array(UserSchema$25),
3096
- 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."),
3097
3194
  total: z.number()
3098
3195
  });
3099
3196
  function listUsersTool$9(proxy) {
@@ -3104,31 +3201,42 @@ function listUsersTool$9(proxy) {
3104
3201
  outputSchema: listUsersOutputSchema$9,
3105
3202
  execute: async (input, { requestContext }) => {
3106
3203
  const platformProxy = proxy.withRequestContext(requestContext);
3107
- const offset = input.cursor === void 0 ? 0 : Number.parseInt(input.cursor, 10);
3108
- if (!Number.isInteger(offset) || offset < 0) throw new platformProxy.ActionError({
3109
- type: "invalid_cursor",
3110
- message: "Cursor must be a non-negative integer."
3111
- });
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
+ };
3112
3218
  const response = await platformProxy.get({
3113
3219
  endpoint: "/v1/users",
3114
3220
  params: {
3115
3221
  offset: String(offset),
3116
3222
  ...input.limit !== void 0 && { limit: String(input.limit) },
3117
- ...input.query !== void 0 && { query: input.query },
3118
- ...input.email_address !== void 0 && { email_address: input.email_address },
3119
- ...input.user_id !== void 0 && { user_id: input.user_id },
3120
- ...input.external_id !== void 0 && { external_id: input.external_id },
3121
- ...input.organization_id !== void 0 && { organization_id: input.organization_id },
3122
- ...input.order_by !== void 0 && { order_by: input.order_by }
3223
+ ...input.order_by !== void 0 && { order_by: input.order_by },
3224
+ ...filterParams
3123
3225
  },
3124
3226
  retries: 3
3125
3227
  });
3126
- const provider = ProviderResponseSchema$238.parse(response.data);
3127
- 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;
3128
3236
  return {
3129
- items: provider.data,
3130
- ...nextOffset < provider.total_count && { next_cursor: String(nextOffset) },
3131
- total: provider.total_count
3237
+ items: users,
3238
+ ...users.length > 0 && nextOffset < total && { next_cursor: String(nextOffset) },
3239
+ total
3132
3240
  };
3133
3241
  }
3134
3242
  });
@@ -3136,8 +3244,8 @@ function listUsersTool$9(proxy) {
3136
3244
  //#endregion
3137
3245
  //#region src/providers/clerk/tools/remove-organization-role-permission.ts
3138
3246
  const removeOrganizationRolePermissionInputSchema = z.object({
3139
- organization_role_id: z.string(),
3140
- permission_id: z.string()
3247
+ organization_role_id: z.string().min(1),
3248
+ permission_id: z.string().min(1)
3141
3249
  });
3142
3250
  const removeOrganizationRolePermissionOutputSchema = z.object({
3143
3251
  id: z.string(),
@@ -3164,8 +3272,8 @@ function removeOrganizationRolePermissionTool(proxy) {
3164
3272
  //#endregion
3165
3273
  //#region src/providers/clerk/tools/revoke-organization-invitation.ts
3166
3274
  const revokeOrganizationInvitationInputSchema = z.object({
3167
- organization_id: z.string(),
3168
- invitation_id: z.string(),
3275
+ organization_id: z.string().min(1),
3276
+ invitation_id: z.string().min(1),
3169
3277
  requesting_user_id: z.string().optional()
3170
3278
  });
3171
3279
  const ResourceSchema$32 = z.object({
@@ -3179,7 +3287,7 @@ const ResourceSchema$32 = z.object({
3179
3287
  "accepted",
3180
3288
  "revoked",
3181
3289
  "expired"
3182
- ]).optional(),
3290
+ ]).or(z.string()).optional(),
3183
3291
  created_at: z.number().optional(),
3184
3292
  updated_at: z.number().optional()
3185
3293
  }).passthrough();
@@ -3202,7 +3310,7 @@ function revokeOrganizationInvitationTool(proxy) {
3202
3310
  }
3203
3311
  //#endregion
3204
3312
  //#region src/providers/clerk/tools/revoke-session.ts
3205
- const revokeSessionInputSchema = z.object({ session_id: z.string() });
3313
+ const revokeSessionInputSchema = z.object({ session_id: z.string().min(1) });
3206
3314
  const ResourceSchema$31 = z.object({
3207
3315
  id: z.string(),
3208
3316
  object: z.string().optional(),
@@ -3216,7 +3324,7 @@ const ResourceSchema$31 = z.object({
3216
3324
  "removed",
3217
3325
  "replaced",
3218
3326
  "revoked"
3219
- ]).optional(),
3327
+ ]).or(z.string()).optional(),
3220
3328
  last_active_at: z.number().optional(),
3221
3329
  expire_at: z.number().optional(),
3222
3330
  abandon_at: z.number().optional(),
@@ -3243,7 +3351,7 @@ function revokeSessionTool(proxy) {
3243
3351
  //#endregion
3244
3352
  //#region src/providers/clerk/tools/update-email-address.ts
3245
3353
  const updateEmailAddressInputSchema = z.object({
3246
- email_address_id: z.string(),
3354
+ email_address_id: z.string().min(1),
3247
3355
  verified: z.boolean().optional(),
3248
3356
  primary: z.boolean().optional(),
3249
3357
  notify_primary_email_address_changed: z.boolean().optional()
@@ -3286,16 +3394,22 @@ function updateEmailAddressTool(proxy) {
3286
3394
  }
3287
3395
  //#endregion
3288
3396
  //#region src/providers/clerk/tools/update-organization-domain.ts
3289
- const EnrollmentModeSchema = z.enum([
3397
+ const EnrollmentModeSchema$1 = z.enum([
3290
3398
  "manual_invitation",
3291
3399
  "automatic_invitation",
3292
3400
  "automatic_suggestion",
3293
3401
  "enterprise_sso"
3294
3402
  ]);
3403
+ const EnrollmentModeSchemaWidened = z.enum([
3404
+ "manual_invitation",
3405
+ "automatic_invitation",
3406
+ "automatic_suggestion",
3407
+ "enterprise_sso"
3408
+ ]).or(z.string());
3295
3409
  const updateOrganizationDomainInputSchema = z.object({
3296
- organization_id: z.string(),
3297
- domain_id: z.string(),
3298
- enrollment_mode: EnrollmentModeSchema.optional(),
3410
+ organization_id: z.string().min(1),
3411
+ domain_id: z.string().min(1),
3412
+ enrollment_mode: EnrollmentModeSchema$1.optional(),
3299
3413
  verified: z.boolean().optional()
3300
3414
  });
3301
3415
  const ResourceSchema$29 = z.object({
@@ -3303,15 +3417,15 @@ const ResourceSchema$29 = z.object({
3303
3417
  object: z.string().optional(),
3304
3418
  organization_id: z.string().optional(),
3305
3419
  name: z.string(),
3306
- enrollment_mode: EnrollmentModeSchema.optional(),
3420
+ enrollment_mode: EnrollmentModeSchemaWidened.optional(),
3307
3421
  affiliation_verification: z.object({
3308
3422
  attempts: z.number().optional(),
3309
3423
  status: z.string().optional()
3310
- }).passthrough().optional(),
3424
+ }).passthrough().nullable().optional(),
3311
3425
  verification: z.object({
3312
3426
  attempts: z.number().optional(),
3313
3427
  status: z.string().optional()
3314
- }).passthrough().optional(),
3428
+ }).passthrough().nullable().optional(),
3315
3429
  verified: z.boolean().optional(),
3316
3430
  created_at: z.number().optional(),
3317
3431
  updated_at: z.number().optional()
@@ -3339,8 +3453,8 @@ function updateOrganizationDomainTool(proxy) {
3339
3453
  //#endregion
3340
3454
  //#region src/providers/clerk/tools/update-organization-membership-metadata.ts
3341
3455
  const updateOrganizationMembershipMetadataInputSchema = z.object({
3342
- organization_id: z.string(),
3343
- user_id: z.string(),
3456
+ organization_id: z.string().min(1),
3457
+ user_id: z.string().min(1),
3344
3458
  public_metadata: z.record(z.string(), z.unknown()).optional(),
3345
3459
  private_metadata: z.record(z.string(), z.unknown()).optional()
3346
3460
  });
@@ -3377,8 +3491,8 @@ function updateOrganizationMembershipMetadataTool(proxy) {
3377
3491
  //#endregion
3378
3492
  //#region src/providers/clerk/tools/update-organization-membership.ts
3379
3493
  const updateOrganizationMembershipInputSchema$1 = z.object({
3380
- organization_id: z.string(),
3381
- user_id: z.string(),
3494
+ organization_id: z.string().min(1),
3495
+ user_id: z.string().min(1),
3382
3496
  role: z.string()
3383
3497
  });
3384
3498
  const ResourceSchema$27 = z.object({
@@ -3411,12 +3525,12 @@ function updateOrganizationMembershipTool$1(proxy) {
3411
3525
  //#endregion
3412
3526
  //#region src/providers/clerk/tools/update-organization-role.ts
3413
3527
  const updateOrganizationRoleInputSchema = z.object({
3414
- organization_role_id: z.string(),
3528
+ organization_role_id: z.string().min(1),
3415
3529
  name: z.string().optional(),
3416
3530
  key: z.string().optional(),
3417
3531
  description: z.string().optional(),
3418
3532
  permissions: z.array(z.string()).optional()
3419
- });
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." });
3420
3534
  const ResourceSchema$26 = z.object({
3421
3535
  id: z.string(),
3422
3536
  object: z.string().optional(),
@@ -3460,7 +3574,8 @@ const updateOrganizationInputSchema$1 = z.object({
3460
3574
  name: z.string().min(1).optional(),
3461
3575
  slug: z.string().optional(),
3462
3576
  admin_delete_enabled: z.boolean().optional(),
3463
- 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()
3464
3579
  });
3465
3580
  const OrganizationSchema$1 = z.object({
3466
3581
  id: z.string(),
@@ -3492,7 +3607,8 @@ function updateOrganizationTool$1(proxy) {
3492
3607
  ...input.name !== void 0 && { name: input.name },
3493
3608
  ...input.slug !== void 0 && { slug: input.slug },
3494
3609
  ...input.admin_delete_enabled !== void 0 && { admin_delete_enabled: input.admin_delete_enabled },
3495
- ...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 }
3496
3612
  },
3497
3613
  retries: 3
3498
3614
  });
@@ -3503,7 +3619,7 @@ function updateOrganizationTool$1(proxy) {
3503
3619
  //#endregion
3504
3620
  //#region src/providers/clerk/tools/update-phone-number.ts
3505
3621
  const updatePhoneNumberInputSchema = z.object({
3506
- phone_number_id: z.string(),
3622
+ phone_number_id: z.string().min(1),
3507
3623
  verified: z.boolean().optional(),
3508
3624
  primary: z.boolean().optional(),
3509
3625
  reserved_for_second_factor: z.boolean().optional()
@@ -3549,14 +3665,14 @@ function updatePhoneNumberTool(proxy) {
3549
3665
  //#region src/providers/clerk/tools/update-user.ts
3550
3666
  const updateUserInputSchema$1 = z.object({
3551
3667
  user_id: z.string().min(1),
3552
- first_name: z.string().optional(),
3553
- last_name: z.string().optional(),
3554
- 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."),
3555
3671
  password: z.string().min(8).optional(),
3556
3672
  skip_password_checks: z.boolean().optional(),
3557
3673
  sign_out_of_other_sessions: z.boolean().optional(),
3558
- external_id: z.string().optional(),
3559
- 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.")
3560
3676
  });
3561
3677
  const UserSchema$24 = z.object({
3562
3678
  id: z.string(),
@@ -3602,24 +3718,30 @@ function updateUserTool$1(proxy) {
3602
3718
  }
3603
3719
  //#endregion
3604
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());
3605
3727
  const verifyOrganizationDomainInputSchema$1 = z.object({
3606
- organization_id: z.string(),
3607
- domain_id: z.string()
3728
+ organization_id: z.string().min(1),
3729
+ domain_id: z.string().min(1)
3608
3730
  });
3609
3731
  const ResourceSchema$24 = z.object({
3610
3732
  id: z.string(),
3611
3733
  object: z.string().optional(),
3612
3734
  organization_id: z.string().optional(),
3613
3735
  name: z.string(),
3614
- enrollment_mode: z.string().optional(),
3736
+ enrollment_mode: EnrollmentModeSchema.optional(),
3615
3737
  affiliation_verification: z.object({
3616
3738
  attempts: z.number().optional(),
3617
3739
  status: z.string().optional()
3618
- }).passthrough().optional(),
3740
+ }).passthrough().nullable().optional(),
3619
3741
  verification: z.object({
3620
3742
  attempts: z.number().optional(),
3621
3743
  status: z.string().optional()
3622
- }).passthrough().optional(),
3744
+ }).passthrough().nullable().optional(),
3623
3745
  verified: z.boolean().optional(),
3624
3746
  created_at: z.number().optional(),
3625
3747
  updated_at: z.number().optional()
@@ -5177,7 +5299,7 @@ const ChannelSchema$2 = z.object({
5177
5299
  recipients: z.array(z.unknown()).optional(),
5178
5300
  icon: z.string().nullable().optional(),
5179
5301
  owner_id: z.string().optional(),
5180
- application_id: z.string().optional(),
5302
+ application_id: z.string().nullable().optional(),
5181
5303
  managed: z.boolean().optional(),
5182
5304
  parent_id: z.string().nullable().optional(),
5183
5305
  last_pin_timestamp: z.string().nullable().optional(),
@@ -55242,7 +55364,7 @@ const cancelEmailInputSchema = z.object({ email_id: z.string() });
55242
55364
  const ProviderResponseSchema$107 = z.object({
55243
55365
  object: z.string().optional(),
55244
55366
  id: z.string().optional(),
55245
- message_id: z.string().optional(),
55367
+ message_id: z.string().nullable().optional(),
55246
55368
  to: z.array(z.string()).optional(),
55247
55369
  from: z.string().optional(),
55248
55370
  created_at: z.string().optional(),
@@ -56492,7 +56614,7 @@ const getEmailInputSchema = z.object({ email_id: z.string() });
56492
56614
  const ProviderResponseSchema$76 = z.object({
56493
56615
  object: z.string().optional(),
56494
56616
  id: z.string().optional(),
56495
- message_id: z.string().optional(),
56617
+ message_id: z.string().nullable().optional(),
56496
56618
  to: z.array(z.string()).optional(),
56497
56619
  from: z.string().optional(),
56498
56620
  created_at: z.string().optional(),
@@ -56579,7 +56701,7 @@ const ProviderResponseSchema$74 = z.object({
56579
56701
  to: z.array(z.string()).optional(),
56580
56702
  from: z.string().optional(),
56581
56703
  subject: z.string().optional(),
56582
- message_id: z.string().optional(),
56704
+ message_id: z.string().nullable().optional(),
56583
56705
  bcc: z.array(z.string()).nullable().optional(),
56584
56706
  cc: z.array(z.string()).nullable().optional(),
56585
56707
  reply_to: z.array(z.string()).nullable().optional(),
@@ -56653,7 +56775,7 @@ const ProviderResponseSchema$72 = z.object({
56653
56775
  current_version_id: z.string().optional(),
56654
56776
  name: z.string().optional(),
56655
56777
  alias: z.string().optional(),
56656
- from: z.string().optional(),
56778
+ from: z.string().nullable().optional(),
56657
56779
  subject: z.string().optional(),
56658
56780
  reply_to: z.array(z.string()).nullable().optional(),
56659
56781
  html: z.string().optional(),
@@ -57376,7 +57498,7 @@ const ProviderResponseSchema$57 = z.object({
57376
57498
  data: z.array(z.object({
57377
57499
  object: z.string().optional(),
57378
57500
  id: z.string().optional(),
57379
- message_id: z.string().optional(),
57501
+ message_id: z.string().nullable().optional(),
57380
57502
  to: z.array(z.string()).optional(),
57381
57503
  from: z.string().optional(),
57382
57504
  created_at: z.string().optional(),
@@ -57495,7 +57617,7 @@ const ProviderResponseSchema$55 = z.object({
57495
57617
  to: z.array(z.string()).optional(),
57496
57618
  from: z.string().optional(),
57497
57619
  subject: z.string().nullable().optional(),
57498
- message_id: z.string().optional(),
57620
+ message_id: z.string().nullable().optional(),
57499
57621
  bcc: z.array(z.string()).nullable().optional(),
57500
57622
  cc: z.array(z.string()).nullable().optional(),
57501
57623
  reply_to: z.array(z.string()).nullable().optional(),
@@ -58183,7 +58305,7 @@ function updateContactTopicsTool(proxy) {
58183
58305
  const config = {
58184
58306
  endpoint: `/contacts/${encodeURIComponent(input["contact_id"])}/topics`,
58185
58307
  retries: 3,
58186
- data: input.body
58308
+ data: input.body.topics
58187
58309
  };
58188
58310
  const response = await platformProxy.patch(config);
58189
58311
  return ProviderResponseSchema$39.parse(response.data);
@@ -74135,8 +74257,10 @@ let nextResolverId = 0;
74135
74257
  * to (or detached from) the project are picked up (or dropped) without a
74136
74258
  * restart.
74137
74259
  *
74138
- * Configuration errors (missing project id, bad ttlMs, malformed integration id)
74139
- * 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.
74140
74264
  * Expected provider absence is silently skipped. Actionable per-integration
74141
74265
  * problems during resolution (needs re-auth or ambiguity) are downgraded to
74142
74266
  * warn-and-skip so one bad integration never takes down the whole toolset.
@@ -74152,6 +74276,8 @@ function tools(options = {}) {
74152
74276
  const integrationOverrides = normalizeIntegrationOverrides(options.integrations);
74153
74277
  validateIntegrationOverrides(integrationOverrides);
74154
74278
  validateIntegrationXor(integrationOverrides);
74279
+ validateRequireApproval(integrationOverrides);
74280
+ rejectRemovedAutoApproveTools(integrationOverrides);
74155
74281
  let cache;
74156
74282
  let inflight;
74157
74283
  let closing;
@@ -74270,6 +74396,30 @@ function validateIntegrationXor(integrations) {
74270
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.`);
74271
74397
  }
74272
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
+ }
74273
74423
  function buildRequests(integrations, catalog) {
74274
74424
  const overrides = integrations;
74275
74425
  const registrations = new Map(TOOLS.map((registration) => [registration.integrationId, registration]));
@@ -74319,16 +74469,19 @@ async function mapTools(connections, requests, options, client, mcpClients, reso
74319
74469
  connectionId: resolution.connectionId,
74320
74470
  allowTools: request.options.allowTools,
74321
74471
  disallowTools: request.options.disallowTools,
74322
- autoApproveTools: request.options.autoApproveTools,
74472
+ requireApproval: request.options.requireApproval,
74323
74473
  client,
74324
74474
  mcpClients,
74325
74475
  resolverId
74326
74476
  });
74327
- } else providerTools = request.registration.createTools({
74328
- connectionId: resolution.connectionId,
74329
- client: options.client,
74330
- ...providerFilterOptions(request.options)
74331
- });
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
+ }
74332
74485
  else if (request.registration.transport === "mcp") {
74333
74486
  for (const connection of resolution.connections) activeMcpKeys.add(`${integrationId}::${connection.id}`);
74334
74487
  providerTools = await buildMcpMultiConnectionTools({
@@ -74336,19 +74489,23 @@ async function mapTools(connections, requests, options, client, mcpClients, reso
74336
74489
  connections: resolution.connections,
74337
74490
  allowTools: request.options.allowTools,
74338
74491
  disallowTools: request.options.disallowTools,
74339
- autoApproveTools: request.options.autoApproveTools,
74492
+ requireApproval: request.options.requireApproval,
74340
74493
  client,
74341
74494
  mcpClients,
74342
74495
  resolverId
74343
74496
  });
74344
- } else providerTools = buildProxyMultiConnectionTools({
74345
- registration: request.registration,
74346
- connections: resolution.connections,
74347
- allowTools: request.options.allowTools,
74348
- disallowTools: request.options.disallowTools,
74349
- client: options.client
74350
- });
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
+ }
74351
74507
  } catch (error) {
74508
+ if (error instanceof MastraConnectConfigError) throw error;
74352
74509
  console.warn(`[@mastra/connect] Skipping ${integrationId}: ${error instanceof Error ? error.message : String(error)}`);
74353
74510
  continue;
74354
74511
  }
@@ -74372,9 +74529,33 @@ async function mapTools(connections, requests, options, client, mcpClients, reso
74372
74529
  function providerFilterOptions(options) {
74373
74530
  return options.allowTools !== void 0 ? { allowTools: options.allowTools } : options.disallowTools !== void 0 ? { disallowTools: options.disallowTools } : {};
74374
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
+ }
74375
74556
  async function discoverMcpTools(input) {
74376
- const { registration, connectionId, allowTools, disallowTools, autoApproveTools, client, mcpClients, resolverId } = input;
74377
- 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;
74378
74559
  const cacheKey = `${registration.integrationId}::${connectionId}`;
74379
74560
  let entry = mcpClients.get(cacheKey);
74380
74561
  if (!entry) {
@@ -74386,7 +74567,7 @@ async function discoverMcpTools(input) {
74386
74567
  id: `mastra-connect-${resolverId}-${registration.integrationId}-${connectionId}`,
74387
74568
  servers: { [registration.integrationId]: {
74388
74569
  ...transport,
74389
- requireToolApproval: ({ toolName }) => !autoApproved.has(`${registration.integrationId}_${String(toolName)}`)
74570
+ ...requireApproval === true ? { requireToolApproval: true } : requireApprovalFor ? { requireToolApproval: ({ toolName }) => requireApprovalFor.has(`${registration.integrationId}_${String(toolName)}`) } : {}
74390
74571
  } }
74391
74572
  })
74392
74573
  };
@@ -74395,8 +74576,10 @@ async function discoverMcpTools(input) {
74395
74576
  const discovery = await entry.client.listToolsWithErrors();
74396
74577
  const error = discovery.errors[registration.integrationId];
74397
74578
  if (error) throw new Error(`MCP tool discovery failed: ${error}`);
74398
- const unknown = [...autoApproved].filter((name) => !(name in discovery.tools));
74399
- 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
+ }
74400
74583
  return applyToolFilter(discovery.tools, {
74401
74584
  allowTools,
74402
74585
  disallowTools
@@ -74498,6 +74681,7 @@ async function channels(options = {}) {
74498
74681
  let cache;
74499
74682
  let inflight;
74500
74683
  let lastFailureAt;
74684
+ let warnedStaleSlackConnection = false;
74501
74685
  const buildSnapshot = async () => {
74502
74686
  let connections;
74503
74687
  try {
@@ -74508,6 +74692,10 @@ async function channels(options = {}) {
74508
74692
  }
74509
74693
  const byIntegrationId = groupByIntegrationId(connections);
74510
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
+ }
74511
74699
  for (const state of states) {
74512
74700
  const integrationId = state.registration.integrationId;
74513
74701
  const overrides = options.integrations?.[integrationId] ?? {};
@@ -74619,7 +74807,9 @@ async function credential(connectionId, options) {
74619
74807
  //#endregion
74620
74808
  //#region src/environment.ts
74621
74809
  function credentialToken(credential) {
74622
- 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;
74623
74813
  }
74624
74814
  /**
74625
74815
  * Wires git's credential helper to read the token from the environment at use