@getnote/mcp 1.5.3 → 1.7.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/README.md +35 -10
- package/dist/client.d.ts +106 -13
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +47 -15
- package/dist/index.js +183 -30
- package/dist/membership.d.ts +2 -0
- package/dist/membership.d.ts.map +1 -0
- package/dist/membership.js +5 -0
- package/package.json +13 -10
- package/src/client.ts +131 -30
- package/src/index.ts +181 -30
- package/src/membership.ts +2 -0
- package/test/client.test.mjs +122 -0
- package/test/skill2-contract.test.mjs +42 -0
package/src/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
17
17
|
import { z } from "zod";
|
|
18
18
|
import { GetNoteClient, GetNoteAPIError, SaveNoteReq, UpdateNoteReq } from "./client.js";
|
|
19
|
+
import { OPENAPI_MEMBERSHIP_PURCHASE_URL } from "./membership.js";
|
|
19
20
|
import { readFileSync, realpathSync } from "node:fs";
|
|
20
21
|
import { join, resolve, isAbsolute, sep } from "node:path";
|
|
21
22
|
|
|
@@ -115,6 +116,18 @@ function getClientId(): string {
|
|
|
115
116
|
process.exit(1);
|
|
116
117
|
}
|
|
117
118
|
|
|
119
|
+
function snowflakeID(value: unknown, field: string): string | number {
|
|
120
|
+
if (typeof value === "string" && /^\d+$/.test(value)) {
|
|
121
|
+
return value;
|
|
122
|
+
}
|
|
123
|
+
if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0) {
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
throw new Error(
|
|
127
|
+
`${field} must be a decimal string; only legacy integers within JavaScript's safe range are accepted`
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
118
131
|
// ─── Tool Definitions ────────────────────────────────────────────────────────
|
|
119
132
|
|
|
120
133
|
const TOOLS: Tool[] = [
|
|
@@ -141,8 +154,8 @@ const TOOLS: Tool[] = [
|
|
|
141
154
|
type: "object" as const,
|
|
142
155
|
properties: {
|
|
143
156
|
id: {
|
|
144
|
-
type: ["
|
|
145
|
-
description: "笔记 ID",
|
|
157
|
+
type: ["string", "number"],
|
|
158
|
+
description: "笔记 ID。必须优先传十进制字符串;仅为兼容旧调用接受 JavaScript 安全整数",
|
|
146
159
|
},
|
|
147
160
|
image_quality: {
|
|
148
161
|
type: "string",
|
|
@@ -153,6 +166,36 @@ const TOOLS: Tool[] = [
|
|
|
153
166
|
required: ["id"],
|
|
154
167
|
},
|
|
155
168
|
},
|
|
169
|
+
{
|
|
170
|
+
name: "get_note_original",
|
|
171
|
+
description: "直接读取笔记原文。链接笔记返回网页原文,录音笔记返回转写原文,文字笔记返回正文;不要把 AI 摘要冒充原文。",
|
|
172
|
+
inputSchema: { type: "object" as const, properties: { id: { type: ["string", "number"], description: "笔记 ID,推荐十进制字符串" } }, required: ["id"] },
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
name: "get_note_transcript",
|
|
176
|
+
description: "直接读取录音、会议或课堂笔记的转写原文;没有转写时明确返回不可用。",
|
|
177
|
+
inputSchema: { type: "object" as const, properties: { id: { type: ["string", "number"], description: "笔记 ID,推荐十进制字符串" } }, required: ["id"] },
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
name: "get_note_attachments",
|
|
181
|
+
description: "直接列出笔记中的图片、音频和文件附件,不需要从完整详情中猜字段。",
|
|
182
|
+
inputSchema: { type: "object" as const, properties: { id: { type: ["string", "number"], description: "笔记 ID,推荐十进制字符串" } }, required: ["id"] },
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
name: "get_note_timeline",
|
|
186
|
+
description: "直接读取录音或会议笔记的结构化时间线和原文资源;没有时间线时明确返回不可用。",
|
|
187
|
+
inputSchema: { type: "object" as const, properties: { id: { type: ["string", "number"], description: "笔记 ID,推荐十进制字符串" } }, required: ["id"] },
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
name: "get_note_quick_note",
|
|
191
|
+
description: "直接读取录音笔记的快捷笔记;没有快捷笔记时明确返回不可用。",
|
|
192
|
+
inputSchema: { type: "object" as const, properties: { id: { type: ["string", "number"], description: "笔记 ID,推荐十进制字符串" } }, required: ["id"] },
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
name: "get_note_todos",
|
|
196
|
+
description: "读取从会议总结中明确的待办章节按规则解析出的条目。返回 source 和 items;空列表表示未识别到明确待办章节,不应让模型自由补写。",
|
|
197
|
+
inputSchema: { type: "object" as const, properties: { id: { type: ["string", "number"], description: "笔记 ID,推荐十进制字符串" } }, required: ["id"] },
|
|
198
|
+
},
|
|
156
199
|
{
|
|
157
200
|
name: "save_note",
|
|
158
201
|
description:
|
|
@@ -180,8 +223,16 @@ const TOOLS: Tool[] = [
|
|
|
180
223
|
description: "标签列表(最多 5 个,每个不超过 10 个汉字)",
|
|
181
224
|
},
|
|
182
225
|
parent_id: {
|
|
183
|
-
type: ["
|
|
184
|
-
description: "父笔记 ID
|
|
226
|
+
type: ["string", "number"],
|
|
227
|
+
description: "父笔记 ID(优先传十进制字符串;创建子笔记时填,父笔记的 is_child_note 必须为 false)",
|
|
228
|
+
},
|
|
229
|
+
topic_id: {
|
|
230
|
+
type: "string",
|
|
231
|
+
description: "目标知识库 ID(来自 list_topics;支持 DEFAULT、BOOKSPACE、CUSTOMER、TEAMSPACE)",
|
|
232
|
+
},
|
|
233
|
+
client_request_id: {
|
|
234
|
+
type: "string",
|
|
235
|
+
description: "可选幂等键(1-128 个 ASCII 字符)。重试同一创建请求时必须复用同一个值",
|
|
185
236
|
},
|
|
186
237
|
link_url: {
|
|
187
238
|
type: "string",
|
|
@@ -218,8 +269,8 @@ const TOOLS: Tool[] = [
|
|
|
218
269
|
type: "object" as const,
|
|
219
270
|
properties: {
|
|
220
271
|
note_id: {
|
|
221
|
-
type: ["
|
|
222
|
-
description: "笔记 ID",
|
|
272
|
+
type: ["string", "number"],
|
|
273
|
+
description: "笔记 ID。必须优先传十进制字符串;仅兼容 JavaScript 安全整数",
|
|
223
274
|
},
|
|
224
275
|
},
|
|
225
276
|
required: ["note_id"],
|
|
@@ -233,8 +284,8 @@ const TOOLS: Tool[] = [
|
|
|
233
284
|
type: "object" as const,
|
|
234
285
|
properties: {
|
|
235
286
|
note_id: {
|
|
236
|
-
type: ["
|
|
237
|
-
description: "笔记 ID
|
|
287
|
+
type: ["string", "number"],
|
|
288
|
+
description: "笔记 ID(必填,优先传十进制字符串)",
|
|
238
289
|
},
|
|
239
290
|
title: {
|
|
240
291
|
type: "string",
|
|
@@ -262,8 +313,8 @@ const TOOLS: Tool[] = [
|
|
|
262
313
|
type: "object" as const,
|
|
263
314
|
properties: {
|
|
264
315
|
note_id: {
|
|
265
|
-
type: ["
|
|
266
|
-
description: "笔记 ID",
|
|
316
|
+
type: ["string", "number"],
|
|
317
|
+
description: "笔记 ID(优先传十进制字符串)",
|
|
267
318
|
},
|
|
268
319
|
tags: {
|
|
269
320
|
type: "array",
|
|
@@ -281,8 +332,8 @@ const TOOLS: Tool[] = [
|
|
|
281
332
|
type: "object" as const,
|
|
282
333
|
properties: {
|
|
283
334
|
note_id: {
|
|
284
|
-
type: ["
|
|
285
|
-
description: "笔记 ID",
|
|
335
|
+
type: ["string", "number"],
|
|
336
|
+
description: "笔记 ID(优先传十进制字符串)",
|
|
286
337
|
},
|
|
287
338
|
tag_id: {
|
|
288
339
|
type: "string",
|
|
@@ -296,7 +347,7 @@ const TOOLS: Tool[] = [
|
|
|
296
347
|
// ── Knowledge / Topics ──
|
|
297
348
|
{
|
|
298
349
|
name: "list_topics",
|
|
299
|
-
description: "
|
|
350
|
+
description: "获取用户创建、拥有或加入的知识库列表,包含普通、书籍、客户档案和团队知识库(TEAMSPACE)。返回 topics[]、has_more、total;保存前可按 name/scope 选择 topic_id。",
|
|
300
351
|
inputSchema: {
|
|
301
352
|
type: "object" as const,
|
|
302
353
|
properties: {
|
|
@@ -365,10 +416,44 @@ const TOOLS: Tool[] = [
|
|
|
365
416
|
items: { type: "string" },
|
|
366
417
|
description: "笔记 ID 列表(字符串格式,最多 20 个)",
|
|
367
418
|
},
|
|
419
|
+
directory_id: {
|
|
420
|
+
type: "string",
|
|
421
|
+
description: "目标目录 ID;不传则加入知识库根目录",
|
|
422
|
+
},
|
|
368
423
|
},
|
|
369
424
|
required: ["topic_id", "note_ids"],
|
|
370
425
|
},
|
|
371
426
|
},
|
|
427
|
+
{
|
|
428
|
+
name: "list_topic_directories",
|
|
429
|
+
description: "浏览知识库文件夹结构及当前目录下的笔记等资源。支持个人、书籍、客户档案和团队知识库。",
|
|
430
|
+
inputSchema: { type: "object" as const, properties: {
|
|
431
|
+
topic_id: { type: "string", description: "知识库 ID" },
|
|
432
|
+
directory_id: { type: "string", description: "目录 ID;不传表示根目录" },
|
|
433
|
+
}, required: ["topic_id"] },
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
name: "create_topic_directory",
|
|
437
|
+
description: "在知识库中创建文件夹。",
|
|
438
|
+
inputSchema: { type: "object" as const, properties: {
|
|
439
|
+
topic_id: { type: "string", description: "知识库 ID" }, name: { type: "string", description: "文件夹名称" },
|
|
440
|
+
parent_id: { type: "string", description: "父目录 ID;不传表示根目录" },
|
|
441
|
+
}, required: ["topic_id", "name"] },
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
name: "update_topic_directory",
|
|
445
|
+
description: "重命名或移动知识库文件夹。未提供的字段保持不变。",
|
|
446
|
+
inputSchema: { type: "object" as const, properties: {
|
|
447
|
+
topic_id: { type: "string" }, directory_id: { type: "string" }, name: { type: "string" }, parent_id: { type: "string" },
|
|
448
|
+
}, required: ["topic_id", "directory_id"] },
|
|
449
|
+
},
|
|
450
|
+
{
|
|
451
|
+
name: "delete_topic_directory",
|
|
452
|
+
description: "删除空的知识库文件夹。属于破坏性操作,调用前必须取得用户确认。",
|
|
453
|
+
inputSchema: { type: "object" as const, properties: {
|
|
454
|
+
topic_id: { type: "string" }, directory_id: { type: "string" },
|
|
455
|
+
}, required: ["topic_id", "directory_id"] },
|
|
456
|
+
},
|
|
372
457
|
{
|
|
373
458
|
name: "remove_note_from_topic",
|
|
374
459
|
description: "将笔记从知识库中移除。",
|
|
@@ -467,6 +552,14 @@ const TOOLS: Tool[] = [
|
|
|
467
552
|
required: ["topic_id"],
|
|
468
553
|
},
|
|
469
554
|
},
|
|
555
|
+
{
|
|
556
|
+
name: "follow_topic_blogger",
|
|
557
|
+
description: "把抖音博主订阅到指定知识库,后续可读取该博主内容。",
|
|
558
|
+
inputSchema: { type: "object" as const, properties: {
|
|
559
|
+
topic_id: { type: "string", description: "知识库 ID" }, link: { type: "string", description: "抖音博主主页或分享链接" },
|
|
560
|
+
platform: { type: "string", enum: ["douyin"], default: "douyin" },
|
|
561
|
+
}, required: ["topic_id", "link"] },
|
|
562
|
+
},
|
|
470
563
|
{
|
|
471
564
|
name: "list_topic_blogger_contents",
|
|
472
565
|
description:
|
|
@@ -479,8 +572,8 @@ const TOOLS: Tool[] = [
|
|
|
479
572
|
description: "知识库 ID(来自 list_topics 的 topic_id 字段)",
|
|
480
573
|
},
|
|
481
574
|
follow_id: {
|
|
482
|
-
type: "number",
|
|
483
|
-
description: "博主订阅 ID
|
|
575
|
+
type: ["string", "number"],
|
|
576
|
+
description: "博主订阅 ID(优先使用 list_topic_bloggers 返回的 follow_id_str;兼容安全整数 follow_id)",
|
|
484
577
|
},
|
|
485
578
|
page: {
|
|
486
579
|
type: "number",
|
|
@@ -542,8 +635,8 @@ const TOOLS: Tool[] = [
|
|
|
542
635
|
description: "知识库 ID(来自 list_topics 的 topic_id 字段)",
|
|
543
636
|
},
|
|
544
637
|
live_id: {
|
|
545
|
-
type: "number",
|
|
546
|
-
description: "直播 ID(来自 list_topic_lives 的 live_id
|
|
638
|
+
type: ["string", "number"],
|
|
639
|
+
description: "直播 ID(来自 list_topic_lives 的 live_id,优先按字符串原样传入)",
|
|
547
640
|
},
|
|
548
641
|
},
|
|
549
642
|
required: ["topic_id", "live_id"],
|
|
@@ -553,7 +646,7 @@ const TOOLS: Tool[] = [
|
|
|
553
646
|
{
|
|
554
647
|
name: "follow_topic_live",
|
|
555
648
|
description:
|
|
556
|
-
"订阅一个得到 App 直播到知识库。直播结束后经 AI 处理即可通过 list_topic_lives 查看。目前仅支持得到 App 直播链接。需要 topic.live.
|
|
649
|
+
"订阅一个得到 App 直播到知识库。直播结束后经 AI 处理即可通过 list_topic_lives 查看。目前仅支持得到 App 直播链接。需要 topic.live.write scope。",
|
|
557
650
|
inputSchema: {
|
|
558
651
|
type: "object" as const,
|
|
559
652
|
properties: {
|
|
@@ -574,7 +667,7 @@ const TOOLS: Tool[] = [
|
|
|
574
667
|
{
|
|
575
668
|
name: "share_note",
|
|
576
669
|
description:
|
|
577
|
-
"生成笔记的公开分享链接。幂等接口,多次调用返回同一个 share_url。需要 note.
|
|
670
|
+
"生成笔记的公开分享链接。幂等接口,多次调用返回同一个 share_url。需要 note.sharing.write scope。",
|
|
578
671
|
inputSchema: {
|
|
579
672
|
type: "object" as const,
|
|
580
673
|
properties: {
|
|
@@ -683,7 +776,42 @@ async function handleTool(
|
|
|
683
776
|
return client.listNotes({ cursor: cursor === "0" ? undefined : cursor });
|
|
684
777
|
}
|
|
685
778
|
case "get_note": {
|
|
686
|
-
return client.getNote(input.id
|
|
779
|
+
return client.getNote(snowflakeID(input.id, "id"), input.image_quality as string | undefined);
|
|
780
|
+
}
|
|
781
|
+
case "get_note_original": {
|
|
782
|
+
const result = await client.getNote(snowflakeID(input.id, "id"));
|
|
783
|
+
const note = result.note;
|
|
784
|
+
const original = note.web_page?.content || note.audio?.original || note.content;
|
|
785
|
+
if (!original) throw new Error("Original content is not available for this note");
|
|
786
|
+
return { id: note.id, note_type: note.note_type, title: note.title, original };
|
|
787
|
+
}
|
|
788
|
+
case "get_note_transcript": {
|
|
789
|
+
const result = await client.getNote(snowflakeID(input.id, "id"));
|
|
790
|
+
const transcript = result.note.audio?.original;
|
|
791
|
+
if (!transcript) throw new Error("Audio transcript is not available for this note");
|
|
792
|
+
return { id: result.note.id, title: result.note.title, transcript };
|
|
793
|
+
}
|
|
794
|
+
case "get_note_attachments": {
|
|
795
|
+
const result = await client.getNote(snowflakeID(input.id, "id"), "original");
|
|
796
|
+
return { id: result.note.id, title: result.note.title, attachments: result.note.attachments || [] };
|
|
797
|
+
}
|
|
798
|
+
case "get_note_timeline": {
|
|
799
|
+
const result = await client.getNote(snowflakeID(input.id, "id"));
|
|
800
|
+
if (!result.note.timeline) throw new Error("Timeline is not available for this note");
|
|
801
|
+
return { id: result.note.id, title: result.note.title, timeline: result.note.timeline };
|
|
802
|
+
}
|
|
803
|
+
case "get_note_quick_note": {
|
|
804
|
+
const result = await client.getNote(snowflakeID(input.id, "id"));
|
|
805
|
+
if (!result.note.quick_note) throw new Error("Quick note is not available for this note");
|
|
806
|
+
return { id: result.note.id, title: result.note.title, quick_note: result.note.quick_note };
|
|
807
|
+
}
|
|
808
|
+
case "get_note_todos": {
|
|
809
|
+
const result = await client.getNote(snowflakeID(input.id, "id"));
|
|
810
|
+
return {
|
|
811
|
+
id: result.note.id,
|
|
812
|
+
title: result.note.title,
|
|
813
|
+
meeting_todos: result.note.meeting_todos || { source: "summary_markdown_rules", items: [] },
|
|
814
|
+
};
|
|
687
815
|
}
|
|
688
816
|
case "save_note": {
|
|
689
817
|
const body: SaveNoteReq = {};
|
|
@@ -693,18 +821,21 @@ async function handleTool(
|
|
|
693
821
|
body.note_type = input.note_type as SaveNoteReq["note_type"];
|
|
694
822
|
if (input.tags !== undefined) body.tags = input.tags as string[];
|
|
695
823
|
if (input.parent_id !== undefined)
|
|
696
|
-
body.parent_id = input.parent_id
|
|
824
|
+
body.parent_id = snowflakeID(input.parent_id, "parent_id");
|
|
825
|
+
if (input.topic_id !== undefined) body.topic_id = input.topic_id as string;
|
|
826
|
+
if (input.client_request_id !== undefined)
|
|
827
|
+
body.client_request_id = input.client_request_id as string;
|
|
697
828
|
if (input.link_url !== undefined) body.link_url = input.link_url as string;
|
|
698
829
|
if (input.image_urls !== undefined)
|
|
699
830
|
body.image_urls = input.image_urls as string[];
|
|
700
831
|
return client.saveNote(body);
|
|
701
832
|
}
|
|
702
833
|
case "delete_note": {
|
|
703
|
-
return client.deleteNote(input.note_id
|
|
834
|
+
return client.deleteNote(snowflakeID(input.note_id, "note_id"));
|
|
704
835
|
}
|
|
705
836
|
case "update_note": {
|
|
706
837
|
const body: { note_id: number | string; title?: string; content?: string; tags?: string[] } = {
|
|
707
|
-
note_id: input.note_id
|
|
838
|
+
note_id: snowflakeID(input.note_id, "note_id"),
|
|
708
839
|
};
|
|
709
840
|
if (input.title !== undefined) body.title = input.title as string;
|
|
710
841
|
if (input.content !== undefined) body.content = input.content as string;
|
|
@@ -718,13 +849,13 @@ async function handleTool(
|
|
|
718
849
|
// ── Tags ──
|
|
719
850
|
case "add_note_tags": {
|
|
720
851
|
return client.addNoteTags(
|
|
721
|
-
input.note_id
|
|
852
|
+
snowflakeID(input.note_id, "note_id"),
|
|
722
853
|
input.tags as string[]
|
|
723
854
|
);
|
|
724
855
|
}
|
|
725
856
|
case "delete_note_tag": {
|
|
726
857
|
return client.deleteNoteTag(
|
|
727
|
-
input.note_id
|
|
858
|
+
snowflakeID(input.note_id, "note_id"),
|
|
728
859
|
input.tag_id as string
|
|
729
860
|
);
|
|
730
861
|
}
|
|
@@ -751,13 +882,26 @@ async function handleTool(
|
|
|
751
882
|
case "batch_add_notes_to_topic": {
|
|
752
883
|
return client.batchAddNotesToTopic({
|
|
753
884
|
topic_id: input.topic_id as string,
|
|
754
|
-
|
|
885
|
+
directory_id: input.directory_id as string | undefined,
|
|
886
|
+
note_ids: (input.note_ids as unknown[]).map((id) => String(snowflakeID(id, "note_ids[]"))),
|
|
755
887
|
});
|
|
756
888
|
}
|
|
889
|
+
case "list_topic_directories": {
|
|
890
|
+
return client.listTopicDirectories({ topic_id: input.topic_id as string, directory_id: input.directory_id as string | undefined });
|
|
891
|
+
}
|
|
892
|
+
case "create_topic_directory": {
|
|
893
|
+
return client.createTopicDirectory({ topic_id: input.topic_id as string, name: input.name as string, parent_id: input.parent_id as string | undefined });
|
|
894
|
+
}
|
|
895
|
+
case "update_topic_directory": {
|
|
896
|
+
return client.updateTopicDirectory({ topic_id: input.topic_id as string, directory_id: input.directory_id as string, name: input.name as string | undefined, parent_id: input.parent_id as string | undefined });
|
|
897
|
+
}
|
|
898
|
+
case "delete_topic_directory": {
|
|
899
|
+
return client.deleteTopicDirectory({ topic_id: input.topic_id as string, directory_id: input.directory_id as string });
|
|
900
|
+
}
|
|
757
901
|
case "remove_note_from_topic": {
|
|
758
902
|
return client.removeNoteFromTopic({
|
|
759
903
|
topic_id: input.topic_id as string,
|
|
760
|
-
note_ids: (input.note_ids as
|
|
904
|
+
note_ids: (input.note_ids as unknown[]).map((id) => String(snowflakeID(id, "note_ids[]"))),
|
|
761
905
|
});
|
|
762
906
|
}
|
|
763
907
|
|
|
@@ -803,10 +947,13 @@ async function handleTool(
|
|
|
803
947
|
page: input.page as number | undefined,
|
|
804
948
|
});
|
|
805
949
|
}
|
|
950
|
+
case "follow_topic_blogger": {
|
|
951
|
+
return client.followTopicBlogger({ topic_id: input.topic_id as string, link: input.link as string, platform: input.platform as string | undefined });
|
|
952
|
+
}
|
|
806
953
|
case "list_topic_blogger_contents": {
|
|
807
954
|
return client.listTopicBloggerContents({
|
|
808
955
|
topic_id: input.topic_id as string,
|
|
809
|
-
follow_id: input.follow_id
|
|
956
|
+
follow_id: snowflakeID(input.follow_id, "follow_id"),
|
|
810
957
|
page: input.page as number | undefined,
|
|
811
958
|
});
|
|
812
959
|
}
|
|
@@ -827,7 +974,7 @@ async function handleTool(
|
|
|
827
974
|
case "get_live_detail": {
|
|
828
975
|
return client.getLiveDetail({
|
|
829
976
|
topic_id: input.topic_id as string,
|
|
830
|
-
live_id: input.live_id
|
|
977
|
+
live_id: snowflakeID(input.live_id, "live_id"),
|
|
831
978
|
});
|
|
832
979
|
}
|
|
833
980
|
|
|
@@ -925,9 +1072,13 @@ async function main() {
|
|
|
925
1072
|
reason: err.reason,
|
|
926
1073
|
message: err.message,
|
|
927
1074
|
request_id: err.requestId,
|
|
1075
|
+
retryable: err.retryable,
|
|
1076
|
+
field: err.field,
|
|
1077
|
+
constraint: err.constraint,
|
|
1078
|
+
expected_type: err.expectedType,
|
|
928
1079
|
};
|
|
929
1080
|
if (err.code === 10201) {
|
|
930
|
-
errPayload.membership_url =
|
|
1081
|
+
errPayload.membership_url = OPENAPI_MEMBERSHIP_PURCHASE_URL;
|
|
931
1082
|
}
|
|
932
1083
|
return {
|
|
933
1084
|
content: [
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import http from "node:http";
|
|
3
|
+
import test from "node:test";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
GetNoteAPIError,
|
|
7
|
+
GetNoteClient,
|
|
8
|
+
parseJsonPreservingLargeIntegerStrings,
|
|
9
|
+
} from "../dist/client.js";
|
|
10
|
+
import { OPENAPI_MEMBERSHIP_PURCHASE_URL } from "../dist/membership.js";
|
|
11
|
+
|
|
12
|
+
test("membership errors use the MCP-specific OpenAPI purchase channel", () => {
|
|
13
|
+
assert.equal(
|
|
14
|
+
OPENAPI_MEMBERSHIP_PURCHASE_URL,
|
|
15
|
+
"https://www.biji.com/checkout?product_alias=9Ab36BB3ZD&spm=openapi_mcp"
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("large snowflake IDs are parsed and re-encoded as strings", () => {
|
|
20
|
+
const parsed = parseJsonPreservingLargeIntegerStrings(`{
|
|
21
|
+
"id": 1916020531058082912,
|
|
22
|
+
"follow_id": 1916020531058082913,
|
|
23
|
+
"children_ids": [1916020531058082914]
|
|
24
|
+
}`);
|
|
25
|
+
assert.equal(parsed.id, "1916020531058082912");
|
|
26
|
+
assert.equal(parsed.follow_id, "1916020531058082913");
|
|
27
|
+
assert.deepEqual(parsed.children_ids, ["1916020531058082914"]);
|
|
28
|
+
assert.match(JSON.stringify(parsed), /"1916020531058082912"/);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("HTTP 200 success=false exposes the complete structured error", async () => {
|
|
32
|
+
const server = http.createServer((_req, res) => {
|
|
33
|
+
res.setHeader("content-type", "application/json");
|
|
34
|
+
res.end(JSON.stringify({
|
|
35
|
+
success: false,
|
|
36
|
+
data: null,
|
|
37
|
+
error: {
|
|
38
|
+
code: 10000,
|
|
39
|
+
message: "参数错误",
|
|
40
|
+
reason: "invalid_request",
|
|
41
|
+
retryable: false,
|
|
42
|
+
field: "parent_id",
|
|
43
|
+
constraint: "non_negative_decimal_integer",
|
|
44
|
+
expected_type: "decimal string or JSON integer",
|
|
45
|
+
},
|
|
46
|
+
request_id: "req_test",
|
|
47
|
+
}));
|
|
48
|
+
});
|
|
49
|
+
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
50
|
+
const address = server.address();
|
|
51
|
+
const baseURL = `http://127.0.0.1:${address.port}`;
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
await assert.rejects(
|
|
55
|
+
() => new GetNoteClient("key", "client", baseURL).getNote("1e3"),
|
|
56
|
+
(err) => {
|
|
57
|
+
assert.ok(err instanceof GetNoteAPIError);
|
|
58
|
+
assert.equal(err.field, "parent_id");
|
|
59
|
+
assert.equal(err.constraint, "non_negative_decimal_integer");
|
|
60
|
+
assert.equal(err.expectedType, "decimal string or JSON integer");
|
|
61
|
+
assert.equal(err.requestId, "req_test");
|
|
62
|
+
assert.equal(err.retryable, false);
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
} finally {
|
|
67
|
+
server.close();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("OSS multipart fields use the signed names and order", async () => {
|
|
72
|
+
let body = "";
|
|
73
|
+
const server = http.createServer((req, res) => {
|
|
74
|
+
req.setEncoding("utf8");
|
|
75
|
+
req.on("data", (chunk) => {
|
|
76
|
+
body += chunk;
|
|
77
|
+
});
|
|
78
|
+
req.on("end", () => {
|
|
79
|
+
res.setHeader("content-type", "application/json");
|
|
80
|
+
res.end(JSON.stringify({ h: { c: 0 }, c: { image: { id: "img_1" } } }));
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
84
|
+
const address = server.address();
|
|
85
|
+
const host = `http://127.0.0.1:${address.port}`;
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
const client = new GetNoteClient("key", "client", host);
|
|
89
|
+
const result = await client.uploadImageToOSS({
|
|
90
|
+
accessid: "access",
|
|
91
|
+
host,
|
|
92
|
+
policy: "policy",
|
|
93
|
+
signature: "signature",
|
|
94
|
+
expire: 0,
|
|
95
|
+
callback: "callback",
|
|
96
|
+
object_key: "object",
|
|
97
|
+
access_url: "https://example.test/object",
|
|
98
|
+
oss_content_type: "image/png",
|
|
99
|
+
}, Buffer.from("image"));
|
|
100
|
+
assert.equal(result.image_id, "img_1");
|
|
101
|
+
|
|
102
|
+
const names = [
|
|
103
|
+
'name="key"',
|
|
104
|
+
'name="OSSAccessKeyId"',
|
|
105
|
+
'name="policy"',
|
|
106
|
+
'name="signature"',
|
|
107
|
+
'name="callback"',
|
|
108
|
+
'name="Content-Type"',
|
|
109
|
+
'name="file"',
|
|
110
|
+
];
|
|
111
|
+
let previous = -1;
|
|
112
|
+
for (const name of names) {
|
|
113
|
+
const current = body.indexOf(name);
|
|
114
|
+
assert.ok(current > previous, `${name} must follow the previous signed field`);
|
|
115
|
+
previous = current;
|
|
116
|
+
}
|
|
117
|
+
assert.equal(body.includes('name="Signature"'), false);
|
|
118
|
+
assert.equal(body.includes('name="success_action_status"'), false);
|
|
119
|
+
} finally {
|
|
120
|
+
server.close();
|
|
121
|
+
}
|
|
122
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import test from "node:test";
|
|
4
|
+
|
|
5
|
+
const indexSource = fs.readFileSync(new URL("../src/index.ts", import.meta.url), "utf8");
|
|
6
|
+
const clientSource = fs.readFileSync(new URL("../src/client.ts", import.meta.url), "utf8");
|
|
7
|
+
|
|
8
|
+
test("Skill 2.0 first-class tools stay registered", () => {
|
|
9
|
+
for (const name of [
|
|
10
|
+
"get_note_original",
|
|
11
|
+
"get_note_transcript",
|
|
12
|
+
"get_note_attachments",
|
|
13
|
+
"get_note_timeline",
|
|
14
|
+
"get_note_quick_note",
|
|
15
|
+
"get_note_todos",
|
|
16
|
+
"list_topic_directories",
|
|
17
|
+
"create_topic_directory",
|
|
18
|
+
"update_topic_directory",
|
|
19
|
+
"delete_topic_directory",
|
|
20
|
+
"follow_topic_blogger",
|
|
21
|
+
]) {
|
|
22
|
+
assert.match(indexSource, new RegExp(`name: ["']${name}["']`), `${name} must be registered`);
|
|
23
|
+
assert.match(indexSource, new RegExp(`case ["']${name}["']`), `${name} must have a handler`);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("Knowledge directory and blogger tools use the public OpenAPI routes", () => {
|
|
28
|
+
for (const route of [
|
|
29
|
+
"/resource/knowledge/directories",
|
|
30
|
+
"/resource/knowledge/directory/create",
|
|
31
|
+
"/resource/knowledge/directory/update",
|
|
32
|
+
"/resource/knowledge/directory/delete",
|
|
33
|
+
"/resource/knowledge/blogger/follow",
|
|
34
|
+
]) {
|
|
35
|
+
assert.ok(clientSource.includes(route), `${route} must remain in the client contract`);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("team knowledge bases remain part of the public tool contract", () => {
|
|
40
|
+
assert.match(indexSource, /TEAMSPACE/, "TEAMSPACE must be documented by list/save tools");
|
|
41
|
+
assert.match(indexSource, /note\.content\.trash/, "delegate-capable note deletion scope must remain explicit");
|
|
42
|
+
});
|