@layervai/qurl-mcp 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +98 -0
  3. package/dist/client.d.ts +278 -0
  4. package/dist/client.d.ts.map +1 -0
  5. package/dist/client.js +156 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/index.d.ts +3 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +34 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/prompts/audit-links.d.ts +7 -0
  12. package/dist/prompts/audit-links.d.ts.map +1 -0
  13. package/dist/prompts/audit-links.js +31 -0
  14. package/dist/prompts/audit-links.js.map +1 -0
  15. package/dist/prompts/rotate-access.d.ts +18 -0
  16. package/dist/prompts/rotate-access.d.ts.map +1 -0
  17. package/dist/prompts/rotate-access.js +41 -0
  18. package/dist/prompts/rotate-access.js.map +1 -0
  19. package/dist/prompts/secure-a-service.d.ts +38 -0
  20. package/dist/prompts/secure-a-service.d.ts.map +1 -0
  21. package/dist/prompts/secure-a-service.js +141 -0
  22. package/dist/prompts/secure-a-service.js.map +1 -0
  23. package/dist/resources/_shared.d.ts +31 -0
  24. package/dist/resources/_shared.d.ts.map +1 -0
  25. package/dist/resources/_shared.js +42 -0
  26. package/dist/resources/_shared.js.map +1 -0
  27. package/dist/resources/links.d.ts +15 -0
  28. package/dist/resources/links.d.ts.map +1 -0
  29. package/dist/resources/links.js +22 -0
  30. package/dist/resources/links.js.map +1 -0
  31. package/dist/resources/usage.d.ts +15 -0
  32. package/dist/resources/usage.d.ts.map +1 -0
  33. package/dist/resources/usage.js +18 -0
  34. package/dist/resources/usage.js.map +1 -0
  35. package/dist/server.d.ts +37 -0
  36. package/dist/server.d.ts.map +1 -0
  37. package/dist/server.js +58 -0
  38. package/dist/server.js.map +1 -0
  39. package/dist/tools/_shared.d.ts +78 -0
  40. package/dist/tools/_shared.d.ts.map +1 -0
  41. package/dist/tools/_shared.js +80 -0
  42. package/dist/tools/_shared.js.map +1 -0
  43. package/dist/tools/batch-create.d.ts +426 -0
  44. package/dist/tools/batch-create.d.ts.map +1 -0
  45. package/dist/tools/batch-create.js +81 -0
  46. package/dist/tools/batch-create.js.map +1 -0
  47. package/dist/tools/create-qurl.d.ts +316 -0
  48. package/dist/tools/create-qurl.d.ts.map +1 -0
  49. package/dist/tools/create-qurl.js +106 -0
  50. package/dist/tools/create-qurl.js.map +1 -0
  51. package/dist/tools/delete-qurl.d.ts +55 -0
  52. package/dist/tools/delete-qurl.d.ts.map +1 -0
  53. package/dist/tools/delete-qurl.js +76 -0
  54. package/dist/tools/delete-qurl.js.map +1 -0
  55. package/dist/tools/extend-qurl.d.ts +238 -0
  56. package/dist/tools/extend-qurl.d.ts.map +1 -0
  57. package/dist/tools/extend-qurl.js +45 -0
  58. package/dist/tools/extend-qurl.js.map +1 -0
  59. package/dist/tools/get-qurl.d.ts +231 -0
  60. package/dist/tools/get-qurl.d.ts.map +1 -0
  61. package/dist/tools/get-qurl.js +39 -0
  62. package/dist/tools/get-qurl.js.map +1 -0
  63. package/dist/tools/list-qurls.d.ts +395 -0
  64. package/dist/tools/list-qurls.d.ts.map +1 -0
  65. package/dist/tools/list-qurls.js +72 -0
  66. package/dist/tools/list-qurls.js.map +1 -0
  67. package/dist/tools/mint-link.d.ts +384 -0
  68. package/dist/tools/mint-link.d.ts.map +1 -0
  69. package/dist/tools/mint-link.js +75 -0
  70. package/dist/tools/mint-link.js.map +1 -0
  71. package/dist/tools/output-schemas.d.ts +1261 -0
  72. package/dist/tools/output-schemas.d.ts.map +1 -0
  73. package/dist/tools/output-schemas.js +173 -0
  74. package/dist/tools/output-schemas.js.map +1 -0
  75. package/dist/tools/resolve-qurl.d.ts +72 -0
  76. package/dist/tools/resolve-qurl.d.ts.map +1 -0
  77. package/dist/tools/resolve-qurl.js +42 -0
  78. package/dist/tools/resolve-qurl.js.map +1 -0
  79. package/dist/tools/update-qurl.d.ts +330 -0
  80. package/dist/tools/update-qurl.d.ts.map +1 -0
  81. package/dist/tools/update-qurl.js +96 -0
  82. package/dist/tools/update-qurl.js.map +1 -0
  83. package/package.json +58 -0
