@sea-ecommerce/admin-mcp-server 0.1.2 → 0.1.3
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/README.md +1 -1
- package/dist/derlux-admin-mcp.js +59 -16
- package/package.json +1 -1
- package/skill/SKILL.md +4 -2
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
| `update_product_prices` | 替换变体价格(多币种) | 写(dry_run 默认) |
|
|
18
18
|
| `upload_product_image` / `add_product_to_sales_channel` | 追加图片 / 挂渠道 | 写(dry_run 默认) |
|
|
19
19
|
| `create_product_content` / `get_product_content` | 详情页富内容块(hero/richtext/specs/图集/faq/video) | 写 / 读 |
|
|
20
|
-
| `set_product_stock` |
|
|
20
|
+
| `set_product_stock` | 给商品建仓/改库存(自动建库存条目 + 关联变体,幂等) | 写(dry_run 默认) |
|
|
21
21
|
| `list_stock_locations` / `create_stock_location` | 列 / 增仓库 | 写(dry_run 默认) |
|
|
22
22
|
| `get_inventory_levels` / `update_inventory_level` | 查 / 改库存水平 | 写(dry_run 默认) |
|
|
23
23
|
| `list_orders` / `get_order` | 查订单 | 读 |
|
package/dist/derlux-admin-mcp.js
CHANGED
|
@@ -21858,6 +21858,19 @@ var MedusaAdminClient = class {
|
|
|
21858
21858
|
body
|
|
21859
21859
|
);
|
|
21860
21860
|
}
|
|
21861
|
+
/**
|
|
21862
|
+
* 把库存条目关联到变体(POST /admin/products/{pid}/variants/{vid}/inventory-items)。
|
|
21863
|
+
* ⚠️ 关联是「变体能查到库存」的关键:只有关联后,变体的 manage_inventory 才指向该条目,
|
|
21864
|
+
* 且设置 manage_inventory=true 时 Medusa 不会因「无关联条目」而另建同 SKU 条目(撞唯一约束)。
|
|
21865
|
+
* 重复关联会报已存在,调用方应 try/catch 吞掉「已关联」类错误。
|
|
21866
|
+
*/
|
|
21867
|
+
linkVariantInventoryItem(productId, variantId, inventoryItemId) {
|
|
21868
|
+
return this.request(
|
|
21869
|
+
"POST",
|
|
21870
|
+
`/admin/products/${encodeURIComponent(productId)}/variants/${encodeURIComponent(variantId)}/inventory-items`,
|
|
21871
|
+
{ inventory_item_id: inventoryItemId, required_quantity: 1 }
|
|
21872
|
+
);
|
|
21873
|
+
}
|
|
21861
21874
|
/**
|
|
21862
21875
|
* 幂等地设置某库存条目在指定仓库的库存数量:
|
|
21863
21876
|
* 已有 (item, location) 水平 → 更新;没有 → 创建。
|
|
@@ -21912,35 +21925,65 @@ async function applyProductStock(ctx2, opts) {
|
|
|
21912
21925
|
location = list.find((l) => /main warehouse/i.test(l.name)) || list[0];
|
|
21913
21926
|
if (!location) throw new Error("\u6CA1\u6709\u4EFB\u4F55\u53EF\u7528\u4ED3\u5E93\uFF0C\u8BF7\u5148 create_stock_location");
|
|
21914
21927
|
}
|
|
21915
|
-
|
|
21916
|
-
|
|
21928
|
+
const findItem = async () => {
|
|
21929
|
+
if (!variant.sku) return null;
|
|
21917
21930
|
const items = await client2.listInventoryItems({ sku: variant.sku, limit: 10 });
|
|
21918
|
-
|
|
21919
|
-
}
|
|
21920
|
-
if (
|
|
21921
|
-
if (!variant.sku)
|
|
21922
|
-
|
|
21931
|
+
return (items?.inventory_items || []).find((i) => i.sku === variant.sku) || null;
|
|
21932
|
+
};
|
|
21933
|
+
if (opts.manageInventory) {
|
|
21934
|
+
if (!variant.sku) {
|
|
21935
|
+
throw new Error(`\u53D8\u4F53\u6CA1\u6709 SKU\uFF0C\u65E0\u6CD5\u5173\u8054\u5E93\u5B58\u6761\u76EE\uFF08\u8BF7\u5148 update_product \u8865 sku\uFF09`);
|
|
21936
|
+
}
|
|
21937
|
+
let iitem2 = await findItem();
|
|
21938
|
+
if (!iitem2) {
|
|
21939
|
+
const created = await client2.createInventoryItem({
|
|
21940
|
+
sku: variant.sku,
|
|
21941
|
+
title: variant.title || void 0
|
|
21942
|
+
});
|
|
21943
|
+
iitem2 = created?.inventory_item ?? created;
|
|
21944
|
+
}
|
|
21945
|
+
try {
|
|
21946
|
+
await client2.linkVariantInventoryItem(product.id, variant.id, iitem2.id);
|
|
21947
|
+
} catch {
|
|
21948
|
+
}
|
|
21949
|
+
if (Boolean(variant.manage_inventory) !== opts.manageInventory) {
|
|
21950
|
+
await client2.updateProduct(product.id, {
|
|
21951
|
+
variants: [{ id: variant.id, manage_inventory: opts.manageInventory }]
|
|
21952
|
+
});
|
|
21953
|
+
}
|
|
21954
|
+
iitem2 = await findItem() || iitem2;
|
|
21955
|
+
const level = await client2.upsertInventoryLevel(iitem2.id, location.id, opts.quantity);
|
|
21956
|
+
return {
|
|
21957
|
+
product_id: product.id,
|
|
21958
|
+
variant_id: variant.id,
|
|
21923
21959
|
sku: variant.sku,
|
|
21924
|
-
|
|
21925
|
-
|
|
21926
|
-
|
|
21960
|
+
location_id: location.id,
|
|
21961
|
+
location_name: location.name,
|
|
21962
|
+
inventory_item_id: iitem2.id,
|
|
21963
|
+
manage_inventory: opts.manageInventory,
|
|
21964
|
+
stocked_quantity: level.stocked_quantity,
|
|
21965
|
+
level_created: level.created
|
|
21966
|
+
};
|
|
21927
21967
|
}
|
|
21928
|
-
const level = await client2.upsertInventoryLevel(iitem.id, location.id, opts.quantity);
|
|
21929
21968
|
if (Boolean(variant.manage_inventory) !== opts.manageInventory) {
|
|
21930
21969
|
await client2.updateProduct(product.id, {
|
|
21931
21970
|
variants: [{ id: variant.id, manage_inventory: opts.manageInventory }]
|
|
21932
21971
|
});
|
|
21933
21972
|
}
|
|
21973
|
+
const iitem = await findItem();
|
|
21974
|
+
if (iitem) {
|
|
21975
|
+
await client2.upsertInventoryLevel(iitem.id, location.id, 0);
|
|
21976
|
+
}
|
|
21934
21977
|
return {
|
|
21935
21978
|
product_id: product.id,
|
|
21936
21979
|
variant_id: variant.id,
|
|
21937
21980
|
sku: variant.sku,
|
|
21938
21981
|
location_id: location.id,
|
|
21939
21982
|
location_name: location.name,
|
|
21940
|
-
inventory_item_id: iitem
|
|
21941
|
-
manage_inventory:
|
|
21942
|
-
stocked_quantity:
|
|
21943
|
-
|
|
21983
|
+
inventory_item_id: iitem?.id ?? null,
|
|
21984
|
+
manage_inventory: false,
|
|
21985
|
+
stocked_quantity: 0,
|
|
21986
|
+
note: "\u5DF2\u5173\u95ED\u5E93\u5B58\u7BA1\u7406\u5E76\u6E05\u96F6\u5E93\u5B58"
|
|
21944
21987
|
};
|
|
21945
21988
|
}
|
|
21946
21989
|
var stockTools = [
|
|
@@ -22779,7 +22822,7 @@ var config2 = loadConfig();
|
|
|
22779
22822
|
var auth = new AuthManager(config2);
|
|
22780
22823
|
var client = new MedusaAdminClient(config2, auth);
|
|
22781
22824
|
var ctx = { client, config: config2 };
|
|
22782
|
-
var server = new McpServer({ name: "derlux-admin", version: "0.1.
|
|
22825
|
+
var server = new McpServer({ name: "derlux-admin", version: "0.1.3" });
|
|
22783
22826
|
for (const def of toolDefs) {
|
|
22784
22827
|
server.tool(def.name, def.description, def.schema, async (args) => {
|
|
22785
22828
|
try {
|
package/package.json
CHANGED
package/skill/SKILL.md
CHANGED
|
@@ -130,7 +130,9 @@ description: 运营使用本地 AI agent(derlux-admin MCP server)操作 DERL
|
|
|
130
130
|
- `name`(string,**必填**);`address`(可选:`{address_1?,address_2?,city?,country_code?,province?,postal_code?,phone?}`);`metadata`(`record<string,string>`,可选);`confirm`(默认 false)。
|
|
131
131
|
- **`set_product_stock`**:给商品建仓/改库存(**运营最常用的库存工具**,幂等)。
|
|
132
132
|
- `product_id`(string,**必填**,商品 id 或 handle);`sku`(string,可选,目标变体;省略取第一个变体);`location_id`(string,可选,省略=Main Warehouse/第一个仓库);`quantity`(int ≥0,**必填**,绝对值非增量);`manage_inventory`(bool,默认 true);`confirm`(默认 false)。
|
|
133
|
-
-
|
|
133
|
+
- 行为(`manage_inventory=true`):按变体 SKU 查库存条目(缺失则自动创建)→ **关联条目到变体**(`POST .../variants/{id}/inventory-items`,已关联则忽略)→ 置变体 `manage_inventory=true` → 幂等写 (条目, 仓库) 库存水平。重复调用安全。
|
|
134
|
+
- ⚠️ 「关联」是变体能查到库存的关键:只建条目不关联,前台仍显示缺货。本工具已自动处理关联,运营无需关心。
|
|
135
|
+
- (`manage_inventory=false`)关闭库存管理并把库存清零。
|
|
134
136
|
- **`update_inventory_level`**:直接改某**库存条目**(`inventory_item_id`)在某仓库的数量(upsert,幂等)。
|
|
135
137
|
- `inventory_item_id`(string,**必填**);`location_id`(string,**必填**);`stocked_quantity`(int ≥0,**必填**);`confirm`(默认 false)。已知 `inventory_item_id` 时用;否则优先 `set_product_stock`。
|
|
136
138
|
|
|
@@ -209,7 +211,7 @@ agent 客户端(Codex / Claude Desktop / Cursor / Workbuddy / CodeBuddy 等)
|
|
|
209
211
|
- 有变体就必须有 product options,工具已自动补一个 `Default` 选项,你无需关心;**更新**商品时 `options` 字段被移除(2.16+),工具不会误传。
|
|
210
212
|
- 商品创建/更新体**不接受 `translations` 字段**;翻译由工具自动走 `/admin/translations/batch`。`get_product` 默认字段不含 `translations` 关系,**核对翻译请用 `get_translations`**,不要凭 `get_product` 返回为空就误判没写入。
|
|
211
213
|
- 图片走 `/admin/uploads` 上传后再挂到商品(无独立 `/admin/products/{id}/images` 端点)。
|
|
212
|
-
- 库存查询/写入端点已按 2.21 契约校准(`/admin/inventory-items` + `location-levels`,sku 唯一约束);`set_product_stock`
|
|
214
|
+
- 库存查询/写入端点已按 2.21 契约校准(`/admin/inventory-items` + `location-levels`,sku 唯一约束);`set_product_stock` 会**关联条目↔变体**并幂等可重放(变体只有关联到库存条目,前台才显示有货;只建条目不关联会撞唯一约束或前台缺货,工具已自动处理)。
|
|
213
215
|
- 自定义端点 `warehouse-tasks` / `return-requests` / `product-contents` 为本项目扩展。
|
|
214
216
|
- 文档问答(`search_docs` / `ask_usage`)依赖知识源目录;npx 形态下默认 `./docs`,若问不到相关内容,提示运营换关键词或查后台手册。
|
|
215
217
|
- 用受限的 `csr` 账号即可完成日常运营;敏感动作由后端 RBAC 拦截。
|