@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
@@ -0,0 +1,162 @@
1
+ import { type FileHandle } from "node:fs/promises";
2
+ import { z } from "zod";
3
+ import type { IQURLClient } from "../client.js";
4
+ import { type ToolRuntimeOptions } from "./_shared.js";
5
+ import { type ConnectorConfig } from "./upload-file-shared.js";
6
+ export declare const uploadFileQurlSchema: z.ZodObject<{
7
+ file_path: z.ZodString;
8
+ file_name: z.ZodOptional<z.ZodString>;
9
+ content_type: z.ZodOptional<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 type UploadFileQurlInput = z.infer<typeof uploadFileQurlSchema>;
41
+ export declare function readFileWithinLimit(fileHandle: FileHandle, maxBytes: number, initialSize: number): Promise<Uint8Array>;
42
+ export declare function uploadGeneratedFileAndMint(client: IQURLClient, input: UploadFileQurlInput, connectorConfig: ConnectorConfig): Promise<{
43
+ resource_id: string;
44
+ qurl_id: string;
45
+ qurl_link: string;
46
+ qurl_site: string | undefined;
47
+ expires_at: string;
48
+ file_name: string;
49
+ content_type: string;
50
+ size_bytes: number;
51
+ branded_domain: string | undefined;
52
+ type: string | undefined;
53
+ }>;
54
+ export declare function uploadFileQurlTool(client: IQURLClient, runtime: ToolRuntimeOptions): {
55
+ name: string;
56
+ title: string;
57
+ description: string;
58
+ inputSchema: z.ZodObject<{
59
+ file_path: z.ZodString;
60
+ file_name: z.ZodOptional<z.ZodString>;
61
+ content_type: z.ZodOptional<z.ZodEnum<{
62
+ "application/pdf": "application/pdf";
63
+ "image/gif": "image/gif";
64
+ "image/jpeg": "image/jpeg";
65
+ "image/png": "image/png";
66
+ "image/webp": "image/webp";
67
+ }>>;
68
+ email_delivery: z.ZodOptional<z.ZodObject<{
69
+ to: z.ZodArray<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodEmail>>;
70
+ subject: z.ZodOptional<z.ZodString>;
71
+ message: z.ZodOptional<z.ZodString>;
72
+ }, z.core.$strip>>;
73
+ label: z.ZodOptional<z.ZodString>;
74
+ expires_in: z.ZodOptional<z.ZodString>;
75
+ one_time_use: z.ZodOptional<z.ZodBoolean>;
76
+ max_sessions: z.ZodOptional<z.ZodNumber>;
77
+ session_duration: z.ZodOptional<z.ZodString>;
78
+ access_policy: z.ZodOptional<z.ZodObject<{
79
+ ip_allowlist: z.ZodOptional<z.ZodArray<z.ZodString>>;
80
+ ip_denylist: z.ZodOptional<z.ZodArray<z.ZodString>>;
81
+ geo_allowlist: z.ZodOptional<z.ZodArray<z.ZodString>>;
82
+ geo_denylist: z.ZodOptional<z.ZodArray<z.ZodString>>;
83
+ user_agent_allow_regex: z.ZodOptional<z.ZodString>;
84
+ user_agent_deny_regex: z.ZodOptional<z.ZodString>;
85
+ ai_agent_policy: z.ZodOptional<z.ZodObject<{
86
+ block_all: z.ZodOptional<z.ZodBoolean>;
87
+ deny_categories: z.ZodOptional<z.ZodArray<z.ZodString>>;
88
+ allow_categories: z.ZodOptional<z.ZodArray<z.ZodString>>;
89
+ }, z.core.$strip>>;
90
+ }, z.core.$strip>>;
91
+ }, z.core.$strip>;
92
+ outputSchema: z.ZodObject<{
93
+ resource_id: z.ZodString;
94
+ qurl_id: z.ZodString;
95
+ qurl_link: z.ZodString;
96
+ qurl_site: z.ZodOptional<z.ZodString>;
97
+ expires_at: z.ZodOptional<z.ZodString>;
98
+ file_name: z.ZodString;
99
+ content_type: z.ZodString;
100
+ size_bytes: z.ZodNumber;
101
+ branded_domain: z.ZodOptional<z.ZodString>;
102
+ type: z.ZodOptional<z.ZodString>;
103
+ email_delivery: z.ZodOptional<z.ZodObject<{
104
+ attempted: z.ZodBoolean;
105
+ enabled: z.ZodBoolean;
106
+ recipients: z.ZodArray<z.ZodString>;
107
+ sent: z.ZodNumber;
108
+ failed: z.ZodNumber;
109
+ skipped_reason: z.ZodOptional<z.ZodString>;
110
+ results: z.ZodArray<z.ZodObject<{
111
+ email: z.ZodString;
112
+ success: z.ZodBoolean;
113
+ skipped: z.ZodBoolean;
114
+ error: z.ZodOptional<z.ZodString>;
115
+ message_id: z.ZodOptional<z.ZodString>;
116
+ }, z.core.$strip>>;
117
+ }, z.core.$strip>>;
118
+ }, z.core.$loose>;
119
+ annotations: {
120
+ title: string;
121
+ readOnlyHint: boolean;
122
+ destructiveHint: boolean;
123
+ idempotentHint: boolean;
124
+ openWorldHint: boolean;
125
+ };
126
+ handler: (input: {
127
+ file_path: string;
128
+ file_name?: string | undefined;
129
+ content_type?: "application/pdf" | "image/gif" | "image/jpeg" | "image/png" | "image/webp" | undefined;
130
+ email_delivery?: {
131
+ to: string[];
132
+ subject?: string | undefined;
133
+ message?: string | undefined;
134
+ } | undefined;
135
+ label?: string | undefined;
136
+ expires_in?: string | undefined;
137
+ one_time_use?: boolean | undefined;
138
+ max_sessions?: number | undefined;
139
+ session_duration?: string | undefined;
140
+ access_policy?: {
141
+ ip_allowlist?: string[] | undefined;
142
+ ip_denylist?: string[] | undefined;
143
+ geo_allowlist?: string[] | undefined;
144
+ geo_denylist?: string[] | undefined;
145
+ user_agent_allow_regex?: string | undefined;
146
+ user_agent_deny_regex?: string | undefined;
147
+ ai_agent_policy?: {
148
+ block_all?: boolean | undefined;
149
+ deny_categories?: string[] | undefined;
150
+ allow_categories?: string[] | undefined;
151
+ } | undefined;
152
+ } | undefined;
153
+ }) => Promise<{
154
+ content: Array<{
155
+ type: "text";
156
+ text: string;
157
+ }>;
158
+ structuredContent?: Record<string, unknown>;
159
+ isError?: boolean;
160
+ }>;
161
+ };
162
+ //# sourceMappingURL=upload-file-qurl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-file-qurl.d.ts","sourceRoot":"","sources":["../../src/tools/upload-file-qurl.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGnE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,cAAc,CAAC;AAQtB,OAAO,EAUL,KAAK,eAAe,EACrB,MAAM,yBAAyB,CAAC;AAGjC,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyBA,CAAC;AAElC,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEvE,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,UAAU,CAAC,CAkCrB;AAuDD,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,mBAAmB,EAC1B,eAAe,EAAE,eAAe;;;;;;;;;;;GAoBjC;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkDlF"}
@@ -0,0 +1,167 @@
1
+ import { Buffer } from "node:buffer";
2
+ import { constants } from "node:fs";
3
+ import { open, realpath } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
5
+ import { isAbsolute, relative, resolve, sep } from "node:path";
6
+ import { z } from "zod";
7
+ import { allowsServerApiKeyFallback, withMissingApiKeyHandler, } from "./_shared.js";
8
+ import { emailDeliveryInputSchema, maybeDeliverToolEmail, toEmailAugmentedResult, uploadEmailDetailLines, } from "./email-delivery.js";
9
+ import { uploadMintOptionsShape } from "./upload-mint-options.js";
10
+ import { getConnectorConfig, getMaxUploadFileBytes, inferContentType, mintUploadedFile, normalizeFileName, supportedMimeTypes, uploadToConnector, validateFileNameContentType, validateFileSignature, } from "./upload-file-shared.js";
11
+ import { uploadFileQurlOutputSchema } from "./output-schemas.js";
12
+ export const uploadFileQurlSchema = z
13
+ .object({
14
+ file_path: z
15
+ .string()
16
+ .min(1)
17
+ .max(4096)
18
+ .describe("Path to a local PDF or raster image file on the MCP server host"),
19
+ file_name: z
20
+ .string()
21
+ .min(1)
22
+ .max(255)
23
+ .optional()
24
+ .describe("Optional override for the uploaded filename; defaults to the source basename"),
25
+ content_type: z
26
+ .enum(supportedMimeTypes)
27
+ .optional()
28
+ .describe("Optional MIME type confirmation. It must match the filename extension. Supported: application/pdf, image/png, image/jpeg, image/webp, image/gif"),
29
+ email_delivery: emailDeliveryInputSchema
30
+ .optional()
31
+ .describe("Optional email notification settings for sending the uploaded file's qURL to one or more recipients."),
32
+ })
33
+ .extend(uploadMintOptionsShape);
34
+ export async function readFileWithinLimit(fileHandle, maxBytes, initialSize) {
35
+ // Read at most one byte beyond the limit. Unlike FileHandle.readFile(), this
36
+ // remains bounded if the file grows after the initial stat. Start near the
37
+ // observed size so a small file does not reserve the full configured limit.
38
+ // allocUnsafe is safe because only the initialized prefix is returned below;
39
+ // never return `buffer` without slicing it to totalBytesRead.
40
+ let buffer = Buffer.allocUnsafe(Math.min(maxBytes + 1, Math.max(1, initialSize + 1)));
41
+ let totalBytesRead = 0;
42
+ while (true) {
43
+ if (totalBytesRead === buffer.byteLength) {
44
+ if (totalBytesRead > maxBytes)
45
+ break;
46
+ const nextCapacity = Math.min(maxBytes + 1, Math.max(buffer.byteLength * 2, buffer.byteLength + 64 * 1024));
47
+ const expanded = Buffer.allocUnsafe(nextCapacity);
48
+ buffer.copy(expanded, 0, 0, totalBytesRead);
49
+ buffer = expanded;
50
+ }
51
+ const { bytesRead } = await fileHandle.read(buffer, totalBytesRead, buffer.byteLength - totalBytesRead, null);
52
+ if (bytesRead === 0)
53
+ break;
54
+ totalBytesRead += bytesRead;
55
+ }
56
+ if (totalBytesRead > maxBytes) {
57
+ throw new Error("File exceeds the configured upload size limit.");
58
+ }
59
+ return buffer.subarray(0, totalBytesRead);
60
+ }
61
+ async function uploadLocalFileAndMint(client, input, connectorConfig) {
62
+ // Preflight config before reading local files so misconfigured hosts fail fast.
63
+ const sourcePath = resolve(input.file_path);
64
+ // O_NOFOLLOW protects the final component. Intermediate directory symlinks
65
+ // still follow normal filesystem semantics; this tool is stdio-only and the
66
+ // local user explicitly chooses the server-host path to share. Callers must
67
+ // never expose this helper to HTTP input or pass an HTTP caller-controlled path.
68
+ const fileName = normalizeFileName(input.file_name ?? sourcePath);
69
+ const contentType = input.content_type ?? inferContentType(fileName);
70
+ if (!contentType) {
71
+ throw new Error("Unsupported file type. Provide a PDF, PNG, JPEG, WEBP, or GIF file, or set content_type explicitly.");
72
+ }
73
+ validateFileNameContentType(fileName, contentType);
74
+ const maxBytes = getMaxUploadFileBytes();
75
+ let fileHandle;
76
+ try {
77
+ fileHandle = await open(sourcePath, constants.O_RDONLY | constants.O_NOFOLLOW);
78
+ }
79
+ catch (error) {
80
+ if (error.code === "ELOOP") {
81
+ throw new Error("file_path must not point to a symbolic link");
82
+ }
83
+ throw error;
84
+ }
85
+ let fileData;
86
+ try {
87
+ const sourceStat = await fileHandle.stat();
88
+ if (!sourceStat.isFile())
89
+ throw new Error("file_path must point to a regular file");
90
+ if (sourceStat.size === 0)
91
+ throw new Error("File is empty.");
92
+ if (sourceStat.size > maxBytes) {
93
+ throw new Error("File exceeds the configured upload size limit.");
94
+ }
95
+ fileData = await readFileWithinLimit(fileHandle, maxBytes, sourceStat.size);
96
+ }
97
+ finally {
98
+ await fileHandle.close();
99
+ }
100
+ validateFileSignature(fileData, contentType);
101
+ const upload = await uploadToConnector(fileData, fileName, contentType, connectorConfig);
102
+ return mintUploadedFile(client, upload.resource_id, { name: fileName, contentType, sizeBytes: fileData.byteLength }, input);
103
+ }
104
+ export async function uploadGeneratedFileAndMint(client, input, connectorConfig) {
105
+ const sourcePath = resolve(input.file_path);
106
+ const [canonicalTempPath, canonicalSourcePath] = await Promise.all([
107
+ realpath(tmpdir()),
108
+ realpath(sourcePath),
109
+ ]);
110
+ const relativeToTemp = relative(canonicalTempPath, canonicalSourcePath);
111
+ if (isAbsolute(relativeToTemp) ||
112
+ relativeToTemp === ".." ||
113
+ relativeToTemp.startsWith(`..${sep}`)) {
114
+ throw new Error("Generated upload files must remain inside the server temporary directory.");
115
+ }
116
+ return uploadLocalFileAndMint(client, { ...input, file_path: canonicalSourcePath }, connectorConfig);
117
+ }
118
+ export function uploadFileQurlTool(client, runtime) {
119
+ return {
120
+ name: "upload_file_qurl",
121
+ title: "Upload File qURL",
122
+ description: "Upload a local PDF or raster image file to a qURL connector, then mint an access link for it. " +
123
+ "Use this when the content already exists on the MCP server host and you need a shareable file qURL rather than a proxy to an existing website URL. " +
124
+ "This stdio-only tool can read any supported file that the local MCP process user can access; invoke it only for a path the user explicitly chose to share. " +
125
+ "Deploy stdio under a restricted OS account or container whose readable files are limited to intended shareable content. " +
126
+ "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. " +
127
+ "The tool reads `file_path`, uploads the file to `${QURL_CONNECTOR_URL}/api/upload`, then mints a qURL from the returned `resource_id`. " +
128
+ "If `one_time_use` is omitted, the tool defaults it to `true` for safer file distribution. " +
129
+ "Requires both `QURL_API_KEY` and `QURL_CONNECTOR_URL` in the server environment or runtime config. " +
130
+ "**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 }`.",
131
+ inputSchema: uploadFileQurlSchema,
132
+ outputSchema: uploadFileQurlOutputSchema,
133
+ annotations: {
134
+ title: "Upload File qURL",
135
+ readOnlyHint: false,
136
+ destructiveHint: false,
137
+ idempotentHint: false,
138
+ openWorldHint: true,
139
+ },
140
+ handler: withMissingApiKeyHandler(async (input) => {
141
+ // getToolFactoriesForMode also omits this factory from HTTP registration;
142
+ // retain the handler guard for direct embedding and future registry changes.
143
+ if (runtime.mode !== "stdio") {
144
+ throw new Error("upload_file_qurl is available only in stdio mode");
145
+ }
146
+ const allowServerApiKeyFallback = allowsServerApiKeyFallback(runtime);
147
+ const connectorConfig = getConnectorConfig(allowServerApiKeyFallback);
148
+ const result = await uploadLocalFileAndMint(client, input, connectorConfig);
149
+ const emailResult = await maybeDeliverToolEmail({
150
+ allowServerApiKeyFallback,
151
+ delivery: input.email_delivery,
152
+ defaultSubject: "Your secure file access link is ready",
153
+ detailLines: uploadEmailDetailLines({
154
+ intro: "A secure qURL file link has been created for you.",
155
+ fileName: result.file_name,
156
+ contentType: result.content_type,
157
+ qurlLink: result.qurl_link,
158
+ expiresAt: result.expires_at,
159
+ qurlSite: result.qurl_site,
160
+ label: input.label,
161
+ }),
162
+ });
163
+ return toEmailAugmentedResult(result, emailResult);
164
+ }),
165
+ };
166
+ }
167
+ //# sourceMappingURL=upload-file-qurl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-file-qurl.js","sourceRoot":"","sources":["../../src/tools/upload-file-qurl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAmB,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,GAEzB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,s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"}
@@ -0,0 +1,36 @@
1
+ import { type IQURLClient, type MintLinkInput } from "../client.js";
2
+ export declare const supportedMimeTypes: readonly ["application/pdf", "image/gif", "image/jpeg", "image/png", "image/webp"];
3
+ export declare const mimeTypeByExtension: Map<string, "application/pdf" | "image/gif" | "image/jpeg" | "image/png" | "image/webp">;
4
+ type ConnectorUploadResponse = {
5
+ resource_id: string;
6
+ };
7
+ export type ConnectorConfig = {
8
+ apiKey: string;
9
+ uploadUrl: string;
10
+ };
11
+ export declare function getConnectorConfig(allowServerApiKeyFallback?: boolean): ConnectorConfig;
12
+ export declare function getConnectorUploadUrl(connectorURL: string): string;
13
+ export declare function normalizeFileName(input: string): string;
14
+ export declare function inferContentType(filePath: string): "application/pdf" | "image/gif" | "image/jpeg" | "image/png" | "image/webp" | undefined;
15
+ export declare function getMaxUploadFileBytes(): number;
16
+ export declare function validateFileNameContentType(fileName: string, contentType: string): void;
17
+ export declare function validateFileSignature(fileData: Uint8Array, contentType: string): void;
18
+ export declare function mintUploadedFile(client: IQURLClient, resourceId: string, file: {
19
+ name: string;
20
+ contentType: string;
21
+ sizeBytes: number;
22
+ }, input: MintLinkInput): Promise<{
23
+ resource_id: string;
24
+ qurl_id: string;
25
+ qurl_link: string;
26
+ qurl_site: string | undefined;
27
+ expires_at: string;
28
+ file_name: string;
29
+ content_type: string;
30
+ size_bytes: number;
31
+ branded_domain: string | undefined;
32
+ type: string | undefined;
33
+ }>;
34
+ export declare function uploadToConnector(fileData: Uint8Array, fileName: string, contentType: string, connectorConfig: ConnectorConfig): Promise<ConnectorUploadResponse>;
35
+ export {};
36
+ //# sourceMappingURL=upload-file-shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-file-shared.d.ts","sourceRoot":"","sources":["../../src/tools/upload-file-shared.ts"],"names":[],"mappings":"AAOA,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,aAAa,EACnB,MAAM,cAAc,CAAC;AAMtB,eAAO,MAAM,kBAAkB,oFAM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