diwen-mcp 6.2.0 → 6.3.1
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/LICENSE +3 -3
- package/README.md +62 -29
- package/package.json +4 -4
- package/selftest.mjs +5 -1
- package/server.mjs +61 -3
package/LICENSE
CHANGED
|
@@ -17,7 +17,7 @@ Copyright (c) 2026 Pondsi(作者)
|
|
|
17
17
|
凡使用/集成本项目,须在你的程序文档、关于页或随附说明中:
|
|
18
18
|
(a) 注明使用了本项目(Diwen / 迪文);
|
|
19
19
|
(b) 写明本项目作者:**Pondsi**;
|
|
20
|
-
(c) 附本项目仓库链接 https://github.com/Pondsi/
|
|
20
|
+
(c) 附本项目仓库链接 https://github.com/Pondsi/dsh-diwen 。
|
|
21
21
|
|
|
22
22
|
四、保留权利
|
|
23
23
|
除本条款明确授予的权利外,其余一切权利(包括但不限于再分发权、修改后再分发权、闭源核心与数据的提取权)均保留给作者。
|
|
@@ -33,7 +33,7 @@ Copyright (c) 2026 Pondsi(作者)
|
|
|
33
33
|
English summary (non-binding; Chinese text above governs):
|
|
34
34
|
- Use & commercial use: FREE, no prior authorization required. You may integrate Diwen into your own programs (component/dependency/plugin/MCP service) and sell your programs.
|
|
35
35
|
- No redistribution of the project itself (source, closed core, encrypted data). Your programs may be distributed only with Diwen as a dependency/reference that cannot be extracted as a standalone project. Open-core: you may not decrypt/extract/redistribute the closed core & data.
|
|
36
|
-
- Attribution REQUIRED: credit "Diwen / 迪文", name the author "Pondsi", link https://github.com/Pondsi/
|
|
36
|
+
- Attribution REQUIRED: credit "Diwen / 迪文", name the author "Pondsi", link https://github.com/Pondsi/dsh-diwen .
|
|
37
37
|
- All other rights reserved. Provided "AS IS", without warranty.
|
|
38
38
|
|
|
39
|
-
Contact: via https://github.com/Pondsi/
|
|
39
|
+
Contact: via https://github.com/Pondsi/dsh-diwen (issues).
|
package/README.md
CHANGED
|
@@ -1,44 +1,51 @@
|
|
|
1
1
|
# diwen-mcp
|
|
2
2
|
|
|
3
|
-
迪文(Diwen)概念坐标系统的 **MCP server
|
|
3
|
+
迪文(Diwen)概念坐标系统的 **MCP server**:**零第三方协议依赖**(手写 stdio JSON-RPC,不依赖 MCP SDK)的**开源薄壳**,核心能力来自已发布的 npm [`diwen`](https://www.npmjs.com/package/diwen) 包(闭源核心 + 加密概念数据),把核心能力暴露为**三个** MCP 工具。
|
|
4
4
|
|
|
5
5
|
- `diwen_map` —— 中文自然语言 → 迪文填空契约(公理②:映射不唯一,需模型选义;公理④:无对应概念 → verbatim 如实保留)
|
|
6
6
|
- `diwen_describe` —— 迪文概念 ID → 中文唯一释义(公理①)
|
|
7
|
+
- `diwen_select` —— 批量云端义项选择(C14 云内级联 / C3 多家族加权投票;需云端密钥)
|
|
7
8
|
|
|
8
9
|
> **许可:允许商用(免费、无需另行授权)、不可再分发、必须署名作者 Pondsi。** 详见 [LICENSE](./LICENSE)。
|
|
9
|
-
> 仓库:https://github.com/Pondsi/
|
|
10
|
+
> 仓库:https://github.com/Pondsi/dsh-diwen
|
|
10
11
|
|
|
11
12
|
---
|
|
12
13
|
|
|
13
14
|
## 1. open-core 边界(壳开源,核心/数据闭源)
|
|
14
15
|
|
|
15
|
-
| 部分 |
|
|
16
|
+
| 部分 | 位置(npm 安装后) | 形态 |
|
|
16
17
|
| --- | --- | --- |
|
|
17
|
-
| MCP 协议壳(本包) | `
|
|
18
|
-
| 加载壳 + 解密环境 |
|
|
19
|
-
| **核心逻辑** |
|
|
20
|
-
| **概念数据** |
|
|
18
|
+
| MCP 协议壳(本包) | `node_modules/diwen-mcp/server.mjs`、`selftest.mjs` | **源码公开可读**,手写 JSON-RPC,无第三方协议依赖 |
|
|
19
|
+
| 加载壳 + 解密环境 | `node_modules/diwen/index.mjs`、`node_modules/diwen/env.cjs` | 源码公开可读 |
|
|
20
|
+
| **核心逻辑** | `node_modules/diwen/dist/core.mjs` | **闭源** |
|
|
21
|
+
| **概念数据** | `node_modules/diwen/dist/data.enc` | **加密**(运行时由 `env.cjs` 解密到临时目录并设 `DIWEN_DATA_DIR`) |
|
|
21
22
|
|
|
22
|
-
本包只做协议转换与参数校验,**不含任何语言学逻辑或数据**:全部能力来自 `import * as diwen from '
|
|
23
|
+
本包只做协议转换与参数校验,**不含任何语言学逻辑或数据**:全部能力来自 `import * as diwen from 'diwen'`,结果**原样透传**(不改写 contract、不吞并未覆盖词、不伪造概念)。
|
|
23
24
|
|
|
24
25
|
「壳源码可读」不等于宽松许可:本包整体适用随附的自定义许可(**不是 MIT**),仍禁止再分发与提取闭源核心/数据。
|
|
25
26
|
|
|
26
|
-
## 2.
|
|
27
|
+
## 2. 前置条件与安装
|
|
27
28
|
|
|
28
29
|
- Node.js **>= 18**(自测在 v24 上通过)。
|
|
29
|
-
-
|
|
30
|
-
-
|
|
30
|
+
- **依赖已发布的 npm `diwen`(`^6.4.0`)**:闭源核心 + 加密数据 + 分词器 `@node-rs/jieba` 均由该包提供。`npm install diwen-mcp` 会自动拉取 `diwen`,**无需相邻 `packages/diwen` 目录、无需自行构建核心**。
|
|
31
|
+
- 本包 `dependencies = { "diwen": "^6.4.0" }`;`diwen` 6.3.0 起含 `cascadeSelect`/`ensembleSelect`(`diwen_select` 所需)。
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install diwen-mcp
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
> 仓库内开发(克隆本仓时):`cd packages/diwen-mcp && npm install`(拉取 npm diwen),再 `node server.mjs`。
|
|
31
38
|
|
|
32
39
|
## 3. 运行
|
|
33
40
|
|
|
34
41
|
```bash
|
|
35
|
-
node
|
|
42
|
+
npx diwen-mcp # 等价于 node node_modules/diwen-mcp/server.mjs
|
|
36
43
|
```
|
|
37
44
|
|
|
38
45
|
stdio 纪律(MCP stdio transport):
|
|
39
46
|
|
|
40
47
|
- **stdout 只写 JSON-RPC 响应**,每行一条 JSON(newline-delimited)。壳内已把 `console.log/info/debug/dir` 改道 stderr,防止污染协议流。
|
|
41
|
-
- **日志全部走 stderr**(`console.error`),例如启动行 `[diwen-mcp] diwen-mcp v6.
|
|
48
|
+
- **日志全部走 stderr**(`console.error`),例如启动行 `[diwen-mcp] diwen-mcp v6.3.1 ready (stdio, MCP 2024-11-05); tools: diwen_map, diwen_describe, diwen_select`。
|
|
42
49
|
- 协议版本:`2024-11-05`。支持 `initialize`、`ping`、`tools/list`、`tools/call`;通知(`notifications/initialized`、`notifications/cancelled` 等无 `id` 的消息)一律忽略、不回响应。
|
|
43
50
|
- 关闭 stdin 即干净退出(exit 0);亦响应 `SIGINT`/`SIGTERM`。
|
|
44
51
|
|
|
@@ -51,20 +58,20 @@ stdio 纪律(MCP stdio transport):
|
|
|
51
58
|
"mcpServers": {
|
|
52
59
|
"diwen": {
|
|
53
60
|
"command": "node",
|
|
54
|
-
"args": ["<绝对路径>/
|
|
61
|
+
"args": ["<绝对路径>/node_modules/diwen-mcp/server.mjs"]
|
|
55
62
|
}
|
|
56
63
|
}
|
|
57
64
|
}
|
|
58
65
|
```
|
|
59
66
|
|
|
60
|
-
Windows
|
|
67
|
+
Windows 示例(路径按实际安装位置替换,JSON 中反斜杠需转义):
|
|
61
68
|
|
|
62
69
|
```json
|
|
63
70
|
{
|
|
64
71
|
"mcpServers": {
|
|
65
72
|
"diwen": {
|
|
66
73
|
"command": "node",
|
|
67
|
-
"args": ["C:\\path\\to\\
|
|
74
|
+
"args": ["C:\\path\\to\\node_modules\\diwen-mcp\\server.mjs"]
|
|
68
75
|
}
|
|
69
76
|
}
|
|
70
77
|
}
|
|
@@ -75,7 +82,7 @@ POSIX 示例:
|
|
|
75
82
|
```json
|
|
76
83
|
{
|
|
77
84
|
"mcpServers": {
|
|
78
|
-
"diwen": { "command": "node", "args": ["/path/to/
|
|
85
|
+
"diwen": { "command": "node", "args": ["/path/to/node_modules/diwen-mcp/server.mjs"] }
|
|
79
86
|
}
|
|
80
87
|
}
|
|
81
88
|
```
|
|
@@ -130,7 +137,33 @@ POSIX 示例:
|
|
|
130
137
|
|
|
131
138
|
返回 `{ok, id, coord, lemma_zh, field, bfo_type, nsm, pinyin, definitions, slots, semanticApproval}`。实测 `id:1223` → `coord:"46:19"`、`lemma_zh:"折"`、`bfo_type:"Process"`、`nsm:["DO"]`、`semanticApproval:false`。ID 不存在时 `ok:false` 且工具结果 `isError:true`。
|
|
132
139
|
|
|
133
|
-
###
|
|
140
|
+
### `diwen_select`
|
|
141
|
+
|
|
142
|
+
批量云端义项选择(高级 WSD)。对多个用例用云端模型选义,两种模式:
|
|
143
|
+
|
|
144
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
145
|
+
| --- | --- | --- | --- |
|
|
146
|
+
| `cases` | array | 是 | 选义用例数组,每项 `{id:string, surface:string, sentence:string}`(非空) |
|
|
147
|
+
| `mode` | string | 否 | `cascade`(默认)\| `ensemble` |
|
|
148
|
+
| `weights` | object | 否 | 仅 `ensemble`:按模型赋权(如 `{"deepseek-v4-pro":2}`),默认等权 |
|
|
149
|
+
|
|
150
|
+
- **`cascade`(C14 云内级联)**:小云模型跑全部易例,难例(verbatim/null)升级大云模型,省成本;返回 `escalated` 升级计数。
|
|
151
|
+
- **`ensemble`(C3 多家族加权投票)**:多个不同家族云端模型投票,去单模型偏差;`weights` 按模型赋权。
|
|
152
|
+
- **密钥前提**:需云端密钥——设环境变量 `DIWEN_KEYS_FILE` 指向你的密钥文件(或 `DIWEN_CLOUD_BASE` 覆盖 base)。**无密钥时 `isError:true`**,文案提示「设 `DIWEN_KEYS_FILE` 指向密钥文件」。
|
|
153
|
+
- 返回 `content[0].text` 为 JSON:`{ predictions: {<id> → {conceptId, verbatim, sense_key}}, models, escalated, semanticApproval: false }`。公理④:无概念 → verbatim。`semanticApproval` 恒 `false`。
|
|
154
|
+
|
|
155
|
+
请求:
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
{"jsonrpc":"2.0","id":9,"method":"tools/call",
|
|
159
|
+
"params":{"name":"diwen_select","arguments":{
|
|
160
|
+
"cases":[{"id":"c1","surface":"开","sentence":"学校明天开运动会。"}],
|
|
161
|
+
"mode":"cascade"}}}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
> 离线 `deterministic`/`off` 与本地 ollama `decision` 路径无需密钥;`diwen_select` 是云端路径,必须自备密钥。
|
|
165
|
+
|
|
166
|
+
### 选义模式(diwen_map 的 `model`)
|
|
134
167
|
|
|
135
168
|
| `model` | 行为 | 联网/外部进程 |
|
|
136
169
|
| --- | --- | --- |
|
|
@@ -141,7 +174,7 @@ POSIX 示例:
|
|
|
141
174
|
|
|
142
175
|
### 错误语义
|
|
143
176
|
|
|
144
|
-
- **工具级失败** → `result.isError: true` + 文本说明:参数非法(缺 `text`、`model` 不在枚举、`enhance` 非 boolean、`id`
|
|
177
|
+
- **工具级失败** → `result.isError: true` + 文本说明:参数非法(缺 `text`、`model` 不在枚举、`enhance` 非 boolean、`id` 非整数、`cases` 非数组/项缺字段、`mode` 不在枚举)、未知工具名、概念不存在、云端密钥缺失、核心抛错。
|
|
145
178
|
- **协议级错误** → JSON-RPC `error`:`-32700` 非法 JSON 行、`-32600` 非法请求/不支持 batch、`-32601` 未知方法、`-32603` 内部错误。
|
|
146
179
|
|
|
147
180
|
## 5. 恒真约定
|
|
@@ -154,36 +187,36 @@ POSIX 示例:
|
|
|
154
187
|
## 6. 自测
|
|
155
188
|
|
|
156
189
|
```bash
|
|
157
|
-
node packages/diwen-mcp/selftest.mjs
|
|
190
|
+
node node_modules/diwen-mcp/selftest.mjs # 仓库内:node packages/diwen-mcp/selftest.mjs
|
|
158
191
|
```
|
|
159
192
|
|
|
160
|
-
spawn `server.mjs` 并走完整流程:`initialize` → `notifications/initialized`(断言无响应)→ `tools/list
|
|
193
|
+
spawn `server.mjs` 并走完整流程:`initialize` → `notifications/initialized`(断言无响应)→ `tools/list`(断言**恰好三个工具**)→ `tools/call(diwen_map, text='我吃饭', model='deterministic')` → `tools/call(diwen_describe, id=1223)` → 错误路径(`isError:true` / `-32601` / `-32700`)→ 关闭 stdin 断言 exit 0。
|
|
161
194
|
|
|
162
|
-
共 **
|
|
195
|
+
共 **45 项断言**,含:协议版本与 `serverInfo`、**三工具** `inputSchema`(`diwen_map.required=[text]`、`diwen_describe.required=[id]`、`diwen_select.required=[cases]` 且 `mode` enum=`cascade/ensemble`)、`slots` 八格齐全、`span` 边界、`uncovered` 逐项与原文 verbatim 一致、`semanticApproval === false`、**stdout 每行都是合法 JSON-RPC**(无杂散输出)、通知零响应。全部通过时打印 `PASS 45/45 checks`,退出码 0;任一失败退出码 1 并附 server stderr。
|
|
196
|
+
|
|
197
|
+
> `diwen_select` 的真实云端调用需密钥与网络,不在零网络自测内;其参数校验/schema 由上述断言覆盖,云端端到端经真机验证(开运动会→hold3047 / 严重→severe3048)。
|
|
163
198
|
|
|
164
199
|
## 7. 已知限制
|
|
165
200
|
|
|
166
201
|
- **仅 stdio**:无 HTTP/SSE/WebSocket 传输,无鉴权、无多客户端会话隔离;请按本地单客户端进程使用。
|
|
167
|
-
- **请求串行处理**:为保证响应顺序与 stdout 不交错,请求排队执行;一旦 `decision`/`auto`
|
|
168
|
-
-
|
|
202
|
+
- **请求串行处理**:为保证响应顺序与 stdout 不交错,请求排队执行;一旦 `decision`/`auto`/`diwen_select` 真正触发模型调用,该慢调用会阻塞后续请求。
|
|
203
|
+
- **依赖 npm `diwen`**:`diwen` 未安装或版本不匹配(低于依赖下限 `^6.4.0`)时进程启动即失败(错误在 stderr);本包不能脱离 `diwen` 独立运行。
|
|
169
204
|
- **首次调用有解密开销**:`env.cjs` 需解密概念数据到临时目录(实测 import 约 0.3s 量级,随机器/数据量变化)。
|
|
170
|
-
- **覆盖限制**:`status:"partial"` / `uncovered` 常见,属数据覆盖问题(`我吃饭` 实测仅 `我` 有概念,覆盖率 1/3);`decision` 的真实模型调用需本地 ollama
|
|
205
|
+
- **覆盖限制**:`status:"partial"` / `uncovered` 常见,属数据覆盖问题(`我吃饭` 实测仅 `我` 有概念,覆盖率 1/3);`decision` 的真实模型调用需本地 ollama,`diwen_select` 需云端密钥,这两条路径未在零网络自测内验证。
|
|
171
206
|
- 不支持 JSON-RPC batch(`2024-11-05` 无此能力)。
|
|
172
207
|
|
|
173
208
|
## 8. 许可与署名(必须)
|
|
174
209
|
|
|
175
210
|
自定义许可(见 [LICENSE](./LICENSE),与仓库根 `LICENSE` 同文,即 2026-11-18 起的「允许商用」版本):
|
|
176
211
|
|
|
177
|
-
> 提示:截至本包创建时,`../diwen/LICENSE` 仍是**旧修订版**(商业使用须书面授权),与根 `LICENSE` 不一致。本包随附的是**根 `LICENSE` 的现行文本**;以现行文本为准。
|
|
178
|
-
|
|
179
212
|
1. **允许商用**:个人与商业目的免费使用、集成,**无需事先取得作者授权**;可集成进你自己的程序(组件/依赖/插件/**MCP 服务**)并销售你的程序。
|
|
180
213
|
2. **不可再分发**:不得将本项目(源码、闭源核心、加密数据,整体或实质性部分)单独或随你的程序再分发、转售、公开镜像或上传他库;你的程序只能以「依赖/引用」形式包含它,且接收者不得能提取为独立项目。**不得解密、提取、绕过或再分发闭源核心与数据。**
|
|
181
|
-
3. **必须署名**:在你的程序文档/关于页/随附说明中注明使用了 **Diwen / 迪文**、作者 **Pondsi**、仓库链接 **https://github.com/Pondsi/
|
|
214
|
+
3. **必须署名**:在你的程序文档/关于页/随附说明中注明使用了 **Diwen / 迪文**、作者 **Pondsi**、仓库链接 **https://github.com/Pondsi/dsh-diwen** 。
|
|
182
215
|
|
|
183
216
|
其余权利保留;按「现状」提供,无任何担保。违反条款(尤其再分发与署名义务)将自动终止已授予的权利。
|
|
184
217
|
|
|
185
218
|
署名示例(可直接复制到你的 README / 关于页):
|
|
186
219
|
|
|
187
220
|
```text
|
|
188
|
-
This product uses Diwen (迪文) by Pondsi — https://github.com/Pondsi/
|
|
221
|
+
This product uses Diwen (迪文) by Pondsi — https://github.com/Pondsi/dsh-diwen
|
|
189
222
|
```
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "diwen-mcp",
|
|
3
|
-
"version": "6.
|
|
4
|
-
"description": "迪文(Diwen)MCP server
|
|
3
|
+
"version": "6.3.1",
|
|
4
|
+
"description": "迪文(Diwen)MCP server:开源 stdio 壳(零第三方协议依赖,手写 JSON-RPC,不依赖 MCP SDK),暴露 diwen_map / diwen_describe / diwen_select(云端级联/集成选义),核心依赖已发布的 npm diwen 包(闭源核心+加密概念数据)。允许商用、不可再分发、须署名 Pondsi。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "server.mjs",
|
|
7
7
|
"bin": {
|
|
8
8
|
"diwen-mcp": "server.mjs"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"diwen": "^6.
|
|
11
|
+
"diwen": "^6.4.0"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
14
|
"server.mjs",
|
|
@@ -38,4 +38,4 @@
|
|
|
38
38
|
},
|
|
39
39
|
"license": "SEE LICENSE IN LICENSE",
|
|
40
40
|
"author": "Pondsi"
|
|
41
|
-
}
|
|
41
|
+
}
|
package/selftest.mjs
CHANGED
|
@@ -140,15 +140,19 @@ async function main() {
|
|
|
140
140
|
const tools = list.result?.tools ?? [];
|
|
141
141
|
show('tools', tools.map((t) => t.name));
|
|
142
142
|
assert('tools/list 无错误', !list.error);
|
|
143
|
-
assert('
|
|
143
|
+
assert('恰好三个工具', tools.length === 3, `count=${tools.length}`);
|
|
144
144
|
const map = tools.find((t) => t.name === 'diwen_map');
|
|
145
145
|
const desc = tools.find((t) => t.name === 'diwen_describe');
|
|
146
|
+
const sel = tools.find((t) => t.name === 'diwen_select');
|
|
146
147
|
assert('diwen_map 存在且含 inputSchema', !!map && map.inputSchema?.type === 'object');
|
|
147
148
|
assert('diwen_map.required = [text]', JSON.stringify(map?.inputSchema?.required) === '["text"]');
|
|
148
149
|
assert('diwen_map 声明 model/enhance', !!map?.inputSchema?.properties?.model && !!map?.inputSchema?.properties?.enhance);
|
|
149
150
|
assert('diwen_map.model enum 四值', JSON.stringify(map?.inputSchema?.properties?.model?.enum) === JSON.stringify(['auto', 'deterministic', 'decision', 'off']));
|
|
150
151
|
assert('diwen_describe 存在且含 inputSchema', !!desc && desc.inputSchema?.type === 'object');
|
|
151
152
|
assert('diwen_describe.required = [id]', JSON.stringify(desc?.inputSchema?.required) === '["id"]');
|
|
153
|
+
assert('diwen_select 存在且含 inputSchema', !!sel && sel.inputSchema?.type === 'object');
|
|
154
|
+
assert('diwen_select.required = [cases]', JSON.stringify(sel?.inputSchema?.required) === '["cases"]');
|
|
155
|
+
assert('diwen_select.mode enum cascade/ensemble', JSON.stringify(sel?.inputSchema?.properties?.mode?.enum) === JSON.stringify(['cascade', 'ensemble']));
|
|
152
156
|
assert('通知未产生响应', stray.length === 0, `stray=${JSON.stringify(stray)}`);
|
|
153
157
|
|
|
154
158
|
// --- 4. tools/call diwen_map --------------------------------------------
|
package/server.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// 迪文(Diwen)MCP server —— 开源 stdio 壳(open-core)。
|
|
3
3
|
// 本文件开源;核心与概念数据闭源,由 ../diwen(dist/core.mjs + dist/data.enc + env.cjs 解密壳)提供。
|
|
4
|
-
// 许可:允许商用(无需另行授权)、不可再分发、必须署名作者 Pondsi。见 LICENSE / https://github.com/Pondsi/
|
|
4
|
+
// 许可:允许商用(无需另行授权)、不可再分发、必须署名作者 Pondsi。见 LICENSE / https://github.com/Pondsi/dsh-diwen
|
|
5
5
|
//
|
|
6
6
|
// 传输:stdio,逐行(newline-delimited)JSON-RPC 2.0,MCP protocol version 2024-11-05。
|
|
7
7
|
// 纪律:stdout 只写 JSON-RPC 响应;一切日志走 stderr(console.error)。
|
|
@@ -72,6 +72,37 @@ const TOOLS = [
|
|
|
72
72
|
additionalProperties: false,
|
|
73
73
|
},
|
|
74
74
|
},
|
|
75
|
+
{
|
|
76
|
+
name: 'diwen_select',
|
|
77
|
+
description:
|
|
78
|
+
'批量云端义项选择(高级 WSD)。对多个 {id,surface,sentence} 用例用云端模型选义:' +
|
|
79
|
+
"mode='cascade'(C14 云内级联:小云易例/大云难例,省成本)或 'ensemble'(C3 多家族加权投票,去单模型偏差)。" +
|
|
80
|
+
'需云端密钥(环境变量 DIWEN_KEYS_FILE 指向密钥文件,或 DIWEN_CLOUD_BASE 覆盖 base);无密钥时 isError:true 并提示。' +
|
|
81
|
+
'返回 {predictions{id→{conceptId,verbatim,sense_key}}, models, semanticApproval:false}。公理④无概念→verbatim。仅中文。',
|
|
82
|
+
inputSchema: {
|
|
83
|
+
type: 'object',
|
|
84
|
+
properties: {
|
|
85
|
+
cases: {
|
|
86
|
+
type: 'array',
|
|
87
|
+
description: '选义用例数组,每项 {id, surface, sentence}。',
|
|
88
|
+
items: {
|
|
89
|
+
type: 'object',
|
|
90
|
+
properties: {
|
|
91
|
+
id: { type: 'string' },
|
|
92
|
+
surface: { type: 'string', description: '目标词(中文)。' },
|
|
93
|
+
sentence: { type: 'string', description: '含目标词的中文句子。' },
|
|
94
|
+
},
|
|
95
|
+
required: ['id', 'surface', 'sentence'],
|
|
96
|
+
additionalProperties: false,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
mode: { type: 'string', enum: ['cascade', 'ensemble'], description: "默认 'cascade'。" },
|
|
100
|
+
weights: { type: 'object', description: "ensemble 模式按模型赋权(如 {'deepseek-v4-pro':2}),默认等权。" },
|
|
101
|
+
},
|
|
102
|
+
required: ['cases'],
|
|
103
|
+
additionalProperties: false,
|
|
104
|
+
},
|
|
105
|
+
},
|
|
75
106
|
];
|
|
76
107
|
|
|
77
108
|
// ---------------------------------------------------------------------------
|
|
@@ -142,6 +173,32 @@ function callDescribe(args) {
|
|
|
142
173
|
}
|
|
143
174
|
}
|
|
144
175
|
|
|
176
|
+
async function callSelect(args) {
|
|
177
|
+
const cases = args.cases;
|
|
178
|
+
if (!Array.isArray(cases) || cases.length === 0) {
|
|
179
|
+
return toolResult('diwen_select: 参数 cases 必须是非空数组 [{id,surface,sentence}]。', true);
|
|
180
|
+
}
|
|
181
|
+
for (const c of cases) {
|
|
182
|
+
if (!c || typeof c.id !== 'string' || typeof c.surface !== 'string' || typeof c.sentence !== 'string') {
|
|
183
|
+
return toolResult('diwen_select: 每个 case 须含字符串 id/surface/sentence。', true);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const mode = args.mode ?? 'cascade';
|
|
187
|
+
if (mode !== 'cascade' && mode !== 'ensemble') {
|
|
188
|
+
return toolResult("diwen_select: mode 必须是 'cascade' | 'ensemble'。", true);
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
const candidates = diwen.loadCandidates();
|
|
192
|
+
const r = mode === 'cascade'
|
|
193
|
+
? await diwen.cascadeSelect(cases, candidates)
|
|
194
|
+
: await diwen.ensembleSelect(cases, candidates, args.weights ? { weights: args.weights } : {});
|
|
195
|
+
return toolResult({ predictions: r.predictions, models: r.models, escalated: r.escalated, semanticApproval: false });
|
|
196
|
+
} catch (err) {
|
|
197
|
+
console.error('[diwen-mcp] diwen_select error:', errText(err));
|
|
198
|
+
return toolResult(`diwen_select 执行失败(多为云端密钥缺失:设 DIWEN_KEYS_FILE 指向密钥文件): ${errText(err)}`, true);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
145
202
|
async function callTool(params) {
|
|
146
203
|
const name = params.name;
|
|
147
204
|
const args = params.arguments;
|
|
@@ -151,7 +208,8 @@ async function callTool(params) {
|
|
|
151
208
|
const a = args ?? {};
|
|
152
209
|
if (name === 'diwen_map') return callMap(a);
|
|
153
210
|
if (name === 'diwen_describe') return callDescribe(a);
|
|
154
|
-
|
|
211
|
+
if (name === 'diwen_select') return callSelect(a);
|
|
212
|
+
return toolResult(`未知工具: ${String(name)}(可用: diwen_map, diwen_describe, diwen_select)`, true);
|
|
155
213
|
}
|
|
156
214
|
|
|
157
215
|
// ---------------------------------------------------------------------------
|
|
@@ -229,4 +287,4 @@ for (const sig of ['SIGINT', 'SIGTERM']) {
|
|
|
229
287
|
process.on(sig, () => process.exit(0));
|
|
230
288
|
}
|
|
231
289
|
|
|
232
|
-
console.error(`[diwen-mcp] ${SERVER_NAME} v${SERVER_VERSION} ready (stdio, MCP ${PROTOCOL_VERSION}); tools: diwen_map, diwen_describe`);
|
|
290
|
+
console.error(`[diwen-mcp] ${SERVER_NAME} v${SERVER_VERSION} ready (stdio, MCP ${PROTOCOL_VERSION}); tools: diwen_map, diwen_describe, diwen_select`);
|