diwen-mcp 6.2.0 → 6.3.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/package.json +4 -4
- package/selftest.mjs +5 -1
- package/server.mjs +60 -2
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "diwen-mcp",
|
|
3
|
-
"version": "6.
|
|
4
|
-
"description": "迪文(Diwen)MCP server:开源零依赖 stdio 壳,暴露 diwen_map / diwen_describe
|
|
3
|
+
"version": "6.3.0",
|
|
4
|
+
"description": "迪文(Diwen)MCP server:开源零依赖 stdio 壳,暴露 diwen_map / diwen_describe / diwen_select(云端级联/集成选义),依赖已发布的 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.3.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
|
@@ -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`);
|