bulkflow-mcp 0.0.0-stage → 1.1.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.
- package/index.js +233 -0
- package/package.json +13 -4
- package/README.md +0 -3
package/index.js
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
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
|
+
server.tool(
|
|
88
|
+
"get_products",
|
|
89
|
+
"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.",
|
|
90
|
+
{ jobId: z.string(), cursor: z.string().optional(), limit: z.number().int().min(1).max(100).optional() },
|
|
91
|
+
async ({ jobId, cursor, limit }) => {
|
|
92
|
+
const qs = new URLSearchParams();
|
|
93
|
+
if (cursor) qs.set("cursor", cursor);
|
|
94
|
+
if (limit) qs.set("limit", String(limit));
|
|
95
|
+
const r = await call("GET", `/api/mcp/v1/jobs/${encodeURIComponent(jobId)}/products?${qs}`);
|
|
96
|
+
return { content: [{ type: "text", text: JSON.stringify(r) }] };
|
|
97
|
+
},
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
server.tool(
|
|
101
|
+
"list_projects",
|
|
102
|
+
"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'.",
|
|
103
|
+
{ brandSlug: z.string().optional(), cursor: z.string().optional(), limit: z.number().int().min(1).max(50).optional() },
|
|
104
|
+
async ({ brandSlug, cursor, limit }) => {
|
|
105
|
+
const qs = new URLSearchParams();
|
|
106
|
+
if (brandSlug) qs.set("brandSlug", brandSlug);
|
|
107
|
+
if (cursor) qs.set("cursor", cursor);
|
|
108
|
+
if (limit) qs.set("limit", String(limit));
|
|
109
|
+
const r = await call("GET", `/api/mcp/v1/projects?${qs}`);
|
|
110
|
+
return { content: [{ type: "text", text: JSON.stringify(r) }] };
|
|
111
|
+
},
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
server.tool(
|
|
115
|
+
"list_exports",
|
|
116
|
+
"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.",
|
|
117
|
+
{ jobId: z.string() },
|
|
118
|
+
async ({ jobId }) => {
|
|
119
|
+
const r = await call("GET", `/api/mcp/v1/jobs/${encodeURIComponent(jobId)}/exports`);
|
|
120
|
+
return { content: [{ type: "text", text: JSON.stringify(r) }] };
|
|
121
|
+
},
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
server.tool(
|
|
125
|
+
"bulk_update_products",
|
|
126
|
+
"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.",
|
|
127
|
+
{
|
|
128
|
+
productIds: z.array(z.string()).min(1).max(200),
|
|
129
|
+
category: z.string().optional(),
|
|
130
|
+
material: z.string().optional(),
|
|
131
|
+
price: z.number().nullable().optional(),
|
|
132
|
+
currency: z.string().optional(),
|
|
133
|
+
moq: z.number().nullable().optional(),
|
|
134
|
+
reviewState: z.enum(["approved", "removed", "flagged", "none"]).optional(),
|
|
135
|
+
},
|
|
136
|
+
async ({ productIds, ...patch }) => {
|
|
137
|
+
const r = await call("PATCH", "/api/mcp/v1/products/bulk", { productIds, ...patch });
|
|
138
|
+
return { content: [{ type: "text", text: JSON.stringify(r) }] };
|
|
139
|
+
},
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
server.tool(
|
|
143
|
+
"download_sheet",
|
|
144
|
+
"Get a real, clickable download link for the job's Excel sheet. IMPORTANT: before calling this, ask the user which format they want from the `availableFormats` list returned by get_job_status — never pick one yourself. 'default' is BulkFlow's standard sheet (always available); 'importwale', 'shopify' and 'flipkart' only appear in availableFormats if the account has them enabled.",
|
|
145
|
+
{
|
|
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
|
+
async ({ jobId, format }) => {
|
|
150
|
+
const r = await downloadFile(jobId, format || "default");
|
|
151
|
+
return { content: [{ type: "text", text: JSON.stringify(r) }] };
|
|
152
|
+
},
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
server.tool(
|
|
156
|
+
"list_needs_review",
|
|
157
|
+
"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.",
|
|
158
|
+
{ jobId: z.string() },
|
|
159
|
+
async ({ jobId }) => {
|
|
160
|
+
const r = await call("GET", `/api/mcp/v1/jobs/${encodeURIComponent(jobId)}/needs-review`);
|
|
161
|
+
return { content: [{ type: "text", text: JSON.stringify(r) }] };
|
|
162
|
+
},
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
server.tool(
|
|
166
|
+
"update_product",
|
|
167
|
+
"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.",
|
|
168
|
+
{
|
|
169
|
+
productId: z.string(),
|
|
170
|
+
name: z.string().optional(),
|
|
171
|
+
description: z.string().optional(),
|
|
172
|
+
category: z.string().optional(),
|
|
173
|
+
material: z.string().optional(),
|
|
174
|
+
price: z.number().nullable().optional(),
|
|
175
|
+
currency: z.string().optional(),
|
|
176
|
+
moq: z.number().nullable().optional(),
|
|
177
|
+
variants: z
|
|
178
|
+
.array(z.object({ sku: z.string(), price: z.number().nullable().optional(), stock: z.number().nullable().optional() }))
|
|
179
|
+
.optional()
|
|
180
|
+
.describe("Edit existing variants by their sku (from get_products) — a sku with no match is skipped, not an error"),
|
|
181
|
+
reviewState: z.enum(["approved", "removed", "flagged", "none"]).optional(),
|
|
182
|
+
},
|
|
183
|
+
async ({ productId, ...patch }) => {
|
|
184
|
+
const r = await call("PATCH", `/api/mcp/v1/products/${encodeURIComponent(productId)}`, patch);
|
|
185
|
+
return { content: [{ type: "text", text: JSON.stringify(r) }] };
|
|
186
|
+
},
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
server.tool(
|
|
190
|
+
"list_brands",
|
|
191
|
+
"List the brands available on this BulkFlow account, to offer as choices before starting a job or exporting.",
|
|
192
|
+
{},
|
|
193
|
+
async () => {
|
|
194
|
+
const r = await call("GET", "/api/mcp/v1/brands");
|
|
195
|
+
return { content: [{ type: "text", text: JSON.stringify(r) }] };
|
|
196
|
+
},
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
server.tool(
|
|
200
|
+
"get_export_preview",
|
|
201
|
+
"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.",
|
|
202
|
+
{ jobId: z.string() },
|
|
203
|
+
async ({ jobId }) => {
|
|
204
|
+
const r = await call("GET", `/api/mcp/v1/jobs/${encodeURIComponent(jobId)}/export`);
|
|
205
|
+
return { content: [{ type: "text", text: JSON.stringify(r) }] };
|
|
206
|
+
},
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
server.tool(
|
|
210
|
+
"export_to_website",
|
|
211
|
+
"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.",
|
|
212
|
+
{
|
|
213
|
+
jobId: z.string(),
|
|
214
|
+
connectionId: z.string(),
|
|
215
|
+
edits: z
|
|
216
|
+
.array(
|
|
217
|
+
z.object({
|
|
218
|
+
productId: z.string(),
|
|
219
|
+
include: z.boolean().optional(),
|
|
220
|
+
fields: z.record(z.any()).optional(),
|
|
221
|
+
shopifyStatus: z.enum(["draft", "active"]).optional(),
|
|
222
|
+
}),
|
|
223
|
+
)
|
|
224
|
+
.optional(),
|
|
225
|
+
},
|
|
226
|
+
async ({ jobId, connectionId, edits }) => {
|
|
227
|
+
const r = await call("POST", `/api/mcp/v1/jobs/${encodeURIComponent(jobId)}/export`, { connectionId, edits });
|
|
228
|
+
return { content: [{ type: "text", text: JSON.stringify(r) }] };
|
|
229
|
+
},
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
const transport = new StdioServerTransport();
|
|
233
|
+
await server.connect(transport);
|
package/package.json
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bulkflow-mcp",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.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