@layervai/qurl-mcp 0.4.0 → 0.5.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 (173) hide show
  1. package/README.md +742 -46
  2. package/assets/fonts/NotoSansSC-Regular.ttf +0 -0
  3. package/assets/fonts/OFL.txt +93 -0
  4. package/assets/fonts/README.md +18 -0
  5. package/dist/auth/request-context.d.ts +13 -0
  6. package/dist/auth/request-context.d.ts.map +1 -0
  7. package/dist/auth/request-context.js +21 -0
  8. package/dist/auth/request-context.js.map +1 -0
  9. package/dist/auth/static-bearer.d.ts +12 -0
  10. package/dist/auth/static-bearer.d.ts.map +1 -0
  11. package/dist/auth/static-bearer.js +47 -0
  12. package/dist/auth/static-bearer.js.map +1 -0
  13. package/dist/client.d.ts +112 -23
  14. package/dist/client.d.ts.map +1 -1
  15. package/dist/client.js +173 -78
  16. package/dist/client.js.map +1 -1
  17. package/dist/config.d.ts +98 -0
  18. package/dist/config.d.ts.map +1 -0
  19. package/dist/config.js +543 -0
  20. package/dist/config.js.map +1 -0
  21. package/dist/credential-rate-limit-store.d.ts +38 -0
  22. package/dist/credential-rate-limit-store.d.ts.map +1 -0
  23. package/dist/credential-rate-limit-store.js +135 -0
  24. package/dist/credential-rate-limit-store.js.map +1 -0
  25. package/dist/email-addresses.d.ts +7 -0
  26. package/dist/email-addresses.d.ts.map +1 -0
  27. package/dist/email-addresses.js +36 -0
  28. package/dist/email-addresses.js.map +1 -0
  29. package/dist/email-types.d.ts +33 -0
  30. package/dist/email-types.d.ts.map +1 -0
  31. package/dist/email-types.js +28 -0
  32. package/dist/email-types.js.map +1 -0
  33. package/dist/emf-metrics.d.ts +25 -0
  34. package/dist/emf-metrics.d.ts.map +1 -0
  35. package/dist/emf-metrics.js +87 -0
  36. package/dist/emf-metrics.js.map +1 -0
  37. package/dist/http-config.d.ts +38 -0
  38. package/dist/http-config.d.ts.map +1 -0
  39. package/dist/http-config.js +243 -0
  40. package/dist/http-config.js.map +1 -0
  41. package/dist/http-routes.d.ts +5 -0
  42. package/dist/http-routes.d.ts.map +1 -0
  43. package/dist/http-routes.js +12 -0
  44. package/dist/http-routes.js.map +1 -0
  45. package/dist/http.d.ts +33 -0
  46. package/dist/http.d.ts.map +1 -0
  47. package/dist/http.js +1116 -0
  48. package/dist/http.js.map +1 -0
  49. package/dist/index.d.ts +1 -1
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +42 -25
  52. package/dist/index.js.map +1 -1
  53. package/dist/logging.d.ts +7 -0
  54. package/dist/logging.d.ts.map +1 -0
  55. package/dist/logging.js +110 -0
  56. package/dist/logging.js.map +1 -0
  57. package/dist/prompts/secure-a-service.d.ts +16 -4
  58. package/dist/prompts/secure-a-service.d.ts.map +1 -1
  59. package/dist/prompts/secure-a-service.js +7 -15
  60. package/dist/prompts/secure-a-service.js.map +1 -1
  61. package/dist/server.d.ts +18 -6
  62. package/dist/server.d.ts.map +1 -1
  63. package/dist/server.js +41 -8
  64. package/dist/server.js.map +1 -1
  65. package/dist/services/email.d.ts +17 -0
  66. package/dist/services/email.d.ts.map +1 -0
  67. package/dist/services/email.js +351 -0
  68. package/dist/services/email.js.map +1 -0
  69. package/dist/services/html.d.ts +5 -0
  70. package/dist/services/html.d.ts.map +1 -0
  71. package/dist/services/html.js +28 -0
  72. package/dist/services/html.js.map +1 -0
  73. package/dist/services/legal-pages.d.ts +12 -0
  74. package/dist/services/legal-pages.d.ts.map +1 -0
  75. package/dist/services/legal-pages.js +588 -0
  76. package/dist/services/legal-pages.js.map +1 -0
  77. package/dist/services/text-pdf.d.ts +16 -0
  78. package/dist/services/text-pdf.d.ts.map +1 -0
  79. package/dist/services/text-pdf.js +141 -0
  80. package/dist/services/text-pdf.js.map +1 -0
  81. package/dist/services/video-page.d.ts +4 -0
  82. package/dist/services/video-page.d.ts.map +1 -0
  83. package/dist/services/video-page.js +311 -0
  84. package/dist/services/video-page.js.map +1 -0
  85. package/dist/text.d.ts +4 -0
  86. package/dist/text.d.ts.map +1 -0
  87. package/dist/text.js +16 -0
  88. package/dist/text.js.map +1 -0
  89. package/dist/tools/_shared.d.ts +13 -3
  90. package/dist/tools/_shared.d.ts.map +1 -1
  91. package/dist/tools/_shared.js +31 -7
  92. package/dist/tools/_shared.js.map +1 -1
  93. package/dist/tools/batch-create.d.ts +36 -343
  94. package/dist/tools/batch-create.d.ts.map +1 -1
  95. package/dist/tools/batch-create.js +7 -4
  96. package/dist/tools/batch-create.js.map +1 -1
  97. package/dist/tools/create-qurl.d.ts +79 -237
  98. package/dist/tools/create-qurl.d.ts.map +1 -1
  99. package/dist/tools/create-qurl.js +77 -47
  100. package/dist/tools/create-qurl.js.map +1 -1
  101. package/dist/tools/delete-qurl.d.ts +5 -22
  102. package/dist/tools/delete-qurl.d.ts.map +1 -1
  103. package/dist/tools/delete-qurl.js +19 -13
  104. package/dist/tools/delete-qurl.js.map +1 -1
  105. package/dist/tools/email-delivery.d.ts +37 -0
  106. package/dist/tools/email-delivery.d.ts.map +1 -0
  107. package/dist/tools/email-delivery.js +115 -0
  108. package/dist/tools/email-delivery.js.map +1 -0
  109. package/dist/tools/extend-qurl.d.ts +36 -189
  110. package/dist/tools/extend-qurl.d.ts.map +1 -1
  111. package/dist/tools/extend-qurl.js +3 -3
  112. package/dist/tools/extend-qurl.js.map +1 -1
  113. package/dist/tools/get-qurl.d.ts +36 -185
  114. package/dist/tools/get-qurl.d.ts.map +1 -1
  115. package/dist/tools/get-qurl.js +8 -5
  116. package/dist/tools/get-qurl.js.map +1 -1
  117. package/dist/tools/list-qurl-sessions.d.ts +45 -0
  118. package/dist/tools/list-qurl-sessions.d.ts.map +1 -0
  119. package/dist/tools/list-qurl-sessions.js +33 -0
  120. package/dist/tools/list-qurl-sessions.js.map +1 -0
  121. package/dist/tools/list-qurls.d.ts +38 -319
  122. package/dist/tools/list-qurls.d.ts.map +1 -1
  123. package/dist/tools/list-qurls.js +45 -20
  124. package/dist/tools/list-qurls.js.map +1 -1
  125. package/dist/tools/mint-link.d.ts +72 -303
  126. package/dist/tools/mint-link.d.ts.map +1 -1
  127. package/dist/tools/mint-link.js +35 -21
  128. package/dist/tools/mint-link.js.map +1 -1
  129. package/dist/tools/output-schemas.d.ts +326 -1112
  130. package/dist/tools/output-schemas.d.ts.map +1 -1
  131. package/dist/tools/output-schemas.js +141 -40
  132. package/dist/tools/output-schemas.js.map +1 -1
  133. package/dist/tools/resolve-qurl.d.ts +6 -37
  134. package/dist/tools/resolve-qurl.d.ts.map +1 -1
  135. package/dist/tools/resolve-qurl.js +5 -5
  136. package/dist/tools/resolve-qurl.js.map +1 -1
  137. package/dist/tools/revoke-qurl-token.d.ts +41 -0
  138. package/dist/tools/revoke-qurl-token.d.ts.map +1 -0
  139. package/dist/tools/revoke-qurl-token.js +40 -0
  140. package/dist/tools/revoke-qurl-token.js.map +1 -0
  141. package/dist/tools/terminate-qurl-sessions.d.ts +41 -0
  142. package/dist/tools/terminate-qurl-sessions.d.ts.map +1 -0
  143. package/dist/tools/terminate-qurl-sessions.js +68 -0
  144. package/dist/tools/terminate-qurl-sessions.js.map +1 -0
  145. package/dist/tools/update-qurl-token.d.ts +142 -0
  146. package/dist/tools/update-qurl-token.d.ts.map +1 -0
  147. package/dist/tools/update-qurl-token.js +75 -0
  148. package/dist/tools/update-qurl-token.js.map +1 -0
  149. package/dist/tools/update-qurl.d.ts +43 -264
  150. package/dist/tools/update-qurl.d.ts.map +1 -1
  151. package/dist/tools/update-qurl.js +57 -8
  152. package/dist/tools/update-qurl.js.map +1 -1
  153. package/dist/tools/upload-file-data-qurl.d.ts +182 -0
  154. package/dist/tools/upload-file-data-qurl.d.ts.map +1 -0
  155. package/dist/tools/upload-file-data-qurl.js +200 -0
  156. package/dist/tools/upload-file-data-qurl.js.map +1 -0
  157. package/dist/tools/upload-file-qurl.d.ts +162 -0
  158. package/dist/tools/upload-file-qurl.d.ts.map +1 -0
  159. package/dist/tools/upload-file-qurl.js +167 -0
  160. package/dist/tools/upload-file-qurl.js.map +1 -0
  161. package/dist/tools/upload-file-shared.d.ts +36 -0
  162. package/dist/tools/upload-file-shared.d.ts.map +1 -0
  163. package/dist/tools/upload-file-shared.js +347 -0
  164. package/dist/tools/upload-file-shared.js.map +1 -0
  165. package/dist/tools/upload-mint-options.d.ts +22 -0
  166. package/dist/tools/upload-mint-options.d.ts.map +1 -0
  167. package/dist/tools/upload-mint-options.js +29 -0
  168. package/dist/tools/upload-mint-options.js.map +1 -0
  169. package/dist/tools/upload-text-qurl.d.ts +144 -0
  170. package/dist/tools/upload-text-qurl.d.ts.map +1 -0
  171. package/dist/tools/upload-text-qurl.js +102 -0
  172. package/dist/tools/upload-text-qurl.js.map +1 -0
  173. package/package.json +27 -8
