harmonyos-guides-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.
Files changed (3) hide show
  1. package/README.md +26 -11
  2. package/dist/index.js +20 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -16,10 +16,12 @@
16
16
 
17
17
  | 工具 | 作用 |
18
18
  |------|------|
19
- | `search_guides({query, limit?})` | 全文检索指南(中文友好),返回相关度排序的文档列表(含标题、分类路径) |
19
+ | `search_guides({query, limit?})` | 全文检索指南(BM25 + CJK 权重 + 同义词扩展,中文友好),返回相关度排序的文档列表(含标题、分类路径) |
20
20
  | `get_guide({name})` | 读取指定指南(docId)的完整 Markdown 正文 |
21
21
  | `list_guides_by_topic({topic?})` | 按分类路径浏览;支持多级下钻(如 `媒体` → `媒体 / Audio Kit`) |
22
22
 
23
+ **检索算法**:BM25 排序(TF 饱和 + 文档长度归一化 + IDF)→ CJK 单字×0.3 / 双字 bigram×0.5 降权(抑制跨词边界噪声)→ 域内同义词软 OR 扩展(`data/synonyms.json` 驱动)。同义词词典数据驱动,编辑 JSON 即可扩展,无需改代码。
24
+
23
25
  数据规模:5489 篇指南,顶级类含 基础入门(34)、应用框架(835)、系统(778)、媒体(295)、图形(182)、应用服务(710) 等。
24
26
 
25
27
  ## 安装(最终用户)
@@ -31,19 +33,32 @@
31
33
  "mcpServers": {
32
34
  "harmonyos-guides": {
33
35
  "command": "npx",
34
- "args": ["-y", "harmonyos-guides-mcp"]
36
+ "args": ["-y", "harmonyos-guides-mcp@latest"]
35
37
  }
36
38
  }
37
39
  }
