@getnote/mcp 1.3.1

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/src/index.ts ADDED
@@ -0,0 +1,897 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * getnote-mcp — MCP server for Get笔记 (GetNotes) Open API
4
+ *
5
+ * Usage:
6
+ * GETNOTE_API_KEY=your_key GETNOTE_CLIENT_ID=your_client_id node dist/index.js
7
+ * or pass --api-key and --client-id flags
8
+ */
9
+
10
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
11
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
12
+ import {
13
+ CallToolRequestSchema,
14
+ ListToolsRequestSchema,
15
+ Tool,
16
+ } from "@modelcontextprotocol/sdk/types.js";
17
+ import { z } from "zod";
18
+ import { GetNoteClient, GetNoteAPIError, SaveNoteReq, UpdateNoteReq } from "./client.js";
19
+
20
+ // ─── Config ──────────────────────────────────────────────────────────────────
21
+
22
+ function getApiKey(): string {
23
+ // 1. --api-key flag
24
+ const flagIdx = process.argv.indexOf("--api-key");
25
+ if (flagIdx !== -1 && process.argv[flagIdx + 1]) {
26
+ return process.argv[flagIdx + 1];
27
+ }
28
+ // 2. environment variable
29
+ const envKey = process.env.GETNOTE_API_KEY;
30
+ if (envKey) return envKey;
31
+
32
+ console.error(
33
+ "Error: API key required. Set GETNOTE_API_KEY env var or pass --api-key <key>"
34
+ );
35
+ process.exit(1);
36
+ }
37
+
38
+ function getClientId(): string {
39
+ // 1. --client-id flag
40
+ const flagIdx = process.argv.indexOf("--client-id");
41
+ if (flagIdx !== -1 && process.argv[flagIdx + 1]) {
42
+ return process.argv[flagIdx + 1];
43
+ }
44
+ // 2. environment variable
45
+ const envKey = process.env.GETNOTE_CLIENT_ID;
46
+ if (envKey) return envKey;
47
+
48
+ console.error(
49
+ "Error: Client ID required. Set GETNOTE_CLIENT_ID env var or pass --client-id <id>"
50
+ );
51
+ process.exit(1);
52
+ }
53
+
54
+ // ─── Tool Definitions ────────────────────────────────────────────────────────
55
+
56
+ const TOOLS: Tool[] = [
57
+ // ── Notes ──
58
+ {
59
+ name: "list_notes",
60
+ description:
61
+ "获取笔记列表(每次固定返回 20 条)。首次请求 since_id 传 0,后续用上一页最后一条笔记的 ID。",
62
+ inputSchema: {
63
+ type: "object" as const,
64
+ properties: {
65
+ since_id: {
66
+ type: ["number", "string"],
67
+ description: "游标,返回 ID 小于此值的笔记。首次传 0",
68
+ default: 0,
69
+ },
70
+ },
71
+ required: [],
72
+ },
73
+ },
74
+ {
75
+ name: "get_note",
76
+ description: "获取指定笔记的详细内容,包括正文、标签、附件、音频转录、网页链接等。",
77
+ inputSchema: {
78
+ type: "object" as const,
79
+ properties: {
80
+ id: {
81
+ type: ["number", "string"],
82
+ description: "笔记 ID",
83
+ },
84
+ image_quality: {
85
+ type: "string",
86
+ enum: ["original"],
87
+ description: "图片质量。传 'original' 返回正文中图片的原图链接(无压缩)",
88
+ },
89
+ },
90
+ required: ["id"],
91
+ },
92
+ },
93
+ {
94
+ name: "save_note",
95
+ description:
96
+ "新建笔记(⚠️ 仅支持新建,不支持编辑已有笔记)。支持纯文本笔记(plain_text)、链接笔记(link)和图片笔记(img_text)。\n\n🔗 **笔记内链**:Get笔记正文支持链接到其他笔记,格式为 `https://biji.com/note/{note_id}`。如需在笔记正文中引用其他笔记,按此格式填写 content 中的链接。若当前笔记后续会被分享出去,则应优先调用 `share_note` 工具获取被引用笔记的分享链接,并以分享链接替代内链写入正文。\n\n**图片笔记流程**:先用 upload_image 上传图片获取 image_url,再调用此接口传入 image_urls。\n\n**返回值说明**:\n- `plain_text`:同步返回 `id`、`title`、`created_at`、`updated_at`。\n- `link`(分享链接:`biji.com/note/share_note/*` 或 `d.biji.com/*` 短链):同步返回 `id`、`title`、`created_at`、`updated_at`,**无需轮询**。\n- `link`(普通链接):返回 `tasks` 数组(每项含 `task_id` 和 `url`),需用 `get_note_task_progress` 轮询进度。",
97
+ inputSchema: {
98
+ type: "object" as const,
99
+ properties: {
100
+ title: {
101
+ type: "string",
102
+ description: "笔记标题",
103
+ },
104
+ content: {
105
+ type: "string",
106
+ description: "笔记正文(Markdown 格式)。链接笔记不需要此字段",
107
+ },
108
+ note_type: {
109
+ type: "string",
110
+ enum: ["plain_text", "link", "img_text"],
111
+ description: "笔记类型:plain_text(纯文本,默认)、link(链接笔记)、img_text(图片笔记)",
112
+ default: "plain_text",
113
+ },
114
+ tags: {
115
+ type: "array",
116
+ items: { type: "string" },
117
+ description: "标签列表(最多 5 个,每个不超过 10 个汉字)",
118
+ },
119
+ parent_id: {
120
+ type: ["number", "string"],
121
+ description: "父笔记 ID(创建子笔记时填,父笔记的 is_child_note 必须为 false)",
122
+ },
123
+ link_url: {
124
+ type: "string",
125
+ description: "链接 URL(note_type=link 时必填)。分享链接(biji.com/note/share_note/* 或 d.biji.com/* 短链)同步返回笔记 ID;普通链接异步处理需轮询",
126
+ },
127
+ image_urls: {
128
+ type: "array",
129
+ items: { type: "string" },
130
+ description: "图片 URL 列表(note_type=img_text 时必填)",
131
+ },
132
+ },
133
+ required: [],
134
+ },
135
+ },
136
+ {
137
+ name: "get_note_task_progress",
138
+ description:
139
+ "查询创建笔记任务的处理进度。用于链接笔记(note_type=link)创建后,通过 save_note 返回的 task_id 轮询任务状态,直到 status 变为 success(可获取 note_id)或 failed(可获取 error_msg)。建议每 10~30 秒轮询一次,约 3 分钟内完成。需要 note.content.read scope。",
140
+ inputSchema: {
141
+ type: "object" as const,
142
+ properties: {
143
+ task_id: {
144
+ type: "string",
145
+ description: "任务 ID(创建链接笔记时 save_note 返回的 tasks[].task_id)",
146
+ },
147
+ },
148
+ required: ["task_id"],
149
+ },
150
+ },
151
+ {
152
+ name: "delete_note",
153
+ description: "删除笔记(移入回收站)。需要 note.content.trash scope。",
154
+ inputSchema: {
155
+ type: "object" as const,
156
+ properties: {
157
+ note_id: {
158
+ type: ["number", "string"],
159
+ description: "笔记 ID",
160
+ },
161
+ },
162
+ required: ["note_id"],
163
+ },
164
+ },
165
+ {
166
+ name: "update_note",
167
+ description:
168
+ "更新已有笔记的标题、内容或标签。⚠️ 仅支持 plain_text 类型笔记,链接笔记、图片笔记等暂不支持更新。至少需要传 title、content、tags 中的一个。tags 是替换操作,会覆盖原有标签。",
169
+ inputSchema: {
170
+ type: "object" as const,
171
+ properties: {
172
+ note_id: {
173
+ type: ["number", "string"],
174
+ description: "笔记 ID(必填)",
175
+ },
176
+ title: {
177
+ type: "string",
178
+ description: "新标题(可选,不传则不更新)",
179
+ },
180
+ content: {
181
+ type: "string",
182
+ description: "新内容,Markdown 格式(可选,不传则不更新)",
183
+ },
184
+ tags: {
185
+ type: "array",
186
+ items: { type: "string" },
187
+ description: "新标签列表(可选,不传则保持原标签;传则替换原有标签)",
188
+ },
189
+ },
190
+ required: ["note_id"],
191
+ },
192
+ },
193
+
194
+ // ── Tags ──
195
+ {
196
+ name: "add_note_tags",
197
+ description: "为指定笔记添加标签。",
198
+ inputSchema: {
199
+ type: "object" as const,
200
+ properties: {
201
+ note_id: {
202
+ type: ["number", "string"],
203
+ description: "笔记 ID",
204
+ },
205
+ tags: {
206
+ type: "array",
207
+ items: { type: "string" },
208
+ description: "要添加的标签名称列表",
209
+ },
210
+ },
211
+ required: ["note_id", "tags"],
212
+ },
213
+ },
214
+ {
215
+ name: "delete_note_tag",
216
+ description: "删除笔记的指定标签(系统标签不可删除)。",
217
+ inputSchema: {
218
+ type: "object" as const,
219
+ properties: {
220
+ note_id: {
221
+ type: ["number", "string"],
222
+ description: "笔记 ID",
223
+ },
224
+ tag_id: {
225
+ type: "string",
226
+ description: "要删除的标签 ID(来自 add_note_tags 返回或 get_note 的 tags[].id 字段)",
227
+ },
228
+ },
229
+ required: ["note_id", "tag_id"],
230
+ },
231
+ },
232
+
233
+ // ── Knowledge / Topics ──
234
+ {
235
+ name: "list_topics",
236
+ description: "获取知识库列表(每页固定 20 条)。返回 topics[]、has_more、total。每个 topic 包含 topic_id(知识库 ID,后续所有接口的 topic_id 参数均传此值)、name、description、cover、stats(笔记数、文件数、博主数、直播数)等。",
237
+ inputSchema: {
238
+ type: "object" as const,
239
+ properties: {
240
+ page: {
241
+ type: "number",
242
+ description: "页码,从 1 开始(默认 1)",
243
+ default: 1,
244
+ },
245
+ },
246
+ required: [],
247
+ },
248
+ },
249
+ {
250
+ name: "create_topic",
251
+ description: "创建新的知识库。⚠️ 限制:每天最多创建 50 个知识库,北京时间自然日 00:00 重置。",
252
+ inputSchema: {
253
+ type: "object" as const,
254
+ properties: {
255
+ name: {
256
+ type: "string",
257
+ description: "知识库名称(必填)",
258
+ },
259
+ description: {
260
+ type: "string",
261
+ description: "知识库描述(可选)",
262
+ },
263
+ cover: {
264
+ type: "string",
265
+ description: "封面图片 URL(可选)",
266
+ },
267
+ },
268
+ required: ["name"],
269
+ },
270
+ },
271
+ {
272
+ name: "list_topic_notes",
273
+ description: "获取指定知识库内的笔记列表(每页 20 条)。",
274
+ inputSchema: {
275
+ type: "object" as const,
276
+ properties: {
277
+ topic_id: {
278
+ type: "string",
279
+ description: "知识库 ID",
280
+ },
281
+ page: {
282
+ type: "number",
283
+ description: "页码,从 1 开始(默认 1)",
284
+ default: 1,
285
+ },
286
+ },
287
+ required: ["topic_id"],
288
+ },
289
+ },
290
+ {
291
+ name: "batch_add_notes_to_topic",
292
+ description: "批量将笔记添加到知识库(每批最多 20 个)。",
293
+ inputSchema: {
294
+ type: "object" as const,
295
+ properties: {
296
+ topic_id: {
297
+ type: "string",
298
+ description: "知识库 ID",
299
+ },
300
+ note_ids: {
301
+ type: "array",
302
+ items: { type: "string" },
303
+ description: "笔记 ID 列表(字符串格式,最多 20 个)",
304
+ },
305
+ },
306
+ required: ["topic_id", "note_ids"],
307
+ },
308
+ },
309
+ {
310
+ name: "remove_note_from_topic",
311
+ description: "将笔记从知识库中移除。",
312
+ inputSchema: {
313
+ type: "object" as const,
314
+ properties: {
315
+ topic_id: {
316
+ type: "string",
317
+ description: "知识库 ID",
318
+ },
319
+ note_ids: {
320
+ type: "array",
321
+ items: { type: "string" },
322
+ description: "笔记 ID 列表(字符串格式)",
323
+ },
324
+ },
325
+ required: ["topic_id", "note_ids"],
326
+ },
327
+ },
328
+
329
+ // ── Image ──
330
+ {
331
+ name: "get_upload_config",
332
+ description:
333
+ "获取图片上传配置,包括支持的文件类型、大小限制等。上传图片前先调用此接口了解约束。",
334
+ inputSchema: {
335
+ type: "object" as const,
336
+ properties: {},
337
+ required: [],
338
+ },
339
+ },
340
+ {
341
+ name: "get_upload_token",
342
+ description:
343
+ "获取 OSS 图片上传凭证。返回 accessid/host/policy/signature 等字段,用于 multipart/form-data POST 上传图片到阿里云 OSS。上传成功后获取 image_id,再用 save_note 创建图片笔记。⚠️ mime_type 必须与实际文件格式一致,否则 OSS 签名失败。",
344
+ inputSchema: {
345
+ type: "object" as const,
346
+ properties: {
347
+ mime_type: {
348
+ type: "string",
349
+ enum: ["jpg", "png", "gif", "webp", "jpeg"],
350
+ description: "图片类型:jpg | png | gif | webp,默认 png",
351
+ },
352
+ count: {
353
+ type: "number",
354
+ description: "需要的 token 数量,默认 1,最大 9(批量上传时使用)",
355
+ default: 1,
356
+ },
357
+ },
358
+ required: [],
359
+ },
360
+ },
361
+ {
362
+ name: "upload_image",
363
+ description:
364
+ "上传图片到 OSS。返回 image_url(用于创建图片笔记的 image_urls 参数)。",
365
+ inputSchema: {
366
+ type: "object" as const,
367
+ properties: {
368
+ image_path: {
369
+ type: "string",
370
+ description: "本地图片文件路径",
371
+ },
372
+ image_base64: {
373
+ type: "string",
374
+ description: "图片的 Base64 编码数据(与 image_path 二选一)",
375
+ },
376
+ mime_type: {
377
+ type: "string",
378
+ description: "图片类型(如 png、jpg、jpeg),默认 png",
379
+ default: "png",
380
+ },
381
+ },
382
+ required: [],
383
+ },
384
+ },
385
+
386
+ // ── Knowledge / Bloggers ──
387
+ {
388
+ name: "list_topic_bloggers",
389
+ description:
390
+ "获取知识库订阅的博主列表。需要 topic.blogger.read scope。",
391
+ inputSchema: {
392
+ type: "object" as const,
393
+ properties: {
394
+ topic_id: {
395
+ type: "string",
396
+ description: "知识库 ID(来自 list_topics 的 topic_id 字段)",
397
+ },
398
+ page: {
399
+ type: "number",
400
+ description: "页码,从 1 开始,默认 1",
401
+ },
402
+ },
403
+ required: ["topic_id"],
404
+ },
405
+ },
406
+ {
407
+ name: "list_topic_blogger_contents",
408
+ description:
409
+ "获取知识库中某个博主发布的内容列表(摘要,不含原文)。需要 topic.blogger.read scope。",
410
+ inputSchema: {
411
+ type: "object" as const,
412
+ properties: {
413
+ topic_id: {
414
+ type: "string",
415
+ description: "知识库 ID(来自 list_topics 的 topic_id 字段)",
416
+ },
417
+ follow_id: {
418
+ type: "number",
419
+ description: "博主订阅 ID(来自 list_topic_bloggers 的 follow_id 字段)",
420
+ },
421
+ page: {
422
+ type: "number",
423
+ description: "页码,从 1 开始,默认 1",
424
+ },
425
+ },
426
+ required: ["topic_id", "follow_id"],
427
+ },
428
+ },
429
+ {
430
+ name: "get_blogger_content_detail",
431
+ description:
432
+ "获取博主内容详情,包含完整原文(post_media_text)。需要 topic.blogger.read scope。",
433
+ inputSchema: {
434
+ type: "object" as const,
435
+ properties: {
436
+ topic_id: {
437
+ type: "string",
438
+ description: "知识库 ID(来自 list_topics 的 topic_id 字段)",
439
+ },
440
+ post_id: {
441
+ type: "string",
442
+ description: "内容 ID(来自 list_topic_blogger_contents 的 post_id_alias 字段)",
443
+ },
444
+ },
445
+ required: ["topic_id", "post_id"],
446
+ },
447
+ },
448
+
449
+ // ── Knowledge / Lives ──
450
+ {
451
+ name: "list_topic_lives",
452
+ description:
453
+ "获取知识库中已完成且 AI 已处理的直播列表。需要 topic.live.read scope。",
454
+ inputSchema: {
455
+ type: "object" as const,
456
+ properties: {
457
+ topic_id: {
458
+ type: "string",
459
+ description: "知识库 ID(来自 list_topics 的 topic_id 字段)",
460
+ },
461
+ page: {
462
+ type: "number",
463
+ description: "页码,从 1 开始,默认 1",
464
+ },
465
+ },
466
+ required: ["topic_id"],
467
+ },
468
+ },
469
+ {
470
+ name: "get_live_detail",
471
+ description:
472
+ "获取直播详情,包含 AI 摘要(post_summary)和完整原文转写(post_media_text)。需要 topic.live.read scope。",
473
+ inputSchema: {
474
+ type: "object" as const,
475
+ properties: {
476
+ topic_id: {
477
+ type: "string",
478
+ description: "知识库 ID(来自 list_topics 的 topic_id 字段)",
479
+ },
480
+ live_id: {
481
+ type: "number",
482
+ description: "直播 ID(来自 list_topic_lives 的 live_id 字段)",
483
+ },
484
+ },
485
+ required: ["topic_id", "live_id"],
486
+ },
487
+ },
488
+
489
+ {
490
+ name: "follow_topic_live",
491
+ description:
492
+ "订阅一个得到 App 直播到知识库。直播结束后经 AI 处理即可通过 list_topic_lives 查看。目前仅支持得到 App 直播链接。需要 topic.live.read scope。",
493
+ inputSchema: {
494
+ type: "object" as const,
495
+ properties: {
496
+ topic_id: {
497
+ type: "string",
498
+ description: "知识库 ID",
499
+ },
500
+ link: {
501
+ type: "string",
502
+ description: "得到 App 直播链接(目前仅支持得到)",
503
+ },
504
+ },
505
+ required: ["topic_id", "link"],
506
+ },
507
+ },
508
+
509
+ // ── Note / Sharing ──
510
+ {
511
+ name: "share_note",
512
+ description:
513
+ "生成笔记的公开分享链接。幂等接口,多次调用返回同一个 share_url。需要 note.content.read scope。",
514
+ inputSchema: {
515
+ type: "object" as const,
516
+ properties: {
517
+ note_id: {
518
+ type: "string",
519
+ description: "笔记 ID(字符串格式)",
520
+ },
521
+ share_exclude_audio: {
522
+ type: "boolean",
523
+ description: "是否排除音频内容,默认 false",
524
+ },
525
+ },
526
+ required: ["note_id"],
527
+ },
528
+ },
529
+
530
+ // ── Knowledge / Subscribe ──
531
+ {
532
+ name: "list_subscribe_topics",
533
+ description:
534
+ "获取当前用户订阅的知识库列表(他人公开的,非自己创建)。返回 topics[]、has_more、total。",
535
+ inputSchema: {
536
+ type: "object" as const,
537
+ properties: {
538
+ page: {
539
+ type: "number",
540
+ description: "页码,从 1 开始,默认 1",
541
+ },
542
+ },
543
+ required: [],
544
+ },
545
+ },
546
+
547
+ // ── Quota ──
548
+ {
549
+ name: "get_quota",
550
+ description:
551
+ "查询当前 API Key 的调用配额,包括 read/write/write_note 三类的日/月剩余次数。",
552
+ inputSchema: {
553
+ type: "object" as const,
554
+ properties: {},
555
+ required: [],
556
+ },
557
+ },
558
+
559
+ // ── Recall / Search ──
560
+ {
561
+ name: "recall",
562
+ description:
563
+ "全局语义搜索:在所有笔记中进行语义召回。适用场景:「搜一下」「找找我哪些笔记提到了 XX」。返回结果按相关度从高到低排序。需要 note.recall.read scope。",
564
+ inputSchema: {
565
+ type: "object" as const,
566
+ properties: {
567
+ query: {
568
+ type: "string",
569
+ description: "搜索关键词或语义描述(必填)",
570
+ },
571
+ top_k: {
572
+ type: "number",
573
+ description: "返回数量,默认 3,最大 10",
574
+ default: 3,
575
+ },
576
+ },
577
+ required: ["query"],
578
+ },
579
+ },
580
+ {
581
+ name: "recall_knowledge",
582
+ description:
583
+ "知识库语义搜索:在指定知识库范围内进行语义召回。适用场景:「在我的 XX 知识库搜一下 XX」。返回结果按相关度从高到低排序。需要 note.topic.recall.read scope。",
584
+ inputSchema: {
585
+ type: "object" as const,
586
+ properties: {
587
+ topic_id: {
588
+ type: "string",
589
+ description: "知识库 ID(来自 list_topics 的 topic_id 字段)(必填)",
590
+ },
591
+ query: {
592
+ type: "string",
593
+ description: "搜索关键词或语义描述(必填)",
594
+ },
595
+ top_k: {
596
+ type: "number",
597
+ description: "返回数量,默认 3,最大 10",
598
+ default: 3,
599
+ },
600
+ },
601
+ required: ["topic_id", "query"],
602
+ },
603
+ },
604
+ ];
605
+
606
+ // ─── Tool Handlers ───────────────────────────────────────────────────────────
607
+
608
+ type ToolInput = Record<string, unknown>;
609
+
610
+ async function handleTool(
611
+ name: string,
612
+ input: ToolInput,
613
+ client: GetNoteClient
614
+ ): Promise<unknown> {
615
+ switch (name) {
616
+ // ── Notes ──
617
+ case "list_notes": {
618
+ const since_id = (input.since_id as number | string | undefined) ?? 0;
619
+ return client.listNotes({ since_id });
620
+ }
621
+ case "get_note": {
622
+ return client.getNote(input.id as number | string, input.image_quality as string | undefined);
623
+ }
624
+ case "save_note": {
625
+ const body: SaveNoteReq = {};
626
+ if (input.title !== undefined) body.title = input.title as string;
627
+ if (input.content !== undefined) body.content = input.content as string;
628
+ if (input.note_type !== undefined)
629
+ body.note_type = input.note_type as SaveNoteReq["note_type"];
630
+ if (input.tags !== undefined) body.tags = input.tags as string[];
631
+ if (input.parent_id !== undefined)
632
+ body.parent_id = input.parent_id as number | string;
633
+ if (input.link_url !== undefined) body.link_url = input.link_url as string;
634
+ if (input.image_urls !== undefined)
635
+ body.image_urls = input.image_urls as string[];
636
+ return client.saveNote(body);
637
+ }
638
+ case "delete_note": {
639
+ return client.deleteNote(input.note_id as number | string);
640
+ }
641
+ case "update_note": {
642
+ const body: { note_id: number | string; title?: string; content?: string; tags?: string[] } = {
643
+ note_id: input.note_id as number | string,
644
+ };
645
+ if (input.title !== undefined) body.title = input.title as string;
646
+ if (input.content !== undefined) body.content = input.content as string;
647
+ if (input.tags !== undefined) body.tags = input.tags as string[];
648
+ return client.updateNote(body);
649
+ }
650
+ case "get_note_task_progress": {
651
+ return client.getNoteTaskProgress(input.task_id as string);
652
+ }
653
+
654
+ // ── Tags ──
655
+ case "add_note_tags": {
656
+ return client.addNoteTags(
657
+ input.note_id as number | string,
658
+ input.tags as string[]
659
+ );
660
+ }
661
+ case "delete_note_tag": {
662
+ return client.deleteNoteTag(
663
+ input.note_id as number | string,
664
+ input.tag_id as string
665
+ );
666
+ }
667
+
668
+ // ── Knowledge ──
669
+ case "list_topics": {
670
+ return client.listTopics({
671
+ page: input.page as number | undefined,
672
+ });
673
+ }
674
+ case "create_topic": {
675
+ return client.createTopic({
676
+ name: input.name as string,
677
+ description: input.description as string | undefined,
678
+ cover: input.cover as string | undefined,
679
+ });
680
+ }
681
+ case "list_topic_notes": {
682
+ return client.listTopicNotes({
683
+ topic_id: input.topic_id as string,
684
+ page: input.page as number | undefined,
685
+ });
686
+ }
687
+ case "batch_add_notes_to_topic": {
688
+ return client.batchAddNotesToTopic({
689
+ topic_id: input.topic_id as string,
690
+ note_ids: (input.note_ids as (number | string)[]).map(String),
691
+ });
692
+ }
693
+ case "remove_note_from_topic": {
694
+ return client.removeNoteFromTopic({
695
+ topic_id: input.topic_id as string,
696
+ note_ids: (input.note_ids as (number | string)[]).map(String),
697
+ });
698
+ }
699
+
700
+ // ── Image ──
701
+ case "get_upload_config": {
702
+ return client.getUploadConfig();
703
+ }
704
+ case "get_upload_token": {
705
+ return client.getUploadToken({
706
+ mime_type: input.mime_type as string | undefined,
707
+ count: input.count as number | undefined,
708
+ });
709
+ }
710
+ case "upload_image": {
711
+ const fs = await import("fs");
712
+ let imageData: Buffer;
713
+
714
+ if (input.image_path) {
715
+ // 从文件路径读取
716
+ imageData = fs.readFileSync(input.image_path as string);
717
+ } else if (input.image_base64) {
718
+ // 从 Base64 解码
719
+ imageData = Buffer.from(input.image_base64 as string, "base64");
720
+ } else {
721
+ throw new Error("Either image_path or image_base64 is required");
722
+ }
723
+
724
+ // mime_type 传扩展名格式(如 png、jpg)
725
+ const mimeType = (input.mime_type as string) || "png";
726
+ const result = await client.uploadImage(imageData, mimeType);
727
+ return {
728
+ success: true,
729
+ image_url: result.access_url, // 用于创建图片笔记
730
+ image_id: result.image_id // OSS 回调返回的 ID
731
+ };
732
+ }
733
+
734
+ // ── Knowledge / Bloggers ──
735
+ case "list_topic_bloggers": {
736
+ return client.listTopicBloggers({
737
+ topic_id: input.topic_id as string,
738
+ page: input.page as number | undefined,
739
+ });
740
+ }
741
+ case "list_topic_blogger_contents": {
742
+ return client.listTopicBloggerContents({
743
+ topic_id: input.topic_id as string,
744
+ follow_id: input.follow_id as number | string,
745
+ page: input.page as number | undefined,
746
+ });
747
+ }
748
+ case "get_blogger_content_detail": {
749
+ return client.getBloggerContentDetail({
750
+ topic_id: input.topic_id as string,
751
+ post_id: input.post_id as string,
752
+ });
753
+ }
754
+
755
+ // ── Knowledge / Lives ──
756
+ case "list_topic_lives": {
757
+ return client.listTopicLives({
758
+ topic_id: input.topic_id as string,
759
+ page: input.page as number | undefined,
760
+ });
761
+ }
762
+ case "get_live_detail": {
763
+ return client.getLiveDetail({
764
+ topic_id: input.topic_id as string,
765
+ live_id: input.live_id as number | string,
766
+ });
767
+ }
768
+
769
+ case "follow_topic_live": {
770
+ return client.followTopicLive({
771
+ topic_id: input.topic_id as string,
772
+ link: input.link as string,
773
+ });
774
+ }
775
+
776
+ // ── Note / Sharing ──
777
+ case "share_note": {
778
+ return client.shareNote({
779
+ note_id: input.note_id as string,
780
+ share_exclude_audio: input.share_exclude_audio as boolean | undefined,
781
+ });
782
+ }
783
+
784
+ // ── Knowledge / Subscribe ──
785
+ case "list_subscribe_topics": {
786
+ return client.listSubscribeTopics({
787
+ page: input.page as number | undefined,
788
+ });
789
+ }
790
+
791
+ // ── Quota ──
792
+ case "get_quota": {
793
+ return client.getQuota();
794
+ }
795
+
796
+ // ── Recall / Search ──
797
+ case "recall": {
798
+ return client.recall({
799
+ query: input.query as string,
800
+ top_k: input.top_k as number | undefined,
801
+ });
802
+ }
803
+ case "recall_knowledge": {
804
+ return client.recallKnowledge({
805
+ topic_id: input.topic_id as string,
806
+ query: input.query as string,
807
+ top_k: input.top_k as number | undefined,
808
+ });
809
+ }
810
+
811
+ default:
812
+ throw new Error(`Unknown tool: ${name}`);
813
+ }
814
+ }
815
+
816
+ // ─── Main ────────────────────────────────────────────────────────────────────
817
+
818
+ async function main() {
819
+ const apiKey = getApiKey();
820
+ const clientId = getClientId();
821
+ const client = new GetNoteClient(apiKey, clientId);
822
+
823
+ const server = new Server(
824
+ {
825
+ name: "getnote-mcp",
826
+ version: "1.2.0",
827
+ },
828
+ {
829
+ capabilities: {
830
+ tools: {},
831
+ },
832
+ }
833
+ );
834
+
835
+ // List tools
836
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
837
+ tools: TOOLS,
838
+ }));
839
+
840
+ // Call tool
841
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
842
+ const { name, arguments: args } = request.params;
843
+ const input = (args ?? {}) as ToolInput;
844
+
845
+ try {
846
+ const result = await handleTool(name, input, client);
847
+ return {
848
+ content: [
849
+ {
850
+ type: "text" as const,
851
+ text: JSON.stringify(result, null, 2),
852
+ },
853
+ ],
854
+ };
855
+ } catch (err) {
856
+ if (err instanceof GetNoteAPIError) {
857
+ const errPayload: Record<string, unknown> = {
858
+ error: true,
859
+ code: err.code,
860
+ reason: err.reason,
861
+ message: err.message,
862
+ request_id: err.requestId,
863
+ };
864
+ if (err.code === 10201) {
865
+ errPayload.membership_url = "https://www.biji.com/checkout?product_alias=6AydVpYeKl";
866
+ }
867
+ return {
868
+ content: [
869
+ {
870
+ type: "text" as const,
871
+ text: JSON.stringify(errPayload, null, 2),
872
+ },
873
+ ],
874
+ isError: true,
875
+ };
876
+ }
877
+ return {
878
+ content: [
879
+ {
880
+ type: "text" as const,
881
+ text: `Error: ${err instanceof Error ? err.message : String(err)}`,
882
+ },
883
+ ],
884
+ isError: true,
885
+ };
886
+ }
887
+ });
888
+
889
+ const transport = new StdioServerTransport();
890
+ await server.connect(transport);
891
+ console.error("getnote-mcp server started");
892
+ }
893
+
894
+ main().catch((err) => {
895
+ console.error("Fatal error:", err);
896
+ process.exit(1);
897
+ });