@@ -0,0 +1,80 @@
1
+ import { z } from "zod";
2
+ import { QURLAPIError } from "../client.js";
3
+ // SDK's `structuredContent` is `Record<string, unknown>`; payloads are
4
+ // typed against API response shapes. Single seam for the cast.
5
+ // `T extends object` rules out primitives and `null` at compile time;
6
+ // `{ length?: never }` rules out arrays. The constraint does *not*
7
+ // reject `Map`/`Set`/`Date`/class instances with non-public state — in
8
+ // practice every call site passes a plain object literal derived from
9
+ // an API response, and asserting that contract structurally would need
10
+ // a runtime check. Tighter `Record<string, unknown>` would be ideal,
11
+ // but client-defined interfaces lack the implicit index signature.
12
+ export function toStructuredContent(value) {
13
+ return value;
14
+ }
15
+ /**
16
+ * Wrap a tool handler so that a thrown `QURLAPIError` with
17
+ * `code: "missing_api_key"` is converted into an `isError: true` content
18
+ * block instead of propagating as a JSON-RPC error. MCP hosts surface
19
+ * `isError: true` content blocks more prominently than transport-level
20
+ * errors, so a missing-key misconfig becomes immediately actionable in
21
+ * the host UI rather than buried in a generic error toast.
22
+ *
23
+ * Other API errors continue to throw — they're real failures that callers
24
+ * should treat as exceptional, and the JSON-RPC error path carries the
25
+ * statusCode/code metadata the host needs to surface them properly.
26
+ */
27
+ export function withMissingApiKeyHandler(inner) {
28
+ return async (input) => {
29
+ try {
30
+ return await inner(input);
31
+ }
32
+ catch (err) {
33
+ if (err instanceof QURLAPIError && err.code === "missing_api_key") {
34
+ return {
35
+ isError: true,
36
+ content: [{ type: "text", text: err.message }],
37
+ };
38
+ }
39
+ throw err;
40
+ }
41
+ };
42
+ }
43
+ /**
44
+ * Convert a ZodError into an MCP tool error result.
45
+ *
46
+ * Used by tools that register a base schema with the MCP SDK and re-parse
47
+ * with a refined schema inside the handler — the MCP SDK cannot serialize
48
+ * Zod refinements to JSON Schema, so cross-field constraints have to be
49
+ * checked at call time and converted into a tool error response.
50
+ */
51
+ export function zodErrorToToolResult(error) {
52
+ return {
53
+ isError: true,
54
+ content: [
55
+ {
56
+ type: "text",
57
+ text: error.issues.map((i) => i.message).join("; "),
58
+ },
59
+ ],
60
+ };
61
+ }
62
+ /**
63
+ * Zod schema for a tool's resource_id parameter.
64
+ *
65
+ * The API accepts both a resource ID (r_ prefix) and a qURL display ID
66
+ * (q_ prefix) on get/update/extend/mint_link, and resolves a q_ ID to its
67
+ * parent resource automatically. DELETE is the one exception — it only
68
+ * accepts r_ IDs and defines its own schema.
69
+ *
70
+ * Rejects empty strings so a malformed call can't hit `/v1/qurls/` with
71
+ * an empty path segment.
72
+ */
73
+ export function resourceIdSchema(verb) {
74
+ return z
75
+ .string()
76
+ .min(1)
77
+ .describe(`The resource ID (r_ prefix) or qURL display ID (q_ prefix) to ${verb}. ` +
78
+ "If a q_ ID is passed, the API resolves it to the parent resource automatically.");
79
+ }
80
+ //# sourceMappingURL=_shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_shared.js","sourceRoot":"","sources":["../../src/tools/_shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAiB,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAqC5C,uEAAuE;AACvE,+DAA+D;AAC/D,sEAAsE;AACtE,mEAAmE;AACnE,uEAAuE;AACvE,sEAAsE;AACtE,uEAAuE;AACvE,qEAAqE;AACrE,mEAAmE;AACnE,MAAM,UAAU,mBAAmB,CACjC,KAAQ;IAER,OAAO,KAA2C,CAAC;AACrD,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,wBAAwB,CACtC,KAAwC;IAExC,OAAO,KAAK,EAAE,KAAK,EAAE,EAAE;QACrB,IAAI,CAAC;YACH,OAAO,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,GAAG,YAAY,YAAY,IAAI,GAAG,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;gBAClE,OAAO;oBACL,OAAO,EAAE,IAAI;oBACb,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;iBAC/C,CAAC;YACJ,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAe;IAClD,OAAO;QACL,OAAO,EAAE,IAAa;QACtB,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAe;gBACrB,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;aACpD;SACF;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,OAAO,CAAC;SACL,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,QAAQ,CACP,iEAAiE,IAAI,IAAI;QACvE,iFAAiF,CACpF,CAAC;AACN,CAAC"}
@@ -0,0 +1,426 @@
1
+ import { z } from "zod";
2
+ import type { IQURLClient } from "../client.js";
3
+ export declare const batchCreateSchema: z.ZodObject<{
4
+ items: z.ZodArray<z.ZodObject<{
5
+ target_url: z.ZodString;
6
+ label: z.ZodOptional<z.ZodString>;
7
+ expires_in: z.ZodOptional<z.ZodString>;
8
+ one_time_use: z.ZodOptional<z.ZodBoolean>;
9
+ max_sessions: z.ZodOptional<z.ZodNumber>;
10
+ session_duration: z.ZodOptional<z.ZodString>;
11
+ custom_domain: z.ZodOptional<z.ZodString>;
12
+ access_policy: z.ZodOptional<z.ZodObject<{
13
+ ip_allowlist: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
14
+ ip_denylist: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
15
+ geo_allowlist: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
16
+ geo_denylist: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
17
+ user_agent_allow_regex: z.ZodOptional<z.ZodString>;
18
+ user_agent_deny_regex: z.ZodOptional<z.ZodString>;
19
+ ai_agent_policy: z.ZodOptional<z.ZodObject<{
20
+ block_all: z.ZodOptional<z.ZodBoolean>;
21
+ deny_categories: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
22
+ allow_categories: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
23
+ }, "strip", z.ZodTypeAny, {
24
+ block_all?: boolean | undefined;
25
+ deny_categories?: string[] | undefined;
26
+ allow_categories?: string[] | undefined;
27
+ }, {
28
+ block_all?: boolean | undefined;
29
+ deny_categories?: string[] | undefined;
30
+ allow_categories?: string[] | undefined;
31
+ }>>;
32
+ }, "strip", z.ZodTypeAny, {
33
+ ip_allowlist?: string[] | undefined;
34
+ ip_denylist?: string[] | undefined;
35
+ geo_allowlist?: string[] | undefined;
36
+ geo_denylist?: string[] | undefined;
37
+ user_agent_allow_regex?: string | undefined;
38
+ user_agent_deny_regex?: string | undefined;
39
+ ai_agent_policy?: {
40
+ block_all?: boolean | undefined;
41
+ deny_categories?: string[] | undefined;
42
+ allow_categories?: string[] | undefined;
43
+ } | undefined;
44
+ }, {
45
+ ip_allowlist?: string[] | undefined;
46
+ ip_denylist?: string[] | undefined;
47
+ geo_allowlist?: string[] | undefined;
48
+ geo_denylist?: string[] | undefined;
49
+ user_agent_allow_regex?: string | undefined;
50
+ user_agent_deny_regex?: string | undefined;
51
+ ai_agent_policy?: {
52
+ block_all?: boolean | undefined;
53
+ deny_categories?: string[] | undefined;
54
+ allow_categories?: string[] | undefined;
55
+ } | undefined;
56
+ }>>;
57
+ }, "strip", z.ZodTypeAny, {
58
+ target_url: string;
59
+ label?: string | undefined;
60
+ one_time_use?: boolean | undefined;
61
+ max_sessions?: number | undefined;
62
+ session_duration?: string | undefined;
63
+ access_policy?: {
64
+ ip_allowlist?: string[] | undefined;
65
+ ip_denylist?: string[] | undefined;
66
+ geo_allowlist?: string[] | undefined;
67
+ geo_denylist?: string[] | undefined;
68
+ user_agent_allow_regex?: string | undefined;
69
+ user_agent_deny_regex?: string | undefined;
70
+ ai_agent_policy?: {
71
+ block_all?: boolean | undefined;
72
+ deny_categories?: string[] | undefined;
73
+ allow_categories?: string[] | undefined;
74
+ } | undefined;
75
+ } | undefined;
76
+ custom_domain?: string | undefined;
77
+ expires_in?: string | undefined;
78
+ }, {
79
+ target_url: string;
80
+ label?: string | undefined;
81
+ one_time_use?: boolean | undefined;
82
+ max_sessions?: number | undefined;
83
+ session_duration?: string | undefined;
84
+ access_policy?: {
85
+ ip_allowlist?: string[] | undefined;
86
+ ip_denylist?: string[] | undefined;
87
+ geo_allowlist?: string[] | undefined;
88
+ geo_denylist?: string[] | undefined;
89
+ user_agent_allow_regex?: string | undefined;
90
+ user_agent_deny_regex?: string | undefined;
91
+ ai_agent_policy?: {
92
+ block_all?: boolean | undefined;
93
+ deny_categories?: string[] | undefined;
94
+ allow_categories?: string[] | undefined;
95
+ } | undefined;
96
+ } | undefined;
97
+ custom_domain?: string | undefined;
98
+ expires_in?: string | undefined;
99
+ }>, "many">;
100
+ }, "strip", z.ZodTypeAny, {
101
+ items: {
102
+ target_url: string;
103
+ label?: string | undefined;
104
+ one_time_use?: boolean | undefined;
105
+ max_sessions?: number | undefined;
106
+ session_duration?: string | undefined;
107
+ access_policy?: {
108
+ ip_allowlist?: string[] | undefined;
109
+ ip_denylist?: string[] | undefined;
110
+ geo_allowlist?: string[] | undefined;
111
+ geo_denylist?: string[] | undefined;
112
+ user_agent_allow_regex?: string | undefined;
113
+ user_agent_deny_regex?: string | undefined;
114
+ ai_agent_policy?: {
115
+ block_all?: boolean | undefined;
116
+ deny_categories?: string[] | undefined;
117
+ allow_categories?: string[] | undefined;
118
+ } | undefined;
119
+ } | undefined;
120
+ custom_domain?: string | undefined;
121
+ expires_in?: string | undefined;
122
+ }[];
123
+ }, {
124
+ items: {
125
+ target_url: string;
126
+ label?: string | undefined;
127
+ one_time_use?: boolean | undefined;
128
+ max_sessions?: number | undefined;
129
+ session_duration?: string | undefined;
130
+ access_policy?: {
131
+ ip_allowlist?: string[] | undefined;
132
+ ip_denylist?: string[] | undefined;
133
+ geo_allowlist?: string[] | undefined;
134
+ geo_denylist?: string[] | undefined;
135
+ user_agent_allow_regex?: string | undefined;
136
+ user_agent_deny_regex?: string | undefined;
137
+ ai_agent_policy?: {
138
+ block_all?: boolean | undefined;
139
+ deny_categories?: string[] | undefined;
140
+ allow_categories?: string[] | undefined;
141
+ } | undefined;
142
+ } | undefined;
143
+ custom_domain?: string | undefined;
144
+ expires_in?: string | undefined;
145
+ }[];
146
+ }>;
147
+ export declare function batchCreateTool(client: IQURLClient): {
148
+ name: string;
149
+ title: string;
150
+ description: string;
151
+ inputSchema: z.ZodObject<{
152
+ items: z.ZodArray<z.ZodObject<{
153
+ target_url: z.ZodString;
154
+ label: z.ZodOptional<z.ZodString>;
155
+ expires_in: z.ZodOptional<z.ZodString>;
156
+ one_time_use: z.ZodOptional<z.ZodBoolean>;
157
+ max_sessions: z.ZodOptional<z.ZodNumber>;
158
+ session_duration: z.ZodOptional<z.ZodString>;
159
+ custom_domain: z.ZodOptional<z.ZodString>;
160
+ access_policy: z.ZodOptional<z.ZodObject<{
161
+ ip_allowlist: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
162
+ ip_denylist: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
163
+ geo_allowlist: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
164
+ geo_denylist: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
165
+ user_agent_allow_regex: z.ZodOptional<z.ZodString>;
166
+ user_agent_deny_regex: z.ZodOptional<z.ZodString>;
167
+ ai_agent_policy: z.ZodOptional<z.ZodObject<{
168
+ block_all: z.ZodOptional<z.ZodBoolean>;
169
+ deny_categories: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
170
+ allow_categories: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
171
+ }, "strip", z.ZodTypeAny, {
172
+ block_all?: boolean | undefined;
173
+ deny_categories?: string[] | undefined;
174
+ allow_categories?: string[] | undefined;
175
+ }, {
176
+ block_all?: boolean | undefined;
177
+ deny_categories?: string[] | undefined;
178
+ allow_categories?: string[] | undefined;
179
+ }>>;
180
+ }, "strip", z.ZodTypeAny, {
181
+ ip_allowlist?: string[] | undefined;
182
+ ip_denylist?: string[] | undefined;
183
+ geo_allowlist?: string[] | undefined;
184
+ geo_denylist?: string[] | undefined;
185
+ user_agent_allow_regex?: string | undefined;
186
+ user_agent_deny_regex?: string | undefined;
187
+ ai_agent_policy?: {
188
+ block_all?: boolean | undefined;
189
+ deny_categories?: string[] | undefined;
190
+ allow_categories?: string[] | undefined;
191
+ } | undefined;
192
+ }, {
193
+ ip_allowlist?: string[] | undefined;
194
+ ip_denylist?: string[] | undefined;
195
+ geo_allowlist?: string[] | undefined;
196
+ geo_denylist?: string[] | undefined;
197
+ user_agent_allow_regex?: string | undefined;
198
+ user_agent_deny_regex?: string | undefined;
199
+ ai_agent_policy?: {
200
+ block_all?: boolean | undefined;
201
+ deny_categories?: string[] | undefined;
202
+ allow_categories?: string[] | undefined;
203
+ } | undefined;
204
+ }>>;
205
+ }, "strip", z.ZodTypeAny, {
206
+ target_url: string;
207
+ label?: string | undefined;
208
+ one_time_use?: boolean | undefined;
209
+ max_sessions?: number | undefined;
210
+ session_duration?: string | undefined;
211
+ access_policy?: {
212
+ ip_allowlist?: string[] | undefined;
213
+ ip_denylist?: string[] | undefined;
214
+ geo_allowlist?: string[] | undefined;
215
+ geo_denylist?: string[] | undefined;
216
+ user_agent_allow_regex?: string | undefined;
217
+ user_agent_deny_regex?: string | undefined;
218
+ ai_agent_policy?: {
219
+ block_all?: boolean | undefined;
220
+ deny_categories?: string[] | undefined;
221
+ allow_categories?: string[] | undefined;
222
+ } | undefined;
223
+ } | undefined;
224
+ custom_domain?: string | undefined;
225
+ expires_in?: string | undefined;
226
+ }, {
227
+ target_url: string;
228
+ label?: string | undefined;
229
+ one_time_use?: boolean | undefined;
230
+ max_sessions?: number | undefined;
231
+ session_duration?: string | undefined;
232
+ access_policy?: {
233
+ ip_allowlist?: string[] | undefined;
234
+ ip_denylist?: string[] | undefined;
235
+ geo_allowlist?: string[] | undefined;
236
+ geo_denylist?: string[] | undefined;
237
+ user_agent_allow_regex?: string | undefined;
238
+ user_agent_deny_regex?: string | undefined;
239
+ ai_agent_policy?: {
240
+ block_all?: boolean | undefined;
241
+ deny_categories?: string[] | undefined;
242
+ allow_categories?: string[] | undefined;
243
+ } | undefined;
244
+ } | undefined;
245
+ custom_domain?: string | undefined;
246
+ expires_in?: string | undefined;
247
+ }>, "many">;
248
+ }, "strip", z.ZodTypeAny, {
249
+ items: {
250
+ target_url: string;
251
+ label?: string | undefined;
252
+ one_time_use?: boolean | undefined;
253
+ max_sessions?: number | undefined;
254
+ session_duration?: string | undefined;
255
+ access_policy?: {
256
+ ip_allowlist?: string[] | undefined;
257
+ ip_denylist?: string[] | undefined;
258
+ geo_allowlist?: string[] | undefined;
259
+ geo_denylist?: string[] | undefined;
260
+ user_agent_allow_regex?: string | undefined;
261
+ user_agent_deny_regex?: string | undefined;
262
+ ai_agent_policy?: {
263
+ block_all?: boolean | undefined;
264
+ deny_categories?: string[] | undefined;
265
+ allow_categories?: string[] | undefined;
266
+ } | undefined;
267
+ } | undefined;
268
+ custom_domain?: string | undefined;
269
+ expires_in?: string | undefined;
270
+ }[];
271
+ }, {
272
+ items: {
273
+ target_url: string;
274
+ label?: string | undefined;
275
+ one_time_use?: boolean | undefined;
276
+ max_sessions?: number | undefined;
277
+ session_duration?: string | undefined;
278
+ access_policy?: {
279
+ ip_allowlist?: string[] | undefined;
280
+ ip_denylist?: string[] | undefined;
281
+ geo_allowlist?: string[] | undefined;
282
+ geo_denylist?: string[] | undefined;
283
+ user_agent_allow_regex?: string | undefined;
284
+ user_agent_deny_regex?: string | undefined;
285
+ ai_agent_policy?: {
286
+ block_all?: boolean | undefined;
287
+ deny_categories?: string[] | undefined;
288
+ allow_categories?: string[] | undefined;
289
+ } | undefined;
290
+ } | undefined;
291
+ custom_domain?: string | undefined;
292
+ expires_in?: string | undefined;
293
+ }[];
294
+ }>;
295
+ outputSchema: z.ZodObject<{
296
+ succeeded: z.ZodNumber;
297
+ failed: z.ZodNumber;
298
+ results: z.ZodArray<z.ZodDiscriminatedUnion<"success", [z.ZodObject<{
299
+ index: z.ZodNumber;
300
+ success: z.ZodLiteral<true>;
301
+ resource_id: z.ZodString;
302
+ qurl_link: z.ZodString;
303
+ qurl_site: z.ZodString;
304
+ expires_at: z.ZodString;
305
+ }, "strip", z.ZodTypeAny, {
306
+ qurl_site: string;
307
+ expires_at: string;
308
+ resource_id: string;
309
+ qurl_link: string;
310
+ index: number;
311
+ success: true;
312
+ }, {
313
+ qurl_site: string;
314
+ expires_at: string;
315
+ resource_id: string;
316
+ qurl_link: string;
317
+ index: number;
318
+ success: true;
319
+ }>, z.ZodObject<{
320
+ index: z.ZodNumber;
321
+ success: z.ZodLiteral<false>;
322
+ error: z.ZodObject<{
323
+ code: z.ZodString;
324
+ message: z.ZodString;
325
+ }, "strip", z.ZodTypeAny, {
326
+ code: string;
327
+ message: string;
328
+ }, {
329
+ code: string;
330
+ message: string;
331
+ }>;
332
+ }, "strip", z.ZodTypeAny, {
333
+ error: {
334
+ code: string;
335
+ message: string;
336
+ };
337
+ index: number;
338
+ success: false;
339
+ }, {
340
+ error: {
341
+ code: string;
342
+ message: string;
343
+ };
344
+ index: number;
345
+ success: false;
346
+ }>]>, "many">;
347
+ request_id: z.ZodOptional<z.ZodString>;
348
+ }, "strip", z.ZodTypeAny, {
349
+ succeeded: number;
350
+ failed: number;
351
+ results: ({
352
+ qurl_site: string;
353
+ expires_at: string;
354
+ resource_id: string;
355
+ qurl_link: string;
356
+ index: number;
357
+ success: true;
358
+ } | {
359
+ error: {
360
+ code: string;
361
+ message: string;
362
+ };
363
+ index: number;
364
+ success: false;
365
+ })[];
366
+ request_id?: string | undefined;
367
+ }, {
368
+ succeeded: number;
369
+ failed: number;
370
+ results: ({
371
+ qurl_site: string;
372
+ expires_at: string;
373
+ resource_id: string;
374
+ qurl_link: string;
375
+ index: number;
376
+ success: true;
377
+ } | {
378
+ error: {
379
+ code: string;
380
+ message: string;
381
+ };
382
+ index: number;
383
+ success: false;
384
+ })[];
385
+ request_id?: string | undefined;
386
+ }>;
387
+ annotations: {
388
+ title: string;
389
+ readOnlyHint: boolean;
390
+ destructiveHint: boolean;
391
+ idempotentHint: boolean;
392
+ openWorldHint: boolean;
393
+ };
394
+ handler: (input: {
395
+ items: {
396
+ target_url: string;
397
+ label?: string | undefined;
398
+ one_time_use?: boolean | undefined;
399
+ max_sessions?: number | undefined;
400
+ session_duration?: string | undefined;
401
+ access_policy?: {
402
+ ip_allowlist?: string[] | undefined;
403
+ ip_denylist?: string[] | undefined;
404
+ geo_allowlist?: string[] | undefined;
405
+ geo_denylist?: string[] | undefined;
406
+ user_agent_allow_regex?: string | undefined;
407
+ user_agent_deny_regex?: string | undefined;
408
+ ai_agent_policy?: {
409
+ block_all?: boolean | undefined;
410
+ deny_categories?: string[] | undefined;
411
+ allow_categories?: string[] | undefined;
412
+ } | undefined;
413
+ } | undefined;
414
+ custom_domain?: string | undefined;
415
+ expires_in?: string | undefined;
416
+ }[];
417
+ }) => Promise<{
418
+ content: Array<{
419
+ type: "text";
420
+ text: string;
421
+ }>;
422
+ structuredContent?: Record<string, unknown>;
423
+ isError?: boolean;
424
+ }>;
425
+ };
426
+ //# sourceMappingURL=batch-create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch-create.d.ts","sourceRoot":"","sources":["../../src/tools/batch-create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAqB,WAAW,EAAE,MAAM,cAAc,CAAC;AAanE,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAM5B,CAAC;AAEH,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+DlD"}
@@ -0,0 +1,81 @@
1
+ import { z } from "zod";
2
+ import { createQurlSchema } from "./create-qurl.js";
3
+ import { toStructuredContent, withMissingApiKeyHandler } from "./_shared.js";
4
+ import { batchCreateOutputSchema } from "./output-schemas.js";
5
+ function isBatchPayload(value) {
6
+ if (typeof value !== "object" || value === null)
7
+ return false;
8
+ const v = value;
9
+ return (typeof v.succeeded === "number" && typeof v.failed === "number" && Array.isArray(v.results));
10
+ }
11
+ export const batchCreateSchema = z.object({
12
+ items: z
13
+ .array(createQurlSchema)
14
+ .min(1)
15
+ .max(100)
16
+ .describe("Array of qURL creation requests (1-100 items)"),
17
+ });
18
+ export function batchCreateTool(client) {
19
+ return {
20
+ name: "batch_create_qurls",
21
+ title: "Batch Create qURLs",
22
+ description: "Create up to 100 qURLs in a single request. The single-call alternative to looping `create_qurl` — saves round trips and returns a single envelope of per-item results. " +
23
+ "**Not transactional:** items succeed or fail independently (see `succeeded`/`failed` counts and per-item `error`). " +
24
+ "Use this when you need to mint many qURLs at once (e.g. provisioning a vendor list, distributing per-customer share links). " +
25
+ "Use `create_qurl` for a single resource. " +
26
+ "**Response shape:** `{ succeeded: number, failed: number, results: BatchItemResult[], request_id?: string }`. Each `results[i]` carries `index` (matching the input position), `success`, plus either `qurl_link` + `resource_id` + `qurl_site` + `expires_at` (success) OR `error: { code, message }` (failure). " +
27
+ "**Partial failure signaling:** the handler sets `isError: true` on the tool response whenever `failed > 0`, so agents can branch without parsing JSON. The HTTP layer also returns 400 when every item fails — that's surfaced through the same shape (read `data.results[*].error`). " +
28
+ "**One-shot links:** like `create_qurl`, every `qurl_link` in the response is shown ONCE. Don't lose them.",
29
+ inputSchema: batchCreateSchema,
30
+ outputSchema: batchCreateOutputSchema,
31
+ annotations: {
32
+ title: "Batch Create qURLs",
33
+ readOnlyHint: false,
34
+ destructiveHint: false,
35
+ idempotentHint: false,
36
+ openWorldHint: true,
37
+ },
38
+ handler: withMissingApiKeyHandler(async (input) => {
39
+ const result = await client.batchCreate(input);
40
+ // Defense-in-depth: batchCreate passes through HTTP 400, which is
41
+ // contracted to carry a BatchCreateResponse body with per-item errors.
42
+ // If the API ever returns 400 with a different shape (e.g., a
43
+ // top-level malformed-request error), the downstream `failed > 0`
44
+ // access would be meaningless — surface the raw response as an error
45
+ // so agents get a real signal instead of silent mis-interpretation.
46
+ if (!isBatchPayload(result.data)) {
47
+ return {
48
+ content: [
49
+ {
50
+ type: "text",
51
+ text: `Unexpected batchCreate response shape: ${JSON.stringify(result).slice(0, 500)}`,
52
+ },
53
+ ],
54
+ isError: true,
55
+ };
56
+ }
57
+ const data = result.data;
58
+ // Spread request_id only when present so structuredContent doesn't
59
+ // expose an explicit `request_id: undefined` key to hosts that
60
+ // consume the raw object (JSON.stringify drops it; structured
61
+ // consumers don't). `!== undefined` rather than truthy so an
62
+ // empty-string request_id (shouldn't happen, but cheap to guard)
63
+ // doesn't silently drop.
64
+ const payload = {
65
+ ...data,
66
+ ...(result.meta?.request_id !== undefined && { request_id: result.meta.request_id }),
67
+ };
68
+ return {
69
+ content: [
70
+ {
71
+ type: "text",
72
+ text: JSON.stringify(payload),
73
+ },
74
+ ],
75
+ structuredContent: toStructuredContent(payload),
76
+ isError: data.failed > 0,
77
+ };
78
+ }),
79
+ };
80
+ }
81
+ //# sourceMappingURL=batch-create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch-create.js","sourceRoot":"","sources":["../../src/tools/batch-create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,SAAS,cAAc,CAAC,KAAc;IACpC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,MAAM,CAAC,GAAG,KAA2E,CAAC;IACtF,OAAO,CACL,OAAO,CAAC,CAAC,SAAS,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAC5F,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,KAAK,EAAE,CAAC;SACL,KAAK,CAAC,gBAAgB,CAAC;SACvB,GAAG,CAAC,CAAC,CAAC;SACN,GAAG,CAAC,GAAG,CAAC;SACR,QAAQ,CAAC,+CAA+C,CAAC;CAC7D,CAAC,CAAC;AAEH,MAAM,UAAU,eAAe,CAAC,MAAmB;IACjD,OAAO;QACL,IAAI,EAAE,oBAAoB;QAC1B,KAAK,EAAE,oBAAoB;QAC3B,WAAW,EACT,0KAA0K;YAC1K,qHAAqH;YACrH,8HAA8H;YAC9H,2CAA2C;YAC3C,oTAAoT;YACpT,wRAAwR;YACxR,2GAA2G;QAC7G,WAAW,EAAE,iBAAiB;QAC9B,YAAY,EAAE,uBAAuB;QACrC,WAAW,EAAE;YACX,KAAK,EAAE,oBAAoB;YAC3B,YAAY,EAAE,KAAK;YACnB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,KAAK;YACrB,aAAa,EAAE,IAAI;SACpB;QACD,OAAO,EAAE,wBAAwB,CAAC,KAAK,EAAE,KAAwC,EAAE,EAAE;YACnF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAC/C,kEAAkE;YAClE,uEAAuE;YACvE,8DAA8D;YAC9D,kEAAkE;YAClE,qEAAqE;YACrE,oEAAoE;YACpE,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;gBACjC,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAe;4BACrB,IAAI,EAAE,0CAA0C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;yBACvF;qBACF;oBACD,OAAO,EAAE,IAAI;iBACd,CAAC;YACJ,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;YACzB,mEAAmE;YACnE,+DAA+D;YAC/D,8DAA8D;YAC9D,6DAA6D;YAC7D,iEAAiE;YACjE,yBAAyB;YACzB,MAAM,OAAO,GAAG;gBACd,GAAG,IAAI;gBACP,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,KAAK,SAAS,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;aACrF,CAAC;YACF,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;qBAC9B;iBACF;gBACD,iBAAiB,EAAE,mBAAmB,CAAC,OAAO,CAAC;gBAC/C,OAAO,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC;aACzB,CAAC;QACJ,CAAC,CAAC;KACH,CAAC;AACJ,CAAC"}