38
40
  ```
39
41
 
40
- 或全局安装:`npm install -g harmonyos-guides-mcp`。任何支持 stdio 的 MCP 客户端(opencode / Cursor / Cline / Continue)同样配置。
42
+ > `@latest` 每次启动联网拉最新版;也可固定版本如 `@0.2.1` 避免版本漂移与启动联网。或全局安装:`npm install -g harmonyos-guides-mcp`。任何支持 stdio 的 MCP 客户端(opencode / Cursor / Cline / Continue)同样配置。
41
43
 
42
44
  ### 环境变量
43
45
 
44
46
  | 变量 | 默认 | 说明 |
45
47
  |------|------|------|
46
48
  | `BP_DOCS_DIR` | 包内 `data/docs` | 文档目录(一般无需改) |
49
+ | `BP_LOG` | 包内 `data/index_log.txt` | 分类日志(驱动文档分类,缺失会报错;一般无需改) |
50
+
51
+ > `data/synonyms.json` 为同义词词典(随包),缺失时检索退化为无同义词扩展,不影响正常使用。`data/INDEX.md` 是人读文档索引(代码不读)。
52
+
53
+ ### 数据布局(包内 `data/`)
54
+
55
+ ```
56
+ data/
57
+ ├── docs/ # 纯 .md 文档(5489 篇)
58
+ ├── index_log.txt # 分类日志(机器读,驱动分类)
59
+ ├── synonyms.json # 同义词词典(检索用,可编辑扩展)
60
+ └── INDEX.md # 人读文档索引(按大类分组,代码不读)
61
+ ```
47
62
 
48
63
  ## 更新
49
64
 
@@ -79,20 +94,20 @@ npm ls -g harmonyos-guides-mcp # 本地已装版本
79
94
  "mcp": {
80
95
  "harmonyos-best-practices": {
81
96
  "type": "local",
82
- "command": ["npx", "-y", "harmonyos-best-practices-mcp"],
97
+ "command": ["npx", "-y", "harmonyos-best-practices-mcp@latest"],
83
98
  "environment": { "BP_CODE_DIR": "/abs/path/to/best_practices_code" }
84
99
  },
85
100
  "harmonyos-guides": {
86
101
  "type": "local",
87
- "command": ["npx", "-y", "harmonyos-guides-mcp"]
102
+ "command": ["npx", "-y", "harmonyos-guides-mcp@latest"]
88
103
  },
89
104
  "harmonyos-api-references": {
90
105
  "type": "local",
91
- "command": ["npx", "-y", "harmonyos-api-references-mcp"]
106
+ "command": ["npx", "-y", "harmonyos-api-references-mcp@latest"]
92
107
  },
93
108
  "harmonyos-ui-design-guides": {
94
109
  "type": "local",
95
- "command": ["npx", "-y", "harmonyos-ui-design-guides-mcp"]
110
+ "command": ["npx", "-y", "harmonyos-ui-design-guides-mcp@latest"]
96
111
  }
97
112
  }
98
113
  }
@@ -105,20 +120,20 @@ npm ls -g harmonyos-guides-mcp # 本地已装版本
105
120
  "mcpServers": {
106
121
  "harmonyos-best-practices": {
107
122
  "command": "npx",
108
- "args": ["-y", "harmonyos-best-practices-mcp"],
123
+ "args": ["-y", "harmonyos-best-practices-mcp@latest"],
109
124
  "env": { "BP_CODE_DIR": "/abs/path/to/best_practices_code" }
110
125
  },
111
126
  "harmonyos-guides": {
112
127
  "command": "npx",
113
- "args": ["-y", "harmonyos-guides-mcp"]
128
+ "args": ["-y", "harmonyos-guides-mcp@latest"]
114
129
  },
115
130
  "harmonyos-api-references": {
116
131
  "command": "npx",
117
- "args": ["-y", "harmonyos-api-references-mcp"]
132
+ "args": ["-y", "harmonyos-api-references-mcp@latest"]
118
133
  },
119
134
  "harmonyos-ui-design-guides": {
120
135
  "command": "npx",
121
- "args": ["-y", "harmonyos-ui-design-guides-mcp"]
136
+ "args": ["-y", "harmonyos-ui-design-guides-mcp@latest"]
122
137
  }
123
138
  }
124
139
  }
package/dist/index.js CHANGED
@@ -10,6 +10,19 @@ const server = new McpServer({
10
10
  version: "0.1.0",
11
11
  });
12
12
  const SEP = " / ";
13
+ /**
14
+ * Normalize a category path for tolerant prefix matching: strip full/half-width
15
+ * parenthetical qualifiers from each segment, e.g.
16
+ * "媒体 / Media Kit(媒体服务)" -> "媒体 / Media Kit".
17
+ * Lets users drill down without knowing the exact parenthetical suffix.
18
+ */
19
+ function normPath(p) {
20
+ return p
21
+ .split(SEP)
22
+ .map((seg) => seg.replace(/[((][^))]*[))]/g, "").trim())
23
+ .join(SEP)
24
+ .trim();
25
+ }
13
26
  /* ------------------------------------------------------------------ *
14
27
  * Tool 1: search_guides
15
28
  * ------------------------------------------------------------------ */
@@ -62,12 +75,19 @@ server.tool("list_guides_by_topic", "按分类路径浏览鸿蒙指南(Browse gu
62
75
  `\n\n用 list_guides_by_topic({topic:"<类名>"}) 下钻查看该类下文档.`);
63
76
  }
64
77
  // Prefix match: path === topic OR path startsWith "topic / "
78
+ // Tolerant of parenthetical qualifiers in path segments, e.g. the real path
79
+ // "媒体 / Media Kit(媒体服务)" should still match topic "媒体 / Media Kit".
80
+ // Strip full/half-width parenthetical content ((…)/…) before comparing.
65
81
  const prefix = topic.trim();
82
+ const normPrefix = normPath(prefix);
66
83
  const matched = [];
67
84
  for (const meta of store.docs.values()) {
68
85
  if (meta.path === prefix || meta.path.startsWith(prefix + SEP)) {
69
86
  matched.push(meta);
70
87
  }
88
+ else if (normPrefix && (normPath(meta.path) === normPrefix || normPath(meta.path).startsWith(normPrefix + SEP))) {
89
+ matched.push(meta);
90
+ }
71
91
  }
72
92
  if (matched.length === 0) {
73
93
  return text(`未找到路径 "${prefix}"。顶级类: ${[...store.topics.keys()].sort().join("、")}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "harmonyos-guides-mcp",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "MCP server exposing HarmonyOS official development guides for API/Kit usage retrieval during development.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",