mn-docs-mcp 0.1.0 → 0.2.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.
@@ -0,0 +1,28 @@
1
+ name: Publish Package
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ permissions:
9
+ id-token: write # Required for OIDC
10
+ contents: read
11
+
12
+ jobs:
13
+ publish:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+
18
+ - uses: actions/setup-node@v4
19
+ with:
20
+ node-version: '24'
21
+ registry-url: 'https://registry.npmjs.org'
22
+ - uses: pnpm/action-setup@v4
23
+ with:
24
+ version: '10'
25
+ - run: pnpm install --frozen-lockfile
26
+ - run: pnpm publish --provenance --access public --no-git-checks
27
+ env:
28
+ NODE_AUTH_TOKEN: ""
package/README.md CHANGED
@@ -24,54 +24,38 @@ pnpm preview # 预览构建结果
24
24
 
25
25
  ## 本地MCP搜索
26
26
 
27
- 本项目内置一个本地MCPServer,支持stdio与HTTP两种方式,返回纯文本片段,适合AI直接调用。
27
+ 本项目内置一个本地MCPServer,支持stdio与HTTPStream两种方式,返回纯文本片段,适合AI直接调用。
28
28
 
29
29
  embedding模型使用本地BGE-small-zh-v1.5(ONNX),首次启动会自动下载到 `.mcp/models`。模型文件约95.8MB,向量维度为512。
30
30
 
31
- 可选配置:
31
+ ### 快速开始(npx)
32
32
 
33
- ```
34
- MCP_HTTP_PORT=8788
35
- ```
36
-
37
- 如果你需要代理或镜像下载模型:
38
-
39
- ```
40
- export HTTPS_PROXY=http://127.0.0.1:7890
41
- export HF_ENDPOINT=https://hf-mirror.com
42
- ```
43
-
44
- ### 启动stdio版MCP
45
-
46
- ```bash
47
- pnpm mcp
48
- ```
49
-
50
- ### 启动HTTP版MCP
51
-
52
- ```bash
53
- pnpm mcp-http
54
- ```
55
-
56
- 以上两种启动方式会在检测到文档更新时自动重建索引。
33
+ ### MCP配置示例(npx)
57
34
 
58
- ### 强制重建索引
59
-
60
- ```bash
61
- pnpm mcp:force-build
35
+ ```json
36
+ {
37
+ "mcpServers": {
38
+ "mn-docs": {
39
+ "command": "npx",
40
+ "args": [
41
+ "mn-docs-mcp"
42
+ ]
43
+ }
44
+ }
45
+ }
62
46
  ```
63
47
 
64
- ### MCP配置
48
+ ### MCP配置示例(本地clone)
65
49
 
66
50
  ```json
