mn-docs-mcp 0.3.1 → 0.4.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 +2 -1
- package/mcp/lib.mjs +7 -13
- package/package.json +1 -2
- package/src/content/docs/guides/cookbook/webview-bidirectional-js.md +1 -1
- package/src/content/docs/guides/lifecycle-and-window.md +1 -1
- package/src/content/docs/guides/native-ui.md +3 -3
- package/src/content/docs/reference/global/jsb.md +14 -15
- package/.env.example +0 -4
package/README.md
CHANGED
|
@@ -26,7 +26,8 @@ pnpm preview # 预览构建结果
|
|
|
26
26
|
|
|
27
27
|
本项目内置一个本地MCPServer,支持stdio与HTTPStream两种方式,返回纯文本片段,适合AI直接调用。
|
|
28
28
|
|
|
29
|
-
embedding模型使用本地BGE-small-zh-v1.5(ONNX),首次启动会自动下载到
|
|
29
|
+
embedding模型使用本地BGE-small-zh-v1.5(ONNX),首次启动会自动下载到transformers.js默认缓存目录。模型文件约95.8MB,向量维度为512。
|
|
30
|
+
模型下载使用固定remoteHost镜像https://hf-mirror.com,不再依赖.env配置。
|
|
30
31
|
|
|
31
32
|
### 快速开始(npx)
|
|
32
33
|
|
package/mcp/lib.mjs
CHANGED
|
@@ -5,7 +5,6 @@ import { fileURLToPath } from 'node:url';
|
|
|
5
5
|
import matter from 'gray-matter';
|
|
6
6
|
import { env, pipeline } from '@huggingface/transformers';
|
|
7
7
|
import { Agent, ProxyAgent, setGlobalDispatcher } from 'undici';
|
|
8
|
-
import dotenv from 'dotenv';
|
|
9
8
|
|
|
10
9
|
const __filename = fileURLToPath(import.meta.url);
|
|
11
10
|
const __dirname = path.dirname(__filename);
|
|
@@ -104,10 +103,6 @@ function logDownloadProgress(info) {
|
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
105
|
|
|
107
|
-
function loadEnv() {
|
|
108
|
-
dotenv.config({ path: path.join(ROOT_DIR, '.env') });
|
|
109
|
-
}
|
|
110
|
-
|
|
111
106
|
function setupProxy() {
|
|
112
107
|
if (proxyInitialized) return;
|
|
113
108
|
proxyInitialized = true;
|
|
@@ -123,25 +118,22 @@ function setupProxy() {
|
|
|
123
118
|
|
|
124
119
|
async function getExtractor() {
|
|
125
120
|
if (extractorPromise) return extractorPromise;
|
|
126
|
-
loadEnv();
|
|
127
121
|
setupProxy();
|
|
128
122
|
|
|
129
123
|
// 抑制 Hugging Face Transformers 的警告输出
|
|
130
|
-
env.cacheDir = path.join(MCP_DIR, 'models');
|
|
131
124
|
env.allowRemoteModels = true;
|
|
132
125
|
env.disableProgressBars = true; // 禁用库自带的进度条
|
|
133
126
|
env.disableSymlinksWarning = true; // 禁用符号链接警告
|
|
127
|
+
env.remoteHost = 'https://hf-mirror.com';
|
|
134
128
|
|
|
135
129
|
// 设置日志级别为 error,避免 info/warning 级别日志干扰
|
|
136
130
|
if (!process.env.LOG_LEVEL) {
|
|
137
131
|
process.env.LOG_LEVEL = 'error';
|
|
138
132
|
}
|
|
139
133
|
|
|
140
|
-
|
|
141
|
-
env.
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const modelDir = path.join(env.cacheDir, 'Xenova', 'bge-small-zh-v1.5');
|
|
134
|
+
const modelDir = env.cacheDir
|
|
135
|
+
? path.join(env.cacheDir, 'Xenova', 'bge-small-zh-v1.5')
|
|
136
|
+
: null;
|
|
145
137
|
const create = async () =>
|
|
146
138
|
pipeline('feature-extraction', MODEL_ID, {
|
|
147
139
|
progress_callback: logDownloadProgress,
|
|
@@ -166,7 +158,9 @@ async function getExtractor() {
|
|
|
166
158
|
// 清除上次的进度状态,为重试做准备
|
|
167
159
|
lastDownloadProgress = -1;
|
|
168
160
|
logInfo(`模型下载失败,准备重试(${attempt}/${MAX_EXTRACTOR_RETRIES})...`);
|
|
169
|
-
|
|
161
|
+
if (modelDir) {
|
|
162
|
+
await fs.rm(modelDir, { recursive: true, force: true });
|
|
163
|
+
}
|
|
170
164
|
}
|
|
171
165
|
}
|
|
172
166
|
throw new Error('模型加载失败');
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mn-docs-mcp",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/Temsys-Shen/marginnote-addon-docs.git"
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"@huggingface/transformers": "^3.7.3",
|
|
15
15
|
"@pagefind/default-ui": "^1.4.0",
|
|
16
16
|
"astro": "^5.6.1",
|
|
17
|
-
"dotenv": "^16.4.5",
|
|
18
17
|
"fastmcp": "^3.34.0",
|
|
19
18
|
"gray-matter": "^4.0.3",
|
|
20
19
|
"sharp": "^0.34.2",
|
|
@@ -42,7 +42,7 @@ description: 理解 scene/notebook/document 生命周期及何时可安全使用
|
|
|
42
42
|
|
|
43
43
|
```javascript
|
|
44
44
|
notebookWillOpen: function (topicid) {
|
|
45
|
-
|
|
45
|
+
console.log("MNLOG Open Notebook: %@", topicid);
|
|
46
46
|
|
|
47
47
|
NSTimer.scheduledTimerWithTimeInterval(0.2, false, function () {
|
|
48
48
|
var showPanel = NSUserDefaults.standardUserDefaults().objectForKey("my_addon_show_panel");
|
|
@@ -56,9 +56,9 @@ UIAlertView.showWithTitleMessageStyleCancelButtonTitleOtherButtonTitlesTapBlock(
|
|
|
56
56
|
["确定"],
|
|
57
57
|
function (alert, buttonIndex) {
|
|
58
58
|
if (buttonIndex === 0) {
|
|
59
|
-
|
|
59
|
+
console.log("用户点击了确定");
|
|
60
60
|
} else {
|
|
61
|
-
|
|
61
|
+
console.log("用户取消");
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
);
|
|
@@ -118,7 +118,7 @@ webViewShouldStartLoadWithRequestNavigationType: function (webView, request, typ
|
|
|
118
118
|
|
|
119
119
|
```javascript
|
|
120
120
|
self.webView.evaluateJavaScript("document.title", function (result) {
|
|
121
|
-
|
|
121
|
+
console.log("页面标题: %@", result);
|
|
122
122
|
});
|
|
123
123
|
```
|
|
124
124
|
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
title: JSB
|
|
3
3
|
description: JavaScript 桥接核心,连接插件 JS 与运行时对象的入口对象。
|
|
4
4
|
---
|
|
5
|
-
|
|
6
5
|
JSB(JavaScript Bridge)是插件运行时的桥接核心对象:类定义、插件入口、日志与包内脚本加载都通过它完成。
|
|
7
6
|
|
|
8
7
|
## 实例成员 (Instance members)
|
|
@@ -23,11 +22,11 @@ defineClass(declaration: string, instanceMembers: object, classMembers?: object)
|
|
|
23
22
|
|
|
24
23
|
**Parameters:**
|
|
25
24
|
|
|
26
|
-
| Name
|
|
27
|
-
|
|
|
28
|
-
| `declaration`
|
|
29
|
-
| `instanceMembers` | `object`
|
|
30
|
-
| `classMembers`
|
|
25
|
+
| Name | Type | Description |
|
|
26
|
+
| :------------------ | :---------- | :------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
27
|
+
| `declaration` | `string` | 类声明,例如 `'MyAddon : JSExtension'`。 |
|
|
28
|
+
| `instanceMembers` | `object` | 实例方法与属性的集合。在此对象中定义的方法/属性在**实例**上调用(如 `sceneWillConnect`、`notebookWillOpen`、`queryAddonCommandStatus` 等)。 |
|
|
29
|
+
| `classMembers` | `object?` | 类方法与属性的集合。在此对象中定义的方法在**类**上调用(如 `addonDidConnect`)。 |
|
|
31
30
|
|
|
32
31
|
**Return Value:**
|
|
33
32
|
|
|
@@ -43,8 +42,8 @@ newAddon(mainPath: string): any
|
|
|
43
42
|
|
|
44
43
|
**Parameters:**
|
|
45
44
|
|
|
46
|
-
| Name
|
|
47
|
-
|
|
|
45
|
+
| Name | Type | Description |
|
|
46
|
+
| :----------- | :--------- | :----------------- |
|
|
48
47
|
| `mainPath` | `string` | 插件包根目录路径。 |
|
|
49
48
|
|
|
50
49
|
**Return Value:**
|
|
@@ -53,7 +52,7 @@ newAddon(mainPath: string): any
|
|
|
53
52
|
|
|
54
53
|
### `log`
|
|
55
54
|
|
|
56
|
-
|
|
55
|
+
向系统控制台输出日志,类似 `console.log`。在MN4已不可用。MN3中使用参考[log,error](https://ohmymn.marginnote.cn/api/marginnote/#log-error)
|
|
57
56
|
|
|
58
57
|
```javascript
|
|
59
58
|
log(format: string, ...args: any[]): void
|
|
@@ -61,10 +60,10 @@ log(format: string, ...args: any[]): void
|
|
|
61
60
|
|
|
62
61
|
**Parameters:**
|
|
63
62
|
|
|
64
|
-
| Name
|
|
65
|
-
|
|
|
66
|
-
| `format`
|
|
67
|
-
| `...args` | `any[]`
|
|
63
|
+
| Name | Type | Description |
|
|
64
|
+
| :---------- | :--------- | :------------------------------------------------------ |
|
|
65
|
+
| `format` | `string` | 格式化字符串,支持 `%@`、`%d` 等 Objective-C 格式。 |
|
|
66
|
+
| `...args` | `any[]` | 对应格式化字符串的参数。 |
|
|
68
67
|
|
|
69
68
|
### `require`
|
|
70
69
|
|
|
@@ -76,8 +75,8 @@ require(name: string): void
|
|
|
76
75
|
|
|
77
76
|
**Parameters:**
|
|
78
77
|
|
|
79
|
-
| Name
|
|
80
|
-
|
|
|
78
|
+
| Name | Type | Description |
|
|
79
|
+
| :------- | :--------- | :---------------------------- |
|
|
81
80
|
| `name` | `string` | 插件包内 JS 文件路径/文件名。 |
|
|
82
81
|
|
|
83
82
|
**Note:**
|
package/.env.example
DELETED