bulkflow-mcp 0.0.0-stage → 1.2.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 (3) hide show
  1. package/index.js +235 -0
  2. package/package.json +13 -4
  3. package/README.md +0 -3
package/index.js ADDED
@@ -0,0 +1,235 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { z } from "zod";
5
+
6
+ const TOKEN = process.env.BULKFLOW_MCP_TOKEN;
7
+ const BASE = (process.env.BULKFLOW_API_BASE || "https://www.bulkflowai.com").replace(/\/$/, "");
8
+
9
+ if (!TOKEN) {
10
+ console.error(
11
+ "BULKFLOW_MCP_TOKEN is not set. Generate one at " + BASE + "/settings/mcp and put it in your MCP config's env.",
12
+ );
13
+ process.exit(1);
14
+ }
15
+
16
+ async function call(method, path, body) {
17
+ const res = await fetch(`${BASE}${path}`, {
18
+ method,
19
+ headers: {
20
+ Authorization: `Bearer ${TOKEN}`,
21
+ "Content-Type": "application/json",
22
+ },
23
+ body: body ? JSON.stringify(body) : undefined,
24
+ });
25
+ const json = await res.json().catch(() => ({}));
26
+ if (!res.ok) {
27
+ // Upgrade-required (402) and plan-cap errors come through here as plain
28
+ // text — the model relays json.error to the user verbatim instead of
29
+ // silently stopping or retrying.
30
+ const suffix = json.upgradeUrl ? ` Upgrade: ${json.upgradeUrl}` : "";
31
+ throw new Error((json.error || `Request failed (${res.status})`) + suffix);
32
+ }
33
+ return json;
34
+ }
35
+
36
+ /** Fetches the sheet's raw bytes (not JSON) and base64-encodes them so the
37
+ * file can come back inline in chat, not just as a link. Falls back to
38
+ * link-only above ~4MB (Vercel's function response limit makes a bigger
39
+ * inline payload unreliable anyway). */
40
+ async function downloadFile(jobId, format) {
41
+ const url = `${BASE}/api/mcp/v1/jobs/${encodeURIComponent(jobId)}/download?format=${encodeURIComponent(format)}`;
42
+ const res = await fetch(url, { headers: { Authorization: `Bearer ${TOKEN}` } });
43
+ if (!res.ok) {
44
+ const json = await res.json().catch(() => ({}));
45
+ throw new Error(json.error || `Download failed (${res.status})`);
46
+ }
47
+ const contentType = res.headers.get("content-type") || "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
48
+ const disposition = res.headers.get("content-disposition") || "";
49
+ const fileName = /filename="([^"]+)"/.exec(disposition)?.[1] || "bulkflow-sheet.xlsx";
50
+ const bytes = Buffer.from(await res.arrayBuffer());
51
+ const inlined = bytes.length <= 4 * 1024 * 1024;
52
+ return {
53
+ downloadUrl: `${url}&token=${encodeURIComponent(TOKEN)}`,
54
+ fileName,
55
+ mimeType: contentType,
56
+ base64: inlined ? bytes.toString("base64") : undefined,
57
+ inlined,
58
+ };
59
+ }
60
+
61
+ const server = new McpServer({ name: "bulkflow-ai", version: "1.0.0" });
62
+
63
+ server.tool(
64
+ "start_job",
65
+ "Start a new BulkFlow sourcing job from one or more supplier/product links (1688, Alibaba, Everful Wholesale, AliExpress, Made-in-China). Returns a jobId to poll with get_job_status.",
66
+ {
67
+ urls: z.array(z.string()).min(1).describe("One or more product/store URLs to source from"),
68
+ brandSlug: z.string().optional().describe("Which brand (from list_brands) to attach this job to"),
69
+ name: z.string().optional().describe("Optional name for the job/project"),
70
+ },
71
+ async ({ urls, brandSlug, name }) => {
72
+ const r = await call("POST", "/api/mcp/v1/jobs", { urls, brandSlug, name });
73
+ return { content: [{ type: "text", text: JSON.stringify(r) }] };
74
+ },
75
+ );
76
+
77
+ server.tool(
78
+ "get_job_status",
79
+ "Check progress/status of a BulkFlow job started with start_job. Poll this every ~15-30s until done=true.",
80
+ { jobId: z.string() },
81
+ async ({ jobId }) => {
82
+ const r = await call("GET", `/api/mcp/v1/jobs/${encodeURIComponent(jobId)}`);
83
+ return { content: [{ type: "text", text: JSON.stringify(r) }] };
84
+ },
85
+ );
86
+
87
+ const GET_PRODUCTS_DESC =
88
+ "Get the actual sheet data (name, price, MOQ, variants, images) for every product in a job, regardless of review state and with no website connection needed. Use this whenever the user just wants the data/sheet from a finished job — it always works, unlike get_export_preview which needs an approved+connected website. Paginated — pass the returned nextCursor back in to get the next page.";
89
+ const GET_PRODUCTS_SCHEMA = { jobId: z.string(), cursor: z.string().optional(), limit: z.number().int().min(1).max(100).optional() };
90
+ const getProductsHandler = async ({ jobId, cursor, limit }) => {
91
+ const qs = new URLSearchParams();
92
+ if (cursor) qs.set("cursor", cursor);
93
+ if (limit) qs.set("limit", String(limit));
94
+ const r = await call("GET", `/api/mcp/v1/jobs/${encodeURIComponent(jobId)}/products?${qs}`);
95
+ return { content: [{ type: "text", text: JSON.stringify(r) }] };
96
+ };
97
+
98
+ server.tool("get_products", GET_PRODUCTS_DESC, GET_PRODUCTS_SCHEMA, getProductsHandler);
99
+ server.tool("list_products", "Alias of get_products. " + GET_PRODUCTS_DESC, GET_PRODUCTS_SCHEMA, getProductsHandler);
100
+
101
+ server.tool(
102
+ "list_projects",
103
+ "List this account's past sourcing jobs/projects — use this when the user refers to an old job by name instead of a jobId, or asks 'what have I sourced before'.",
104
+ { brandSlug: z.string().optional(), cursor: z.string().optional(), limit: z.number().int().min(1).max(50).optional() },
105
+ async ({ brandSlug, cursor, limit }) => {
106
+ const qs = new URLSearchParams();
107
+ if (brandSlug) qs.set("brandSlug", brandSlug);
108
+ if (cursor) qs.set("cursor", cursor);
109
+ if (limit) qs.set("limit", String(limit));
110
+ const r = await call("GET", `/api/mcp/v1/projects?${qs}`);
111
+ return { content: [{ type: "text", text: JSON.stringify(r) }] };
112
+ },
113
+ );
114
+
115
+ server.tool(
116
+ "list_exports",
117
+ "List the Excel sheets already generated for a job (file name, row count, when) — the files themselves aren't re-servable; call download_sheet to regenerate the same data fresh.",
118
+ { jobId: z.string() },
119
+ async ({ jobId }) => {
120
+ const r = await call("GET", `/api/mcp/v1/jobs/${encodeURIComponent(jobId)}/exports`);
121
+ return { content: [{ type: "text", text: JSON.stringify(r) }] };
122
+ },
123
+ );
124
+
125
+ server.tool(
126
+ "bulk_update_products",
127
+ "Apply the same field edits and/or review-state change (approved/removed/flagged/none) to up to 200 products in one call — e.g. approve a whole batch at once.",
128
+ {
129
+ productIds: z.array(z.string()).min(1).max(200),
130
+ category: z.string().optional(),
131
+ material: z.string().optional(),
132
+ price: z.number().nullable().optional(),
133
+ currency: z.string().optional(),
134
+ moq: z.number().nullable().optional(),
135
+ reviewState: z.enum(["approved", "removed", "flagged", "none"]).optional(),
136
+ },
137
+ async ({ productIds, ...patch }) => {
138
+ const r = await call("PATCH", "/api/mcp/v1/products/bulk", { productIds, ...patch });
139
+ return { content: [{ type: "text", text: JSON.stringify(r) }] };
140
+ },
141
+ );
142
+
143
+ const DOWNLOAD_SHEET_DESC =
144
+ "Export / download the job's Excel sheet. Returns a base64-encoded file inline (so it can be handed to the user directly in chat, no network fetch needed) plus a download link as a fallback. Use this for ANY request to export, download, or get the sheet/spreadsheet for a job. IMPORTANT: before calling this, ask the user which format they want from the `availableFormats` list returned by get_job_status — never pick one yourself.";
145
+ const DOWNLOAD_SHEET_SCHEMA = {
146
+ jobId: z.string(),
147
+ format: z.enum(["default", "importwale", "shopify", "flipkart"]).optional().describe("Which sheet format — defaults to BulkFlow's standard sheet"),
148
+ };
149
+ const downloadSheetHandler = async ({ jobId, format }) => {
150
+ const r = await downloadFile(jobId, format || "default");
151
+ return { content: [{ type: "text", text: JSON.stringify(r) }] };
152
+ };
153
+
154
+ server.tool("download_sheet", DOWNLOAD_SHEET_DESC, DOWNLOAD_SHEET_SCHEMA, downloadSheetHandler);
155
+ server.tool("export_sheet", "Alias of download_sheet. " + DOWNLOAD_SHEET_DESC, DOWNLOAD_SHEET_SCHEMA, downloadSheetHandler);
156
+
157
+ server.tool(
158
+ "list_needs_review",
159
+ "List the products in a finished job that were flagged 'Needs Review' (missing price/category/description/etc) so they can be fixed one by one.",
160
+ { jobId: z.string() },
161
+ async ({ jobId }) => {
162
+ const r = await call("GET", `/api/mcp/v1/jobs/${encodeURIComponent(jobId)}/needs-review`);
163
+ return { content: [{ type: "text", text: JSON.stringify(r) }] };
164
+ },
165
+ );
166
+
167
+ server.tool(
168
+ "update_product",
169
+ "Edit a product's fields (name, description, category, material, price, currency, moq), its variants (by sku, from get_products), and/or set its review state (approved/removed/flagged/none) — the chat equivalent of fixing a Needs Review row and approving it.",
170
+ {
171
+ productId: z.string(),
172
+ name: z.string().optional(),
173
+ description: z.string().optional(),
174
+ category: z.string().optional(),
175
+ material: z.string().optional(),
176
+ price: z.number().nullable().optional(),
177
+ currency: z.string().optional(),
178
+ moq: z.number().nullable().optional(),
179
+ variants: z
180
+ .array(z.object({ sku: z.string(), price: z.number().nullable().optional(), stock: z.number().nullable().optional() }))
181
+ .optional()
182
+ .describe("Edit existing variants by their sku (from get_products) — a sku with no match is skipped, not an error"),
183
+ reviewState: z.enum(["approved", "removed", "flagged", "none"]).optional(),
184
+ },
185
+ async ({ productId, ...patch }) => {
186
+ const r = await call("PATCH", `/api/mcp/v1/products/${encodeURIComponent(productId)}`, patch);
187
+ return { content: [{ type: "text", text: JSON.stringify(r) }] };
188
+ },
189
+ );
190
+
191
+ server.tool(
192
+ "list_brands",
193
+ "List the brands available on this BulkFlow account, to offer as choices before starting a job or exporting.",
194
+ {},
195
+ async () => {
196
+ const r = await call("GET", "/api/mcp/v1/brands");
197
+ return { content: [{ type: "text", text: JSON.stringify(r) }] };
198
+ },
199
+ );
200
+
201
+ server.tool(
202
+ "get_export_preview",
203
+ "List the connected websites and the approved products ready to send for a job, before calling export_to_website. Call this first to ask the user which connection and which products to include.",
204
+ { jobId: z.string() },
205
+ async ({ jobId }) => {
206
+ const r = await call("GET", `/api/mcp/v1/jobs/${encodeURIComponent(jobId)}/export`);
207
+ return { content: [{ type: "text", text: JSON.stringify(r) }] };
208
+ },
209
+ );
210
+
211
+ server.tool(
212
+ "export_to_website",
213
+ "Send the approved products from a job to one of the user's connected websites (from get_export_preview). Optionally override per-product fields, exclude rows, or set Shopify draft/live status.",
214
+ {
215
+ jobId: z.string(),
216
+ connectionId: z.string(),
217
+ edits: z
218
+ .array(
219
+ z.object({
220
+ productId: z.string(),
221
+ include: z.boolean().optional(),
222
+ fields: z.record(z.any()).optional(),
223
+ shopifyStatus: z.enum(["draft", "active"]).optional(),
224
+ }),
225
+ )
226
+ .optional(),
227
+ },
228
+ async ({ jobId, connectionId, edits }) => {
229
+ const r = await call("POST", `/api/mcp/v1/jobs/${encodeURIComponent(jobId)}/export`, { connectionId, edits });
230
+ return { content: [{ type: "text", text: JSON.stringify(r) }] };
231
+ },
232
+ );
233
+
234
+ const transport = new StdioServerTransport();
235
+ await server.connect(transport);
package/package.json CHANGED
@@ -1,6 +1,15 @@
1
1
  {
2
2
  "name": "bulkflow-mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.2.0",
4
+ "description": "MCP server for BulkFlow AI — source, review and export products from Claude Desktop or ChatGPT.",
5
+ "type": "module",
6
+ "bin": {
7
+ "bulkflow-mcp": "index.js"
8
+ },
9
+ "main": "index.js",
10
+ "license": "UNLICENSED",
11
+ "dependencies": {
12
+ "@modelcontextprotocol/sdk": "^1.12.0",
13
+ "zod": "^3.24.1"
14
+ }
15
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.