dsh-plugin-tool-management 0.21.1 → 0.21.3
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/CHANGELOG.md +111 -1
- package/README.md +43 -7
- package/README_EN.md +41 -7
- package/docs/{update.md → UPDATE.md} +38 -36
- package/docs/images/1-EN.png +0 -0
- package/docs/images/1.png +0 -0
- package/docs/images/2-EN.png +0 -0
- package/docs/images/2.png +0 -0
- package/docs/images/3-EN.png +0 -0
- package/docs/images/3.png +0 -0
- package/docs/images/4-EN.png +0 -0
- package/docs/images/4.png +0 -0
- package/docs/images/5-EN.png +0 -0
- package/docs/images/5.png +0 -0
- package/docs/images/6-EN.png +0 -0
- package/docs/images/6.png +0 -0
- package/docs/images/7-EN.png +0 -0
- package/docs/images/7.png +0 -0
- package/docs/images/8-EN.png +0 -0
- package/docs/images/8.png +0 -0
- package/lib/approval-policy.js +2 -2
- package/lib/audit-log.js +1 -1
- package/lib/boot/reconcile.js +157 -0
- package/lib/client.js +6668 -3145
- package/lib/compat/capability-specs.js +13 -17
- package/lib/compat/host-contracts.js +2 -0
- package/lib/compat/host-probe.js +35 -38
- package/lib/compat/host-roots.js +86 -15
- package/lib/compat/patch-dialect.js +14 -1
- package/lib/compat/preset-reach.js +75 -102
- package/lib/compat/probe.js +86 -131
- package/lib/compat/runtime-notes.js +1 -1
- package/lib/context-inject-contract.js +6 -5
- package/lib/context-inject-frame.js +124 -73
- package/lib/context-inject-select.js +66 -12
- package/lib/context-inject-surface.js +52 -4
- package/lib/context-inject.js +176 -39
- package/lib/desktop-cookie-prune.js +95 -0
- package/lib/diagnostics.js +79 -0
- package/lib/exports/transcript.js +4 -4
- package/lib/host-names.js +6 -6
- package/lib/http-api.js +73 -48
- package/lib/http-fence.js +44 -9
- package/lib/hub.js +12 -13
- package/lib/imports/parsers.js +25 -21
- package/lib/imports/unzip.js +48 -0
- package/lib/imports/upload.js +13 -37
- package/lib/index.js +3026 -279
- package/lib/mcp/disabled-tools.js +97 -0
- package/lib/mcp/loader-token.js +4 -4
- package/lib/mcp/manager.js +636 -226
- package/lib/mcp/override-blocks.js +1 -1
- package/lib/mcp/patch-yaml.js +42 -31
- package/lib/mcp/restart-marker.js +110 -0
- package/lib/mcp/secret-guard.js +6 -6
- package/lib/mcp/state-section.js +190 -60
- package/lib/mcp/tool-visibility.js +364 -73
- package/lib/memories/archive-engine.js +67 -42
- package/lib/memories/archive.js +23 -3
- package/lib/memories/constants.js +40 -127
- package/lib/memories/discovery.js +41 -12
- package/lib/memories/index-io.js +238 -33
- package/lib/memories/projection.js +36 -20
- package/lib/memories/prompt-layer.js +38 -0
- package/lib/memories/search.js +86 -0
- package/lib/memories/service.js +350 -111
- package/lib/memories/snapshot.js +83 -36
- package/lib/op-registry.js +73 -15
- package/lib/ops/candidates.js +14 -5
- package/lib/ops/compat.js +56 -13
- package/lib/ops/ctx.js +1 -1
- package/lib/ops/memory.js +89 -20
- package/lib/ops/prompts.js +57 -13
- package/lib/ops/quick-prompts.js +25 -2
- package/lib/ops/scene-records.js +29 -23
- package/lib/ops/scene-sync.js +30 -10
- package/lib/ops/scope.js +1094 -0
- package/lib/ops/sessions.js +15 -11
- package/lib/ops/snapshot.js +65 -29
- package/lib/ops/state-doctor.js +40 -5
- package/lib/ops/trash-retention.js +2 -1
- package/lib/ops/trash.js +6 -6
- package/lib/paths.js +50 -3
- package/lib/prompts/preset-id.js +5 -1
- package/lib/prompts/project-instructions.js +162 -0
- package/lib/prompts/quick-service.js +6 -4
- package/lib/prompts/service.js +30 -18
- package/lib/request-gate.js +32 -29
- package/lib/scene-linkage.js +17 -4
- package/lib/scene-prompt-sync.js +11 -10
- package/lib/scene-settings.js +1 -0
- package/lib/scenes/candidates.js +17 -11
- package/lib/scope/intent-store.js +106 -0
- package/lib/scope/intent.js +376 -0
- package/lib/scope/resolve.js +190 -0
- package/lib/scope/scope-overrides.js +894 -0
- package/lib/scope/store.js +263 -0
- package/lib/scope/workspace-key.js +64 -0
- package/lib/sessions/archive-schemas.js +9 -0
- package/lib/sessions/bridge.js +42 -56
- package/lib/sessions/history.js +9 -9
- package/lib/sessions/workspace.js +21 -23
- package/lib/settings-sidecars.js +51 -24
- package/lib/sidebar-settings.js +1 -0
- package/lib/skills/catalog.js +207 -35
- package/lib/skills/core-util.js +5 -0
- package/lib/skills/core.js +36 -23
- package/lib/skills/frontmatter.js +144 -11
- package/lib/skills/homes.js +2 -0
- package/lib/skills/import-pipeline.js +8 -1
- package/lib/skills/manager-state.js +30 -6
- package/lib/skills/official.js +14 -11
- package/lib/skills/readonly-discovery.js +1 -0
- package/lib/skills/service.js +157 -31
- package/lib/skills/skill-roots.js +25 -7
- package/lib/skills/skill-trash.js +14 -3
- package/lib/skills/system-trash.js +3 -1
- package/lib/skills/upload-pipeline.js +19 -3
- package/lib/slash-settings.js +1 -0
- package/lib/stale-write.js +82 -0
- package/lib/subagents/catalog.js +52 -18
- package/lib/subagents/child-preset.js +7 -10
- package/lib/subagents/persona-parse.js +35 -13
- package/lib/subagents/persona-write.js +12 -8
- package/lib/subagents/run-provider.js +13 -15
- package/lib/subagents/service.js +16 -14
- package/lib/subagents/tool-filter.js +1 -1
- package/lib/subagents/tools.js +113 -41
- package/lib/token-config.js +34 -14
- package/lib/tool-table-switch.js +142 -49
- package/lib/tools/deps.js +172 -6
- package/lib/tools/mcp.js +231 -54
- package/lib/tools/memory.js +139 -39
- package/lib/tools/prompt.js +81 -17
- package/lib/tools/remove.js +52 -26
- package/lib/tools/scene.js +139 -42
- package/lib/tools/skills.js +211 -51
- package/lib/tools/subagent.js +63 -32
- package/lib/tools/table.js +63 -25
- package/lib/trash-id.js +3 -2
- package/lib/trash-retention.js +7 -7
- package/lib/update-check.js +222 -0
- package/package.json +18 -15
package/lib/tools/mcp.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// MCP 域的 model
|
|
1
|
+
// MCP 域的 model 工具(从 index.ts 的注册区抽出;合并):
|
|
2
2
|
// mcp_manager_list / mcp_manager_switch / mcp_manager_save。
|
|
3
3
|
//
|
|
4
|
-
//
|
|
4
|
+
// 两条合并理由:
|
|
5
5
|
// · set_enabled + restart → switch:两者都是"拨一下这台服务器",只是动词不同。合并后
|
|
6
6
|
// 由 `action` 自报动词,工具名不再需要用长度去区分"启停"与"重启"。
|
|
7
7
|
// · add + edit → save:改一台已配置的服务器(含 URL / 命令)与新增一台危险度同级
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// 所以 switch 里只有 on|off 过 `lockedSceneGuard()`,restart 不过;与面板侧
|
|
14
14
|
// `guardLockedOps(frozenOps('all'))` 的口径逐字一致(两处口径不同才是真的"说假话")。
|
|
15
15
|
//
|
|
16
|
-
// restart
|
|
16
|
+
// restart 现在是**唯一**的重启入口:面板侧那颗重启键用户此前已删除(复核,
|
|
17
17
|
// 客户端已无任何 restart 调用方)。这不是要把它也删掉 —— 工具是模型按需调用的面,与面板
|
|
18
18
|
// 按钮是两回事;面板删掉只说明"不想让人手点",而"服务器卡住、让模型重连一下"这条恢复路径
|
|
19
19
|
// 仍然成立,且它正是上面那条"锁定期间唯一不冻结的写"的立足点。删掉它等于把场景锁定时的
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
// `mcpm-edit` 里那句 `if (row[field] === undefined) return` 就不会生效,于是
|
|
27
27
|
// `resolveMaskedKv({}, 旧值)` 把整份 headers / env 静默清空、连 warning 都不给。
|
|
28
28
|
import { DEFAULT_MCP_NOTE_MAX_LENGTH, normalizeMcpNote } from '../mcp/state-section.js';
|
|
29
|
-
import { text } from './deps.js';
|
|
29
|
+
import { effectiveScope, globalActionNote, globalUnchangedNote, isolationOffNote, requireGlobalScope, scopeGlobalOnlyDesc, scopeOnlyNote, scopeSessionDesc, sessionLayerOn, text } from './deps.js';
|
|
30
30
|
/** 「去看清单」那句:`mcp_manager_list` 不在模型手里时不能点名它(调用方按 `toolVisibleFor` 决定给不给)。 */
|
|
31
31
|
const MCP_LIST_HINT = ' (see mcp_manager_list — all=true also lists disabled ones)';
|
|
32
32
|
/**
|
|
33
33
|
* 指不到 `mcp_manager_list` 时的**中性出口**:不点名任何工具,两条常驻来源都成立
|
|
34
34
|
* —— 模型自己的 `mcp__<server>__<tool>` 工具名(就在它的 schema 里),以及注入段。
|
|
35
35
|
*
|
|
36
|
-
*
|
|
36
|
+
* 为什么必须有这一句:`mcp_manager_switch` 是默认**唯一可见**
|
|
37
37
|
* 的 MCP 工具,猜错 serverName 时若报错里只有「没有这台服务器:X」,模型拿不到任何补救线索
|
|
38
38
|
* —— 它只能猜第二次。出口要么指向工具(那条工具得在它手里),要么指向这两条常驻来源。
|
|
39
39
|
*/
|
|
@@ -71,29 +71,46 @@ function kvToText(map) {
|
|
|
71
71
|
function argsToText(value) {
|
|
72
72
|
return Array.isArray(value) ? value.join(' ') : String(value == null ? '' : value);
|
|
73
73
|
}
|
|
74
|
+
/** 注册 MCP 域的 model 工具(列表 / 预览 / 启停 / 导入)。 */
|
|
74
75
|
export function buildMcpTools(deps) {
|
|
75
76
|
const { defineTool, register } = deps;
|
|
76
77
|
/**
|
|
77
78
|
* 那句"去看清单"要不要给:`mcp_manager_list` 在出厂默认里就是关着的,点名一条模型没有的工具
|
|
78
79
|
* 只会让它白跑一趟(执行侧拦住它,而它看不出为什么)。
|
|
79
80
|
*
|
|
80
|
-
* 判据按 **agent**
|
|
81
|
+
* 判据按 **agent** 而不是全局开关:全局关着、但这个人设没砍掉
|
|
81
82
|
* 它时,那句话是对的;反过来,全局开着、而这个人设用 `toolsDeny` 砍掉了它时,只读全局开关
|
|
82
83
|
* 就会让我们点名一条它手里没有的工具。与注入框架 `how` 行同一份判据(`toolVisibleFor`)。
|
|
83
84
|
*/
|
|
84
85
|
const listHint = (agent) => (deps.toolVisibleFor('mcp_manager_list', agent) ? MCP_LIST_HINT : '');
|
|
86
|
+
/**
|
|
87
|
+
* 本作用域里某个工具那一格的生效值(四层并值)。`undefined` = 这一层没话说,落到全局。
|
|
88
|
+
*
|
|
89
|
+
* 必须问:`mcp_manager_switch` 的 `tool` 分支默认写的是**会话层** `mcpTools`,
|
|
90
|
+
* 而 `mcpm-tools` 报的是**全局**停用表 —— 不投影的话,本作用域刚关掉的工具在清单里
|
|
91
|
+
* 仍显示为开着,模型据此回答"它开着"就是错的(运行侧确实已经拒了它)。
|
|
92
|
+
*/
|
|
93
|
+
const toolFlag = (agent, key) => {
|
|
94
|
+
if (deps.sessionFlagOf === undefined)
|
|
95
|
+
return undefined;
|
|
96
|
+
try {
|
|
97
|
+
return deps.sessionFlagOf(agent, 'mcpTools', key);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
85
103
|
register(defineTool({
|
|
86
104
|
name: 'mcp_manager_list',
|
|
87
|
-
// 注入段与本工具的关系要**如实说成筛过的视图**(而非"同一份清单"
|
|
88
|
-
//
|
|
89
|
-
// 是行动依据 —— 模型要知道"
|
|
105
|
+
// 注入段与本工具的关系要**如实说成筛过的视图**(而非"同一份清单"):注入段只列当前真有
|
|
106
|
+
// 工具注册的服务器(停用与掉线的都不进),也不带 level / loader / 工具数。把这个盲区写出来
|
|
107
|
+
// 是行动依据 —— 模型要知道"停用 / 掉线的那台去哪查"就得靠这句(all=true)。
|
|
90
108
|
//
|
|
91
|
-
//
|
|
92
|
-
// ① 括号里那句把 "Current MCP servers" reminder 的**内容**逐项列了一遍(可用 / 曾连上 /
|
|
109
|
+
// ① 括号里那句把 "Current MCP servers" reminder 的**内容**逐项列了一遍(可用 / 工具全停 /
|
|
93
110
|
// 备注 / 停用不进),而那段 reminder 每轮就在模型上下文里,它自己看得到;
|
|
94
111
|
// ② `where loader:on:<phase> is the loader's current phase` —— 用自己解释自己
|
|
95
112
|
// (phase 就是 phase),零信息。字段名本身留在输出里,模型照抄即可。
|
|
96
|
-
description: 'List configured MCP servers (level
|
|
113
|
+
description: 'List configured MCP servers (level, enabled state, loader status, tool count excluding switched-off ones, hint). The "Current MCP servers" reminder is a filtered view; this is the full one — all=true also includes disabled servers. Pass tools=true for each server\'s tool names.',
|
|
97
114
|
parameters: {
|
|
98
115
|
all: { type: 'boolean', description: 'Include disabled servers (default false).' },
|
|
99
116
|
tools: { type: 'boolean', description: 'Also list each server\'s tool names, marking the switched-off ones (default false).' },
|
|
@@ -110,16 +127,43 @@ export function buildMcpTools(deps) {
|
|
|
110
127
|
if (!r.ok)
|
|
111
128
|
throw new Error(r.error);
|
|
112
129
|
const all = r.rows || [];
|
|
113
|
-
//
|
|
130
|
+
// 默认只列「已启用」的(与技能 / 记忆列表同口径):停用的服务器
|
|
114
131
|
// 模型调不到,列出来只是噪音。表头给出全量口径,所以不会变成盲区。
|
|
115
|
-
|
|
132
|
+
// 会话层:本会话隐藏的服务器 —— 它们**此刻一条工具都调不到**,与全局停用同形。
|
|
133
|
+
// 默认口径下按停用处理(不列);`all=true` 时列出来并标注,否则模型会以为这台服务器不存在。
|
|
134
|
+
// 逐行问谓词:行数组就是全集,判据(覆盖 → 场景层 → 基线)在 index.ts 一份。
|
|
135
|
+
const offHere = new Set();
|
|
136
|
+
if (deps.sessionHiddenServer) {
|
|
137
|
+
for (const x of all) {
|
|
138
|
+
if (deps.sessionHiddenServer(exec && exec.agent, String(x.serverName)))
|
|
139
|
+
offHere.add(String(x.serverName));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const isOff = (x) => x.disabled === true || offHere.has(String(x.serverName));
|
|
143
|
+
const shown = showAll ? all : all.filter((x) => !isOff(x));
|
|
116
144
|
const lines = [];
|
|
117
145
|
for (const x of shown) {
|
|
118
146
|
const note = normalizeMcpNote(x.notes, DEFAULT_MCP_NOTE_MAX_LENGTH);
|
|
119
147
|
// 工具数 = 可用数(停用表扣减后):段里给模型的是同一个口径,模型据此与
|
|
120
148
|
// 自己 schema 里的 `mcp__*` 工具对得上;被场景收窄 / 手动关掉的工具不算。
|
|
121
149
|
const usableTools = typeof x.enabledToolCount === 'number' ? x.enabledToolCount : x.toolCount;
|
|
122
|
-
|
|
150
|
+
// 「本会话关掉」必须与「全局停用」分开说:前者换个对话就回来了,后者要改配置。
|
|
151
|
+
// 还有第三种:**全局意图 off、但本会话认领着它**(租约)—— 对这里调用
|
|
152
|
+
// 模型的那个会话来说它是可用的,但别的对话看不到;不说清就会被读成"全局开着"。
|
|
153
|
+
const serverName = String(x.serverName);
|
|
154
|
+
const globalOn = x.intent === 'blocked' ? false : (typeof x.globalOn === 'boolean' ? x.globalOn : x.disabled !== true);
|
|
155
|
+
const sessionOff = offHere.has(serverName);
|
|
156
|
+
const leases = typeof x.leaseCount === 'number' ? x.leaseCount : 0;
|
|
157
|
+
const state = x.intent === 'blocked'
|
|
158
|
+
? 'stopped-machine-wide (every conversation)'
|
|
159
|
+
: !globalOn
|
|
160
|
+
? (sessionOff
|
|
161
|
+
? 'disabled-globally' + (leases > 0 ? ' (kept running by ' + leases + ' conversation(s))' : '')
|
|
162
|
+
: 'enabled-in-this-conversation (global: off' + (leases > 0 ? ', kept running by ' + leases + ' conversation(s)' : '') + ')')
|
|
163
|
+
: sessionOff
|
|
164
|
+
? 'off-here (global: enabled)'
|
|
165
|
+
: 'enabled';
|
|
166
|
+
lines.push('server:' + x.serverName + ' | level:' + x.level + ' | ' + state +
|
|
123
167
|
(x.live ? ' | loader:' + (x.live.enabled ? 'on' : 'off') + (x.live.phase ? ':' + x.live.phase : '') : '') +
|
|
124
168
|
(typeof usableTools === 'number' ? ' | tools:' + usableTools : '') +
|
|
125
169
|
(note ? ' | user-hint:' + note : ''));
|
|
@@ -130,17 +174,40 @@ export function buildMcpTools(deps) {
|
|
|
130
174
|
// **不调 `mcpm-tools-refresh`**:那个会临时起进程(npx 冷启动可能几十秒),
|
|
131
175
|
// 那是界面上的显式动作,不该由一次列表调用顺手触发。
|
|
132
176
|
const t = await deps.mcpmTools({ serverName: String(x.serverName) });
|
|
177
|
+
// 停用表读不出来:下面每一行都标 (off)(执行侧确实全拒),但必须说清原因 ——
|
|
178
|
+
// 否则模型会读成"用户把这些工具关了",进而去建议用户打开它们。
|
|
179
|
+
if (t && t.disabledState === 'unknown') {
|
|
180
|
+
lines.push(' (disabled-tools table unreadable: every mcp__ tool is refused until it is repaired)');
|
|
181
|
+
}
|
|
133
182
|
const items = t && t.ok !== false ? (t.tools || []) : [];
|
|
134
183
|
if (!items.length) {
|
|
135
184
|
lines.push(' ' + (x.disabled ? '(tools not recorded: server is off)' : '(no tools recorded)'));
|
|
136
185
|
continue;
|
|
137
186
|
}
|
|
138
|
-
lines.push(' tools: ' + items.map((it) =>
|
|
187
|
+
lines.push(' tools: ' + items.map((it) => {
|
|
188
|
+
// 服务器在这一层整个不可用时,逐工具不再重复标注:上面那行已经说了它不可用。
|
|
189
|
+
// 停用表读不出来时同理 —— 那一档执行侧全拒,(on here) 会与上面那句打架。
|
|
190
|
+
const here = offHere.has(String(x.serverName)) || (t && t.disabledState === 'unknown')
|
|
191
|
+
? undefined
|
|
192
|
+
: toolFlag(exec && exec.agent, String(x.serverName) + '/' + String(it.name));
|
|
193
|
+
const off = here === undefined ? it.enabled === false : !here;
|
|
194
|
+
if (!off)
|
|
195
|
+
return String(it.name) + (it.enabled === false ? ' (on here)' : '');
|
|
196
|
+
return String(it.name) + (it.enabled === false ? ' (off)' : ' (off here)');
|
|
197
|
+
}).join(', '));
|
|
139
198
|
}
|
|
199
|
+
// 会话层(`mcp_manager_list` 标注本会话可见性):本会话停用的服务器
|
|
200
|
+
// 与全局停用**同形**(默认不列、all=true 标注),但两者的含义完全不同 —— 前者换个对话
|
|
201
|
+
// 就回来,后者要改配置。表头点一句,模型才不会把这份清单当成"这台机器的配置"。
|
|
202
|
+
const sessionLine = offHere.size === 0
|
|
203
|
+
? ''
|
|
204
|
+
: '\n' + offHere.size + ' server(s) are switched off here (' +
|
|
205
|
+
[...offHere].join(', ') + ') — the connection is still up, and conversations outside this scope keep them.\n';
|
|
140
206
|
const header = 'MCP servers: ' + (showAll
|
|
141
207
|
? all.length + ' configured'
|
|
142
208
|
: shown.length + ' enabled of ' + all.length + ' configured' +
|
|
143
|
-
(shown.length === all.length ? '' : ' (pass all=true for every configured server)')) +
|
|
209
|
+
(shown.length === all.length ? '' : ' (pass all=true for every configured server)')) +
|
|
210
|
+
(sessionLine === '' ? '\n' : sessionLine);
|
|
144
211
|
// 注入边界:压制型预设(persona complete / 关闭运行时上下文,如极简)下本插件
|
|
145
212
|
// 默认不注入 —— 模型只有 mcp__* 的工具名与参数,没有服务级信息。不说明的话,
|
|
146
213
|
// 模型会把「能调用这些工具」当成「已经知道有哪些 server、用户给它们写了什么备注」。
|
|
@@ -153,34 +220,60 @@ export function buildMcpTools(deps) {
|
|
|
153
220
|
name: 'mcp_manager_switch',
|
|
154
221
|
// 为什么 action 是必填枚举而不是两个可选布尔:模型最容易犯的错是"想重启却只传了 server",
|
|
155
222
|
// 让它在三个动词里选一个,比让它猜两个布尔的组合省一次往返。
|
|
156
|
-
// `restart` 的含义只在 `action`
|
|
223
|
+
// `restart` 的含义只在 `action` 参数里说一次:描述里那句
|
|
157
224
|
// "(reconnects and re-syncs tools)" 与参数说明逐字重复,而模型读参数时两处都在手上。
|
|
158
|
-
description: 'Turn one
|
|
225
|
+
description: 'Turn one MCP server on or off, restart it, or stop it machine-wide; pass `tool` to target named tools on it. `off` leaves a server running while any conversation still uses it, `stop` ends it for them too. Blocked while the active scene is locked, except restart (the recovery path). Only when the user asks or approves.',
|
|
159
226
|
parameters: {
|
|
160
|
-
// 出口必须指向**常驻**来源,不能指向 `mcp_manager_list
|
|
227
|
+
// 出口必须指向**常驻**来源,不能指向 `mcp_manager_list`:
|
|
161
228
|
// 那条工具在出厂默认里就是关着的,`listHint()` 在它不可见时返回空串,于是猜错名字时的
|
|
162
229
|
// 报错退化成「没有这台服务器:<你猜的>」—— 一个字都不告诉它还能去哪看。
|
|
163
230
|
// 指向模型自己的工具表(`mcp__<server>__<tool>` 就在它的 schema 里)与常驻注入段,
|
|
164
231
|
// 这两条**不需要任何工具可见**就成立。
|
|
165
|
-
server: { type: 'string', required: true, description: 'Server name
|
|
166
|
-
action: { type: 'string', required: true, enum: ['on', 'off', 'restart'], description: 'on = enable, off = disable, restart = reconnect and re-sync tools.' },
|
|
232
|
+
server: { type: 'string', required: true, description: 'Server name — the one in your own `mcp__<server>__<tool>` names.' },
|
|
233
|
+
action: { type: 'string', required: true, enum: ['on', 'off', 'restart', 'stop'], description: 'on = enable, off = disable, restart = reconnect and re-sync tools, stop = disable and disconnect anything still using it.' },
|
|
167
234
|
level: { type: 'string', description: 'project or global — only to disambiguate same-name servers.' },
|
|
168
|
-
|
|
235
|
+
// 支持数组:关 8 个工具原本要 8 次调用,每次都带着整份工具表
|
|
236
|
+
// 重新推理一遍 —— 那是这份工具集里最贵的开销,而工具描述本身只占百分之几。
|
|
237
|
+
tool: { type: 'array', items: { type: 'string' }, description: 'Tool name(s) on that server (no mcp__ prefix) — one or several. Only for on/off.' },
|
|
238
|
+
// 默认只改**这个对话**,别的对话不受影响。写全局要显式说明。
|
|
239
|
+
// 开启一台机器级关着的服务器时,那一步在全局发生(连接是进程级的)—— 租约
|
|
240
|
+
// 这个词一句带过就够,别的对话看不到它。
|
|
241
|
+
scope: { type: 'string', enum: ['session', 'global'], description: scopeSessionDesc('turning one on here starts it for this scope only (other scopes cannot see it). global = every conversation (off leaves it running while any conversation still uses it; stop cuts it). restart / stop are always global.') },
|
|
169
242
|
},
|
|
170
243
|
output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
|
|
171
244
|
async execute(args, exec) {
|
|
172
245
|
const action = String((args && args.action) || '');
|
|
173
|
-
if (action !== 'on' && action !== 'off' && action !== 'restart') {
|
|
174
|
-
throw new Error('action must be on / off / restart (got: ' + (action || '(empty)') + ')');
|
|
246
|
+
if (action !== 'on' && action !== 'off' && action !== 'restart' && action !== 'stop') {
|
|
247
|
+
throw new Error('action must be on / off / restart / stop (got: ' + (action || '(empty)') + ')');
|
|
175
248
|
}
|
|
176
249
|
const server = String((args && args.server) || '').trim();
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
250
|
+
// 单值仍然接受(旧提示词 / 手写调用),数组是新增的批量形态。
|
|
251
|
+
const rawTool = args && args.tool !== undefined && args.tool !== null ? args.tool : undefined;
|
|
252
|
+
const tools = (Array.isArray(rawTool) ? rawTool : rawTool === undefined ? [] : [rawTool])
|
|
253
|
+
.map((t) => String(t).trim())
|
|
254
|
+
.filter((t) => t !== '');
|
|
255
|
+
if (tools.length > 0 && (action === 'restart' || action === 'stop')) {
|
|
256
|
+
throw new Error('restart and stop are whole-server actions (' + (action === 'stop' ? 'stopping cuts off every conversation using it' : 'off, wait for it to drop, then back on at its previous state') + '); a single tool cannot be ' + action + 'ped');
|
|
180
257
|
}
|
|
258
|
+
// 默认写**本会话**(别的对话不受影响),`scope: "global"` 才改补丁。
|
|
259
|
+
// 两条边界决定了这里的分支:
|
|
260
|
+
// · restart 是进程级动作(要真停一次再起),没有会话版本 —— 永远走全局;
|
|
261
|
+
// · 会话层写不碰补丁、不进场景档案,所以不需要冻结守卫与 syncSwitchToScene
|
|
262
|
+
// —— 例外是"在本会话里打开一台全局关着的服务器":连接是进程级的,那一步把它
|
|
263
|
+
// 作为本会话的租约跑起来(见下面的 sessionOnly 分支)。
|
|
264
|
+
const scope = effectiveScope(deps, args);
|
|
265
|
+
// 调用方是否**以为**自己在改会话层(省略 scope 也算)。全局粒度下这个以为会落空,
|
|
266
|
+
// 回执必须点出来 —— 否则 agent 会把"机器级改动"转述成"只影响这个对话"。
|
|
267
|
+
const askedForSession = (args && args.scope) !== 'global';
|
|
268
|
+
// restart 与 stop 都是机器级动作(重启要真停一次;彻底停止定义上就压过所有会话),
|
|
269
|
+
// 没有会话版本 —— 与 restart 同一条,忽略 scope 并如实点出来。
|
|
270
|
+
const sessionOnly = scope !== 'global' && action !== 'restart' && action !== 'stop';
|
|
181
271
|
// on|off 会写补丁(`mcpm-set-enabled` / `mcpm-tool-enabled` 在登记表里是 frozen),
|
|
182
272
|
// 所以过场景冻结守卫;restart 不过 —— 它是锁定期间唯一的恢复入口(见文件头)。
|
|
183
|
-
|
|
273
|
+
// 会话层写入(`sessionOnly`)也不被场景锁挡住:它写的是侧车,与全局状态无关
|
|
274
|
+
// (与面板的 `scopeWriteLocked()` 同口径)。那个"租约跑起来"的例外
|
|
275
|
+
// 同样不受场景锁管:它是进入本会话的前置条件,不是一次独立的全局配置改动。
|
|
276
|
+
if (action !== 'restart' && !sessionOnly) {
|
|
184
277
|
const blocked = await deps.lockedSceneGuard();
|
|
185
278
|
if (blocked)
|
|
186
279
|
throw new Error(blocked);
|
|
@@ -191,24 +284,101 @@ export function buildMcpTools(deps) {
|
|
|
191
284
|
const level = args && args.level !== undefined ? String(args.level) : undefined;
|
|
192
285
|
const row = locate(list.rows || [], server, level, listHint(exec && exec.agent));
|
|
193
286
|
const enabled = action === 'on';
|
|
194
|
-
if (
|
|
195
|
-
const
|
|
196
|
-
if (
|
|
197
|
-
throw new Error(
|
|
198
|
-
//
|
|
199
|
-
//
|
|
200
|
-
|
|
287
|
+
if (sessionOnly) {
|
|
288
|
+
const setter = deps.sessionScopeSet;
|
|
289
|
+
if (setter === undefined)
|
|
290
|
+
throw new Error('per-conversation switches are unavailable in this host: pass scope="global" to change the config for every conversation');
|
|
291
|
+
// 开启一台全局关着的服务器时,op 侧把它作为本会话的租约跑起来(连接是进程级的,
|
|
292
|
+
// 没有会话版本)—— 用户要求「仍按租约运行」。那一步的影响由回执里的 `warnings`
|
|
293
|
+
// 如实带出来(哪些临时跑起来了),这里不重写一份判定。
|
|
294
|
+
const one = async (domain, key) => {
|
|
295
|
+
const r = await setter(exec && exec.agent, domain, key, enabled);
|
|
296
|
+
if (!r || r.ok === false)
|
|
297
|
+
throw new Error((r && r.error) || 'failed to switch this here');
|
|
298
|
+
return r;
|
|
299
|
+
};
|
|
300
|
+
const globalNote = ' Pass scope="global" to change it for every conversation.';
|
|
301
|
+
// 回执必须说清写的是哪一层:用户看到「已停用」而全局其实没变时,才不会以为别的对话也变了。
|
|
302
|
+
// 措辞用 `scopeOnlyNote()`(不再写死「本对话」)。
|
|
303
|
+
if (tools.length === 0) {
|
|
304
|
+
const r = await one('mcp', String(row.serverName));
|
|
305
|
+
const warnings = r.warnings !== undefined && r.warnings.length > 0 ? '\n' + r.warnings.join('\n') : '';
|
|
306
|
+
return 'OK: ' + String(row.serverName) + ' now ' + (enabled ? 'enabled' : 'disabled') + scopeOnlyNote(deps) +
|
|
307
|
+
(r.cleared === true ? ' (that matches what this scope would see anyway, so the override was removed)' : '') + warnings +
|
|
308
|
+
(warnings === '' ? '\n' + globalUnchangedNote(deps) : '') + globalNote;
|
|
309
|
+
}
|
|
310
|
+
let cleared = 0;
|
|
311
|
+
const warningsAll = [];
|
|
312
|
+
for (const t of tools) {
|
|
313
|
+
const r = await one('mcpTools', String(row.serverName) + '/' + t);
|
|
314
|
+
if (r.cleared === true)
|
|
315
|
+
cleared += 1;
|
|
316
|
+
if (r.warnings !== undefined)
|
|
317
|
+
warningsAll.push(...r.warnings);
|
|
318
|
+
}
|
|
319
|
+
const what = tools.length === 1
|
|
320
|
+
? 'tool ' + tools[0] + ' on ' + String(row.serverName)
|
|
321
|
+
: tools.length + ' tools on ' + String(row.serverName) + ' (' + tools.join(', ') + ')';
|
|
322
|
+
const warnings = warningsAll.length > 0 ? '\n' + warningsAll.join('\n') : '';
|
|
323
|
+
return 'OK: ' + what + ' now ' + (enabled ? 'enabled' : 'disabled') + scopeOnlyNote(deps) +
|
|
324
|
+
(cleared === tools.length ? ' (that matches what this scope would see anyway, so the overrides were removed)' : '') + warnings +
|
|
325
|
+
(warnings === '' ? '\n' + globalUnchangedNote(deps) : '') + globalNote;
|
|
326
|
+
}
|
|
327
|
+
// 走到这里说明这次是**全局**动作:显式 scope="global"、restart / stop(它们没有
|
|
328
|
+
// 会话版本),或者隔离被关掉了(全局粒度)。默认值是 session,所以模型很可能以为
|
|
329
|
+
// 自己在改本会话;不点一句就是一次静默的「改了全局」。
|
|
330
|
+
const scopeIgnored = action === 'restart'
|
|
331
|
+
? '\nnote: this one is global (a restart has no per-conversation version); every conversation is affected.'
|
|
332
|
+
: action === 'stop'
|
|
333
|
+
? '\nnote: stop is global — it ends the server even for conversations still using it.'
|
|
334
|
+
: (scope === 'global' && askedForSession ? isolationOffNote(deps) : '');
|
|
335
|
+
if (tools.length > 0) {
|
|
336
|
+
// 批量时逐条写、逐条同步场景档案;任一失败就抛,回执里说清是哪一条。
|
|
337
|
+
const syncErrs = [];
|
|
338
|
+
for (const t of tools) {
|
|
339
|
+
const r = await deps.mcpmToolEnabled({ serverName: String(row.serverName), tool: t, enabled });
|
|
340
|
+
if (!r || r.ok === false)
|
|
341
|
+
throw new Error('failed to switch tool ' + t + ': ' + ((r && r.error) || 'unknown error'));
|
|
342
|
+
// 与面板同一条同步:`mcpm-tool-enabled` 在登记表里带 syncsArchive,漏了就是
|
|
343
|
+
// "页面拨的进档案、模型拨的不进"。
|
|
344
|
+
const syncErr = await deps.syncSwitchToScene('mcpm-tool-enabled', { serverName: String(row.serverName), tool: t, enabled });
|
|
345
|
+
if (syncErr)
|
|
346
|
+
syncErrs.push(tools.length === 1 ? String(syncErr) : t + ': ' + String(syncErr));
|
|
347
|
+
}
|
|
201
348
|
// 整台停用时,工具级开关在运行时本来就不生效(那个工具压根不存在)—— 不说的话
|
|
202
349
|
// 模型会以为已经生效。与记忆族"启用了一条不在启用场景里的记忆"同一条理由。
|
|
203
350
|
const offNote = row.disabled ? ' (note: the whole server is off right now, so this tool-level switch only takes effect once the server is on)' : '';
|
|
204
|
-
|
|
205
|
-
|
|
351
|
+
const what = tools.length === 1
|
|
352
|
+
? 'tool ' + tools[0]
|
|
353
|
+
: tools.length + ' tools (' + tools.join(', ') + ')';
|
|
354
|
+
return 'OK: ' + String(row.serverName) + ' ' + what + ' now ' + (enabled ? 'enabled' : 'disabled') + offNote +
|
|
355
|
+
(syncErrs.length > 0 ? '\nWARN: the current scene archive was not synced (' + syncErrs.join('; ') + ')' : '') + scopeIgnored;
|
|
206
356
|
}
|
|
207
357
|
if (action === 'restart') {
|
|
208
358
|
const r = await deps.mcpmRestart({ id: row.id, level: row.level });
|
|
209
359
|
if (!r || r.ok === false)
|
|
210
360
|
throw new Error((r && r.error) || 'restart failed');
|
|
211
|
-
return 'OK: ' + String(row.serverName) + ' (' + row.level + ') restarted';
|
|
361
|
+
return 'OK: ' + String(row.serverName) + ' (' + row.level + ') restarted' + scopeIgnored;
|
|
362
|
+
}
|
|
363
|
+
// 全局开关 = **意图**:off 不再立刻停 —— 还在用它的会话会按租约继续跑
|
|
364
|
+
// 只有 stop(blocked)会连它们一起切断。直接写补丁会让"谁也看不到"与"连接停不停"
|
|
365
|
+
// 变成同一件事,那正是会话级开启串到新会话里的根源。
|
|
366
|
+
if (deps.scopeIntentSet) {
|
|
367
|
+
const value = action === 'stop' ? 'blocked' : enabled ? 'on' : 'off';
|
|
368
|
+
// 这一条走的是 handlers 表(与面板同一条路径):场景档案同步由那层包装做,
|
|
369
|
+
// 回执里的 `sceneSyncError` 才是"档案没跟上"的真相。
|
|
370
|
+
const r = await deps.scopeIntentSet('mcp', [String(row.serverName)], value);
|
|
371
|
+
if (!r || r.ok === false)
|
|
372
|
+
throw new Error((r && r.error) || 'failed to switch this server');
|
|
373
|
+
const syncErr = r.sceneSyncError ? String(r.sceneSyncError) : null;
|
|
374
|
+
const warnings = r.warnings !== undefined && r.warnings.length > 0 ? '\n' + r.warnings.join('\n') : '';
|
|
375
|
+
const what = action === 'stop'
|
|
376
|
+
? 'stopped machine-wide (every conversation, including any that still had it on)'
|
|
377
|
+
: enabled
|
|
378
|
+
? 'enabled for every conversation'
|
|
379
|
+
: 'disabled globally (conversations already using it keep the connection until none does; use stop to cut them off now)';
|
|
380
|
+
return 'OK: ' + String(row.serverName) + ' (' + row.level + ') now ' + what + warnings +
|
|
381
|
+
(syncErr ? '\nWARN: the current scene archive was not synced (' + syncErr + ')' : '') + scopeIgnored;
|
|
212
382
|
}
|
|
213
383
|
const r = await deps.mcpmSetEnabled({ id: row.id, level: row.level, enabled });
|
|
214
384
|
if (!r || r.ok === false)
|
|
@@ -221,32 +391,36 @@ export function buildMcpTools(deps) {
|
|
|
221
391
|
}));
|
|
222
392
|
register(defineTool({
|
|
223
393
|
name: 'mcp_manager_save',
|
|
224
|
-
description: 'Add a new MCP server, or update the one with this name — the receipt says which. Omitted fields keep their current values, so never restate the whole server. Pass `hint`
|
|
394
|
+
description: 'Add a new MCP server, or update the one with this name — the receipt says which. Omitted fields keep their current values, so never restate the whole server. Pass `hint` for a usage note. Blocked while the active scene is locked. Only on the user\'s instruction.',
|
|
225
395
|
parameters: {
|
|
226
396
|
server: { type: 'string', required: true, description: 'Server name (1-32 chars, [A-Za-z0-9_-]) — the name the mcp__<server>__ tools use.' },
|
|
227
|
-
transport: { type: 'string', description: 'streamable-http or stdio. Required when creating
|
|
228
|
-
url: { type: 'string', description: 'Server URL (streamable-http).
|
|
229
|
-
command: { type: 'string', description: 'Executable to spawn (stdio).
|
|
230
|
-
args: { type: 'string', description: 'Arguments, space or comma separated (stdio).
|
|
231
|
-
headers: { type: 'string', description: 'Extra headers, key=value per line (streamable-http).
|
|
232
|
-
env: { type: 'string', description: 'Extra env vars, key=value per line (stdio).
|
|
397
|
+
transport: { type: 'string', description: 'streamable-http or stdio. Required when creating.' },
|
|
398
|
+
url: { type: 'string', description: 'Server URL (streamable-http).' },
|
|
399
|
+
command: { type: 'string', description: 'Executable to spawn (stdio).' },
|
|
400
|
+
args: { type: 'string', description: 'Arguments, space or comma separated (stdio).' },
|
|
401
|
+
headers: { type: 'string', description: 'Extra headers, key=value per line (streamable-http). Omitting it is what preserves the real secrets.' },
|
|
402
|
+
env: { type: 'string', description: 'Extra env vars, key=value per line (stdio).' },
|
|
233
403
|
level: { type: 'string', description: 'project or global (project when creating); only needed for same-name servers.' },
|
|
234
|
-
//
|
|
404
|
+
// 名字与注入段对齐:注入段与工具输出都写 `user-hint`
|
|
235
405
|
// (对应注入行里那句 `user hint:`),参数名跟着叫 `hint`,一份数据三个面一个词。
|
|
236
406
|
// 「写什么」那半句已经由注入框架的 `how` 行逐字说过("选服务器之前先看一眼"),
|
|
237
|
-
//
|
|
238
|
-
hint: { type: 'string', description: "Short hint for later (≤300 chars; longer is stored whole but truncated in listings). '' clears the existing hint
|
|
407
|
+
// 这里只留参数独有的信息:长度上限与截断行为。
|
|
408
|
+
hint: { type: 'string', description: "Short hint for later (≤300 chars; longer is stored whole but truncated in listings). '' clears the existing hint." },
|
|
409
|
+
// MCP 服务器是**机器级**配置(cordis 补丁),没有「本会话的一份」。这个参数只为一件事:
|
|
410
|
+
// 模型以为自己在改会话时,当场纠回来(见 deps.ts 的 requireGlobalScope)。
|
|
411
|
+
scope: { type: 'string', enum: ['session', 'global'], description: scopeGlobalOnlyDesc('the server config is machine-wide', 'hide a server here with mcp_manager_switch') },
|
|
239
412
|
},
|
|
240
413
|
output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
|
|
241
414
|
async execute(args, exec) {
|
|
242
415
|
const blocked = await deps.lockedSceneGuard();
|
|
243
416
|
if (blocked)
|
|
244
417
|
throw new Error(blocked);
|
|
418
|
+
requireGlobalScope(args, 'MCP servers', !sessionLayerOn(deps));
|
|
245
419
|
const server = String((args && args.server) || '').trim();
|
|
246
420
|
if (!server)
|
|
247
421
|
throw new Error('missing argument: server (the server name)');
|
|
248
422
|
const levelArg = args && args.level !== undefined ? String(args.level) : undefined;
|
|
249
|
-
// `hint`
|
|
423
|
+
// `hint` 的三态:省略 = 保持;`''` = **清空**;非空 = 设置。
|
|
250
424
|
// 此前用 `hintText.trim() !== ''` 判"要不要写备注",把"清空"与"省略"混成一件事 ——
|
|
251
425
|
// 模型传 `hint: ""` 想清掉已有备注时收到「没有要改的东西」,而 op 侧 `mcpm-note`
|
|
252
426
|
// 本来就支持空串清空(`manager.ts:431`)。判据改成"参数给没给",不是"值空不空"。
|
|
@@ -285,14 +459,16 @@ export function buildMcpTools(deps) {
|
|
|
285
459
|
if (!r || r.ok === false)
|
|
286
460
|
throw new Error((r && r.error) || 'failed to add the server');
|
|
287
461
|
// 备注单独走 `mcpm-note`(`mcpm-add` 不认这个字段)。失败**不回滚**主写入:
|
|
288
|
-
// 服务器已经建好了,"备注没写上"是 warning
|
|
462
|
+
// 服务器已经建好了,"备注没写上"是 warning,不是失败(与界面同规格)。
|
|
289
463
|
let warn = '';
|
|
290
464
|
if (hintGiven && !clearsNote) {
|
|
291
465
|
const n = await deps.mcpmNote({ id: String(r.row.id), note: hintText });
|
|
292
466
|
if (!n || n.ok === false)
|
|
293
467
|
warn = '\nWARN: the server was created, but the hint was not written (' + ((n && n.error) || 'unknown reason') + ')';
|
|
294
468
|
}
|
|
295
|
-
|
|
469
|
+
// 会话层:服务器是**机器级**配置(cordis 补丁),本会话只能把它藏起来。
|
|
470
|
+
return 'OK: created ' + r.row.id + ' at ' + r.row.level + warn +
|
|
471
|
+
globalActionNote(deps, exec && exec.agent, 'mcp', 'MCP');
|
|
296
472
|
}
|
|
297
473
|
// ── 改:省略 = 保持,且必须**显式填回**(见文件头那条 parseKv 的坑)────────
|
|
298
474
|
const cur = locate(hits, server, levelArg, listHint(exec && exec.agent));
|
|
@@ -374,7 +550,7 @@ export function buildMcpTools(deps) {
|
|
|
374
550
|
const r = await deps.mcpmEdit(payload);
|
|
375
551
|
if (!r || r.ok === false)
|
|
376
552
|
throw new Error((r && r.error) || 'failed to update the server');
|
|
377
|
-
// `hint` 进 `changed`
|
|
553
|
+
// `hint` 进 `changed` 必须**等写成功之后**:此前按意图先算进去,
|
|
378
554
|
// mcpmNote 失败时回执一边说"改了 hint"、一边 WARN"备注没写进去",模型读不出到底改没改。
|
|
379
555
|
const changed = touched.concat(levelChanged ? ['level'] : []);
|
|
380
556
|
let warn = '';
|
|
@@ -392,7 +568,8 @@ export function buildMcpTools(deps) {
|
|
|
392
568
|
if (ignored.length) {
|
|
393
569
|
warn += '\nWARN: ' + ignored.join(' / ') + ' do not apply to the current transport (' + transport + ') and were ignored';
|
|
394
570
|
}
|
|
395
|
-
return 'OK: updated ' + String(cur.serverName) + ' (changed ' + changed.join(', ') + ')' + warn
|
|
571
|
+
return 'OK: updated ' + String(cur.serverName) + ' (changed ' + changed.join(', ') + ')' + warn +
|
|
572
|
+
globalActionNote(deps, exec && exec.agent, 'mcp', 'MCP');
|
|
396
573
|
},
|
|
397
574
|
}));
|
|
398
575
|
}
|