mn-docs-mcp 0.3.2 → 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/.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",
|
package/.env.example
DELETED