@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/.github/workflows/release.yml +32 -0
- package/LICENSE +21 -0
- package/README.md +190 -0
- package/dist/client.d.ts +406 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +244 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +861 -0
- package/package.json +42 -0
- package/src/client.ts +714 -0
- package/src/index.ts +897 -0
- package/tsconfig.json +19 -0
package/dist/client.js
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.GetNoteClient = exports.GetNoteAPIError = void 0;
|
|
40
|
+
const axios_1 = __importDefault(require("axios"));
|
|
41
|
+
const BASE_URL = "https://openapi.biji.com/open/api/v1";
|
|
42
|
+
class GetNoteAPIError extends Error {
|
|
43
|
+
code;
|
|
44
|
+
reason;
|
|
45
|
+
requestId;
|
|
46
|
+
constructor(code, reason, message, requestId) {
|
|
47
|
+
super(message);
|
|
48
|
+
this.code = code;
|
|
49
|
+
this.reason = reason;
|
|
50
|
+
this.requestId = requestId;
|
|
51
|
+
this.name = "GetNoteAPIError";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.GetNoteAPIError = GetNoteAPIError;
|
|
55
|
+
class GetNoteClient {
|
|
56
|
+
http;
|
|
57
|
+
constructor(apiKey, clientId) {
|
|
58
|
+
this.http = axios_1.default.create({
|
|
59
|
+
baseURL: BASE_URL,
|
|
60
|
+
headers: {
|
|
61
|
+
Authorization: `Bearer ${apiKey}`,
|
|
62
|
+
"X-Client-ID": clientId,
|
|
63
|
+
"Content-Type": "application/json",
|
|
64
|
+
},
|
|
65
|
+
timeout: 30000,
|
|
66
|
+
});
|
|
67
|
+
this.http.interceptors.response.use((res) => res, (err) => {
|
|
68
|
+
throw err;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
async request(method, path, params, data) {
|
|
72
|
+
try {
|
|
73
|
+
const res = await this.http.request({
|
|
74
|
+
method,
|
|
75
|
+
url: path,
|
|
76
|
+
params,
|
|
77
|
+
data,
|
|
78
|
+
});
|
|
79
|
+
const body = res.data;
|
|
80
|
+
if (!body.success) {
|
|
81
|
+
const err = body.error;
|
|
82
|
+
throw new GetNoteAPIError(err?.code ?? -1, err?.reason ?? "unknown", err?.message ?? "API request failed", body.request_id);
|
|
83
|
+
}
|
|
84
|
+
return body.data;
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
if (err instanceof GetNoteAPIError)
|
|
88
|
+
throw err;
|
|
89
|
+
if (axios_1.default.isAxiosError(err) && err.response) {
|
|
90
|
+
const body = err.response.data;
|
|
91
|
+
if (body?.error) {
|
|
92
|
+
throw new GetNoteAPIError(body.error.code, body.error.reason, body.error.message, body.request_id);
|
|
93
|
+
}
|
|
94
|
+
throw new Error(`HTTP ${err.response.status}: ${err.message}`);
|
|
95
|
+
}
|
|
96
|
+
throw err;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// ─── Notes ───────────────────────────────────────────────────────────────
|
|
100
|
+
async listNotes(params) {
|
|
101
|
+
return this.request("GET", "/resource/note/list", {
|
|
102
|
+
since_id: params.since_id,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
async getNote(id, image_quality) {
|
|
106
|
+
return this.request("GET", "/resource/note/detail", { id, image_quality });
|
|
107
|
+
}
|
|
108
|
+
async saveNote(body) {
|
|
109
|
+
return this.request("POST", "/resource/note/save", undefined, body);
|
|
110
|
+
}
|
|
111
|
+
async deleteNote(note_id) {
|
|
112
|
+
return this.request("POST", "/resource/note/delete", undefined, {
|
|
113
|
+
note_id,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
async updateNote(body) {
|
|
117
|
+
return this.request("POST", "/resource/note/update", undefined, body);
|
|
118
|
+
}
|
|
119
|
+
async getNoteTaskProgress(task_id) {
|
|
120
|
+
return this.request("POST", "/resource/note/task/progress", undefined, { task_id });
|
|
121
|
+
}
|
|
122
|
+
// ─── Tags ────────────────────────────────────────────────────────────────
|
|
123
|
+
async addNoteTags(note_id, tags) {
|
|
124
|
+
return this.request("POST", "/resource/note/tags/add", undefined, { note_id, tags });
|
|
125
|
+
}
|
|
126
|
+
async deleteNoteTag(note_id, tag_id) {
|
|
127
|
+
return this.request("POST", "/resource/note/tags/delete", undefined, { note_id, tag_id });
|
|
128
|
+
}
|
|
129
|
+
// ─── Image ───────────────────────────────────────────────────────────────
|
|
130
|
+
async getUploadConfig() {
|
|
131
|
+
return this.request("GET", "/resource/image/config");
|
|
132
|
+
}
|
|
133
|
+
async getUploadToken(params) {
|
|
134
|
+
return this.request("GET", "/resource/image/upload_token", { count: params.count, mime_type: params.mime_type });
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 上传图片到 OSS(使用预签名 URL)
|
|
138
|
+
* @param signUrl 预签名上传 URL(从 getUploadToken 获取的 sign_url)
|
|
139
|
+
* @param token 上传凭证
|
|
140
|
+
* @param imageData 图片数据(Buffer 或 Uint8Array)
|
|
141
|
+
* @returns OSS 回调响应(包含 image_id)
|
|
142
|
+
*/
|
|
143
|
+
async uploadImageToOSS(token, imageData) {
|
|
144
|
+
// 使用 FormData 构建 multipart 请求
|
|
145
|
+
const FormData = (await Promise.resolve().then(() => __importStar(require("form-data")))).default;
|
|
146
|
+
const form = new FormData();
|
|
147
|
+
form.append("OSSAccessKeyId", token.accessid);
|
|
148
|
+
form.append("policy", token.policy);
|
|
149
|
+
form.append("Signature", token.signature);
|
|
150
|
+
form.append("key", token.object_key);
|
|
151
|
+
form.append("callback", token.callback);
|
|
152
|
+
form.append("success_action_status", "200");
|
|
153
|
+
form.append("file", imageData, {
|
|
154
|
+
filename: "image",
|
|
155
|
+
contentType: token.oss_content_type,
|
|
156
|
+
});
|
|
157
|
+
const response = await fetch(token.host, {
|
|
158
|
+
method: "POST",
|
|
159
|
+
body: form,
|
|
160
|
+
headers: form.getHeaders(),
|
|
161
|
+
});
|
|
162
|
+
if (!response.ok) {
|
|
163
|
+
throw new Error(`OSS upload failed: ${response.status}`);
|
|
164
|
+
}
|
|
165
|
+
// 解析回调响应: {"h":{"c":0},"c":{"image":{"id":"xxx"}}}
|
|
166
|
+
const result = await response.json();
|
|
167
|
+
if (result.h?.c !== 0) {
|
|
168
|
+
throw new Error("OSS callback failed");
|
|
169
|
+
}
|
|
170
|
+
return { image_id: result.c.image.id };
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* 完整的图片上传流程:获取 token + 上传到 OSS
|
|
174
|
+
* @param imageData 图片数据
|
|
175
|
+
* @param mimeType MIME 类型(如 png, jpg)
|
|
176
|
+
* @returns 上传结果(包含 image_id 和 access_url)
|
|
177
|
+
*/
|
|
178
|
+
async uploadImage(imageData, mimeType = "png") {
|
|
179
|
+
// 1. 获取上传凭证(现在直接返回单个对象)
|
|
180
|
+
const token = await this.getUploadToken({ mime_type: mimeType });
|
|
181
|
+
// 2. 上传到 OSS
|
|
182
|
+
const { image_id } = await this.uploadImageToOSS(token, imageData);
|
|
183
|
+
// 3. 返回结果
|
|
184
|
+
return { image_id, access_url: token.access_url };
|
|
185
|
+
}
|
|
186
|
+
// ─── Knowledge / Topics ─────────────────────────────────────────────────
|
|
187
|
+
async listTopics(params) {
|
|
188
|
+
return this.request("GET", "/resource/knowledge/list", {
|
|
189
|
+
page: params?.page,
|
|
190
|
+
size: params?.size,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
async createTopic(body) {
|
|
194
|
+
return this.request("POST", "/resource/knowledge/create", undefined, body);
|
|
195
|
+
}
|
|
196
|
+
async listTopicNotes(params) {
|
|
197
|
+
return this.request("GET", "/resource/knowledge/notes", { topic_id: params.topic_id, page: params.page });
|
|
198
|
+
}
|
|
199
|
+
async batchAddNotesToTopic(body) {
|
|
200
|
+
return this.request("POST", "/resource/knowledge/note/batch-add", undefined, body);
|
|
201
|
+
}
|
|
202
|
+
async removeNoteFromTopic(body) {
|
|
203
|
+
return this.request("POST", "/resource/knowledge/note/remove", undefined, body);
|
|
204
|
+
}
|
|
205
|
+
// ─── Knowledge / Bloggers ────────────────────────────────────────────────
|
|
206
|
+
async listTopicBloggers(params) {
|
|
207
|
+
return this.request("GET", "/resource/knowledge/bloggers", { topic_id: params.topic_id, page: params.page });
|
|
208
|
+
}
|
|
209
|
+
async listTopicBloggerContents(params) {
|
|
210
|
+
return this.request("GET", "/resource/knowledge/blogger/contents", { topic_id: params.topic_id, follow_id: params.follow_id, page: params.page });
|
|
211
|
+
}
|
|
212
|
+
async getBloggerContentDetail(params) {
|
|
213
|
+
return this.request("GET", "/resource/knowledge/blogger/content/detail", { topic_id: params.topic_id, post_id: params.post_id });
|
|
214
|
+
}
|
|
215
|
+
// ─── Knowledge / Lives ───────────────────────────────────────────────────
|
|
216
|
+
async listTopicLives(params) {
|
|
217
|
+
return this.request("GET", "/resource/knowledge/lives", { topic_id: params.topic_id, page: params.page });
|
|
218
|
+
}
|
|
219
|
+
async getLiveDetail(params) {
|
|
220
|
+
return this.request("GET", "/resource/knowledge/live/detail", { topic_id: params.topic_id, live_id: params.live_id });
|
|
221
|
+
}
|
|
222
|
+
async followTopicLive(params) {
|
|
223
|
+
return this.request("POST", "/resource/knowledge/live/follow", undefined, { topic_id: params.topic_id, link: params.link });
|
|
224
|
+
}
|
|
225
|
+
async shareNote(params) {
|
|
226
|
+
return this.request("POST", "/resource/note/sharing", undefined, { note_id: params.note_id, share_exclude_audio: params.share_exclude_audio });
|
|
227
|
+
}
|
|
228
|
+
async listSubscribeTopics(params) {
|
|
229
|
+
return this.request("GET", "/resource/knowledge/subscribe/list", { page: params.page });
|
|
230
|
+
}
|
|
231
|
+
// ─── Rate Limit / Quota ──────────────────────────────────────────────────
|
|
232
|
+
async getQuota() {
|
|
233
|
+
return this.request("GET", "/resource/rate-limit/quota");
|
|
234
|
+
}
|
|
235
|
+
// ─── Recall / Search ─────────────────────────────────────────────────────
|
|
236
|
+
async recall(body) {
|
|
237
|
+
return this.request("POST", "/resource/recall", undefined, body);
|
|
238
|
+
}
|
|
239
|
+
async recallKnowledge(body) {
|
|
240
|
+
return this.request("POST", "/resource/recall/knowledge", undefined, body);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.GetNoteClient = GetNoteClient;
|
|
244
|
+
//# sourceMappingURL=client.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;GAMG"}
|