@@ -11,8 +11,16 @@ const tagSchema = z
11
11
  .regex(/^[a-zA-Z0-9][a-zA-Z0-9 _-]*$/, "Tag must start with alphanumeric and contain only letters, numbers, spaces, underscores, or hyphens");
12
12
  export const updateQurlBaseSchema = z.object({
13
13
  resource_id: resourceIdSchema("update"),
14
- extend_by: z.string().min(1).optional().describe('Duration to extend by (e.g., "24h", "7d"). Mutually exclusive with expires_at.'),
15
- expires_at: z.string().datetime().optional().describe("Absolute expiration timestamp (RFC 3339). Mutually exclusive with extend_by."),
14
+ extend_by: z
15
+ .string()
16
+ .min(1)
17
+ .optional()
18
+ .describe('Duration to extend by (e.g., "24h", "7d"). Mutually exclusive with expires_at.'),
19
+ expires_at: z
20
+ .string()
21
+ .datetime({ offset: true })
22
+ .optional()
23
+ .describe("Absolute expiration timestamp (RFC 3339). Mutually exclusive with extend_by."),
16
24
  tags: z
17
25
  .array(tagSchema)
18
26
  .max(10)
@@ -38,6 +46,12 @@ export const updateQurlBaseSchema = z.object({
38
46
  export const updateQurlSchema = updateQurlBaseSchema
39
47
  .refine((data) => !(data.extend_by && data.expires_at), {
40
48
  message: "Provide either extend_by or expires_at, not both",
49
+ })
50
+ .refine((data) => !(hasExpirationUpdate(data) && hasResourceEndpointUpdate(data)), {
51
+ message: "custom_domain and preserve_host use the resource endpoint and cannot be combined with extend_by or expires_at in one update",
52
+ })
53
+ .refine((data) => !(hasResourceEndpointUpdate(data) && data.resource_id.startsWith("q_")), {
54
+ message: "custom_domain and preserve_host updates require a resource identifier (public key, CRID, or legacy r_ ID)",
41
55
  })
42
56
  .refine(
43
57
  // Use `!== undefined` rather than truthy checks so the API's "clear"
@@ -53,14 +67,14 @@ export const updateQurlSchema = updateQurlBaseSchema
53
67
  data.preserve_host !== undefined, {
54
68
  message: "At least one update field (extend_by, expires_at, tags, description, custom_domain, or preserve_host) is required",
55
69
  });
56
- export function updateQurlTool(client) {
70
+ export function updateQurlTool(client, _runtime = { mode: "stdio" }) {
57
71
  return {
58
72
  name: "update_qurl",
59
73
  title: "Update qURL",
60
74
  description: "Update a qURL's expiration, tags, description, custom domain, or proxy host-header behavior. The richer alternative to `extend_qurl` — use `update_qurl` whenever you need anything beyond a relative time push. " +
61
- "Accepts both `r_` and `q_` IDs (q_ is auto-resolved). " +
62
- "**Constraints:** `extend_by` and `expires_at` are mutually exclusive; at least one update field (`extend_by`, `expires_at`, `tags`, `description`, `custom_domain`, `preserve_host`) must be set. " +
63
- "**Clearing fields:** pass `description: \"\"`, `tags: []`, or `custom_domain: \"\"` to clear those fields explicitly. " +
75
+ "Accepts resource public keys, CRIDs, legacy `r_` IDs, and `q_` display IDs for expiration, tags, and description updates (q_ is auto-resolved); custom domain and preserve_host updates require a resource identifier (public key, CRID, or legacy `r_` ID) because the qURL API now serves them from `PATCH /v1/resources/{id}`. " +
76
+ "**Constraints:** `extend_by` and `expires_at` are mutually exclusive; `custom_domain`/`preserve_host` cannot be combined with expiration changes in one call; at least one update field (`extend_by`, `expires_at`, `tags`, `description`, `custom_domain`, `preserve_host`) must be set. " +
77
+ '**Clearing fields:** pass `description: ""`, `tags: []`, or `custom_domain: ""` to clear those fields explicitly. ' +
64
78
  "Use `extend_qurl` when the only change is a relative time push. " +
65
79
  "Use `delete_qurl` when you want to revoke entirely. " +
66
80
  "**Errors:** if the input fails schema refinements (both extend_by + expires_at, or no fields set), the handler returns an `isError: true` content block before any API call. Other API errors throw with the API's `code`/`statusCode`. " +
@@ -79,8 +93,13 @@ export function updateQurlTool(client) {
79
93
  const parsed = updateQurlSchema.safeParse(raw);
80
94
  if (!parsed.success)
81
95
  return zodErrorToToolResult(parsed.error);
82
- const { resource_id, ...body } = parsed.data;
83
- const result = await client.updateQURL(resource_id, body);
96
+ const { resource_id } = parsed.data;
97
+ // Both API endpoints accept tags/description; keep qURL-only updates
98
+ // on /v1/qurls/{id} for q_ auto-resolution, and move custom-domain /
99
+ // host-header changes to /v1/resources/{id} per UpdateResourceRequest.
100
+ const result = hasResourceEndpointUpdate(parsed.data)
101
+ ? await client.updateResource(resource_id, buildResourceUpdateBody(parsed.data))
102
+ : await client.updateQURL(resource_id, buildQurlUpdateBody(parsed.data));
84
103
  return {
85
104
  content: [
86
105
  {
@@ -93,4 +112,34 @@ export function updateQurlTool(client) {
93
112
  }),
94
113
  };
95
114
  }
115
+ function hasExpirationUpdate(data) {
116
+ return data.extend_by !== undefined || data.expires_at !== undefined;
117
+ }
118
+ function hasResourceEndpointUpdate(data) {
119
+ return data.custom_domain !== undefined || data.preserve_host !== undefined;
120
+ }
121
+ function buildQurlUpdateBody(data) {
122
+ const body = {};
123
+ if (data.extend_by !== undefined)
124
+ body.extend_by = data.extend_by;
125
+ if (data.expires_at !== undefined)
126
+ body.expires_at = data.expires_at;
127
+ if (data.tags !== undefined)
128
+ body.tags = data.tags;
129
+ if (data.description !== undefined)
130
+ body.description = data.description;
131
+ return body;
132
+ }
133
+ function buildResourceUpdateBody(data) {
134
+ const body = {};
135
+ if (data.tags !== undefined)
136
+ body.tags = data.tags;
137
+ if (data.description !== undefined)
138
+ body.description = data.description;
139
+ if (data.custom_domain !== undefined)
140
+ body.custom_domain = data.custom_domain;
141
+ if (data.preserve_host !== undefined)
142
+ body.preserve_host = data.preserve_host;
143
+ return body;
144
+ }
96
145
  //# source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,WAAW,CAAC;IACxE,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,uBAAuB,CAAC,IAAsB;IACrD,MAAM,IAAI,GAAwB,EAAE,CAAC;IACrC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;QAAE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IACnD,IAAI,IAAI,CAAC,WAAW,KAAK,SAAS;QAAE,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;IACxE,IAAI,IAAI,CAAC,aAAa,KAAK,SAAS;QAAE,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;IAC9E,IAAI,IAAI,CAAC,aAAa,KAAK,SAAS;QAAE,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;IAC9E,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,182 @@
1
+ import { z } from "zod";
2
+ import type { IQURLClient } from "../client.js";
3
+ import { type ToolRuntimeOptions } from "./_shared.js";
4
+ export declare function maxBase64CharactersForBytes(maxBytes: number): number;
5
+ export declare const MAX_UPLOAD_FILE_BASE64_CHARACTERS: number;
6
+ export declare function createUploadFileDataQurlSchema(maxBase64Characters?: number): z.ZodObject<{
7
+ file_base64: z.ZodString;
8
+ file_name: z.ZodString;
9
+ content_type: z.ZodEnum<{
10
+ "application/pdf": "application/pdf";
11
+ "image/gif": "image/gif";
12
+ "image/jpeg": "image/jpeg";
13
+ "image/png": "image/png";
14
+ "image/webp": "image/webp";
15
+ }>;
16
+ email_delivery: z.ZodOptional<z.ZodObject<{
17
+ to: z.ZodArray<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodEmail>>;
18
+ subject: z.ZodOptional<z.ZodString>;
19
+ message: z.ZodOptional<z.ZodString>;
20
+ }, z.core.$strip>>;
21
+ label: z.ZodOptional<z.ZodString>;
22
+ expires_in: z.ZodOptional<z.ZodString>;
23
+ one_time_use: z.ZodOptional<z.ZodBoolean>;
24
+ max_sessions: z.ZodOptional<z.ZodNumber>;
25
+ session_duration: z.ZodOptional<z.ZodString>;
26
+ access_policy: z.ZodOptional<z.ZodObject<{
27
+ ip_allowlist: z.ZodOptional<z.ZodArray<z.ZodString>>;
28
+ ip_denylist: z.ZodOptional<z.ZodArray<z.ZodString>>;
29
+ geo_allowlist: z.ZodOptional<z.ZodArray<z.ZodString>>;
30
+ geo_denylist: z.ZodOptional<z.ZodArray<z.ZodString>>;
31
+ user_agent_allow_regex: z.ZodOptional<z.ZodString>;
32
+ user_agent_deny_regex: z.ZodOptional<z.ZodString>;
33
+ ai_agent_policy: z.ZodOptional<z.ZodObject<{
34
+ block_all: z.ZodOptional<z.ZodBoolean>;
35
+ deny_categories: z.ZodOptional<z.ZodArray<z.ZodString>>;
36
+ allow_categories: z.ZodOptional<z.ZodArray<z.ZodString>>;
37
+ }, z.core.$strip>>;
38
+ }, z.core.$strip>>;
39
+ }, z.core.$strip>;
40
+ export declare const uploadFileDataQurlSchema: z.ZodObject<{
41
+ file_base64: z.ZodString;
42
+ file_name: z.ZodString;
43
+ content_type: z.ZodEnum<{
44
+ "application/pdf": "application/pdf";
45
+ "image/gif": "image/gif";
46
+ "image/jpeg": "image/jpeg";
47
+ "image/png": "image/png";
48
+ "image/webp": "image/webp";
49
+ }>;
50
+ email_delivery: z.ZodOptional<z.ZodObject<{
51
+ to: z.ZodArray<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodEmail>>;
52
+ subject: z.ZodOptional<z.ZodString>;
53
+ message: z.ZodOptional<z.ZodString>;
54
+ }, z.core.$strip>>;
55
+ label: z.ZodOptional<z.ZodString>;
56
+ expires_in: z.ZodOptional<z.ZodString>;
57
+ one_time_use: z.ZodOptional<z.ZodBoolean>;
58
+ max_sessions: z.ZodOptional<z.ZodNumber>;
59
+ session_duration: z.ZodOptional<z.ZodString>;
60
+ access_policy: z.ZodOptional<z.ZodObject<{
61
+ ip_allowlist: z.ZodOptional<z.ZodArray<z.ZodString>>;
62
+ ip_denylist: z.ZodOptional<z.ZodArray<z.ZodString>>;
63
+ geo_allowlist: z.ZodOptional<z.ZodArray<z.ZodString>>;
64
+ geo_denylist: z.ZodOptional<z.ZodArray<z.ZodString>>;
65
+ user_agent_allow_regex: z.ZodOptional<z.ZodString>;
66
+ user_agent_deny_regex: z.ZodOptional<z.ZodString>;
67
+ ai_agent_policy: z.ZodOptional<z.ZodObject<{
68
+ block_all: z.ZodOptional<z.ZodBoolean>;
69
+ deny_categories: z.ZodOptional<z.ZodArray<z.ZodString>>;
70
+ allow_categories: z.ZodOptional<z.ZodArray<z.ZodString>>;
71
+ }, z.core.$strip>>;
72
+ }, z.core.$strip>>;
73
+ }, z.core.$strip>;
74
+ export declare function uploadFileDataQurlTool(client: IQURLClient, runtime: ToolRuntimeOptions): {
75
+ name: string;
76
+ title: string;
77
+ description: string;
78
+ inputSchema: z.ZodObject<{
79
+ file_base64: z.ZodString;
80
+ file_name: z.ZodString;
81
+ content_type: z.ZodEnum<{
82
+ "application/pdf": "application/pdf";
83
+ "image/gif": "image/gif";
84
+ "image/jpeg": "image/jpeg";
85
+ "image/png": "image/png";
86
+ "image/webp": "image/webp";
87
+ }>;
88
+ email_delivery: z.ZodOptional<z.ZodObject<{
89
+ to: z.ZodArray<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodEmail>>;
90
+ subject: z.ZodOptional<z.ZodString>;
91
+ message: z.ZodOptional<z.ZodString>;
92
+ }, z.core.$strip>>;
93
+ label: z.ZodOptional<z.ZodString>;
94
+ expires_in: z.ZodOptional<z.ZodString>;
95
+ one_time_use: z.ZodOptional<z.ZodBoolean>;
96
+ max_sessions: z.ZodOptional<z.ZodNumber>;
97
+ session_duration: z.ZodOptional<z.ZodString>;
98
+ access_policy: z.ZodOptional<z.ZodObject<{
99
+ ip_allowlist: z.ZodOptional<z.ZodArray<z.ZodString>>;
100
+ ip_denylist: z.ZodOptional<z.ZodArray<z.ZodString>>;
101
+ geo_allowlist: z.ZodOptional<z.ZodArray<z.ZodString>>;
102
+ geo_denylist: z.ZodOptional<z.ZodArray<z.ZodString>>;
103
+ user_agent_allow_regex: z.ZodOptional<z.ZodString>;
104
+ user_agent_deny_regex: z.ZodOptional<z.ZodString>;
105
+ ai_agent_policy: z.ZodOptional<z.ZodObject<{
106
+ block_all: z.ZodOptional<z.ZodBoolean>;
107
+ deny_categories: z.ZodOptional<z.ZodArray<z.ZodString>>;
108
+ allow_categories: z.ZodOptional<z.ZodArray<z.ZodString>>;
109
+ }, z.core.$strip>>;
110
+ }, z.core.$strip>>;
111
+ }, z.core.$strip>;
112
+ outputSchema: z.ZodObject<{
113
+ resource_id: z.ZodString;
114
+ qurl_id: z.ZodString;
115
+ qurl_link: z.ZodString;
116
+ qurl_site: z.ZodOptional<z.ZodString>;
117
+ expires_at: z.ZodOptional<z.ZodString>;
118
+ file_name: z.ZodString;
119
+ content_type: z.ZodString;
120
+ size_bytes: z.ZodNumber;
121
+ branded_domain: z.ZodOptional<z.ZodString>;
122
+ type: z.ZodOptional<z.ZodString>;
123
+ email_delivery: z.ZodOptional<z.ZodObject<{
124
+ attempted: z.ZodBoolean;
125
+ enabled: z.ZodBoolean;
126
+ recipients: z.ZodArray<z.ZodString>;
127
+ sent: z.ZodNumber;
128
+ failed: z.ZodNumber;
129
+ skipped_reason: z.ZodOptional<z.ZodString>;
130
+ results: z.ZodArray<z.ZodObject<{
131
+ email: z.ZodString;
132
+ success: z.ZodBoolean;
133
+ skipped: z.ZodBoolean;
134
+ error: z.ZodOptional<z.ZodString>;
135
+ message_id: z.ZodOptional<z.ZodString>;
136
+ }, z.core.$strip>>;
137
+ }, z.core.$strip>>;
138
+ }, z.core.$loose>;
139
+ annotations: {
140
+ title: string;
141
+ readOnlyHint: boolean;
142
+ destructiveHint: boolean;
143
+ idempotentHint: boolean;
144
+ openWorldHint: boolean;
145
+ };
146
+ handler: (input: {
147
+ file_base64: string;
148
+ file_name: string;
149
+ content_type: "application/pdf" | "image/gif" | "image/jpeg" | "image/png" | "image/webp";
150
+ email_delivery?: {
151
+ to: string[];
152
+ subject?: string | undefined;
153
+ message?: string | undefined;
154
+ } | undefined;
155
+ label?: string | undefined;
156
+ expires_in?: string | undefined;
157
+ one_time_use?: boolean | undefined;
158
+ max_sessions?: number | undefined;
159
+ session_duration?: string | undefined;
160
+ access_policy?: {
161
+ ip_allowlist?: string[] | undefined;
162
+ ip_denylist?: string[] | undefined;
163
+ geo_allowlist?: string[] | undefined;
164
+ geo_denylist?: string[] | undefined;
165
+ user_agent_allow_regex?: string | undefined;
166
+ user_agent_deny_regex?: string | undefined;
167
+ ai_agent_policy?: {
168
+ block_all?: boolean | undefined;
169
+ deny_categories?: string[] | undefined;
170
+ allow_categories?: string[] | undefined;
171
+ } | undefined;
172
+ } | undefined;
173
+ }) => Promise<{
174
+ content: Array<{
175
+ type: "text";
176
+ text: string;
177
+ }>;
178
+ structuredContent?: Record<string, unknown>;
179
+ isError?: boolean;
180
+ }>;
181
+ };
182
+ //# sourceMappingURL=upload-file-data-qurl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-file-data-qurl.d.ts","sourceRoot":"","sources":["../../src/tools/upload-file-data-qurl.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,cAAc,CAAC;AA6BtB,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED,eAAO,MAAM,iCAAiC,QAE7C,CAAC;AAEF,wBAAgB,8BAA8B,CAC5C,mBAAmB,SAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA8BxD;AAED,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAmC,CAAC;AA2HzE,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8EtF"}
@@ -0,0 +1,200 @@
1
+ import { Buffer } from "node:buffer";
2
+ import { z } from "zod";
3
+ import { MAX_UPLOAD_FILE_DATA_BYTES } from "../config.js";
4
+ import { allowsServerApiKeyFallback, withMissingApiKeyHandler, } from "./_shared.js";
5
+ import { emailDeliveryInputSchema, maybeDeliverToolEmail, toEmailAugmentedResult, uploadEmailDetailLines, } from "./email-delivery.js";
6
+ import { getConnectorConfig, getMaxUploadFileBytes, mintUploadedFile, normalizeFileName, supportedMimeTypes, uploadToConnector, validateFileNameContentType, validateFileSignature, } from "./upload-file-shared.js";
7
+ import { uploadFileQurlOutputSchema } from "./output-schemas.js";
8
+ import { uploadMintOptionsShape } from "./upload-mint-options.js";
9
+ // Uploads pass three deliberate bounds: a runtime-derived raw-string schema
10
+ // ceiling, the HTTP JSON-body limit before tool dispatch, and
11
+ // getMaxUploadFileBytes on the normalized decoded payload. The exported schema
12
+ // uses the protocol-wide 100 MB hard maximum for direct consumers; registered
13
+ // tools advertise the operator's configured decoded-byte limit. HTTP only opens
14
+ // a parser ceiling above the 10 MB default for a session already validated by a
15
+ // successful downstream qURL API call (see createHttpRuntime).
16
+ const MAX_DATA_URL_PREFIX_CHARACTERS = 1024;
17
+ export function maxBase64CharactersForBytes(maxBytes) {
18
+ return Math.ceil((maxBytes * 4) / 3) + MAX_DATA_URL_PREFIX_CHARACTERS;
19
+ }
20
+ export const MAX_UPLOAD_FILE_BASE64_CHARACTERS = maxBase64CharactersForBytes(MAX_UPLOAD_FILE_DATA_BYTES);
21
+ export function createUploadFileDataQurlSchema(maxBase64Characters = MAX_UPLOAD_FILE_BASE64_CHARACTERS) {
22
+ return z
23
+ .object({
24
+ file_base64: z
25
+ .string()
26
+ .min(1)
27
+ .max(maxBase64Characters)
28
+ .describe("Base64-encoded PDF or raster image content. Raw base64 and data URLs are both accepted. For compressible images, compress them first and then convert them to base64 before calling this tool."),
29
+ file_name: z
30
+ .string()
31
+ .min(1)
32
+ .max(255)
33
+ .describe("Filename to register with the connector. `.jpg` and `.jpeg` files should use `image/jpeg`."),
34
+ content_type: z
35
+ .enum(supportedMimeTypes)
36
+ .describe("MIME type for the uploaded file. Supported: application/pdf, image/png, image/jpeg, image/webp, image/gif."),
37
+ email_delivery: emailDeliveryInputSchema
38
+ .optional()
39
+ .describe("Optional email notification settings for sending the uploaded file's qURL to one or more recipients."),
40
+ })
41
+ .extend(uploadMintOptionsShape);
42
+ }
43
+ export const uploadFileDataQurlSchema = createUploadFileDataQurlSchema();
44
+ /**
45
+ * Normalize and validate base64 input for file upload.
46
+ *
47
+ * Accepts multiple input formats:
48
+ * - Raw base64: "SGVsbG8gV29ybGQ="
49
+ * - Data URL: "data:image/png;base64,iVBORw0KGgo..."
50
+ * - Base64 with whitespace (e.g., line breaks from copy-paste)
51
+ * - URL-safe base64 (uses - and _ instead of + and /)
52
+ *
53
+ * @param input - Raw base64 string or data URL
54
+ * @returns Normalized standard base64 and the data URL media type, when present
55
+ * @throws Error if input is empty or contains invalid base64 characters
56
+ */
57
+ function normalizeBase64Input(input) {
58
+ const trimmed = input.trim();
59
+ if (!trimmed) {
60
+ throw new Error("file_base64 must not be empty");
61
+ }
62
+ // Step 1: Parse and strip the data URL prefix if present (e.g.,
63
+ // "data:image/png;base64,"). Return its media type so callers do not need
64
+ // to parse the same prefix again. Bound the regex probe independently of
65
+ // the payload ceiling so even a very large hostile string cannot make
66
+ // prefix parsing scale with the file body.
67
+ const dataUrlPrefixProbe = trimmed.slice(0, MAX_DATA_URL_PREFIX_CHARACTERS);
68
+ const dataUrl = /^data:([^;,]*)(?:;[a-z0-9!#$&^_.+-]+=[^;,\s]*)*;base64,/i.exec(dataUrlPrefixProbe);
69
+ if (!dataUrl && trimmed.toLowerCase().startsWith("data:")) {
70
+ throw new Error("Only base64-encoded data URLs are supported.");
71
+ }
72
+ const withoutDataUrl = dataUrl ? trimmed.slice(dataUrl[0].length) : trimmed;
73
+ // Step 2: Remove whitespace (base64 from copy-paste often has line breaks)
74
+ const withoutWhitespace = withoutDataUrl.replace(/\s+/g, "");
75
+ if (!withoutWhitespace) {
76
+ throw new Error("file_base64 must not be empty");
77
+ }
78
+ // Step 3: Accept either the standard or URL-safe alphabet, but reject a
79
+ // mixed alphabet because no conforming encoder emits that representation.
80
+ const usesStandardAlphabet = /^[A-Za-z0-9+/]*={0,2}$/.test(withoutWhitespace);
81
+ const usesUrlSafeAlphabet = !usesStandardAlphabet && /^[A-Za-z0-9_-]*={0,2}$/.test(withoutWhitespace);
82
+ if (!usesStandardAlphabet && !usesUrlSafeAlphabet) {
83
+ throw new Error("file_base64 must be valid base64-encoded content");
84
+ }
85
+ // Step 4: Convert URL-safe base64 to standard base64. URL-safe uses '-'
86
+ // instead of '+' and '_' instead of '/'.
87
+ const normalized = usesStandardAlphabet
88
+ ? withoutWhitespace
89
+ : withoutWhitespace.replace(/-/g, "+").replace(/_/g, "/");
90
+ // Step 5: Validate and fix padding
91
+ // Base64 length must be divisible by 4. Valid lengths mod 4 are: 0, 2, 3
92
+ // Length mod 4 = 1 is always invalid (would represent 6 bits, not enough for a byte)
93
+ const paddingNeeded = normalized.length % 4;
94
+ if (paddingNeeded === 1) {
95
+ throw new Error("file_base64 must be valid base64-encoded content");
96
+ }
97
+ const dataUrlContentType = dataUrl?.[1] ? dataUrl[1].toLowerCase() : undefined;
98
+ // Already properly padded
99
+ if (paddingNeeded === 0) {
100
+ return { base64: normalized, dataUrlContentType };
101
+ }
102
+ // Add missing padding (mod 4 = 2 needs "==", mod 4 = 3 needs "=")
103
+ return {
104
+ base64: normalized.padEnd(normalized.length + (4 - paddingNeeded), "="),
105
+ dataUrlContentType,
106
+ };
107
+ }
108
+ function decodeBase64File(input, maxBytes, contentType) {
109
+ const tooLargeMessage = "Decoded file exceeds the allowed upload size. Reduce the file size and try again.";
110
+ const encodedCharacterLimit = Math.ceil((maxBytes * 4) / 3);
111
+ // Allow normal MIME line wrapping plus a bounded data-URL prefix, but reject
112
+ // runtime-oversized strings before trim/replace normalization copies them.
113
+ const rawCharacterLimit = encodedCharacterLimit + Math.ceil(encodedCharacterLimit / 4) + MAX_DATA_URL_PREFIX_CHARACTERS;
114
+ if (input.length > rawCharacterLimit) {
115
+ throw new Error(tooLargeMessage);
116
+ }
117
+ const normalized = normalizeBase64Input(input);
118
+ if (normalized.dataUrlContentType && normalized.dataUrlContentType !== contentType) {
119
+ throw new Error("Data URL media type does not match content_type.");
120
+ }
121
+ const paddingBytes = normalized.base64.endsWith("==")
122
+ ? 2
123
+ : normalized.base64.endsWith("=")
124
+ ? 1
125
+ : 0;
126
+ const decodedByteLength = (normalized.base64.length / 4) * 3 - paddingBytes;
127
+ if (decodedByteLength > maxBytes) {
128
+ throw new Error(tooLargeMessage);
129
+ }
130
+ const fileData = Buffer.from(normalized.base64, "base64");
131
+ if (fileData.byteLength === 0) {
132
+ throw new Error("file_base64 decoded to an empty file");
133
+ }
134
+ // Keep an actual-byte check after the pre-allocation estimate so decoder or
135
+ // normalization behavior cannot silently weaken the configured limit.
136
+ if (fileData.byteLength > maxBytes) {
137
+ throw new Error(tooLargeMessage);
138
+ }
139
+ validateFileSignature(fileData, contentType);
140
+ return fileData;
141
+ }
142
+ export function uploadFileDataQurlTool(client, runtime) {
143
+ const inputSchema = createUploadFileDataQurlSchema(runtime.maxUploadFileDataBytes === undefined
144
+ ? MAX_UPLOAD_FILE_BASE64_CHARACTERS
145
+ : maxBase64CharactersForBytes(runtime.maxUploadFileDataBytes));
146
+ return {
147
+ name: "upload_file_data_qurl",
148
+ title: "Upload File Data qURL",
149
+ description: "Upload base64-encoded PDF or raster image content to a qURL connector, then mint an access link for it. " +
150
+ "This is the correct tool for a single in-chat image, PDF, or file attachment in either MCP transport, especially when the user wants 'the qURL of this image/file' or wants the generated link emailed. " +
151
+ "Use this when you have the file data available but cannot provide a server-local file path. " +
152
+ "Use `upload_file_qurl` when the file already exists on the MCP server host, use `create_qurl` when you already have a URL, and use `mint_link` when the file has already been uploaded and you only need another token. " +
153
+ "For compressible images, compress them before converting to base64 so the request is smaller and more reliable. " +
154
+ "When the server upload limit is configured above 10 MB, a fresh HTTP session must complete a smaller qURL API call before its first larger upload. " +
155
+ "The tool decodes `file_base64`, uploads the file to `${QURL_CONNECTOR_URL}/api/upload`, then mints a qURL from the returned `resource_id`. " +
156
+ "Supported MIME types are application/pdf, image/png, image/jpeg, image/webp, and image/gif. " +
157
+ "If `one_time_use` is omitted, the tool defaults it to `true` for safer file distribution. " +
158
+ "Requires `QURL_CONNECTOR_URL`; stdio reads `QURL_API_KEY` from server config, while HTTP uses the caller's bearer credential. " +
159
+ "**Returns:** `{ resource_id: string, qurl_id: string, qurl_link: string, qurl_site?: string, expires_at?: string, file_name: string, content_type: string, size_bytes: number, branded_domain?: string, type?: string, email_delivery?: object }`.",
160
+ inputSchema,
161
+ outputSchema: uploadFileQurlOutputSchema,
162
+ annotations: {
163
+ title: "Upload File Data qURL",
164
+ readOnlyHint: false,
165
+ destructiveHint: false,
166
+ idempotentHint: false,
167
+ openWorldHint: true,
168
+ },
169
+ handler: withMissingApiKeyHandler(async (input) => {
170
+ const allowServerApiKeyFallback = allowsServerApiKeyFallback(runtime);
171
+ // Preflight connector config before decoding payloads so auth/config errors fail fast.
172
+ const connectorConfig = getConnectorConfig(allowServerApiKeyFallback);
173
+ const fileName = normalizeFileName(input.file_name);
174
+ validateFileNameContentType(fileName, input.content_type);
175
+ const fileData = decodeBase64File(input.file_base64, getMaxUploadFileBytes(), input.content_type);
176
+ const upload = await uploadToConnector(fileData, fileName, input.content_type, connectorConfig);
177
+ const result = await mintUploadedFile(client, upload.resource_id, {
178
+ name: fileName,
179
+ contentType: input.content_type,
180
+ sizeBytes: fileData.byteLength,
181
+ }, input);
182
+ const emailResult = await maybeDeliverToolEmail({
183
+ allowServerApiKeyFallback,
184
+ delivery: input.email_delivery,
185
+ defaultSubject: "Your secure file access link is ready",
186
+ detailLines: uploadEmailDetailLines({
187
+ intro: "A secure qURL file link has been created for you.",
188
+ fileName,
189
+ contentType: input.content_type,
190
+ qurlLink: result.qurl_link,
191
+ expiresAt: result.expires_at,
192
+ qurlSite: result.qurl_site,
193
+ label: input.label,
194
+ }),
195
+ });
196
+ return toEmailAugmentedResult(result, emailResult);
197
+ }),
198
+ };
199
+ }
200
+ //# sourceMappingURL=upload-file-data-qurl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-file-data-qurl.js","sourceRoot":"","sources":["../../src/tools/upload-file-data-qurl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,GAEzB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,4EAA4E;AAC5E,8DAA8D;AAC9D,+EAA+E;AAC/E,8EAA8E;AAC9E,gFAAgF;AAChF,gFAAgF;AAChF,+DAA+D;AAC/D,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAE5C,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