mn-docs-mcp 0.2.1 → 0.2.2
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/server-http.mjs +23 -2
- package/mcp/server.mjs +24 -2
- package/package.json +1 -1
package/mcp/server-http.mjs
CHANGED
|
@@ -16,8 +16,29 @@ function stripAnsi(text) {
|
|
|
16
16
|
return text.replace(/\x1b\[[0-9;]*m/g, '');
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
function stringWidth(text) {
|
|
20
|
+
const plain = stripAnsi(text);
|
|
21
|
+
let width = 0;
|
|
22
|
+
for (const char of plain) {
|
|
23
|
+
const code = char.codePointAt(0);
|
|
24
|
+
if (!code) continue;
|
|
25
|
+
const isWide =
|
|
26
|
+
(code >= 0x1100 && code <= 0x115f) ||
|
|
27
|
+
(code === 0x2329 || code === 0x232a) ||
|
|
28
|
+
(code >= 0x2e80 && code <= 0xa4cf) ||
|
|
29
|
+
(code >= 0xac00 && code <= 0xd7a3) ||
|
|
30
|
+
(code >= 0xf900 && code <= 0xfaff) ||
|
|
31
|
+
(code >= 0xfe10 && code <= 0xfe19) ||
|
|
32
|
+
(code >= 0xfe30 && code <= 0xfe6f) ||
|
|
33
|
+
(code >= 0xff00 && code <= 0xff60) ||
|
|
34
|
+
(code >= 0xffe0 && code <= 0xffe6);
|
|
35
|
+
width += isWide ? 2 : 1;
|
|
36
|
+
}
|
|
37
|
+
return width;
|
|
38
|
+
}
|
|
39
|
+
|
|
19
40
|
function padLine(line, width) {
|
|
20
|
-
const len =
|
|
41
|
+
const len = stringWidth(line);
|
|
21
42
|
const padding = width - len;
|
|
22
43
|
return line + (padding > 0 ? ' '.repeat(padding) : '');
|
|
23
44
|
}
|
|
@@ -31,7 +52,7 @@ function renderSplash() {
|
|
|
31
52
|
color(`mn-docs-mcp v${version}`, '38;5;45'),
|
|
32
53
|
color(`模式: ${mode} 端口: ${port}`, '38;5;39'),
|
|
33
54
|
];
|
|
34
|
-
const maxWidth = Math.max(...contentLines.map((line) =>
|
|
55
|
+
const maxWidth = Math.max(...contentLines.map((line) => stringWidth(line))) + 4;
|
|
35
56
|
const top = color('╭' + '─'.repeat(maxWidth) + '╮', '38;5;45');
|
|
36
57
|
const bottom = color('╰' + '─'.repeat(maxWidth) + '╯', '38;5;45');
|
|
37
58
|
const body = contentLines.map((line) => {
|
package/mcp/server.mjs
CHANGED
|
@@ -20,8 +20,30 @@ function stripAnsi(text) {
|
|
|
20
20
|
return text.replace(/\x1b\[[0-9;]*m/g, '');
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
function stringWidth(text) {
|
|
24
|
+
const plain = stripAnsi(text);
|
|
25
|
+
let width = 0;
|
|
26
|
+
for (const char of plain) {
|
|
27
|
+
const code = char.codePointAt(0);
|
|
28
|
+
if (!code) continue;
|
|
29
|
+
// CJK / Fullwidth / Wide characters
|
|
30
|
+
const isWide =
|
|
31
|
+
(code >= 0x1100 && code <= 0x115f) ||
|
|
32
|
+
(code === 0x2329 || code === 0x232a) ||
|
|
33
|
+
(code >= 0x2e80 && code <= 0xa4cf) ||
|
|
34
|
+
(code >= 0xac00 && code <= 0xd7a3) ||
|
|
35
|
+
(code >= 0xf900 && code <= 0xfaff) ||
|
|
36
|
+
(code >= 0xfe10 && code <= 0xfe19) ||
|
|
37
|
+
(code >= 0xfe30 && code <= 0xfe6f) ||
|
|
38
|
+
(code >= 0xff00 && code <= 0xff60) ||
|
|
39
|
+
(code >= 0xffe0 && code <= 0xffe6);
|
|
40
|
+
width += isWide ? 2 : 1;
|
|
41
|
+
}
|
|
42
|
+
return width;
|
|
43
|
+
}
|
|
44
|
+
|
|
23
45
|
function padLine(line, width) {
|
|
24
|
-
const len =
|
|
46
|
+
const len = stringWidth(line);
|
|
25
47
|
const padding = width - len;
|
|
26
48
|
return line + (padding > 0 ? ' '.repeat(padding) : '');
|
|
27
49
|
}
|
|
@@ -34,7 +56,7 @@ function renderSplash() {
|
|
|
34
56
|
color(`mn-docs-mcp v${version}`, '38;5;45'),
|
|
35
57
|
color(`模式: ${mode}`, '38;5;39'),
|
|
36
58
|
];
|
|
37
|
-
const maxWidth = Math.max(...contentLines.map((line) =>
|
|
59
|
+
const maxWidth = Math.max(...contentLines.map((line) => stringWidth(line))) + 4;
|
|
38
60
|
const top = color('╭' + '─'.repeat(maxWidth) + '╮', '38;5;45');
|
|
39
61
|
const bottom = color('╰' + '─'.repeat(maxWidth) + '╯', '38;5;45');
|
|
40
62
|
const body = contentLines.map((line) => {
|