@epcc-sdk/sdks-files 0.3.0 → 0.4.1

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.
@@ -0,0 +1,278 @@
1
+ import * as z from "zod";
2
+ const messageOf = (error) => error instanceof Error ? error.message : JSON.stringify(error);
3
+ const toToolResult = async (request) => {
4
+ let text;
5
+ try {
6
+ const result = await request;
7
+ if (result.error === void 0) {
8
+ const structuredContent = typeof result.data === "object" && result.data !== null && !Array.isArray(result.data) ? result.data : { data: result.data ?? null };
9
+ return {
10
+ structuredContent,
11
+ content: [{ type: "text", text: JSON.stringify(structuredContent) }]
12
+ };
13
+ }
14
+ text = result.response ? `HTTP ${result.response.status}: ${JSON.stringify(result.error)}` : messageOf(result.error);
15
+ } catch (error) {
16
+ text = messageOf(error);
17
+ }
18
+ return { isError: true, content: [{ type: "text", text }] };
19
+ };
20
+ const WRAPPER_TYPES = [
21
+ "optional",
22
+ "nullable",
23
+ "default",
24
+ "readonly",
25
+ "nonoptional",
26
+ "catch",
27
+ "prefault"
28
+ ];
29
+ const madeByLoose = /* @__PURE__ */ new WeakSet();
30
+ function shapeCopiedOnFirstRead(copies, shape) {
31
+ const copy = {};
32
+ for (const key of Object.keys(shape)) {
33
+ Object.defineProperty(copy, key, {
34
+ configurable: true,
35
+ enumerable: true,
36
+ get() {
37
+ const value = looseIn(copies, shape[key]);
38
+ Object.defineProperty(copy, key, {
39
+ configurable: true,
40
+ enumerable: true,
41
+ writable: true,
42
+ value
43
+ });
44
+ return value;
45
+ }
46
+ });
47
+ }
48
+ return copy;
49
+ }
50
+ function looseCopyOf(copies, schema) {
51
+ const def = schema._zod.def;
52
+ const copy = (changes) => schema.clone({ ...def, ...changes }, { parent: true });
53
+ const looseChild = (child) => looseIn(copies, child);
54
+ if (def.type === "object") {
55
+ return copy({
56
+ catchall: z.unknown(),
57
+ shape: shapeCopiedOnFirstRead(copies, def.shape)
58
+ });
59
+ }
60
+ if (def.type === "array") {
61
+ return copy({ element: looseChild(def.element) });
62
+ }
63
+ if (def.type === "record") {
64
+ return copy({ valueType: looseChild(def.valueType) });
65
+ }
66
+ if (def.type === "lazy") {
67
+ return copy({ getter: () => looseChild(def.getter()) });
68
+ }
69
+ if (WRAPPER_TYPES.includes(def.type)) {
70
+ return copy({ innerType: looseChild(def.innerType) });
71
+ }
72
+ if (def.type === "union") {
73
+ return copy({ options: def.options.map(looseChild) });
74
+ }
75
+ if (def.type === "intersection") {
76
+ return copy({ left: looseChild(def.left), right: looseChild(def.right) });
77
+ }
78
+ return schema;
79
+ }
80
+ function looseIn(copies, schema) {
81
+ if (madeByLoose.has(schema)) return schema;
82
+ const known = copies.get(schema);
83
+ if (known) return known;
84
+ const copy = looseCopyOf(copies, schema);
85
+ copies.set(schema, copy);
86
+ if (copy !== schema) madeByLoose.add(copy);
87
+ return copy;
88
+ }
89
+ const loose = (schema) => looseIn(/* @__PURE__ */ new WeakMap(), schema);
90
+ const SHARED_SCHEMA_MIN_LENGTH = 1e3;
91
+ function reachesFrom(schema, name) {
92
+ const def = schema._zod.def;
93
+ const reach = (child) => [name, child];
94
+ if (def.type === "object") {
95
+ return Object.keys(def.shape).map((key) => [
96
+ key,
97
+ def.shape[key]
98
+ ]);
99
+ }
100
+ if (def.type === "array") return [reach(def.element)];
101
+ if (def.type === "record") return [reach(def.valueType)];
102
+ if (def.type === "lazy") return [reach(def.getter())];
103
+ if (WRAPPER_TYPES.includes(def.type)) return [reach(def.innerType)];
104
+ if (def.type === "union") {
105
+ return def.options.map((option) => reach(option));
106
+ }
107
+ if (def.type === "intersection") return [reach(def.left), reach(def.right)];
108
+ return [];
109
+ }
110
+ function reachedSchemas(input) {
111
+ const reached = /* @__PURE__ */ new Map();
112
+ const visit = (name, schema) => {
113
+ const seen = reached.get(schema);
114
+ if (seen) {
115
+ seen.count++;
116
+ return;
117
+ }
118
+ reached.set(schema, { name, count: 1 });
119
+ for (const [childName, child] of reachesFrom(schema, name)) {
120
+ visit(childName, child);
121
+ }
122
+ };
123
+ visit("input", input);
124
+ return reached;
125
+ }
126
+ const listedLengthOf = (schema) => JSON.stringify(
127
+ z.toJSONSchema(schema, {
128
+ io: "input",
129
+ target: "draft-7",
130
+ unrepresentable: "any"
131
+ })
132
+ ).length;
133
+ function unusedIdFor(api, name) {
134
+ const base = `${api}_${name.replace(/[^A-Za-z0-9_]/g, "_")}`;
135
+ let id = base;
136
+ for (let suffix = 2; z.globalRegistry._idmap.has(id); suffix++) {
137
+ id = `${base}_${suffix}`;
138
+ }
139
+ return id;
140
+ }
141
+ const withSharedSchemaIds = (api, input) => {
142
+ const candidates = [...reachedSchemas(input)].filter(
143
+ ([schema, { count }]) => count > 1 && madeByLoose.has(schema) && !z.globalRegistry.has(schema)
144
+ ).map(([schema, { name }]) => ({
145
+ schema,
146
+ name,
147
+ length: listedLengthOf(schema)
148
+ })).filter(({ length }) => length >= SHARED_SCHEMA_MIN_LENGTH).sort((a, b) => b.length - a.length);
149
+ let inputLength = listedLengthOf(input);
150
+ for (const { schema, name } of candidates) {
151
+ z.globalRegistry.add(schema, {
152
+ ...z.globalRegistry.get(schema),
153
+ id: unusedIdFor(api, name)
154
+ });
155
+ const lengthWithId = listedLengthOf(input);
156
+ if (lengthWithId < inputLength) {
157
+ inputLength = lengthWithId;
158
+ } else {
159
+ z.globalRegistry.remove(schema);
160
+ }
161
+ }
162
+ return input;
163
+ };
164
+ const dataUriFields = (schema, fields, maxBytes) => schema.extend(
165
+ Object.fromEntries(
166
+ fields.flatMap((field) => {
167
+ const current = schema.shape[field];
168
+ const uri = z.string().meta({
169
+ format: "uri",
170
+ "x-mcp-file": { maxSize: maxBytes },
171
+ description: [
172
+ current.description,
173
+ `Send the file as a data: URI, such as data:text/csv;base64,<base64 bytes>, at most ${maxBytes} bytes once decoded.`
174
+ ].filter(Boolean).join(" ")
175
+ });
176
+ const name = z.string().meta({
177
+ description: `The name of the file sent in ${field}, such as products.csv.`
178
+ }).optional();
179
+ return [
180
+ [field, current.isOptional() ? uri.optional() : uri],
181
+ [`${field}_name`, name]
182
+ ];
183
+ })
184
+ )
185
+ );
186
+ const DATA_URI = /^data:([^,]*),(.*)$/is;
187
+ const PERCENT_ENCODED = /^[0-9a-f]{2}$/i;
188
+ const notADataUriError = (field) => new Error(
189
+ `${field} must be a data: URI, such as data:image/png;base64,iVBORw0KGgo. This tool does not download URLs.`
190
+ );
191
+ const fileTooBigError = (field, bytes, maxBytes) => new Error(
192
+ `${field} is ${bytes} bytes, over the ${maxBytes} bytes this tool accepts`
193
+ );
194
+ function percentDecoded(field, text) {
195
+ const bytes = [];
196
+ const encoder = new TextEncoder();
197
+ for (let index = 0; index < text.length; index++) {
198
+ if (text[index] === "%") {
199
+ const hex = text.slice(index + 1, index + 3);
200
+ if (!PERCENT_ENCODED.test(hex)) throw notADataUriError(field);
201
+ bytes.push(parseInt(hex, 16));
202
+ index += 2;
203
+ } else {
204
+ const codePoint = text.codePointAt(index);
205
+ const character = String.fromCodePoint(codePoint);
206
+ bytes.push(...encoder.encode(character));
207
+ index += character.length - 1;
208
+ }
209
+ }
210
+ return new Uint8Array(bytes);
211
+ }
212
+ function base64Decoded(field, text, maxBytes) {
213
+ const data = text.replace(/\s/g, "");
214
+ const padding = data.endsWith("==") ? 2 : data.endsWith("=") ? 1 : 0;
215
+ const bytes = Math.floor(data.length * 3 / 4) - padding;
216
+ if (bytes > maxBytes) throw fileTooBigError(field, bytes, maxBytes);
217
+ let binary;
218
+ try {
219
+ binary = atob(data);
220
+ } catch {
221
+ throw new Error(`${field} is not valid base64`);
222
+ }
223
+ return Uint8Array.from(binary, (character) => character.charCodeAt(0));
224
+ }
225
+ function fileFromDataUri(field, uri, maxBytes, givenName) {
226
+ const match = typeof uri === "string" ? DATA_URI.exec(uri) : null;
227
+ if (!match) throw notADataUriError(field);
228
+ const parameters = match[1].split(";");
229
+ const isBase64 = parameters.at(-1).toLowerCase() === "base64";
230
+ if (isBase64) parameters.pop();
231
+ const mediaType = parameters.shift().trim();
232
+ const nameParameter = parameters.find(
233
+ (parameter) => parameter.trim().toLowerCase().startsWith("name=")
234
+ );
235
+ let name = field;
236
+ if (typeof givenName === "string" && givenName.trim()) {
237
+ name = givenName.trim();
238
+ } else if (nameParameter) {
239
+ try {
240
+ name = decodeURIComponent(nameParameter.trim().slice("name=".length));
241
+ } catch {
242
+ throw notADataUriError(field);
243
+ }
244
+ }
245
+ const bytes = isBase64 ? base64Decoded(field, match[2], maxBytes) : percentDecoded(field, match[2]);
246
+ if (bytes.length > maxBytes)
247
+ throw fileTooBigError(field, bytes.length, maxBytes);
248
+ return new File([bytes], name, {
249
+ type: mediaType.includes("/") ? mediaType : "text/plain"
250
+ });
251
+ }
252
+ const decodeDataUris = async (body, fields, maxBytes) => {
253
+ if (typeof body !== "object" || body === null) {
254
+ return body;
255
+ }
256
+ const decoded = { ...body };
257
+ for (const field of fields) {
258
+ const givenName = decoded[`${field}_name`];
259
+ delete decoded[`${field}_name`];
260
+ if (decoded[field] !== void 0) {
261
+ decoded[field] = fileFromDataUri(
262
+ field,
263
+ decoded[field],
264
+ maxBytes,
265
+ givenName
266
+ );
267
+ }
268
+ }
269
+ return decoded;
270
+ };
271
+ export {
272
+ dataUriFields,
273
+ decodeDataUris,
274
+ loose,
275
+ toToolResult,
276
+ withSharedSchemaIds
277
+ };
278
+ //# sourceMappingURL=mcp-support.gen.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/client/mcp-support.gen.ts"],"sourcesContent":["import type { ToolCallback } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport type { AnySchema } from \"@modelcontextprotocol/sdk/server/zod-compat.js\"\nimport type {\n CallToolResult,\n ToolAnnotations,\n} from \"@modelcontextprotocol/sdk/types.js\"\nimport * as z from \"zod\"\n\nexport type OperationMeta = {\n id: string\n method: string\n path: string\n risk: \"read\" | \"create\" | \"update\" | \"delete\"\n}\n\nexport type ToolConfig = {\n title?: string\n description?: string\n inputSchema: z.ZodObject<Record<string, z.ZodType<any>>>\n outputSchema?: AnySchema\n annotations?: ToolAnnotations\n _meta: {\n \"com.elasticpath/operation\": OperationMeta\n }\n}\n\nexport type Tool = {\n readonly name: string\n readonly config: ToolConfig\n readonly handler: ToolCallback<AnySchema>\n}\n\nconst messageOf = (error: unknown) =>\n error instanceof Error ? error.message : JSON.stringify(error)\n\nexport const toToolResult = async (\n request: Promise<{\n data?: unknown\n error?: unknown\n response?: Response\n }>,\n): Promise<CallToolResult> => {\n let text: string\n try {\n const result = await request\n if (result.error === undefined) {\n const structuredContent =\n typeof result.data === \"object\" &&\n result.data !== null &&\n !Array.isArray(result.data)\n ? (result.data as Record<string, unknown>)\n : { data: result.data ?? null }\n return {\n structuredContent,\n content: [{ type: \"text\", text: JSON.stringify(structuredContent) }],\n }\n }\n text = result.response\n ? `HTTP ${result.response.status}: ${JSON.stringify(result.error)}`\n : messageOf(result.error)\n } catch (error) {\n text = messageOf(error)\n }\n return { isError: true, content: [{ type: \"text\", text }] }\n}\n\nconst WRAPPER_TYPES = [\n \"optional\",\n \"nullable\",\n \"default\",\n \"readonly\",\n \"nonoptional\",\n \"catch\",\n \"prefault\",\n]\n\ntype LooseCopies = WeakMap<z.ZodType, z.ZodType>\n\nconst madeByLoose = new WeakSet<z.ZodType>()\n\nfunction shapeCopiedOnFirstRead(\n copies: LooseCopies,\n shape: Record<string, z.ZodType>,\n) {\n const copy: Record<string, z.ZodType> = {}\n for (const key of Object.keys(shape)) {\n Object.defineProperty(copy, key, {\n configurable: true,\n enumerable: true,\n get() {\n const value = looseIn(copies, shape[key]!)\n Object.defineProperty(copy, key, {\n configurable: true,\n enumerable: true,\n writable: true,\n value,\n })\n return value\n },\n })\n }\n return copy\n}\n\nfunction looseCopyOf<T extends z.ZodType>(copies: LooseCopies, schema: T): T {\n const def: any = schema._zod.def\n const copy = (changes: object): T =>\n schema.clone({ ...def, ...changes }, { parent: true })\n const looseChild = (child: z.ZodType) => looseIn(copies, child)\n if (def.type === \"object\") {\n return copy({\n catchall: z.unknown(),\n shape: shapeCopiedOnFirstRead(copies, def.shape),\n })\n }\n if (def.type === \"array\") {\n return copy({ element: looseChild(def.element) })\n }\n if (def.type === \"record\") {\n return copy({ valueType: looseChild(def.valueType) })\n }\n if (def.type === \"lazy\") {\n return copy({ getter: () => looseChild(def.getter()) })\n }\n if (WRAPPER_TYPES.includes(def.type)) {\n return copy({ innerType: looseChild(def.innerType) })\n }\n if (def.type === \"union\") {\n return copy({ options: def.options.map(looseChild) })\n }\n if (def.type === \"intersection\") {\n return copy({ left: looseChild(def.left), right: looseChild(def.right) })\n }\n return schema\n}\n\nfunction looseIn<T extends z.ZodType>(copies: LooseCopies, schema: T): T {\n if (madeByLoose.has(schema)) return schema\n const known = copies.get(schema)\n if (known) return known as T\n const copy = looseCopyOf(copies, schema)\n copies.set(schema, copy)\n if (copy !== schema) madeByLoose.add(copy)\n return copy\n}\n\nexport const loose = <T extends z.ZodType>(schema: T): T =>\n looseIn(new WeakMap(), schema)\n\nconst SHARED_SCHEMA_MIN_LENGTH = 1000\n\nfunction reachesFrom(schema: z.ZodType, name: string) {\n const def: any = schema._zod.def\n const reach = (child: z.ZodType): [string, z.ZodType] => [name, child]\n if (def.type === \"object\") {\n return Object.keys(def.shape).map((key): [string, z.ZodType] => [\n key,\n def.shape[key],\n ])\n }\n if (def.type === \"array\") return [reach(def.element)]\n if (def.type === \"record\") return [reach(def.valueType)]\n if (def.type === \"lazy\") return [reach(def.getter())]\n if (WRAPPER_TYPES.includes(def.type)) return [reach(def.innerType)]\n if (def.type === \"union\") {\n return def.options.map((option: z.ZodType) => reach(option))\n }\n if (def.type === \"intersection\") return [reach(def.left), reach(def.right)]\n return []\n}\n\nfunction reachedSchemas(input: z.ZodType) {\n const reached = new Map<z.ZodType, { name: string; count: number }>()\n const visit = (name: string, schema: z.ZodType) => {\n const seen = reached.get(schema)\n if (seen) {\n seen.count++\n return\n }\n reached.set(schema, { name, count: 1 })\n for (const [childName, child] of reachesFrom(schema, name)) {\n visit(childName, child)\n }\n }\n visit(\"input\", input)\n return reached\n}\n\nconst listedLengthOf = (schema: z.ZodType) =>\n JSON.stringify(\n z.toJSONSchema(schema, {\n io: \"input\",\n target: \"draft-7\",\n unrepresentable: \"any\",\n }),\n ).length\n\nfunction unusedIdFor(api: string, name: string) {\n const base = `${api}_${name.replace(/[^A-Za-z0-9_]/g, \"_\")}`\n let id = base\n for (let suffix = 2; z.globalRegistry._idmap.has(id); suffix++) {\n id = `${base}_${suffix}`\n }\n return id\n}\n\nexport const withSharedSchemaIds = <T extends z.ZodType>(\n api: string,\n input: T,\n): T => {\n const candidates = [...reachedSchemas(input)]\n .filter(\n ([schema, { count }]) =>\n count > 1 && madeByLoose.has(schema) && !z.globalRegistry.has(schema),\n )\n .map(([schema, { name }]) => ({\n schema,\n name,\n length: listedLengthOf(schema),\n }))\n .filter(({ length }) => length >= SHARED_SCHEMA_MIN_LENGTH)\n .sort((a, b) => b.length - a.length)\n let inputLength = listedLengthOf(input)\n for (const { schema, name } of candidates) {\n z.globalRegistry.add(schema, {\n ...z.globalRegistry.get(schema),\n id: unusedIdFor(api, name),\n })\n const lengthWithId = listedLengthOf(input)\n if (lengthWithId < inputLength) {\n inputLength = lengthWithId\n } else {\n z.globalRegistry.remove(schema)\n }\n }\n return input\n}\n\ntype FileNameFields<K extends string> = {\n [P in `${K}_name`]: z.ZodOptional<z.ZodString>\n}\n\nexport const dataUriFields = <\n S extends z.ZodRawShape,\n C extends z.core.$ZodObjectConfig,\n K extends string,\n>(\n schema: z.ZodObject<S, C>,\n fields: ReadonlyArray<K>,\n maxBytes: number,\n): z.ZodObject<z.core.util.Extend<S, FileNameFields<K>>, C> =>\n schema.extend(\n Object.fromEntries(\n fields.flatMap((field) => {\n const current = schema.shape[field] as unknown as z.ZodType\n const uri = z.string().meta({\n format: \"uri\",\n \"x-mcp-file\": { maxSize: maxBytes },\n description: [\n current.description,\n `Send the file as a data: URI, such as data:text/csv;base64,<base64 bytes>, at most ${maxBytes} bytes once decoded.`,\n ]\n .filter(Boolean)\n .join(\" \"),\n })\n const name = z\n .string()\n .meta({\n description: `The name of the file sent in ${field}, such as products.csv.`,\n })\n .optional()\n return [\n [field, current.isOptional() ? uri.optional() : uri],\n [`${field}_name`, name],\n ]\n }),\n ),\n ) as unknown as z.ZodObject<z.core.util.Extend<S, FileNameFields<K>>, C>\n\ntype DataUrisDecoded<T, K extends string> = T extends object\n ? Omit<T, K | `${K}_name`> & {\n [P in K & keyof T]: undefined extends T[P] ? File | undefined : File\n }\n : T\n\nconst DATA_URI = /^data:([^,]*),(.*)$/is\nconst PERCENT_ENCODED = /^[0-9a-f]{2}$/i\n\nconst notADataUriError = (field: string) =>\n new Error(\n `${field} must be a data: URI, such as data:image/png;base64,iVBORw0KGgo. This tool does not download URLs.`,\n )\n\nconst fileTooBigError = (field: string, bytes: number, maxBytes: number) =>\n new Error(\n `${field} is ${bytes} bytes, over the ${maxBytes} bytes this tool accepts`,\n )\n\nfunction percentDecoded(field: string, text: string) {\n const bytes: number[] = []\n const encoder = new TextEncoder()\n for (let index = 0; index < text.length; index++) {\n if (text[index] === \"%\") {\n const hex = text.slice(index + 1, index + 3)\n if (!PERCENT_ENCODED.test(hex)) throw notADataUriError(field)\n bytes.push(parseInt(hex, 16))\n index += 2\n } else {\n const codePoint = text.codePointAt(index)!\n const character = String.fromCodePoint(codePoint)\n bytes.push(...encoder.encode(character))\n index += character.length - 1\n }\n }\n return new Uint8Array(bytes)\n}\n\nfunction base64Decoded(field: string, text: string, maxBytes: number) {\n const data = text.replace(/\\s/g, \"\")\n const padding = data.endsWith(\"==\") ? 2 : data.endsWith(\"=\") ? 1 : 0\n const bytes = Math.floor((data.length * 3) / 4) - padding\n if (bytes > maxBytes) throw fileTooBigError(field, bytes, maxBytes)\n let binary: string\n try {\n binary = atob(data)\n } catch {\n throw new Error(`${field} is not valid base64`)\n }\n return Uint8Array.from(binary, (character) => character.charCodeAt(0))\n}\n\nfunction fileFromDataUri(\n field: string,\n uri: unknown,\n maxBytes: number,\n givenName: unknown,\n) {\n const match = typeof uri === \"string\" ? DATA_URI.exec(uri) : null\n if (!match) throw notADataUriError(field)\n const parameters = match[1]!.split(\";\")\n const isBase64 = parameters.at(-1)!.toLowerCase() === \"base64\"\n if (isBase64) parameters.pop()\n const mediaType = parameters.shift()!.trim()\n const nameParameter = parameters.find((parameter) =>\n parameter.trim().toLowerCase().startsWith(\"name=\"),\n )\n let name = field\n if (typeof givenName === \"string\" && givenName.trim()) {\n name = givenName.trim()\n } else if (nameParameter) {\n try {\n name = decodeURIComponent(nameParameter.trim().slice(\"name=\".length))\n } catch {\n throw notADataUriError(field)\n }\n }\n const bytes = isBase64\n ? base64Decoded(field, match[2]!, maxBytes)\n : percentDecoded(field, match[2]!)\n if (bytes.length > maxBytes)\n throw fileTooBigError(field, bytes.length, maxBytes)\n return new File([bytes], name, {\n type: mediaType.includes(\"/\") ? mediaType : \"text/plain\",\n })\n}\n\nexport const decodeDataUris = async <T, K extends string>(\n body: T,\n fields: ReadonlyArray<K>,\n maxBytes: number,\n): Promise<DataUrisDecoded<T, K>> => {\n if (typeof body !== \"object\" || body === null) {\n return body as DataUrisDecoded<T, K>\n }\n const decoded = { ...body } as Record<string, unknown>\n for (const field of fields) {\n const givenName = decoded[`${field}_name`]\n delete decoded[`${field}_name`]\n if (decoded[field] !== undefined) {\n decoded[field] = fileFromDataUri(\n field,\n decoded[field],\n maxBytes,\n givenName,\n )\n }\n }\n return decoded as DataUrisDecoded<T, K>\n}\n"],"mappings":"AAMA,YAAY,OAAO;AA0BnB,MAAM,YAAY,CAAC,UACjB,iBAAiB,QAAQ,MAAM,UAAU,KAAK,UAAU,KAAK;AAExD,MAAM,eAAe,OAC1B,YAK4B;AAC5B,MAAI;AACJ,MAAI;AACF,UAAM,SAAS,MAAM;AACrB,QAAI,OAAO,UAAU,QAAW;AAC9B,YAAM,oBACJ,OAAO,OAAO,SAAS,YACvB,OAAO,SAAS,QAChB,CAAC,MAAM,QAAQ,OAAO,IAA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AQ,IACxC,eAAe,OAAO,MAAM,CAAC,CAAE;AACnC,MAAI,MAAM,SAAS;AACjB,UAAM,gBAAgB,OAAO,MAAM,QAAQ,QAAQ;AACrD,SAAO,IAAI,KAAK,CAAC,KAAK,GAAG,MAAM;AAAA,IAC7B,MAAM,UAAU,SAAS,GAAG,IAAI,YAAY;AAAA,EAC9C,CAAC;AACH;AAEO,MAAM,iBAAiB,OAC5B,MACA,QACA,aACmC;AACnC,MAAI,OAAO,SAAS,YAAY,SAAS,MAAM;AAC7C,WAAO;AAAA,EACT;AACA,QAAM,UAAU,EAAE,GAAG,KAAK;AAC1B,aAAW,SAAS,QAAQ;AAC1B,UAAM,YAAY,QAAQ,GAAG,KAAK,OAAO;AACzC,WAAO,QAAQ,GAAG,KAAK,OAAO;AAC9B,QAAI,QAAQ,KAAK,MAAM,QAAW;AAChC,cAAQ,KAAK,IAAI;AAAA,QACf;AAAA,QACA,QAAQ,KAAK;AAAA,QACb;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var mcp_gen_exports = {};
30
+ __export(mcp_gen_exports, {
31
+ createAFileTool: () => createAFileTool,
32
+ deleteAFileTool: () => deleteAFileTool,
33
+ getAFileTool: () => getAFileTool,
34
+ getAllFilesTool: () => getAllFilesTool,
35
+ tools: () => tools
36
+ });
37
+ module.exports = __toCommonJS(mcp_gen_exports);
38
+ var z = __toESM(require("zod"), 1);
39
+ var import_mcp_support = require('./mcp-support.gen.cjs');
40
+ var import_sdk = require('./sdk.gen.cjs');
41
+ var import_zod = require('./zod.gen.cjs');
42
+ const getAllFilesInput = z.object({
43
+ query: import_zod.zGetAllFilesQuery.strict().optional()
44
+ }).strict();
45
+ const getAllFilesTool = (options) => {
46
+ const handler = (args, extra) => (0, import_mcp_support.toToolResult)(
47
+ (0, import_sdk.getAllFiles)({
48
+ ...args,
49
+ client: options?.client,
50
+ signal: extra.signal,
51
+ throwOnError: false
52
+ })
53
+ );
54
+ return {
55
+ name: "files_get_all_files",
56
+ config: {
57
+ title: "Get all Files",
58
+ description: "Lists the files in the store, such as product images, videos and documents, with each file's link, name, type and size. Filter by file name, width, height or file size, or get several files at once by ID with the in operator; IDs that do not exist are left out without an error. Returns at most 100 files per page.",
59
+ inputSchema: getAllFilesInput,
60
+ annotations: {
61
+ readOnlyHint: true,
62
+ destructiveHint: false,
63
+ idempotentHint: true,
64
+ openWorldHint: true
65
+ },
66
+ _meta: {
67
+ "com.elasticpath/operation": {
68
+ id: "files.getAllFiles",
69
+ method: "GET",
70
+ path: "/v2/files",
71
+ risk: "read"
72
+ }
73
+ }
74
+ },
75
+ handler
76
+ };
77
+ };
78
+ const createAFileInput = (0, import_mcp_support.withSharedSchemaIds)(
79
+ "files",
80
+ z.object({
81
+ body: (0, import_mcp_support.dataUriFields)((0, import_mcp_support.loose)(import_zod.zCreateAFileBody), ["file"], 8388608)
82
+ }).strict()
83
+ );
84
+ const createAFileTool = (options) => {
85
+ const handler = (args, extra) => (0, import_mcp_support.toToolResult)(
86
+ (0, import_mcp_support.decodeDataUris)(args.body, ["file"], 8388608).then(
87
+ (body) => (0, import_sdk.createAFile)({
88
+ ...args,
89
+ client: options?.client,
90
+ signal: extra.signal,
91
+ throwOnError: false,
92
+ body
93
+ })
94
+ )
95
+ );
96
+ return {
97
+ name: "files_create_a_file",
98
+ config: {
99
+ title: "Create a File",
100
+ description: "Uploads a file, such as a product image, video or PDF, or registers an image hosted elsewhere by its URL. Files are limited to 8MB by default; store a larger file elsewhere and register it by URL. Returns the new file's ID and link, which you use to attach the file to a product.",
101
+ inputSchema: createAFileInput,
102
+ annotations: {
103
+ readOnlyHint: false,
104
+ destructiveHint: false,
105
+ idempotentHint: false,
106
+ openWorldHint: true
107
+ },
108
+ _meta: {
109
+ "com.elasticpath/operation": {
110
+ id: "files.createAFile",
111
+ method: "POST",
112
+ path: "/v2/files",
113
+ risk: "create"
114
+ }
115
+ }
116
+ },
117
+ handler
118
+ };
119
+ };
120
+ const deleteAFileInput = z.object({
121
+ path: import_zod.zDeleteAFilePath.strict()
122
+ }).strict();
123
+ const deleteAFileTool = (options) => {
124
+ const handler = (args, extra) => (0, import_mcp_support.toToolResult)(
125
+ (0, import_sdk.deleteAFile)({
126
+ ...args,
127
+ client: options?.client,
128
+ signal: extra.signal,
129
+ throwOnError: false
130
+ })
131
+ );
132
+ return {
133
+ name: "files_delete_a_file",
134
+ config: {
135
+ title: "Delete a File",
136
+ description: "Deletes a file from the store by its ID. To find a file's ID, list the files and filter by file name.",
137
+ inputSchema: deleteAFileInput,
138
+ annotations: {
139
+ readOnlyHint: false,
140
+ destructiveHint: true,
141
+ idempotentHint: true,
142
+ openWorldHint: true
143
+ },
144
+ _meta: {
145
+ "com.elasticpath/operation": {
146
+ id: "files.deleteAFile",
147
+ method: "DELETE",
148
+ path: "/v2/files/{fileID}",
149
+ risk: "delete"
150
+ }
151
+ }
152
+ },
153
+ handler
154
+ };
155
+ };
156
+ const getAFileInput = z.object({
157
+ path: import_zod.zGetAFilePath.strict()
158
+ }).strict();
159
+ const getAFileTool = (options) => {
160
+ const handler = (args, extra) => (0, import_mcp_support.toToolResult)(
161
+ (0, import_sdk.getAFile)({
162
+ ...args,
163
+ client: options?.client,
164
+ signal: extra.signal,
165
+ throwOnError: false
166
+ })
167
+ );
168
+ return {
169
+ name: "files_get_a_file",
170
+ config: {
171
+ title: "Get a File",
172
+ description: "Gets one file by ID, including its link, name, type, size and dimensions. To get several files at once, list the files filtered by ID.",
173
+ inputSchema: getAFileInput,
174
+ annotations: {
175
+ readOnlyHint: true,
176
+ destructiveHint: false,
177
+ idempotentHint: true,
178
+ openWorldHint: true
179
+ },
180
+ _meta: {
181
+ "com.elasticpath/operation": {
182
+ id: "files.getAFile",
183
+ method: "GET",
184
+ path: "/v2/files/{fileID}",
185
+ risk: "read"
186
+ }
187
+ }
188
+ },
189
+ handler
190
+ };
191
+ };
192
+ const tools = (options) => [
193
+ getAllFilesTool(options),
194
+ createAFileTool(options),
195
+ deleteAFileTool(options),
196
+ getAFileTool(options)
197
+ ];
198
+ // Annotate the CommonJS export names for ESM import in node:
199
+ 0 && (module.exports = {
200
+ createAFileTool,
201
+ deleteAFileTool,
202
+ getAFileTool,
203
+ getAllFilesTool,
204
+ tools
205
+ });
206
+ //# sourceMappingURL=mcp.gen.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/client/mcp.gen.ts"],"sourcesContent":["// This file is auto-generated by @hey-api/openapi-ts\n\nimport type { ToolCallback } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport * as z from \"zod\"\n\nimport type { Client } from \"./client\"\nimport {\n dataUriFields,\n decodeDataUris,\n loose,\n type Tool,\n toToolResult,\n withSharedSchemaIds,\n} from \"./mcp-support.gen\"\nimport { createAFile, deleteAFile, getAFile, getAllFiles } from \"./sdk.gen\"\nimport {\n zCreateAFileBody,\n zDeleteAFilePath,\n zGetAFilePath,\n zGetAllFilesQuery,\n} from \"./zod.gen\"\n\ntype ToolOptions = {\n client?: Client\n}\n\nconst getAllFilesInput = z\n .object({\n query: zGetAllFilesQuery.strict().optional(),\n })\n .strict()\n\n/**\n * Get all Files\n *\n * Retrieves all files.\n *\n * ### Filtering\n *\n * For general filtering syntax, see [Filtering](/guides/Getting-Started/filtering).\n *\n * The following operators and attributes are available when filtering on this endpoint.\n *\n * | Attribute | Type | Operators | Example |\n * |:----------------------|:----------|:--------------------------|:-------------|\n * | `id` | `string` | `in` | `in(id,file-id-1,file-id-2,file-id-3)` |\n * | `file_name` | `string` | `eq` / `like` | `eq(file_name, my_image.jpg)` |\n * | `width` | `integer` | `gt` / `ge` / `lt` / `le` | `gt(width,200)` |\n * | `height` | `integer` | `gt` / `ge` / `lt` / `le` | `lt(height,500)` |\n * | `file_size` | `integer` | `gt` / `ge` / `lt` / `le` | `le(file_size,20953)` |\n *\n * #### Bulk File Retrieval\n *\n * To retrieve multiple files by their IDs in a single request, use the `in` operator with a comma-separated list of file IDs:\n *\n * ```\n * GET /v2/files?filter=in(id,06b881bd-f152-4c36-8658-7132a8fab49c,ec73567b-04e8-4000-a11a-7e1407cc2f21)\n * ```\n *\n * This is more efficient than making separate requests for each file and is recommended for bulk operations.\n *\n * **Note on invalid IDs**: If any IDs in the filter are missing, malformed, or do not exist in the store, they will be silently ignored. The response will only include files that were successfully found. For example, if you request 5 IDs but only 3 exist, the response will contain 3 files with `total: 3` in the metadata.\n *\n */\nexport const getAllFilesTool = (options?: ToolOptions) => {\n const handler: ToolCallback<typeof getAllFilesInput> = (args, extra) =>\n toToolResult(\n getAllFiles({\n ...args,\n client: options?.client,\n signal: extra.signal,\n throwOnError: false,\n }),\n )\n return {\n name: \"files_get_all_files\" as const,\n config: {\n title: \"Get all Files\",\n description:\n \"Lists the files in the store, such as product images, videos and documents, with each file's link, name, type and size. Filter by file name, width, height or file size, or get several files at once by ID with the in operator; IDs that do not exist are left out without an error. Returns at most 100 files per page.\",\n inputSchema: getAllFilesInput,\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n _meta: {\n \"com.elasticpath/operation\": {\n id: \"files.getAllFiles\",\n method: \"GET\",\n path: \"/v2/files\",\n risk: \"read\" as const,\n },\n },\n },\n handler,\n }\n}\n\nconst createAFileInput = withSharedSchemaIds(\n \"files\",\n z\n .object({\n body: dataUriFields(loose(zCreateAFileBody), [\"file\"], 8388608),\n })\n .strict(),\n)\n\n/**\n * Create a File\n *\n * Create a File\n */\nexport const createAFileTool = (options?: ToolOptions) => {\n const handler: ToolCallback<typeof createAFileInput> = (args, extra) =>\n toToolResult(\n decodeDataUris(args.body, [\"file\"], 8388608).then((body) =>\n createAFile({\n ...args,\n client: options?.client,\n signal: extra.signal,\n throwOnError: false,\n body,\n }),\n ),\n )\n return {\n name: \"files_create_a_file\" as const,\n config: {\n title: \"Create a File\",\n description:\n \"Uploads a file, such as a product image, video or PDF, or registers an image hosted elsewhere by its URL. Files are limited to 8MB by default; store a larger file elsewhere and register it by URL. Returns the new file's ID and link, which you use to attach the file to a product.\",\n inputSchema: createAFileInput,\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: true,\n },\n _meta: {\n \"com.elasticpath/operation\": {\n id: \"files.createAFile\",\n method: \"POST\",\n path: \"/v2/files\",\n risk: \"create\" as const,\n },\n },\n },\n handler,\n }\n}\n\nconst deleteAFileInput = z\n .object({\n path: zDeleteAFilePath.strict(),\n })\n .strict()\n\n/**\n * Delete a File\n *\n * Delete a File\n */\nexport const deleteAFileTool = (options?: ToolOptions) => {\n const handler: ToolCallback<typeof deleteAFileInput> = (args, extra) =>\n toToolResult(\n deleteAFile({\n ...args,\n client: options?.client,\n signal: extra.signal,\n throwOnError: false,\n }),\n )\n return {\n name: \"files_delete_a_file\" as const,\n config: {\n title: \"Delete a File\",\n description:\n \"Deletes a file from the store by its ID. To find a file's ID, list the files and filter by file name.\",\n inputSchema: deleteAFileInput,\n annotations: {\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n openWorldHint: true,\n },\n _meta: {\n \"com.elasticpath/operation\": {\n id: \"files.deleteAFile\",\n method: \"DELETE\",\n path: \"/v2/files/{fileID}\",\n risk: \"delete\" as const,\n },\n },\n },\n handler,\n }\n}\n\nconst getAFileInput = z\n .object({\n path: zGetAFilePath.strict(),\n })\n .strict()\n\n/**\n * Get a File\n *\n * Get a File\n */\nexport const getAFileTool = (options?: ToolOptions) => {\n const handler: ToolCallback<typeof getAFileInput> = (args, extra) =>\n toToolResult(\n getAFile({\n ...args,\n client: options?.client,\n signal: extra.signal,\n throwOnError: false,\n }),\n )\n return {\n name: \"files_get_a_file\" as const,\n config: {\n title: \"Get a File\",\n description:\n \"Gets one file by ID, including its link, name, type, size and dimensions. To get several files at once, list the files filtered by ID.\",\n inputSchema: getAFileInput,\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n _meta: {\n \"com.elasticpath/operation\": {\n id: \"files.getAFile\",\n method: \"GET\",\n path: \"/v2/files/{fileID}\",\n risk: \"read\" as const,\n },\n },\n },\n handler,\n }\n}\n\nexport const tools = (options?: ToolOptions): Array<Tool> => [\n getAllFilesTool(options),\n createAFileTool(options),\n deleteAFileTool(options),\n getAFileTool(options),\n]\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,QAAmB;AAGnB,yBAOO;AACP,iBAAgE;AAChE,iBAKO;AAMP,MAAM,mBAAmB,EACtB,OAAO;AAAA,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