67
51
  {
68
52
  "mcpServers": {
69
- "mn-docs": {
70
- "command": "pnpm",
53
+ "mn-docs-local": {
54
+ "command": "node",
71
55
  "args": [
72
- "mcp"
56
+ "mcp/cli.mjs"
73
57
  ],
74
- "cwd": "path/to/this/repository"
58
+ "cwd": "/path/to/this/repository"
75
59
  }
76
60
  }
77
61
  }
@@ -1,11 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
3
7
  const args = process.argv.slice(2);
4
8
 
5
9
  let mode = 'stdio';
6
10
  let port;
7
11
  let prebuild = false;
8
- let silent = true;
12
+ let silent = false;
9
13
 
10
14
  for (let i = 0; i < args.length; i += 1) {
11
15
  const arg = args[i];
@@ -25,6 +29,10 @@ for (let i = 0; i < args.length; i += 1) {
25
29
  silent = false;
26
30
  continue;
27
31
  }
32
+ if (arg === '--silent') {
33
+ silent = true;
34
+ continue;
35
+ }
28
36
  if (arg === '--port' && args[i + 1]) {
29
37
  port = args[i + 1];
30
38
  i += 1;
@@ -41,7 +49,8 @@ for (let i = 0; i < args.length; i += 1) {
41
49
  ' --http 启动HTTPStream模式(默认stdio)',
42
50
  ' --port <port> HTTP端口(默认8788)',
43
51
  ' --prebuild 启动后后台预构建索引',
44
- ' --verbose 输出日志(默认静默)',
52
+ ' --verbose 输出日志(覆盖--silent)',
53
+ ' --silent 关闭开屏与日志',
45
54
  ' --stdio 显式使用stdio模式',
46
55
  ].join('\n') + '\n'
47
56
  );
@@ -49,13 +58,27 @@ for (let i = 0; i < args.length; i += 1) {
49
58
  }
50
59
  }
51
60
 
61
+ const __filename = fileURLToPath(import.meta.url);
62
+ const __dirname = path.dirname(__filename);
63
+ const packagePath = path.join(__dirname, '../package.json');
64
+ let version = '0.0.0';
65
+ try {
66
+ const raw = fs.readFileSync(packagePath, 'utf-8');
67
+ version = JSON.parse(raw).version || version;
68
+ } catch {}
69
+
52
70
  if (mode === 'stdio') {
53
71
  process.env.MCP_STDIO = '1';
54
72
  process.env.MCP_SILENT = silent ? '1' : '0';
73
+ process.env.MN_DOCS_VERSION = version;
74
+ process.env.MN_DOCS_MODE = 'stdio';
55
75
  if (prebuild) process.env.MCP_PREBUILD = '1';
56
76
  await import('./server.mjs');
57
77
  } else {
58
78
  if (port) process.env.MCP_HTTP_PORT = String(port);
79
+ process.env.MN_DOCS_VERSION = version;
80
+ process.env.MN_DOCS_MODE = 'http';
81
+ if (port) process.env.MN_DOCS_PORT = String(port);
59
82
  if (prebuild) process.env.MCP_PREBUILD = '1';
60
83
  await import('./server-http.mjs');
61
84
  }
@@ -4,6 +4,29 @@ import { buildIndex, getPaths, isIndexStale, loadIndex, searchDocs } from './lib
4
4
 
5
5
  const TOOL_NAME = 'search_docs';
6
6
  const PORT = Number(process.env.MCP_HTTP_PORT || 8788);
7
+ const IS_SILENT = process.env.MCP_SILENT === '1';
8
+ const NO_COLOR = process.env.MCP_NO_COLOR === '1';
9
+
10
+ function color(text, code) {
11
+ if (NO_COLOR) return text;
12
+ return `\x1b[${code}m${text}\x1b[0m`;
13
+ }
14
+
15
+ function renderSplash() {
16
+ if (IS_SILENT) return;
17
+ const version = process.env.MN_DOCS_VERSION || '0.0.0';
18
+ const mode = process.env.MN_DOCS_MODE || 'http';
19
+ const port = process.env.MN_DOCS_PORT || String(PORT);
20
+ const lines = [
21
+ color('╭──────────────────────────────────────────────────────────────╮', '38;5;45'),
22
+ color('│ mn-docs-mcp', '38;5;45') + color(` v${version}`, '38;5;214') + color(' (Charm风格启动) │', '38;5;45'),
23
+ color('│ │', '38;5;45'),
24
+ color(`│ 模式: ${mode.padEnd(12)} 端口: ${port.padEnd(6)} 状态: 已启动 │`, '38;5;39'),
25
+ color('│ │', '38;5;45'),
26
+ color('╰──────────────────────────────────────────────────────────────╯', '38;5;45'),
27
+ ];
28
+ process.stdout.write(lines.join('\n') + '\n');
29
+ }
7
30
 
8
31
  async function ensureIndex() {
9
32
  const { INDEX_PATH } = getPaths();
@@ -67,8 +90,7 @@ await server.start({
67
90
  },
68
91
  });
69
92
 
70
- // 不阻塞握手,启动后再初始化索引
71
- // 默认不自动构建,避免阻塞握手;仅在首次查询时构建
72
- if (process.env.MCP_PREBUILD === '1') {
73
- setTimeout(() => initIndexInBackground(), 1000);
74
- }
93
+ renderSplash();
94
+
95
+ // 默认自动构建,异步启动避免阻塞握手
96
+ setTimeout(() => initIndexInBackground(), 0);
@@ -4,12 +4,33 @@ import { buildIndex, getPaths, isIndexStale, loadIndex, searchDocs } from './lib
4
4
 
5
5
  const TOOL_NAME = 'search_docs';
6
6
  const IS_SILENT = process.env.MCP_SILENT === '1';
7
+ const NO_COLOR = process.env.MCP_NO_COLOR === '1';
7
8
 
8
9
  function logError(...args) {
9
10
  if (IS_SILENT) return;
10
11
  console.error(...args);
11
12
  }
12
13
 
14
+ function color(text, code) {
15
+ if (NO_COLOR) return text;
16
+ return `\x1b[${code}m${text}\x1b[0m`;
17
+ }
18
+
19
+ function renderSplash() {
20
+ if (IS_SILENT) return;
21
+ const version = process.env.MN_DOCS_VERSION || '0.0.0';
22
+ const mode = process.env.MN_DOCS_MODE || 'stdio';
23
+ const lines = [
24
+ color('╭──────────────────────────────────────────────────────────────╮', '38;5;45'),
25
+ color('│ mn-docs-mcp', '38;5;45') + color(` v${version}`, '38;5;214') + color(' (Charm风格启动) │', '38;5;45'),
26
+ color('│ │', '38;5;45'),
27
+ color(`│ 模式: ${mode.padEnd(12)} 状态: 已启动 │`, '38;5;39'),
28
+ color('│ │', '38;5;45'),
29
+ color('╰──────────────────────────────────────────────────────────────╯', '38;5;45'),
30
+ ];
31
+ process.stderr.write(lines.join('\n') + '\n');
32
+ }
33
+
13
34
  async function ensureIndex() {
14
35
  const { INDEX_PATH } = getPaths();
15
36
  try {
@@ -85,7 +106,7 @@ await server.start({
85
106
  transportType: 'stdio',
86
107
  });
87
108
 
88
- // 默认不自动构建,避免阻塞握手;仅在首次查询时构建
89
- if (process.env.MCP_PREBUILD === '1') {
90
- setTimeout(() => initIndexInBackground(), 1000);
91
- }
109
+ renderSplash();
110
+
111
+ // 默认自动构建,异步启动避免阻塞握手
112
+ setTimeout(() => initIndexInBackground(), 0);
package/package.json CHANGED
@@ -1,19 +1,13 @@
1
1
  {
2
2
  "name": "mn-docs-mcp",
3
3
  "type": "module",
4
- "version": "0.1.0",
5
- "bin": {
6
- "mn-docs-mcp": "scripts/mcp/cli.mjs"
4
+ "version": "0.2.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/Temsys-Shen/marginnote-addon-docs.git"
7
8
  },
8
- "scripts": {
9
- "dev": "astro dev",
10
- "start": "astro dev",
11
- "build": "astro build",
12
- "preview": "astro preview",
13
- "astro": "astro",
14
- "mcp": "MCP_STDIO=1 MCP_SILENT=1 node scripts/mcp/server.mjs",
15
- "mcp-http": "node scripts/mcp/server-http.mjs",
16
- "mcp:force-build": "node scripts/mcp/build-index.mjs"
9
+ "bin": {
10
+ "mn-docs-mcp": "mcp/cli.mjs"
17
11
  },
18
12
  "dependencies": {
19
13
  "@astrojs/starlight": "^0.37.4",
@@ -26,5 +20,12 @@
26
20
  "sharp": "^0.34.2",
27
21
  "undici": "^6.19.8",
28
22
  "zod": "^3.25.76"
23
+ },
24
+ "scripts": {
25
+ "dev": "astro dev",
26
+ "start": "astro dev",
27
+ "build": "astro build",
28
+ "preview": "astro preview",
29
+ "astro": "astro"
29
30
  }
30
- }
31
+ }
File without changes
File without changes
@@ -1,4 +0,0 @@
1
- {
2
- "recommendations": ["astro-build.astro-vscode"],
3
- "unwantedRecommendations": []
4
- }
@@ -1,11 +0,0 @@
1
- {
2
- "version": "0.2.0",
3
- "configurations": [
4
- {
5
- "command": "./node_modules/.bin/astro dev",
6
- "name": "Development server",
7
- "request": "launch",
8
- "type": "node-terminal"
9
- }
10
- ]
11
- }
File without changes
File without changes