@fangcuntai/fangcuntai-mcp 1.6.4 → 1.6.6
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.en.md +1 -2
- package/README.md +4 -4
- package/dist/context/family-context.d.ts +1 -1
- package/dist/context/family-context.js +1 -1
- package/dist/context/write-lock.d.ts +1 -1
- package/dist/context/write-lock.js +2 -2
- package/dist/index.js +3 -1
- package/dist/tools/index.js +0 -2
- package/dist/tools/ledger-note-link.js +2 -2
- package/dist/tools/ledger.js +16 -52
- package/dist/tools/notes.js +81 -23
- package/dist/tools/safety.js +2 -2
- package/package.json +4 -3
- package/dist/tools/drafts.d.ts +0 -3
- package/dist/tools/drafts.js +0 -163
package/README.en.md
CHANGED
|
@@ -9,8 +9,7 @@ Fangcuntai Desktop Assistant MCP server. Connect it to Lobster / OpenClaw, Claud
|
|
|
9
9
|
- Switch between families and ledger books.
|
|
10
10
|
- Query summaries, entries, trends, and categories.
|
|
11
11
|
- Create, delete, and restore ledger entries behind a write confirmation lock.
|
|
12
|
-
- Browse and search notes, organize two-level note folders, and create
|
|
13
|
-
- Review and confirm AI drafts.
|
|
12
|
+
- Browse and search notes, organize two-level note folders, and create notes. Write to-dos as `- [ ]` / `- [x]`; link another note with `[[title]]`.
|
|
14
13
|
- Check subscription status and AI credit balance.
|
|
15
14
|
- Track writes created by the desktop assistant.
|
|
16
15
|
|
package/README.md
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
- 切换家庭和账本,查询收支摘要、账单、趋势与分类。
|
|
10
10
|
- 在确认锁保护下记账、删除、恢复回收站和清空回收站。
|
|
11
|
-
-
|
|
12
|
-
-
|
|
11
|
+
- 查看和搜索记事,整理两层记事文件夹,直接创建记事。待办写成 `- [ ]` / `- [x]`,一篇可用 `[[标题]]` 连到另一篇。
|
|
12
|
+
- 查询订阅和 AI 积分。
|
|
13
13
|
- 写入数据带来源标记,可在方寸台 App 中追踪。
|
|
14
14
|
|
|
15
15
|
MCP 只访问方寸台 API,不直连数据库。
|
|
@@ -19,7 +19,7 @@ MCP 只访问方寸台 API,不直连数据库。
|
|
|
19
19
|
- Node.js 18 或更高版本。
|
|
20
20
|
- 一个方寸台账号。
|
|
21
21
|
- 在方寸台 App 中生成桌面助手令牌:
|
|
22
|
-
**我的 →
|
|
22
|
+
**我的 → AI 配置 → 连接桌面助手**。
|
|
23
23
|
|
|
24
24
|
生成令牌时可选择默认家庭和权限。令牌明文只显示一次,可在 App 中随时撤销。
|
|
25
25
|
|
|
@@ -79,7 +79,7 @@ MCP 只访问方寸台 API,不直连数据库。
|
|
|
79
79
|
|
|
80
80
|
流水列表只有 `has_visible_related_note`,不带篇名。看一篇用 `get_ledger_entry`(要能看见那篇记事)。看一笔相关账单用 `get_note`,没有记账读取权限时不返回金额。
|
|
81
81
|
|
|
82
|
-
挂上或拆开已经存在的记录:`unlock_writes` → `prepare_link_ledger_note` / `prepare_unlink_ledger_note` → 向用户展示篇名、日期、分类和金额 → `confirm_link_ledger_note` / `confirm_unlink_ledger_note
|
|
82
|
+
挂上或拆开已经存在的记录:`unlock_writes` → `prepare_link_ledger_note` / `prepare_unlink_ledger_note` → 向用户展示篇名、日期、分类和金额 → `confirm_link_ledger_note` / `confirm_unlink_ledger_note`。需要同时勾选写入账单和写入记事。
|
|
83
83
|
|
|
84
84
|
同一回合新建账单和记事时,两边传同一个 `link_group`。只有两边都保存成功才挂上;丢掉一边就不会挂。挂接本身不占每月记账条数。
|
|
85
85
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FangcuntaiApiClient } from "../client/api-client.js";
|
|
2
2
|
export declare const TOKEN_SCOPE_READ_LEDGER = "read:ledger";
|
|
3
3
|
export declare const TOKEN_SCOPE_READ_STATS = "read:stats";
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const TOKEN_SCOPE_WRITE_NOTES = "write:notes";
|
|
5
5
|
export declare const TOKEN_SCOPE_WRITE_LEDGER = "write:ledger";
|
|
6
6
|
export declare const TOKEN_SCOPE_DENIED = "\u5F53\u524D\u4EE4\u724C\u672A\u52FE\u9009\u6B64\u9879\u6743\u9650\u3002\u8BF7\u5728\u65B9\u5BF8\u53F0 App\u300C\u8FDE\u63A5\u684C\u9762\u52A9\u624B\u300D\u751F\u6210\u65B0\u4EE4\u724C\u5E76\u52FE\u9009\u5BF9\u5E94\u6743\u9650\uFF1B\u5DF2\u6709\u4EE4\u724C\u4E0D\u80FD\u6539\u6743\u9650\u3002";
|
|
7
7
|
export type AssistantContext = {
|
|
@@ -8,7 +8,7 @@ let activeLedgerBookId = null;
|
|
|
8
8
|
let cachedTokenScopes = null;
|
|
9
9
|
export const TOKEN_SCOPE_READ_LEDGER = "read:ledger";
|
|
10
10
|
export const TOKEN_SCOPE_READ_STATS = "read:stats";
|
|
11
|
-
export const
|
|
11
|
+
export const TOKEN_SCOPE_WRITE_NOTES = "write:notes";
|
|
12
12
|
export const TOKEN_SCOPE_WRITE_LEDGER = "write:ledger";
|
|
13
13
|
export const TOKEN_SCOPE_DENIED = "当前令牌未勾选此项权限。请在方寸台 App「连接桌面助手」生成新令牌并勾选对应权限;已有令牌不能改权限。";
|
|
14
14
|
export function setBoundFamilyId(id) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type PendingKind = "create_ledger" | "
|
|
1
|
+
export type PendingKind = "create_ledger" | "create_note" | "update_ledger" | "delete_ledger" | "empty_ledger_trash" | "delete_note" | "empty_notes_trash" | "delete_note_folder" | "move_note" | "link_ledger_note" | "unlink_ledger_note";
|
|
2
2
|
export type PendingWrite = {
|
|
3
3
|
kind: PendingKind;
|
|
4
4
|
token: string;
|
|
@@ -17,7 +17,7 @@ export function unlockWrites(ttlMs = UNLOCK_TTL_MS) {
|
|
|
17
17
|
return {
|
|
18
18
|
unlocked: true,
|
|
19
19
|
expires_in_seconds: Math.floor(ttlMs / 1000),
|
|
20
|
-
hint: "
|
|
20
|
+
hint: "已解锁写操作。入账/写记事/改账/删除/清空回收站仍须 prepare → 向用户展示摘要 → confirm。",
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
export function lockWrites() {
|
|
@@ -42,7 +42,7 @@ export function getWriteLockStatus() {
|
|
|
42
42
|
/** 写操作前门:未解锁则抛错。 */
|
|
43
43
|
export function requireWritesUnlocked() {
|
|
44
44
|
if (!isWritesUnlocked()) {
|
|
45
|
-
throw new Error("写操作已上锁。请先向用户确认后调用 unlock_writes,再 prepare → confirm
|
|
45
|
+
throw new Error("写操作已上锁。请先向用户确认后调用 unlock_writes,再 prepare → confirm。查账不受影响。");
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
export function createPending(kind, familyId, summary, exec) {
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
2
3
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
4
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
5
|
import { FangcuntaiApiClient } from "./client/api-client.js";
|
|
5
6
|
import { loadConfig } from "./config.js";
|
|
6
7
|
import { registerTools } from "./tools/index.js";
|
|
8
|
+
const { version } = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
7
9
|
async function main() {
|
|
8
10
|
const config = loadConfig();
|
|
9
11
|
const client = new FangcuntaiApiClient(config.apiBase, config.token);
|
|
10
12
|
const server = new McpServer({
|
|
11
13
|
name: "fangcuntai",
|
|
12
|
-
version
|
|
14
|
+
version,
|
|
13
15
|
});
|
|
14
16
|
registerTools(server, client);
|
|
15
17
|
const transport = new StdioServerTransport();
|
package/dist/tools/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { registerAccountTools } from "./account.js";
|
|
2
2
|
import { registerContextTools } from "./context.js";
|
|
3
|
-
import { registerDraftTools } from "./drafts.js";
|
|
4
3
|
import { registerLedgerTools } from "./ledger.js";
|
|
5
4
|
import { registerLedgerNoteLinkTools } from "./ledger-note-link.js";
|
|
6
5
|
import { registerNoteTools } from "./notes.js";
|
|
@@ -11,6 +10,5 @@ export function registerTools(server, client) {
|
|
|
11
10
|
registerLedgerTools(server, client);
|
|
12
11
|
registerLedgerNoteLinkTools(server, client);
|
|
13
12
|
registerNoteTools(server, client);
|
|
14
|
-
registerDraftTools(server, client);
|
|
15
13
|
registerAccountTools(server, client);
|
|
16
14
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { ensureFamilyId, familyPath, requireEntitlement, requireTokenScope, tokenHasAnyScope, TOKEN_SCOPE_READ_LEDGER,
|
|
2
|
+
import { ensureFamilyId, familyPath, requireEntitlement, requireTokenScope, tokenHasAnyScope, TOKEN_SCOPE_READ_LEDGER, TOKEN_SCOPE_WRITE_NOTES, TOKEN_SCOPE_WRITE_LEDGER, } from "../context/family-context.js";
|
|
3
3
|
import { createPending, pendingPublicView, takePending, } from "../context/write-lock.js";
|
|
4
4
|
import { fenToYuan } from "../utils/money.js";
|
|
5
5
|
import { okJson, runTool } from "../utils/response.js";
|
|
@@ -52,7 +52,7 @@ export async function linkRememberedPair(client, familyId, group, side, id) {
|
|
|
52
52
|
}
|
|
53
53
|
async function requireLinkWriteScopes(client) {
|
|
54
54
|
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_LEDGER]);
|
|
55
|
-
await requireTokenScope(client, [
|
|
55
|
+
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_NOTES]);
|
|
56
56
|
}
|
|
57
57
|
function entrySummary(entry, bookName) {
|
|
58
58
|
const amount = Number(entry.amount ?? 0);
|
package/dist/tools/ledger.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { currentLedgerBookId, ensureFamilyId, familyPath, getWorkspaceContext, ledgerBookQuery, requireEntitlement, requireTokenScope, selectLedgerBook, TOKEN_SCOPE_READ_LEDGER, TOKEN_SCOPE_READ_STATS,
|
|
2
|
+
import { currentLedgerBookId, ensureFamilyId, familyPath, getWorkspaceContext, ledgerBookQuery, requireEntitlement, requireTokenScope, selectLedgerBook, TOKEN_SCOPE_READ_LEDGER, TOKEN_SCOPE_READ_STATS, TOKEN_SCOPE_WRITE_NOTES, TOKEN_SCOPE_WRITE_LEDGER, } from "../context/family-context.js";
|
|
3
3
|
import { createPending, pendingPublicView, takePending, } from "../context/write-lock.js";
|
|
4
4
|
import { linkRememberedPair } from "./ledger-note-link.js";
|
|
5
5
|
import { fenToYuan, mapItemsWithYuan, stripLedgerListNoteDetails, yuanToFen } from "../utils/money.js";
|
|
@@ -87,8 +87,7 @@ export function ledgerCreatedWithinLastMonth(createdAtSec, nowMs = Date.now()) {
|
|
|
87
87
|
}
|
|
88
88
|
function buildLedgerUpdatePatch(input) {
|
|
89
89
|
const patch = {};
|
|
90
|
-
|
|
91
|
-
patch.type = input.type;
|
|
90
|
+
// 收入和支出不能互改。相同类型不写入,避免整单保存时把类型再传一遍。
|
|
92
91
|
if (input.amount_yuan !== undefined)
|
|
93
92
|
patch.amount = yuanToFen(input.amount_yuan);
|
|
94
93
|
if (input.category !== undefined)
|
|
@@ -132,7 +131,13 @@ export async function prepareUpdateLedgerEntry(client, input) {
|
|
|
132
131
|
const entry = await client.get(familyPath(familyId, `/ledger/${input.entry_id}`), bookQuery);
|
|
133
132
|
const createdAt = Number(entry.created_at ?? 0);
|
|
134
133
|
if (!ledgerCreatedWithinLastMonth(createdAt)) {
|
|
135
|
-
throw new Error("桌面助手只能改最近 1 个月内添加的记账。更早的请在 App
|
|
134
|
+
throw new Error("桌面助手只能改最近 1 个月内添加的记账。更早的请在 App 里改,或让小家师直接更新。");
|
|
135
|
+
}
|
|
136
|
+
if (input.type) {
|
|
137
|
+
const current = String(entry.type ?? "").trim().toLowerCase();
|
|
138
|
+
if (current !== input.type) {
|
|
139
|
+
throw new Error("已记下的账单,收入和支出不能互改。金额和备注还可以改。");
|
|
140
|
+
}
|
|
136
141
|
}
|
|
137
142
|
const patch = buildLedgerUpdatePatch(input);
|
|
138
143
|
if (input.add_tags?.length) {
|
|
@@ -340,7 +345,7 @@ export function registerLedgerTools(server, client) {
|
|
|
340
345
|
await requireTokenScope(client, [
|
|
341
346
|
TOKEN_SCOPE_READ_LEDGER,
|
|
342
347
|
TOKEN_SCOPE_READ_STATS,
|
|
343
|
-
|
|
348
|
+
TOKEN_SCOPE_WRITE_NOTES,
|
|
344
349
|
TOKEN_SCOPE_WRITE_LEDGER,
|
|
345
350
|
]);
|
|
346
351
|
const familyId = await ensureFamilyId(client);
|
|
@@ -376,10 +381,13 @@ export function registerLedgerTools(server, client) {
|
|
|
376
381
|
client.setToolName("confirm_create_ledger_entry");
|
|
377
382
|
return okJson(await confirmCreateLedgerEntry(client, confirm_token));
|
|
378
383
|
}));
|
|
379
|
-
server.tool("prepare_update_ledger_entry", "准备修改已入账的一笔流水(不直接写入)。须先 unlock_writes。只支持修改最近 1
|
|
384
|
+
server.tool("prepare_update_ledger_entry", "准备修改已入账的一笔流水(不直接写入)。须先 unlock_writes。只支持修改最近 1 个月内添加的内容。收入和支出不能互改。返回 summary + confirm_token,向用户确认后再 confirm_update_ledger_entry。不会另记一笔新账。", {
|
|
380
385
|
entry_id: z.number().int().positive().describe("记账条目 ID"),
|
|
381
386
|
ledger_book_id: optionalBookId,
|
|
382
|
-
type: z
|
|
387
|
+
type: z
|
|
388
|
+
.enum(["expense", "income"])
|
|
389
|
+
.optional()
|
|
390
|
+
.describe("不能改。和原来不同会失败;记错了类型请删掉重记"),
|
|
383
391
|
amount_yuan: z.number().positive().optional().describe("金额(元)"),
|
|
384
392
|
category: z.string().optional(),
|
|
385
393
|
description: z.string().optional(),
|
|
@@ -388,7 +396,7 @@ export function registerLedgerTools(server, client) {
|
|
|
388
396
|
currency: z.string().optional(),
|
|
389
397
|
fund_account_type: z.string().optional().describe("cash / wechat / alipay / bank_card 等"),
|
|
390
398
|
fund_account_detail: z.string().optional(),
|
|
391
|
-
payer: z.string().optional().describe("
|
|
399
|
+
payer: z.string().optional().describe("商家(支出)或来源(收入),外面的店、公司或平台"),
|
|
392
400
|
billing_month: z.string().optional().describe("YYYY-MM"),
|
|
393
401
|
tags: z.array(z.string()).optional().describe("整笔替换标签"),
|
|
394
402
|
add_tags: z.array(z.string()).optional().describe("追加标签,不覆盖已有"),
|
|
@@ -521,48 +529,4 @@ export function registerLedgerTools(server, client) {
|
|
|
521
529
|
workspace: await getWorkspaceContext(client),
|
|
522
530
|
});
|
|
523
531
|
}));
|
|
524
|
-
server.tool("create_ledger_draft", "创建记账草稿(不会直接入账,无需解锁)。正式入账请 unlock_writes → prepare_confirm_ai_draft → confirm_ai_draft。", {
|
|
525
|
-
type: z.enum(["expense", "income"]).default("expense"),
|
|
526
|
-
amount_yuan: z.number().positive().describe("金额(元)"),
|
|
527
|
-
category: z.string().optional().describe("分类 key,如 food / education"),
|
|
528
|
-
description: z.string().optional(),
|
|
529
|
-
date: z.string().optional().describe("YYYY-MM-DD,默认今天"),
|
|
530
|
-
currency: z.string().optional().describe("默认 CNY"),
|
|
531
|
-
ledger_book_id: optionalBookId,
|
|
532
|
-
external_order_id: z
|
|
533
|
-
.string()
|
|
534
|
-
.optional()
|
|
535
|
-
.describe("外部订单号,非必填。确认入账时同一账本内不可重复"),
|
|
536
|
-
}, async (input) => runTool(async () => {
|
|
537
|
-
client.setToolName("create_ledger_draft");
|
|
538
|
-
const familyId = await ensureFamilyId(client);
|
|
539
|
-
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_DRAFT]);
|
|
540
|
-
await requireEntitlement(client, familyId, "can_use_ledger", "当前角色没有记账权限,无法创建记账草稿");
|
|
541
|
-
const recordDate = parseRecordDate(input.date);
|
|
542
|
-
const bookId = currentLedgerBookId(input.ledger_book_id);
|
|
543
|
-
const payload = {
|
|
544
|
-
type: input.type,
|
|
545
|
-
amount: yuanToFen(input.amount_yuan),
|
|
546
|
-
category: input.category ?? "other",
|
|
547
|
-
description: input.description ?? "",
|
|
548
|
-
record_date: recordDate,
|
|
549
|
-
currency: input.currency ?? "CNY",
|
|
550
|
-
source: "desktop_mcp",
|
|
551
|
-
};
|
|
552
|
-
if (bookId > 0)
|
|
553
|
-
payload.ledger_book_id = bookId;
|
|
554
|
-
if (input.external_order_id?.trim()) {
|
|
555
|
-
payload.external_order_id = input.external_order_id.trim();
|
|
556
|
-
}
|
|
557
|
-
const data = await client.post(familyPath(familyId, "/ai-drafts"), {
|
|
558
|
-
draft_type: "ledger",
|
|
559
|
-
payload,
|
|
560
|
-
session_id: "mcp",
|
|
561
|
-
});
|
|
562
|
-
return okJson({
|
|
563
|
-
...data,
|
|
564
|
-
hint: "草稿已创建。确认入账:unlock_writes → prepare_confirm_ai_draft → confirm_ai_draft;或 discard_ai_draft 丢弃。",
|
|
565
|
-
workspace: await getWorkspaceContext(client),
|
|
566
|
-
});
|
|
567
|
-
}));
|
|
568
532
|
}
|
package/dist/tools/notes.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { ensureFamilyId, familyPath, requireEntitlement, requireTokenScope,
|
|
3
|
-
import { tokenCanSeeLedgerAmounts } from "./ledger-note-link.js";
|
|
2
|
+
import { ensureFamilyId, familyPath, requireEntitlement, requireTokenScope, TOKEN_SCOPE_WRITE_LEDGER, TOKEN_SCOPE_WRITE_NOTES, } from "../context/family-context.js";
|
|
3
|
+
import { linkRememberedPair, tokenCanSeeLedgerAmounts } from "./ledger-note-link.js";
|
|
4
4
|
import { fenToYuan, stripNoteListLedgerDetails } from "../utils/money.js";
|
|
5
5
|
import { createPending, pendingPublicView, requireWritesUnlocked, takePending, } from "../context/write-lock.js";
|
|
6
6
|
import { okJson, runTool } from "../utils/response.js";
|
|
@@ -43,7 +43,7 @@ export function registerNoteTools(server, client) {
|
|
|
43
43
|
const data = await client.post(familyPath(familyId, "/notes/folders"), body);
|
|
44
44
|
return okJson({
|
|
45
45
|
...data,
|
|
46
|
-
hint: "文件夹已创建。可用 list_notes(folder_id) 浏览本层,
|
|
46
|
+
hint: "文件夹已创建。可用 list_notes(folder_id) 浏览本层,prepare_create_note(folder_id) 写入该位置。",
|
|
47
47
|
});
|
|
48
48
|
}));
|
|
49
49
|
server.tool("rename_note_folder", "重命名记事文件夹(须先 unlock_writes)。同父下不可与已有名称冲突。", {
|
|
@@ -179,18 +179,23 @@ export function registerNoteTools(server, client) {
|
|
|
179
179
|
const seeLedger = await tokenCanSeeLedgerAmounts(client);
|
|
180
180
|
return okJson(stripNoteListLedgerDetails(data, seeLedger));
|
|
181
181
|
}));
|
|
182
|
-
server.tool("
|
|
182
|
+
server.tool("prepare_create_note", "准备新建一篇记事(先不保存)。须先 unlock_writes。返回摘要 + confirm_token,向用户确认后再 confirm_create_note。visibility 可选 family / personal / selected / owner_only。folder_id 可选:0/省略=未分类,正整数=指定文件夹。待办写成 - [ ] / - [x];引用其他记事用 [[标题]] 或 [说明](note:id)。", {
|
|
183
183
|
title: z.string().min(1),
|
|
184
184
|
content: z.string().optional(),
|
|
185
185
|
visibility: z.enum(["family", "personal", "selected", "owner_only"]).optional(),
|
|
186
|
+
visible_user_ids: z.array(z.number().int().positive()).optional(),
|
|
186
187
|
folder_id: folderIdParam.describe("所属文件夹;0/省略=未分类"),
|
|
188
|
+
tags: z.array(z.string()).optional(),
|
|
187
189
|
link_group: z.string().optional().describe("和同一回合新建的账单使用同一个名字,两边都成功后才挂上"),
|
|
188
190
|
related_entry_ids: z.array(z.number().int().positive()).optional().describe("挂到已经存在的账单;用户没明确要求就不要传"),
|
|
189
191
|
}, async (input) => runTool(async () => {
|
|
190
|
-
client.setToolName("
|
|
192
|
+
client.setToolName("prepare_create_note");
|
|
191
193
|
const familyId = await ensureFamilyId(client);
|
|
192
|
-
await requireTokenScope(client, [
|
|
193
|
-
|
|
194
|
+
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_NOTES]);
|
|
195
|
+
if (input.related_entry_ids?.length) {
|
|
196
|
+
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_LEDGER]);
|
|
197
|
+
}
|
|
198
|
+
await requireEntitlement(client, familyId, "can_view_notes", "当前角色没有记事权限,无法创建记事");
|
|
194
199
|
const payload = {
|
|
195
200
|
title: input.title,
|
|
196
201
|
content: input.content ?? "",
|
|
@@ -199,22 +204,75 @@ export function registerNoteTools(server, client) {
|
|
|
199
204
|
if (input.folder_id !== undefined) {
|
|
200
205
|
payload.folder_id = input.folder_id;
|
|
201
206
|
}
|
|
202
|
-
if (input.
|
|
203
|
-
payload.
|
|
204
|
-
payload.link_after_save = true;
|
|
207
|
+
if (input.visible_user_ids?.length) {
|
|
208
|
+
payload.visible_user_ids = input.visible_user_ids;
|
|
205
209
|
}
|
|
206
|
-
if (input.
|
|
207
|
-
payload.
|
|
208
|
-
payload.link_after_save = true;
|
|
210
|
+
if (input.tags?.length) {
|
|
211
|
+
payload.tags = input.tags;
|
|
209
212
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
+
let folderName = input.folder_id && input.folder_id > 0 ? "" : "未分类";
|
|
214
|
+
if (input.folder_id && input.folder_id > 0) {
|
|
215
|
+
const folders = await client.get(familyPath(familyId, "/notes/folders"));
|
|
216
|
+
const folder = (Array.isArray(folders.items) ? folders.items : []).find((item) => Number(item.id) === input.folder_id);
|
|
217
|
+
folderName = folder ? String(folder.name ?? "") : "";
|
|
218
|
+
}
|
|
219
|
+
const pending = createPending("create_note", familyId, {
|
|
220
|
+
action: "create_note",
|
|
221
|
+
title: input.title,
|
|
222
|
+
content_preview: (input.content ?? "").slice(0, 200),
|
|
223
|
+
visibility: payload.visibility,
|
|
224
|
+
folder_id: input.folder_id ?? 0,
|
|
225
|
+
folder_name: folderName || null,
|
|
226
|
+
tags: input.tags ?? [],
|
|
227
|
+
link_group: input.link_group?.trim() || null,
|
|
228
|
+
}, {
|
|
213
229
|
payload,
|
|
230
|
+
link_group: input.link_group?.trim() || "",
|
|
231
|
+
related_entry_ids: (input.related_entry_ids ?? []).filter((id) => Number.isInteger(id) && id > 0),
|
|
214
232
|
});
|
|
233
|
+
return okJson(pendingPublicView(pending));
|
|
234
|
+
}));
|
|
235
|
+
server.tool("confirm_create_note", "确认新建记事并保存到记事本。必须传入 prepare_create_note 返回的 confirm_token。", {
|
|
236
|
+
confirm_token: z.string().min(1).describe("来自 prepare_create_note"),
|
|
237
|
+
}, async ({ confirm_token }) => runTool(async () => {
|
|
238
|
+
client.setToolName("confirm_create_note");
|
|
239
|
+
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_NOTES]);
|
|
240
|
+
const pending = takePending(confirm_token, "create_note");
|
|
241
|
+
const payload = pending.exec.payload && typeof pending.exec.payload === "object"
|
|
242
|
+
? pending.exec.payload
|
|
243
|
+
: {};
|
|
244
|
+
const data = await client.post(familyPath(pending.familyId, "/notes"), payload);
|
|
245
|
+
const noteId = Number(data.id ?? data.note_id ?? 0);
|
|
246
|
+
const link = await linkRememberedPair(client, pending.familyId, String(pending.exec.link_group ?? ""), "note", noteId);
|
|
247
|
+
const relatedEntryIds = Array.isArray(pending.exec.related_entry_ids)
|
|
248
|
+
? pending.exec.related_entry_ids.map(Number).filter((id) => Number.isInteger(id) && id > 0)
|
|
249
|
+
: [];
|
|
250
|
+
const relatedEntryLinks = [];
|
|
251
|
+
for (const entryId of relatedEntryIds) {
|
|
252
|
+
try {
|
|
253
|
+
await client.post(familyPath(pending.familyId, "/ledger-note-links"), {
|
|
254
|
+
entry_id: entryId,
|
|
255
|
+
note_id: noteId,
|
|
256
|
+
});
|
|
257
|
+
relatedEntryLinks.push({ entry_id: entryId, linked: true });
|
|
258
|
+
}
|
|
259
|
+
catch (err) {
|
|
260
|
+
relatedEntryLinks.push({
|
|
261
|
+
entry_id: entryId,
|
|
262
|
+
linked: false,
|
|
263
|
+
link_error: err instanceof Error ? err.message : String(err),
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
const linkedToExisting = relatedEntryLinks.some((item) => item.linked === true);
|
|
215
268
|
return okJson({
|
|
216
269
|
...data,
|
|
217
|
-
|
|
270
|
+
note_id: noteId || data.note_id,
|
|
271
|
+
link,
|
|
272
|
+
related_entry_links: relatedEntryLinks,
|
|
273
|
+
hint: link?.linked || linkedToExisting
|
|
274
|
+
? "记事已保存,并和对应账单挂在一起。"
|
|
275
|
+
: "记事已保存到记事本。",
|
|
218
276
|
});
|
|
219
277
|
}));
|
|
220
278
|
server.tool("prepare_move_note", "准备将已有记事移到指定文件夹(须先 unlock_writes)。folder_id=0 表示未分类。返回 summary + confirm_token。", {
|
|
@@ -269,7 +327,7 @@ export function registerNoteTools(server, client) {
|
|
|
269
327
|
}, async ({ note_id }) => runTool(async () => {
|
|
270
328
|
client.setToolName("prepare_delete_note");
|
|
271
329
|
const familyId = await ensureFamilyId(client);
|
|
272
|
-
await requireTokenScope(client, [
|
|
330
|
+
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_NOTES]);
|
|
273
331
|
await requireEntitlement(client, familyId, "can_view_notes", "当前角色没有记事权限,无法删除记事");
|
|
274
332
|
const note = await client.get(familyPath(familyId, `/notes/${note_id}`));
|
|
275
333
|
const pending = createPending("delete_note", familyId, {
|
|
@@ -284,7 +342,7 @@ export function registerNoteTools(server, client) {
|
|
|
284
342
|
confirm_token: z.string().min(1),
|
|
285
343
|
}, async ({ confirm_token }) => runTool(async () => {
|
|
286
344
|
client.setToolName("confirm_delete_note");
|
|
287
|
-
await requireTokenScope(client, [
|
|
345
|
+
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_NOTES]);
|
|
288
346
|
const pending = takePending(confirm_token, "delete_note");
|
|
289
347
|
const noteId = Number(pending.exec.note_id);
|
|
290
348
|
await client.delete(familyPath(pending.familyId, `/notes/${noteId}`));
|
|
@@ -300,7 +358,7 @@ export function registerNoteTools(server, client) {
|
|
|
300
358
|
page_size: z.number().int().min(1).max(100).optional(),
|
|
301
359
|
}, async ({ page, page_size }) => runTool(async () => {
|
|
302
360
|
client.setToolName("list_notes_trash");
|
|
303
|
-
await requireTokenScope(client, [
|
|
361
|
+
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_NOTES]);
|
|
304
362
|
const familyId = await ensureFamilyId(client);
|
|
305
363
|
const data = await client.get(familyPath(familyId, "/notes/trash"), { page, page_size });
|
|
306
364
|
return okJson({
|
|
@@ -313,7 +371,7 @@ export function registerNoteTools(server, client) {
|
|
|
313
371
|
}, async ({ note_id }) => runTool(async () => {
|
|
314
372
|
client.setToolName("restore_note");
|
|
315
373
|
const familyId = await ensureFamilyId(client);
|
|
316
|
-
await requireTokenScope(client, [
|
|
374
|
+
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_NOTES]);
|
|
317
375
|
await requireEntitlement(client, familyId, "can_view_notes", "当前角色没有记事权限,无法恢复记事");
|
|
318
376
|
const data = await client.post(familyPath(familyId, `/notes/${note_id}/restore`));
|
|
319
377
|
return okJson({
|
|
@@ -324,7 +382,7 @@ export function registerNoteTools(server, client) {
|
|
|
324
382
|
server.tool("prepare_empty_notes_trash", "准备清空记事回收站(永久删除,不可恢复)。须先 unlock_writes。会返回将删除的条数供用户确认。", {}, async () => runTool(async () => {
|
|
325
383
|
client.setToolName("prepare_empty_notes_trash");
|
|
326
384
|
const familyId = await ensureFamilyId(client);
|
|
327
|
-
await requireTokenScope(client, [
|
|
385
|
+
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_NOTES]);
|
|
328
386
|
await requireEntitlement(client, familyId, "can_view_notes", "当前角色没有记事权限,无法清空回收站");
|
|
329
387
|
const trash = await client.get(familyPath(familyId, "/notes/trash"), { page: 1, page_size: 1 });
|
|
330
388
|
const count = Number(trash.total ?? 0);
|
|
@@ -339,7 +397,7 @@ export function registerNoteTools(server, client) {
|
|
|
339
397
|
confirm_token: z.string().min(1),
|
|
340
398
|
}, async ({ confirm_token }) => runTool(async () => {
|
|
341
399
|
client.setToolName("confirm_empty_notes_trash");
|
|
342
|
-
await requireTokenScope(client, [
|
|
400
|
+
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_NOTES]);
|
|
343
401
|
const pending = takePending(confirm_token, "empty_notes_trash");
|
|
344
402
|
const data = await client.delete(familyPath(pending.familyId, "/notes/trash"));
|
|
345
403
|
return okJson({
|
package/dist/tools/safety.js
CHANGED
|
@@ -5,10 +5,10 @@ export function registerSafetyTools(server) {
|
|
|
5
5
|
server.tool("get_write_lock_status", "查看 MCP 写操作安全锁状态(是否已解锁、剩余秒数、待确认数)。", {}, async () => runTool(async () => {
|
|
6
6
|
return okJson({
|
|
7
7
|
...getWriteLockStatus(),
|
|
8
|
-
policy: "
|
|
8
|
+
policy: "默认上锁。查账/列文件夹可用;记账、写记事、改账、删除记账/记事、清空回收站、删除文件夹、移动记事所属文件夹须 unlock_writes → prepare_* → 用户确认 → confirm_*。新建/改名/移动文件夹须先 unlock_writes。删除进入回收站,可恢复;清空回收站不可恢复。改账只支持最近 1 个月内添加的流水。",
|
|
9
9
|
});
|
|
10
10
|
}));
|
|
11
|
-
server.tool("unlock_writes", "
|
|
11
|
+
server.tool("unlock_writes", "解锁写操作(须先征得用户同意)。解锁后仍须对入账/改账/写记事/删除走 prepare→confirm,确认后直接写正式数据。约 15 分钟无操作会过期。", {
|
|
12
12
|
user_acknowledged: z
|
|
13
13
|
.boolean()
|
|
14
14
|
.describe("必须为 true,表示已向用户说明风险并获得同意"),
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fangcuntai/fangcuntai-mcp",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.6",
|
|
4
4
|
"description": "方寸台桌面助手 MCP — 确认锁 + 来源标记 + 回收站 + 记事文件夹整理,安全地用自然语言管理家庭账本与记事",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
|
-
"fangcuntai-mcp": "
|
|
8
|
+
"fangcuntai-mcp": "dist/index.js"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"dist",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"README.en.md"
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
|
-
"
|
|
16
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
17
|
+
"build": "npm run clean && tsc",
|
|
17
18
|
"start": "node dist/index.js",
|
|
18
19
|
"dev": "tsc && node dist/index.js",
|
|
19
20
|
"organize-notes": "node scripts/organize-notes.mjs",
|
package/dist/tools/drafts.d.ts
DELETED
package/dist/tools/drafts.js
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { ensureFamilyId, familyPath, requireTokenScope, TOKEN_SCOPE_WRITE_DRAFT, TOKEN_SCOPE_WRITE_LEDGER, } from "../context/family-context.js";
|
|
3
|
-
import { createPending, pendingPublicView, takePending, } from "../context/write-lock.js";
|
|
4
|
-
import { linkRememberedPair } from "./ledger-note-link.js";
|
|
5
|
-
import { fenToYuan } from "../utils/money.js";
|
|
6
|
-
import { okJson, runTool } from "../utils/response.js";
|
|
7
|
-
export function registerDraftTools(server, client) {
|
|
8
|
-
server.tool("list_ai_drafts", "列出当前账号自己创建的待确认 AI 草稿(记账/记事)。家长也不能看家人的。可用 session_id=mcp 只看桌面助手草稿。", {
|
|
9
|
-
status: z.string().optional().describe("草稿状态筛选,如 pending"),
|
|
10
|
-
session_id: z.string().optional().describe("可选:mcp 或小家师会话 id"),
|
|
11
|
-
}, async ({ status, session_id }) => runTool(async () => {
|
|
12
|
-
client.setToolName("list_ai_drafts");
|
|
13
|
-
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_DRAFT, TOKEN_SCOPE_WRITE_LEDGER]);
|
|
14
|
-
const familyId = await ensureFamilyId(client);
|
|
15
|
-
const data = await client.get(familyPath(familyId, "/ai-drafts"), {
|
|
16
|
-
status,
|
|
17
|
-
session_id,
|
|
18
|
-
});
|
|
19
|
-
return okJson(data);
|
|
20
|
-
}));
|
|
21
|
-
server.tool("get_ai_draft", "获取单个 AI 草稿详情。", { draft_id: z.string().min(1) }, async ({ draft_id }) => runTool(async () => {
|
|
22
|
-
client.setToolName("get_ai_draft");
|
|
23
|
-
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_DRAFT, TOKEN_SCOPE_WRITE_LEDGER]);
|
|
24
|
-
const familyId = await ensureFamilyId(client);
|
|
25
|
-
const data = await client.get(familyPath(familyId, `/ai-drafts/${draft_id}`));
|
|
26
|
-
return okJson(data);
|
|
27
|
-
}));
|
|
28
|
-
server.tool("prepare_confirm_ai_draft", "准备确认草稿(不写入)。须先 unlock_writes。返回摘要 + confirm_token,用户同意后再 confirm_ai_draft。", { draft_id: z.string().min(1) }, async ({ draft_id }) => runTool(async () => {
|
|
29
|
-
client.setToolName("prepare_confirm_ai_draft");
|
|
30
|
-
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_DRAFT, TOKEN_SCOPE_WRITE_LEDGER]);
|
|
31
|
-
const familyId = await ensureFamilyId(client);
|
|
32
|
-
const draft = await client.get(familyPath(familyId, `/ai-drafts/${draft_id}`));
|
|
33
|
-
if (draft?.draft_type === "reminder") {
|
|
34
|
-
throw new Error("事情提醒功能已下线,无法确认提醒草稿,请丢弃该草稿");
|
|
35
|
-
}
|
|
36
|
-
const payload = draft.payload && typeof draft.payload === "object"
|
|
37
|
-
? draft.payload
|
|
38
|
-
: {};
|
|
39
|
-
const amount = Number(payload.amount ?? 0);
|
|
40
|
-
const summary = {
|
|
41
|
-
action: "confirm_ai_draft",
|
|
42
|
-
draft_id,
|
|
43
|
-
draft_type: draft.draft_type,
|
|
44
|
-
payload_preview: payload,
|
|
45
|
-
};
|
|
46
|
-
if (draft.draft_type === "ledger" && amount > 0) {
|
|
47
|
-
summary.amount_yuan = fenToYuan(amount);
|
|
48
|
-
}
|
|
49
|
-
const pending = createPending("confirm_draft", familyId, summary, {
|
|
50
|
-
draft_id,
|
|
51
|
-
draft_type: draft.draft_type,
|
|
52
|
-
link_group: typeof payload.link_group === "string" ? payload.link_group : "",
|
|
53
|
-
});
|
|
54
|
-
return okJson(pendingPublicView(pending));
|
|
55
|
-
}));
|
|
56
|
-
server.tool("confirm_ai_draft", "确认 AI 草稿并写入正式数据。必须传入 prepare_confirm_ai_draft 返回的 confirm_token(不再接受仅 draft_id)。", {
|
|
57
|
-
confirm_token: z.string().min(1).describe("来自 prepare_confirm_ai_draft"),
|
|
58
|
-
}, async ({ confirm_token }) => runTool(async () => {
|
|
59
|
-
client.setToolName("confirm_ai_draft");
|
|
60
|
-
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_DRAFT, TOKEN_SCOPE_WRITE_LEDGER]);
|
|
61
|
-
const pending = takePending(confirm_token, "confirm_draft");
|
|
62
|
-
const draftId = String(pending.exec.draft_id ?? "");
|
|
63
|
-
if (!draftId)
|
|
64
|
-
throw new Error("确认码缺少 draft_id");
|
|
65
|
-
const data = await client.post(familyPath(pending.familyId, `/ai-drafts/${draftId}/confirm`));
|
|
66
|
-
const result = data.result && typeof data.result === "object" ? data.result : {};
|
|
67
|
-
const createdId = Number(result.id ?? 0);
|
|
68
|
-
const draftType = String(pending.exec.draft_type ?? "");
|
|
69
|
-
const side = draftType === "ledger" ? "entry" : draftType === "note" ? "note" : "";
|
|
70
|
-
const link = side
|
|
71
|
-
? await linkRememberedPair(client, pending.familyId, String(pending.exec.link_group ?? ""), side, createdId)
|
|
72
|
-
: null;
|
|
73
|
-
return okJson({
|
|
74
|
-
...data,
|
|
75
|
-
link,
|
|
76
|
-
hint: link?.linked ? "草稿已确认,并和另一边挂在一起。" : "草稿已确认并写入正式数据。",
|
|
77
|
-
});
|
|
78
|
-
}));
|
|
79
|
-
server.tool("discard_ai_draft", "丢弃 AI 草稿(不可恢复)。丢弃草稿不改正式账本,无需解锁。", { draft_id: z.string().min(1) }, async ({ draft_id }) => runTool(async () => {
|
|
80
|
-
client.setToolName("discard_ai_draft");
|
|
81
|
-
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_DRAFT, TOKEN_SCOPE_WRITE_LEDGER]);
|
|
82
|
-
const familyId = await ensureFamilyId(client);
|
|
83
|
-
await client.post(familyPath(familyId, `/ai-drafts/${draft_id}/discard`));
|
|
84
|
-
return okJson({ ok: true, draft_id });
|
|
85
|
-
}));
|
|
86
|
-
server.tool("prepare_batch_confirm_ai_drafts", "准备批量确认草稿(不写入)。须先 unlock_writes。返回摘要 + confirm_token,用户同意后再 batch_confirm_ai_drafts。", {
|
|
87
|
-
draft_ids: z.array(z.string().min(1)).min(1).max(50).describe("待确认的草稿 ID 列表"),
|
|
88
|
-
}, async ({ draft_ids }) => runTool(async () => {
|
|
89
|
-
client.setToolName("prepare_batch_confirm_ai_drafts");
|
|
90
|
-
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_DRAFT, TOKEN_SCOPE_WRITE_LEDGER]);
|
|
91
|
-
const familyId = await ensureFamilyId(client);
|
|
92
|
-
const drafts = [];
|
|
93
|
-
for (const draft_id of draft_ids) {
|
|
94
|
-
try {
|
|
95
|
-
const draft = await client.get(familyPath(familyId, `/ai-drafts/${draft_id}`));
|
|
96
|
-
if (draft?.draft_type === "reminder") {
|
|
97
|
-
drafts.push({
|
|
98
|
-
draft_id,
|
|
99
|
-
draft_type: "reminder",
|
|
100
|
-
error: "事情提醒已下线,无法确认,请丢弃",
|
|
101
|
-
});
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
const payload = draft.payload && typeof draft.payload === "object"
|
|
105
|
-
? draft.payload
|
|
106
|
-
: {};
|
|
107
|
-
const item = {
|
|
108
|
-
draft_id,
|
|
109
|
-
draft_type: draft.draft_type,
|
|
110
|
-
payload_preview: payload,
|
|
111
|
-
};
|
|
112
|
-
const amount = Number(payload.amount ?? 0);
|
|
113
|
-
if (draft.draft_type === "ledger" && amount > 0) {
|
|
114
|
-
item.amount_yuan = fenToYuan(amount);
|
|
115
|
-
}
|
|
116
|
-
drafts.push(item);
|
|
117
|
-
}
|
|
118
|
-
catch {
|
|
119
|
-
drafts.push({ draft_id, error: "not_found_or_inaccessible" });
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
const confirmableIds = drafts
|
|
123
|
-
.filter((d) => !d.error)
|
|
124
|
-
.map((d) => String(d.draft_id));
|
|
125
|
-
if (confirmableIds.length === 0) {
|
|
126
|
-
throw new Error("没有可确认的草稿(均不可访问或为已下线类型)");
|
|
127
|
-
}
|
|
128
|
-
const summary = {
|
|
129
|
-
action: "batch_confirm_ai_drafts",
|
|
130
|
-
requested_count: draft_ids.length,
|
|
131
|
-
confirmable_count: confirmableIds.length,
|
|
132
|
-
drafts,
|
|
133
|
-
};
|
|
134
|
-
const pending = createPending("batch_confirm_draft", familyId, summary, {
|
|
135
|
-
draft_ids: confirmableIds,
|
|
136
|
-
});
|
|
137
|
-
return okJson(pendingPublicView(pending));
|
|
138
|
-
}));
|
|
139
|
-
server.tool("batch_confirm_ai_drafts", "批量确认 AI 草稿并写入正式记账/记事。必须传入 prepare_batch_confirm_ai_drafts 返回的 confirm_token(不再接受仅 draft_ids)。", {
|
|
140
|
-
confirm_token: z.string().min(1).describe("来自 prepare_batch_confirm_ai_drafts"),
|
|
141
|
-
}, async ({ confirm_token }) => runTool(async () => {
|
|
142
|
-
client.setToolName("batch_confirm_ai_drafts");
|
|
143
|
-
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_DRAFT, TOKEN_SCOPE_WRITE_LEDGER]);
|
|
144
|
-
const pending = takePending(confirm_token, "batch_confirm_draft");
|
|
145
|
-
const draftIds = pending.exec.draft_ids;
|
|
146
|
-
if (!Array.isArray(draftIds) || draftIds.length === 0) {
|
|
147
|
-
throw new Error("确认码缺少 draft_ids");
|
|
148
|
-
}
|
|
149
|
-
const data = await client.post(familyPath(pending.familyId, "/ai-drafts/batch-confirm"), { draft_ids: draftIds });
|
|
150
|
-
return okJson({ ...data, hint: "批量确认已完成;请查看 succeeded/failed。" });
|
|
151
|
-
}));
|
|
152
|
-
server.tool("batch_discard_ai_drafts", "批量丢弃 AI 草稿(不可恢复)。", {
|
|
153
|
-
draft_ids: z.array(z.string().min(1)).min(1).max(50).describe("待丢弃的草稿 ID 列表"),
|
|
154
|
-
}, async ({ draft_ids }) => runTool(async () => {
|
|
155
|
-
client.setToolName("batch_discard_ai_drafts");
|
|
156
|
-
await requireTokenScope(client, [TOKEN_SCOPE_WRITE_DRAFT, TOKEN_SCOPE_WRITE_LEDGER]);
|
|
157
|
-
const familyId = await ensureFamilyId(client);
|
|
158
|
-
const data = await client.post(familyPath(familyId, "/ai-drafts/batch-discard"), {
|
|
159
|
-
draft_ids,
|
|
160
|
-
});
|
|
161
|
-
return okJson(data);
|
|
162
|
-
}));
|
|
163
|
-
}
|