mn-docs-mcp 0.1.7 → 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.
- package/mcp/cli.mjs +25 -2
- package/mcp/server-http.mjs +27 -5
- package/mcp/server.mjs +25 -4
- package/package.json +1 -1
package/mcp/cli.mjs
CHANGED
|
@@ -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 =
|
|
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
|
}
|
package/mcp/server-http.mjs
CHANGED
|
@@ -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
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
93
|
+
renderSplash();
|
|
94
|
+
|
|
95
|
+
// 默认自动构建,异步启动避免阻塞握手
|
|
96
|
+
setTimeout(() => initIndexInBackground(), 0);
|
package/mcp/server.mjs
CHANGED
|
@@ -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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
109
|
+
renderSplash();
|
|
110
|
+
|
|
111
|
+
// 默认自动构建,异步启动避免阻塞握手
|
|
112
|
+
setTimeout(() => initIndexInBackground(), 0);
|