dsh-mcp-status 0.2.0 → 0.2.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/README.md +28 -17
- package/client.js +96 -30
- package/index.js +99 -8
- package/lib/status.js +71 -9
- package/package.json +1 -1
- package/test/status.test.mjs +179 -1
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ An MCP server panel for the DeepSeek Harness Web GUI: it lists every `@deepseek-
|
|
|
23
23
|
| --- | --- |
|
|
24
24
|
| `GET /api/dsh-mcp-status/servers` | 快照:每行的状态、工具数、传输与地址、来源补丁文件、超时与重连策略 |
|
|
25
25
|
| `POST /api/dsh-mcp-status/toggle` | `{ id, enabled }`:改补丁行 → 等热重载 → 返回新状态(超时后主动重排一次) |
|
|
26
|
-
| `POST /api/dsh-mcp-status/retry` | `{ id }
|
|
26
|
+
| `POST /api/dsh-mcp-status/retry` | `{ id }`:真正重新挂载这一行(`dispose` 旧 fiber + `init` 冷启动,重连预算清零),不是等 HMR 碰运气 |
|
|
27
27
|
| `POST /api/dsh-mcp-status/test` | `{ id }`:真握手,返回协议版本 / serverInfo / 工具数 / 失败原因 |
|
|
28
28
|
|
|
29
29
|
写操作要求同源证明,且所有路由都只接受回环来源。
|
|
@@ -40,21 +40,28 @@ An MCP server panel for the DeepSeek Harness Web GUI: it lists every `@deepseek-
|
|
|
40
40
|
|
|
41
41
|
## 状态判定表(每条结论都带依据)
|
|
42
42
|
|
|
43
|
-
状态由 `lib/status.js` 的 `resolveStatus()`
|
|
43
|
+
状态由 `lib/status.js` 的 `resolveStatus()` 纯函数推导。**第一优先是宿主自己的连接状态**
|
|
44
|
+
(`@deepseek-ai/dsh-mcp-client` 导出的 `connectionStatusOf(fiber)`,从 loader 条目的
|
|
45
|
+
`moduleNamespace` 取),探活和工具数只在宿主说「已连接」时做旁证:
|
|
44
46
|
|
|
45
47
|
| 顺序 | 条件 | 状态 | reason |
|
|
46
48
|
| --- | --- | --- | --- |
|
|
47
49
|
| 1 | 行被停用 | 已停用 | `disabled`(用户选择,不是故障) |
|
|
48
50
|
| 2 | loader fiber 失败 | 加载失败 | `fiber-failed` |
|
|
49
|
-
| 3 |
|
|
50
|
-
| 4 |
|
|
51
|
-
| 5 |
|
|
52
|
-
| 6 |
|
|
53
|
-
| 7 |
|
|
54
|
-
| 8 |
|
|
51
|
+
| 3 | 宿主客户端正在首次连接 | 启动中 | `client-connecting` |
|
|
52
|
+
| 4 | 宿主客户端正在重连(第 n/N 次) | 重连中 | `client-reconnecting`(依据里带 n/N) |
|
|
53
|
+
| 5 | 宿主客户端已放弃(连续 10 次失败后工具被注销) | 未连接 | `gave-up` |
|
|
54
|
+
| 6 | 等凭证 / 连接已关闭 / 其它客户端失败 | 未连接 | `waiting-credentials` / `client-closed` / `client-failed` |
|
|
55
|
+
| 7 | 宿主说已连接,但端口拒绝连接,或窗口内刚测失败 | 不可达 | `tcp-refused` / `probe-failed` |
|
|
56
|
+
| 8 | 宿主说已连接,但工具数为 0 | 未连接 | `no-tools` |
|
|
57
|
+
| 9 | 宿主说已连接,且有工具 | 已连接 | `connected` |
|
|
58
|
+
| 10 | 读不到宿主状态(老版本 / 非 mcp-client 行) | 退回观测推导 | `unknown-tools` / `pending` … |
|
|
59
|
+
|
|
60
|
+
第 4、5 条是 0.2.1 的关键修正:以前「重连中」和「已放弃」都被当成绿色——测试连接一成功还会把
|
|
61
|
+
「已连接 + 0 工具」显示成已连接。现在客户端状态优先,成功握手不会压过它。
|
|
55
62
|
|
|
56
63
|
第 8 条的 `no-tools`(界面显示「未连接」)刻意与 `unreachable` 分开:工具数为 0 可能只是这行挂在
|
|
57
|
-
per-agent
|
|
64
|
+
per-agent 作用域、全局注册表看不见,把它当断线会误报也会误拦——但它也不再被算作「已连接」。
|
|
58
65
|
|
|
59
66
|
每行 DTO 带 `reason` 与 `evidence`(fiber / tools / tcp / probe 四个信号,带各自时间戳),
|
|
60
67
|
展开区把依据压成一行——「凭什么绿/红」不再靠猜。
|
|
@@ -67,8 +74,8 @@ per-agent 作用域、全局注册表看不见,把它当断线会误报也会
|
|
|
67
74
|
`- unityMCP (http://127.0.0.1:8080/mcp): unreachable — connect ECONNREFUSED, checked 8s ago.`
|
|
68
75
|
全部恢复后 section 会被注销——健康时 prompt 里不多一个空行。
|
|
69
76
|
- **调用闸门**(`ctx.tools.guard`):`mcp__<server>__*` 的调用在派发前被判为不可用就拒绝,返回可读原因
|
|
70
|
-
(含「去 MCP
|
|
71
|
-
`no-tools`、`disabled` 一律放行——`idle` 不等于断线。
|
|
77
|
+
(含「去 MCP 面板重试」)。拦 `unreachable` / `failed` / `reconnecting`,且只有**证据够新**才会拦:
|
|
78
|
+
快照超过 `2 × refreshMs` 视为过期,`pending`、`no-tools`、`disabled` 一律放行——`idle` 不等于断线。
|
|
72
79
|
|
|
73
80
|
两个消费方都能关:`promptHealth: false` / `guardUnreachable: false`(见下)。
|
|
74
81
|
|
|
@@ -89,9 +96,11 @@ per-agent 作用域、全局注册表看不见,把它当断线会误报也会
|
|
|
89
96
|
## 显示约定
|
|
90
97
|
|
|
91
98
|
- 样式只用 `--dsw-alias-*` 主题令牌,跟随宿主明暗主题;文案走 `ctx.locale`(zh / en)。
|
|
92
|
-
-
|
|
99
|
+
- 状态色:绿=已连接;红=未连接/不可达/加载失败;黄(呼吸)=启动中/重连中;灰=已停用。
|
|
100
|
+
- 顶栏副标题显示的是「状态变化 Ns 前」:面板每 4 s 轮询,但快照里的 `checkedAt` 每次拉取都会刷新,
|
|
101
|
+
所以它不表示新鲜度,只在某一行状态真的变了时计时。
|
|
93
102
|
- 「不可达」= 端口连不上,或最近一次测试失败:徽标立即变红,展开区给出原因;若工具还挂在注册表里,会单独说明那是上一次连接的残留。
|
|
94
|
-
- 行的展开区给出传输、命令/地址、env/header
|
|
103
|
+
- 行的展开区给出传输、命令/地址、env/header **名字**(不显示值)、连接状态、重连策略、调用超时、来源补丁
|
|
95
104
|
文件、条目 id、判定与依据,以及失败原因。
|
|
96
105
|
|
|
97
106
|
## 兼容与依赖
|
|
@@ -125,11 +134,13 @@ node lib/probe.test.mjs # 5 个用例:stdio/http 成功、命令不存在、
|
|
|
125
134
|
|
|
126
135
|
- 停用/启用会改写**当前 profile 的补丁文件**里那一行的 `disabled`;如果该行由其它工具生成(例如同步 MCP 配置的第三方工具),那个工具下次整表重写时可能覆盖本次开关的结果。
|
|
127
136
|
- 面板只读配置、不做新增/编辑;新增与编辑仍在「设置 → 插件 → MCP 服务器配置」。
|
|
128
|
-
- **stdio
|
|
129
|
-
- **闸门可能误拦**:只有「快照新鲜 +
|
|
137
|
+
- **stdio 行没有端口可探**:它们的存活只能靠宿主连接状态 + 工具数;`no-tools` 不算断线,也不会被当成已连接。
|
|
138
|
+
- **闸门可能误拦**:只有「快照新鲜 + 确实不可达 / 正在重连」才拒绝,窗口过期一律放行;不放心就
|
|
130
139
|
`guardUnreachable: false`,退回纯看板行为。
|
|
131
|
-
-
|
|
132
|
-
|
|
140
|
+
- **重试会短暂摘掉这一行的工具**:`dispose` + `init` 是冷启动,重连成功前 `mcp__<server>__*` 不在工具表里,
|
|
141
|
+
这是宿主 mcp-client 自己给出的唯一自救路径(它放弃重连时的提示就是「reload the plugin or restart the Host」)。
|
|
142
|
+
- **宿主不暴露连接状态时退回推导**:0.2.1 起优先读 `connectionStatusOf(fiber)`;拿不到(老版本宿主、非
|
|
143
|
+
mcp-client 行)就退回 fiber / 工具注册表 / TCP / 测试结论四份证据,此时「重连中」无法区分。
|
|
133
144
|
|
|
134
145
|
## License
|
|
135
146
|
|
package/client.js
CHANGED
|
@@ -33,6 +33,7 @@ window.__ModuleLoader__.load({
|
|
|
33
33
|
'panel.emptyHint': '在 设置 → 插件 → MCP 服务器配置 里添加,或把 mcp-client 行写进 profile 补丁。',
|
|
34
34
|
'state.connected': '已连接',
|
|
35
35
|
'state.connecting': '连接中',
|
|
36
|
+
'state.reconnecting': '重连中',
|
|
36
37
|
'state.idle': '未连接',
|
|
37
38
|
'state.unreachable': '未连接(不可达)',
|
|
38
39
|
'state.failed': '加载失败',
|
|
@@ -51,6 +52,7 @@ window.__ModuleLoader__.load({
|
|
|
51
52
|
'action.showConfig': '配置',
|
|
52
53
|
'action.hideConfig': '收起',
|
|
53
54
|
'field.transport': '传输',
|
|
55
|
+
'field.client': '连接状态',
|
|
54
56
|
'field.command': '命令',
|
|
55
57
|
'field.url': '地址',
|
|
56
58
|
'field.env': '环境变量',
|
|
@@ -59,15 +61,27 @@ window.__ModuleLoader__.load({
|
|
|
59
61
|
'field.entry': '条目',
|
|
60
62
|
'field.reason': '判定',
|
|
61
63
|
'field.evidence': '依据',
|
|
62
|
-
'panel.
|
|
64
|
+
'panel.changed': '状态变化 {n}s 前',
|
|
63
65
|
'reason.disabled': '已停用(用户选择,不是故障)',
|
|
64
66
|
'reason.fiber-failed': 'MCP 客户端加载失败',
|
|
65
67
|
'reason.pending': '客户端正在启动',
|
|
68
|
+
'reason.client-connecting': '客户端正在建立连接',
|
|
69
|
+
'reason.client-reconnecting': '客户端正在自动重连',
|
|
70
|
+
'reason.gave-up': '自动重连已放弃(连续失败达到上限,工具已卸载)',
|
|
71
|
+
'reason.client-failed': '客户端连接失败',
|
|
72
|
+
'reason.client-closed': '客户端已关闭',
|
|
73
|
+
'reason.waiting-credentials': '等待凭据',
|
|
66
74
|
'reason.probe-failed': '最近一次连接测试失败',
|
|
67
75
|
'reason.tcp-refused': '端口拒绝连接',
|
|
68
76
|
'reason.no-tools': '没有注册任何工具',
|
|
69
77
|
'reason.connected': '已连接',
|
|
70
78
|
'reason.unknown-tools': '工具表读不到,不下结论',
|
|
79
|
+
'evidence.client': '客户端',
|
|
80
|
+
'evidence.connecting': '连接中',
|
|
81
|
+
'evidence.connected': '已连接',
|
|
82
|
+
'evidence.reconnecting': '重连中',
|
|
83
|
+
'evidence.closed': '已关闭',
|
|
84
|
+
'evidence.waiting-credentials': '等待凭据',
|
|
71
85
|
'evidence.fiber': 'fiber',
|
|
72
86
|
'evidence.tools': '工具',
|
|
73
87
|
'evidence.tcp': 'TCP',
|
|
@@ -84,6 +98,9 @@ window.__ModuleLoader__.load({
|
|
|
84
98
|
'hint.notToggleable': '该服务器由插件包提供,不能在面板里开关',
|
|
85
99
|
'hint.idle': 'MCP 客户端已加载,但没有注册任何工具——通常意味着连接失败。点「测试连接」看原因。',
|
|
86
100
|
'hint.unreachable': '最近一次连接检测失败:下面的错误就是原因。修好后点「重试」重新挂载这一行。',
|
|
101
|
+
'hint.reconnecting': '客户端正在自动重连,工具暂时不可用;连上后面板会自动变绿。',
|
|
102
|
+
'hint.reconnectingN': '客户端正在自动重连(第 {n}/{max} 次),工具暂时不可用;连上后面板会自动变绿。',
|
|
103
|
+
'hint.gaveUp': '自动重连已放弃,工具已卸载——「重试」会重新挂载这一行,重连预算从头算。',
|
|
87
104
|
'hint.staleTools': '工具仍然注册着({n} 个),那是上一次连接成功留下的,不代表现在连着——连接已失效。',
|
|
88
105
|
'hint.failed': '这一行加载失败,展开可看错误信息;「重试」会重新挂载它。',
|
|
89
106
|
'hint.disabled': '已停用:不会连接,也不占工具表。',
|
|
@@ -105,6 +122,7 @@ window.__ModuleLoader__.load({
|
|
|
105
122
|
'panel.emptyHint': 'Add one under Settings → Plugins → MCP server configuration, or write an mcp-client row into the profile patch.',
|
|
106
123
|
'state.connected': 'Connected',
|
|
107
124
|
'state.connecting': 'Connecting',
|
|
125
|
+
'state.reconnecting': 'Reconnecting',
|
|
108
126
|
'state.idle': 'Not connected',
|
|
109
127
|
'state.unreachable': 'Unreachable',
|
|
110
128
|
'state.failed': 'Failed',
|
|
@@ -123,6 +141,7 @@ window.__ModuleLoader__.load({
|
|
|
123
141
|
'action.showConfig': 'Config',
|
|
124
142
|
'action.hideConfig': 'Hide',
|
|
125
143
|
'field.transport': 'Transport',
|
|
144
|
+
'field.client': 'Connection',
|
|
126
145
|
'field.command': 'Command',
|
|
127
146
|
'field.url': 'URL',
|
|
128
147
|
'field.env': 'Environment',
|
|
@@ -131,15 +150,27 @@ window.__ModuleLoader__.load({
|
|
|
131
150
|
'field.entry': 'Entry',
|
|
132
151
|
'field.reason': 'Verdict',
|
|
133
152
|
'field.evidence': 'Evidence',
|
|
134
|
-
'panel.
|
|
153
|
+
'panel.changed': 'changed {n}s ago',
|
|
135
154
|
'reason.disabled': 'disabled by choice — not a fault',
|
|
136
155
|
'reason.fiber-failed': 'the MCP client failed to load',
|
|
137
156
|
'reason.pending': 'the MCP client is starting',
|
|
157
|
+
'reason.client-connecting': 'the MCP client is connecting',
|
|
158
|
+
'reason.client-reconnecting': 'the MCP client is retrying the connection',
|
|
159
|
+
'reason.gave-up': 'reconnect gave up (attempt limit reached, tools unregistered)',
|
|
160
|
+
'reason.client-failed': 'the MCP connection failed',
|
|
161
|
+
'reason.client-closed': 'the MCP client is closed',
|
|
162
|
+
'reason.waiting-credentials': 'waiting for credentials',
|
|
138
163
|
'reason.probe-failed': 'the last connection test failed',
|
|
139
164
|
'reason.tcp-refused': 'the port refuses connections',
|
|
140
165
|
'reason.no-tools': 'no tools registered',
|
|
141
166
|
'reason.connected': 'connected',
|
|
142
167
|
'reason.unknown-tools': 'tool registry unreadable — no verdict',
|
|
168
|
+
'evidence.client': 'client',
|
|
169
|
+
'evidence.connecting': 'connecting',
|
|
170
|
+
'evidence.connected': 'connected',
|
|
171
|
+
'evidence.reconnecting': 'reconnecting',
|
|
172
|
+
'evidence.closed': 'closed',
|
|
173
|
+
'evidence.waiting-credentials': 'waiting credentials',
|
|
143
174
|
'evidence.fiber': 'fiber',
|
|
144
175
|
'evidence.tools': 'tools',
|
|
145
176
|
'evidence.tcp': 'TCP',
|
|
@@ -156,6 +187,9 @@ window.__ModuleLoader__.load({
|
|
|
156
187
|
'hint.notToggleable': 'Provided by a plugin package; it cannot be switched here',
|
|
157
188
|
'hint.idle': 'The MCP client is loaded but registered no tools — usually a failed connection. Test it to see why.',
|
|
158
189
|
'hint.unreachable': 'The latest connection check failed; the error below says why. Fix it, then use Reconnect to remount the row.',
|
|
190
|
+
'hint.reconnecting': 'The MCP client is retrying the connection; tools are unavailable meanwhile. The dot turns green once it reconnects.',
|
|
191
|
+
'hint.reconnectingN': 'The MCP client is retrying the connection (attempt {n} of {max}); tools are unavailable meanwhile.',
|
|
192
|
+
'hint.gaveUp': 'Reconnecting gave up and the tools were unregistered — Reconnect remounts just this row with a fresh attempt budget.',
|
|
159
193
|
'hint.staleTools': '{n} tools are still registered from an earlier successful connection — that no longer means the server is reachable.',
|
|
160
194
|
'hint.failed': 'This row failed to load. Expand it for the error; Reconnect remounts it.',
|
|
161
195
|
'hint.disabled': 'Disabled: no connection is attempted and no tools are registered.',
|
|
@@ -200,7 +234,7 @@ window.__ModuleLoader__.load({
|
|
|
200
234
|
.mcpPanel-dot[data-state=connected]{background:var(--dsw-alias-state-success-primary)}
|
|
201
235
|
.mcpPanel-dot[data-state=idle],.mcpPanel-dot[data-state=unreachable]{background:var(--dsw-alias-state-error-primary)}
|
|
202
236
|
.mcpPanel-dot[data-state=failed]{background:var(--dsw-alias-state-error-primary)}
|
|
203
|
-
.mcpPanel-dot[data-state=connecting]{background:var(--dsw-alias-state-warn-primary);animation:mcpPanel-pulse 1.2s ease-in-out infinite}
|
|
237
|
+
.mcpPanel-dot[data-state=connecting],.mcpPanel-dot[data-state=reconnecting]{background:var(--dsw-alias-state-warn-primary);animation:mcpPanel-pulse 1.2s ease-in-out infinite}
|
|
204
238
|
@keyframes mcpPanel-pulse{0%,100%{opacity:1}50%{opacity:.35}}
|
|
205
239
|
.mcpPanel-id{display:flex;flex-direction:column;gap:2px;min-width:0;flex:1}
|
|
206
240
|
.mcpPanel-nameLine{display:flex;align-items:baseline;gap:8px;min-width:0}
|
|
@@ -208,6 +242,7 @@ window.__ModuleLoader__.load({
|
|
|
208
242
|
.mcpPanel-state{font-size:11.5px;color:var(--dsw-alias-label-secondary);white-space:nowrap}
|
|
209
243
|
.mcpPanel-state[data-state=connected]{color:var(--dsw-alias-state-success-primary)}
|
|
210
244
|
.mcpPanel-state[data-state=idle],.mcpPanel-state[data-state=failed],.mcpPanel-state[data-state=unreachable]{color:var(--dsw-alias-state-error-primary)}
|
|
245
|
+
.mcpPanel-state[data-state=reconnecting]{color:var(--dsw-alias-state-warn-primary)}
|
|
211
246
|
.mcpPanel-target{font-size:11.5px;line-height:16px;color:var(--dsw-alias-label-secondary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-family:var(--dsw-font-family-code,ui-monospace,SFMono-Regular,Menlo,monospace)}
|
|
212
247
|
.mcpPanel-tools{font-size:11px;color:var(--dsw-alias-label-secondary);border:.5px solid var(--dsw-alias-border-l1);border-radius:6px;padding:1px 6px;white-space:nowrap;font-variant-numeric:tabular-nums}
|
|
213
248
|
.mcpPanel-link{appearance:none;border:0;background:0 0;padding:0 2px;font:inherit;font-size:11.5px;color:var(--dsw-alias-brand-primary);cursor:pointer;white-space:nowrap}
|
|
@@ -349,25 +384,40 @@ window.__ModuleLoader__.load({
|
|
|
349
384
|
return text === key ? (server.reason ?? '') : text;
|
|
350
385
|
}
|
|
351
386
|
|
|
387
|
+
/** 一条 evidence 的取值文案:code → 本地化,未知 code 原样显示(宿主新增状态不会变成空白)。 */
|
|
388
|
+
function evidenceValue(t, item) {
|
|
389
|
+
if (item.signal === 'tools') {
|
|
390
|
+
return item.value === null || item.value === undefined ? '?' : String(item.value);
|
|
391
|
+
}
|
|
392
|
+
if (item.signal === 'probe') {
|
|
393
|
+
return item.value === 'ok' ? t('evidence.ok') : (item.detail ?? t('evidence.failed'));
|
|
394
|
+
}
|
|
395
|
+
const key = `evidence.${item.value}`;
|
|
396
|
+
const text = t(key);
|
|
397
|
+
const base = text === key ? String(item.value) : text;
|
|
398
|
+
return item.detail ? `${base} ${item.detail}` : base;
|
|
399
|
+
}
|
|
400
|
+
|
|
352
401
|
/** 依据摘要:把 resolver 的 evidence 压成一行,带时间戳的项标注多久以前。 */
|
|
353
402
|
function describeEvidence(t, server) {
|
|
354
403
|
const now = Date.now();
|
|
355
|
-
|
|
356
|
-
for (const item of server.evidence ?? []) {
|
|
404
|
+
return (server.evidence ?? []).map((item) => {
|
|
357
405
|
const label = t(`evidence.${item.signal}`);
|
|
358
|
-
if (item.signal === 'tools') {
|
|
359
|
-
parts.push(`${label} ${item.value === null || item.value === undefined ? '?' : item.value}`);
|
|
360
|
-
continue;
|
|
361
|
-
}
|
|
362
|
-
const value = item.signal === 'fiber'
|
|
363
|
-
? t(`evidence.${item.value}`)
|
|
364
|
-
: item.signal === 'tcp'
|
|
365
|
-
? t(`evidence.${item.value}`)
|
|
366
|
-
: item.value === 'ok' ? t('evidence.ok') : (item.detail ?? t('evidence.failed'));
|
|
367
406
|
const age = typeof item.at === 'number' ? ` (${Math.max(0, Math.round((now - item.at) / 1000))}s)` : '';
|
|
368
|
-
|
|
407
|
+
return `${label} ${evidenceValue(t, item)}${age}`;
|
|
408
|
+
}).join(' · ');
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/** 宿主连接状态的一句话(重连带次数,失败带 reason code)。 */
|
|
412
|
+
function connectionLabel(t, connection) {
|
|
413
|
+
const key = `evidence.${connection.state}`;
|
|
414
|
+
const text = t(key);
|
|
415
|
+
const base = text === key ? String(connection.state) : text;
|
|
416
|
+
if (connection.state === 'reconnecting' && typeof connection.attempt === 'number') {
|
|
417
|
+
return `${base} ${connection.attempt}/${connection.maxAttempts ?? '?'}`;
|
|
369
418
|
}
|
|
370
|
-
|
|
419
|
+
if (connection.state === 'failed' && connection.reason) return `${base}(${connection.reason})`;
|
|
420
|
+
return base;
|
|
371
421
|
}
|
|
372
422
|
|
|
373
423
|
function ServerCard({ server, t, busy, onToggle, onTest, onRetry, expanded, onExpand }) {
|
|
@@ -378,21 +428,29 @@ window.__ModuleLoader__.load({
|
|
|
378
428
|
const testBusy = busy?.kind === 'test';
|
|
379
429
|
const retryBusy = busy?.kind === 'retry';
|
|
380
430
|
const testResult = busy?.result;
|
|
431
|
+
const connection = server.connection ?? undefined;
|
|
381
432
|
|
|
382
433
|
const hint = state === 'idle' ? t('hint.idle')
|
|
383
|
-
: state === '
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
434
|
+
: state === 'reconnecting'
|
|
435
|
+
? (typeof connection?.attempt === 'number'
|
|
436
|
+
? t('hint.reconnectingN', { n: connection.attempt, max: connection.maxAttempts ?? '?' })
|
|
437
|
+
: t('hint.reconnecting'))
|
|
438
|
+
: state === 'unreachable' ? t('hint.unreachable')
|
|
439
|
+
: state === 'failed' && server.reason === 'gave-up' ? t('hint.gaveUp')
|
|
440
|
+
: state === 'failed' ? t('hint.failed')
|
|
441
|
+
: state === 'disabled' ? t('hint.disabled')
|
|
442
|
+
: state === 'connecting' ? t('hint.pending')
|
|
443
|
+
: null;
|
|
444
|
+
// 连接已不可用、但工具还留在注册表里:那是上一次连接成功留下的残留,必须说清楚。
|
|
445
|
+
const staleTools = (state === 'unreachable' || state === 'reconnecting' || state === 'failed')
|
|
446
|
+
&& (server.toolCount ?? 0) > 0
|
|
390
447
|
? t('hint.staleTools', { n: server.toolCount })
|
|
391
448
|
: null;
|
|
392
449
|
|
|
393
450
|
const fields = [
|
|
394
451
|
[t('field.transport'), transportLabel(server.transport) || '—'],
|
|
395
452
|
];
|
|
453
|
+
if (connection) fields.push([t('field.client'), connectionLabel(t, connection)]);
|
|
396
454
|
if (server.transport === 'stdio') {
|
|
397
455
|
fields.push([t('field.command'), server.detail.command ?? '—']);
|
|
398
456
|
if (server.detail.args?.length) fields.push(['args', server.detail.args.join(' ')]);
|
|
@@ -461,7 +519,7 @@ window.__ModuleLoader__.load({
|
|
|
461
519
|
{ className: 'mcpPanel-nameLine' },
|
|
462
520
|
h('span', { className: 'mcpPanel-name', title: server.serverName }, server.serverName),
|
|
463
521
|
h('span', { className: 'mcpPanel-state', 'data-state': state }, stateLabel(t, state)),
|
|
464
|
-
state === 'connected' || state === 'idle' || state === 'unreachable'
|
|
522
|
+
state === 'connected' || state === 'idle' || state === 'unreachable' || state === 'reconnecting'
|
|
465
523
|
? h(
|
|
466
524
|
'span',
|
|
467
525
|
{ className: 'mcpPanel-tools' },
|
|
@@ -529,13 +587,23 @@ window.__ModuleLoader__.load({
|
|
|
529
587
|
const [busy, setBusy] = useState({});
|
|
530
588
|
const [expanded, setExpanded] = useState({});
|
|
531
589
|
const [refreshing, setRefreshing] = useState(false);
|
|
590
|
+
const [changedAt, setChangedAt] = useState(null);
|
|
591
|
+
const signatureRef = useRef('');
|
|
532
592
|
const mounted = useRef(true);
|
|
533
593
|
|
|
534
594
|
const load = useCallback(async () => {
|
|
535
595
|
try {
|
|
536
596
|
const payload = await requestJson('/servers', { method: 'GET' });
|
|
537
597
|
if (!mounted.current) return;
|
|
538
|
-
|
|
598
|
+
const servers = payload.servers ?? [];
|
|
599
|
+
// 顶栏计时的是「上次状态变化」:只有某行的 state/reason 真的变了才重新计时。
|
|
600
|
+
// 用采快照的时间会是个自指量(每次请求都刚采过,永远是 0s),没有信息量。
|
|
601
|
+
const signature = servers
|
|
602
|
+
.map((server) => `${server.id}:${server.state}:${server.reason}`)
|
|
603
|
+
.join('|');
|
|
604
|
+
if (signatureRef.current !== '' && signatureRef.current !== signature) setChangedAt(Date.now());
|
|
605
|
+
signatureRef.current = signature;
|
|
606
|
+
setSnapshot({ loading: false, servers, error: null, checkedAt: payload.checkedAt });
|
|
539
607
|
} catch (error) {
|
|
540
608
|
if (!mounted.current) return;
|
|
541
609
|
setSnapshot((previous) => ({ ...previous, loading: false, error: error?.message ?? String(error) }));
|
|
@@ -658,11 +726,9 @@ window.__ModuleLoader__.load({
|
|
|
658
726
|
h('div', { className: 'mcpPanel-title' }, t('panel.title')),
|
|
659
727
|
h('div', { className: 'mcpPanel-sub' }, snapshot.loading
|
|
660
728
|
? '…'
|
|
661
|
-
: `${snapshot.servers.length} MCP · ${t('panel.
|
|
662
|
-
n:
|
|
663
|
-
|
|
664
|
-
: Math.max(0, Math.round((Date.now() - snapshot.checkedAt) / 1000)),
|
|
665
|
-
})}`),
|
|
729
|
+
: `${snapshot.servers.length} MCP${changedAt === null ? '' : ` · ${t('panel.changed', {
|
|
730
|
+
n: Math.max(0, Math.round((Date.now() - changedAt) / 1000)),
|
|
731
|
+
})}`}`),
|
|
666
732
|
),
|
|
667
733
|
h(
|
|
668
734
|
'div',
|
package/index.js
CHANGED
|
@@ -98,6 +98,26 @@ function findRowBlock(lines, id) {
|
|
|
98
98
|
return undefined;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
/**
|
|
102
|
+
* 补丁文件里这一行的 disabled 状态。
|
|
103
|
+
* @returns true / false;返回 undefined 表示这些补丁文件里都没有这一行。
|
|
104
|
+
*/
|
|
105
|
+
async function patchRowDisabled(ctx, id) {
|
|
106
|
+
for (const file of candidatePatchFiles(ctx)) {
|
|
107
|
+
let text;
|
|
108
|
+
try {
|
|
109
|
+
text = await readFile(file.path, 'utf8');
|
|
110
|
+
} catch {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const lines = text.split(/\r?\n/);
|
|
114
|
+
const block = findRowBlock(lines, id);
|
|
115
|
+
if (block === undefined) continue;
|
|
116
|
+
return block.disabledIndex !== undefined;
|
|
117
|
+
}
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
|
|
101
121
|
/** 原子写:同目录临时文件 + rename,保留原文件权限位。 */
|
|
102
122
|
async function writeAtomic(file, content) {
|
|
103
123
|
let mode;
|
|
@@ -297,9 +317,11 @@ async function collect(ctx, settings, { withSources = true } = {}) {
|
|
|
297
317
|
const summary = summarize(config);
|
|
298
318
|
const reach = reachable[index];
|
|
299
319
|
const probe = storedProbe(entry.options.id);
|
|
320
|
+
const connection = connectionOf(entry);
|
|
300
321
|
const status = resolveStatus({
|
|
301
322
|
disabled: Boolean(entry.disabled),
|
|
302
323
|
fiberState: entry.fiber?.state ?? null,
|
|
324
|
+
connection,
|
|
303
325
|
toolCount: count === undefined ? null : count,
|
|
304
326
|
reachable: reach === null ? null : reach.ok,
|
|
305
327
|
reachableAt: reach === null ? null : reach.at,
|
|
@@ -326,6 +348,7 @@ async function collect(ctx, settings, { withSources = true } = {}) {
|
|
|
326
348
|
evidence: status.evidence,
|
|
327
349
|
disabled: Boolean(entry.disabled),
|
|
328
350
|
fiberState: entry.fiber?.state ?? null,
|
|
351
|
+
connection: connection ?? null,
|
|
329
352
|
toolCount: count === undefined ? null : count,
|
|
330
353
|
reachable: reach === null ? null : reach.ok,
|
|
331
354
|
reachDetail: reach === null ? null : reach.detail,
|
|
@@ -366,6 +389,35 @@ function errorOf(entry) {
|
|
|
366
389
|
return message === '' ? 'MCP 客户端加载失败' : message;
|
|
367
390
|
}
|
|
368
391
|
|
|
392
|
+
/**
|
|
393
|
+
* 读宿主 `dsh-mcp-client` 自己的连接状态——它是唯一权威的「到底连上没有」。
|
|
394
|
+
*
|
|
395
|
+
* `connectionStatusOf(fiber)` 返回一个 status cell,`current()` 给出
|
|
396
|
+
* connecting / connected / reconnecting(attempt,maxAttempts) / failed(reason) /
|
|
397
|
+
* closed / waiting-credentials。拿不到(旧宿主、条目还没 import)就返回 undefined,
|
|
398
|
+
* 由 resolveStatus 退回观测值推导。宿主状态存在时,我们自己的探测只是旁证。
|
|
399
|
+
*/
|
|
400
|
+
function connectionOf(entry) {
|
|
401
|
+
const read = entry?.moduleNamespace?.connectionStatusOf;
|
|
402
|
+
if (typeof read !== 'function' || entry.fiber === undefined) return undefined;
|
|
403
|
+
try {
|
|
404
|
+
const cell = read(entry.fiber);
|
|
405
|
+
const status = typeof cell?.current === 'function' ? cell.current() : undefined;
|
|
406
|
+
if (status === undefined || status === null || typeof status.state !== 'string') return undefined;
|
|
407
|
+
return {
|
|
408
|
+
state: status.state,
|
|
409
|
+
reason: status.reason ?? null,
|
|
410
|
+
attempt: status.attempt ?? null,
|
|
411
|
+
maxAttempts: status.maxAttempts ?? null,
|
|
412
|
+
lastError: typeof status.lastError === 'string'
|
|
413
|
+
? status.lastError
|
|
414
|
+
: status.lastError?.message ?? null,
|
|
415
|
+
};
|
|
416
|
+
} catch {
|
|
417
|
+
return undefined;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
369
421
|
/**
|
|
370
422
|
* 状态缓存:后台按 refreshMs 刷新,给 system prompt 与 guard 用;
|
|
371
423
|
* 面板请求 `refresh(true)` 时当场重采,保持它原有的新鲜度。
|
|
@@ -423,7 +475,34 @@ async function waitForState(ctx, config, tracker, id, accept, timeoutMs) {
|
|
|
423
475
|
return last;
|
|
424
476
|
}
|
|
425
477
|
|
|
426
|
-
/**
|
|
478
|
+
/**
|
|
479
|
+
* 重连 = 真的把这一行重新挂载:dispose 旧 fiber,再走一次冷启动(`init`)。
|
|
480
|
+
*
|
|
481
|
+
* HMR 的 `reconcileProfile` 只在「源文件真的变了」时才重挂条目,配置没变时什么都不做
|
|
482
|
+
* ——所以不能拿它当重试(只会白等 startupWaitMs);而 `dsh-mcp-client` 放弃重连后自己的
|
|
483
|
+
* 提示就是「reload the plugin or restart the Host」,这里做的正是前者,且只影响这一行。
|
|
484
|
+
*/
|
|
485
|
+
async function restartEntry(ctx, id) {
|
|
486
|
+
const loader = ctx.get('loader');
|
|
487
|
+
const entry = loader === undefined || typeof loader.entries !== 'function'
|
|
488
|
+
? undefined
|
|
489
|
+
: [...loader.entries()].find((item) => item?.options?.id === id);
|
|
490
|
+
if (entry === undefined) throw new Error(`未找到 MCP 服务器条目:${id}`);
|
|
491
|
+
// 用户自己在补丁文件里停用的行,重试不该把它强行拉起来。
|
|
492
|
+
if (await patchRowDisabled(ctx, id)) {
|
|
493
|
+
throw new Error('这一行在补丁文件里是停用状态:先打开开关再重试');
|
|
494
|
+
}
|
|
495
|
+
// 宿主没有可复用的 init/dispose 契约时返回 false,让调用方退回 HMR 重排。
|
|
496
|
+
if (typeof entry.init !== 'function' || entry.fiber === undefined) return false;
|
|
497
|
+
await entry.fiber.dispose();
|
|
498
|
+
// 加载器会把「不是它自己卸载的」条目标记成 disabled,避免立刻自动重挂;
|
|
499
|
+
// 这里要的恰恰是重挂,所以先把标记清掉,否则条目会一直显示为已停用。
|
|
500
|
+
if (entry.options !== undefined) entry.options.disabled = false;
|
|
501
|
+
await entry.init();
|
|
502
|
+
return true;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/** 兜底:补丁监听没接上时用它重排一次(只在源文件变化时才真的重挂)。 */
|
|
427
506
|
async function forceReload(ctx, id) {
|
|
428
507
|
const hmr = ctx.get('hmr');
|
|
429
508
|
if (hmr === undefined || typeof hmr.reconcileProfile !== 'function') return false;
|
|
@@ -477,20 +556,32 @@ async function reconnect(ctx, config, tracker, id) {
|
|
|
477
556
|
const before = await tracker.refresh(true);
|
|
478
557
|
const row = before.servers.find((server) => server.id === id);
|
|
479
558
|
if (row === undefined) throw new Error(`未找到 MCP 服务器条目:${id}`);
|
|
559
|
+
// 重新挂载就是一次新连接:旧的测试结论不再适用。
|
|
480
560
|
probeResults.delete(id);
|
|
481
561
|
reachCache.clear();
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
let
|
|
485
|
-
|
|
562
|
+
|
|
563
|
+
const accept = (server) => server.state === 'connected';
|
|
564
|
+
let attempts = 0;
|
|
565
|
+
let current;
|
|
566
|
+
let restarted = false;
|
|
567
|
+
while (attempts <= RETRY_ROUNDS) {
|
|
486
568
|
attempts += 1;
|
|
487
|
-
|
|
488
|
-
|
|
569
|
+
// restartEntry 只在「真的没法重挂」时返回 false;它抛错是用户该看到的原因
|
|
570
|
+
// (行在补丁文件里被停用、条目找不到、dispose/init 失败),直接冒到路由。
|
|
571
|
+
restarted = await restartEntry(ctx, id);
|
|
572
|
+
if (!restarted) restarted = await forceReload(ctx, id);
|
|
573
|
+
if (!restarted) break;
|
|
574
|
+
// 重挂本身很快(握手几百毫秒),先用短窗口等;同一次请求里第二轮才等满 startupWaitMs。
|
|
575
|
+
const window = attempts === 1 ? Math.min(3000, config.startupWaitMs) : config.startupWaitMs;
|
|
576
|
+
current = await waitForState(ctx, config, tracker, id, accept, window);
|
|
577
|
+
if (current !== undefined && accept(current)) break;
|
|
489
578
|
}
|
|
579
|
+
|
|
490
580
|
return {
|
|
491
581
|
state: current?.state ?? 'unknown',
|
|
492
|
-
settled: current
|
|
582
|
+
settled: current !== undefined && accept(current),
|
|
493
583
|
attempts,
|
|
584
|
+
restarted,
|
|
494
585
|
server: current ?? null,
|
|
495
586
|
};
|
|
496
587
|
}
|
package/lib/status.js
CHANGED
|
@@ -55,29 +55,45 @@ export function normalizeConfig(raw) {
|
|
|
55
55
|
return config;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/** 把宿主的连接状态压成一条 evidence(`3/10` 这类计数放在 detail 里)。 */
|
|
59
|
+
function connectionEvidence(connection) {
|
|
60
|
+
const detail = connection.state === 'reconnecting'
|
|
61
|
+
? `${connection.attempt ?? '?'}/${connection.maxAttempts ?? '?'}`
|
|
62
|
+
: connection.state === 'failed' ? connection.reason ?? null : null;
|
|
63
|
+
return { signal: 'client', value: connection.state, at: null, detail };
|
|
64
|
+
}
|
|
65
|
+
|
|
58
66
|
/**
|
|
59
67
|
* 判定一行 MCP 服务器的状态。
|
|
60
68
|
*
|
|
61
|
-
*
|
|
69
|
+
* 拿得到宿主的连接状态(`connection`,来自 `dsh-mcp-client` 自己的状态机)时,它有权
|
|
70
|
+
* 决定「连着 / 正在重连 / 已放弃 / 已关闭」——我们的探测只是旁证,**绝不能**把宿主已经
|
|
71
|
+
* 放弃的连接说成「已连接」(那正是假绿 bug 的形态)。拿不到时(旧宿主、刚启动)
|
|
72
|
+
* 退回纯观测值推导。
|
|
73
|
+
*
|
|
74
|
+
* 优先级:
|
|
62
75
|
* 1. 停用 → disabled(用户的意愿,不是故障)
|
|
63
|
-
* 2. fiber 失败 → failed
|
|
64
|
-
* 3.
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
76
|
+
* 2. fiber 失败 → failed;fiber 未就绪 → pending
|
|
77
|
+
* 3. 宿主 connecting → pending;reconnecting → reconnecting;
|
|
78
|
+
* failed(gave-up) → failed;closed / waiting-credentials → failed
|
|
79
|
+
* 4. 宿主 connected 再复核旁证:「测试连接」失败或端口拒绝 → unreachable;
|
|
80
|
+
* 0 工具 → idle;否则 connected
|
|
81
|
+
* 5. 无宿主状态(旧路径):「测试连接」失败且(端口不通 或 结论够新)→ unreachable;
|
|
82
|
+
* 端口拒绝 → unreachable;测试成功 → connected;工具表读不到 → connected;
|
|
83
|
+
* 有工具 → connected;没有工具 → idle
|
|
70
84
|
*
|
|
71
85
|
* `idle` 刻意与 `unreachable` 区分:工具数为 0 有可能只是这行挂在 per-agent 作用域
|
|
72
86
|
* (全局注册表看不到),把它当断线会误拦、误报。
|
|
73
87
|
*
|
|
74
88
|
* @param {object} input 观测值
|
|
89
|
+
* @param {object} [input.connection] 宿主连接状态 {state, reason, attempt, maxAttempts, lastError}
|
|
75
90
|
* @returns {{state: string, reason: string, evidence: Array<object>}}
|
|
76
91
|
*/
|
|
77
92
|
export function resolveStatus(input) {
|
|
78
93
|
const {
|
|
79
94
|
disabled = false,
|
|
80
95
|
fiberState = null,
|
|
96
|
+
connection, // { state, reason?, attempt?, maxAttempts? } | undefined
|
|
81
97
|
toolCount, // number | null | undefined(undefined/null = 读不到注册表)
|
|
82
98
|
reachable = null, // boolean | null(stdio 行恒为 null)
|
|
83
99
|
reachableAt = null,
|
|
@@ -86,6 +102,9 @@ export function resolveStatus(input) {
|
|
|
86
102
|
now = Date.now(),
|
|
87
103
|
probeAssertMs = DEFAULT_CONFIG.probeAssertMs,
|
|
88
104
|
} = input;
|
|
105
|
+
const hostState = connection !== undefined && connection !== null && typeof connection.state === 'string'
|
|
106
|
+
? connection.state
|
|
107
|
+
: undefined;
|
|
89
108
|
|
|
90
109
|
const evidence = [];
|
|
91
110
|
const fiberValue = fiberState === FIBER_ACTIVE
|
|
@@ -99,11 +118,45 @@ export function resolveStatus(input) {
|
|
|
99
118
|
if (probe !== undefined) {
|
|
100
119
|
evidence.push({ signal: 'probe', value: probe.ok ? 'ok' : 'failed', at: probe.at, detail: probe.error ?? null });
|
|
101
120
|
}
|
|
121
|
+
if (hostState !== undefined) evidence.push(connectionEvidence(connection));
|
|
102
122
|
|
|
103
123
|
if (disabled) return { state: 'disabled', reason: 'disabled', evidence };
|
|
104
124
|
if (fiberState === FIBER_FAILED) return { state: 'failed', reason: 'fiber-failed', evidence };
|
|
105
125
|
if (fiberState !== FIBER_ACTIVE) return { state: 'pending', reason: 'pending', evidence };
|
|
106
126
|
|
|
127
|
+
if (hostState !== undefined) {
|
|
128
|
+
switch (hostState) {
|
|
129
|
+
case 'connecting':
|
|
130
|
+
return { state: 'pending', reason: 'client-connecting', evidence };
|
|
131
|
+
case 'reconnecting':
|
|
132
|
+
return { state: 'reconnecting', reason: 'client-reconnecting', evidence };
|
|
133
|
+
case 'waiting-credentials':
|
|
134
|
+
return { state: 'failed', reason: 'waiting-credentials', evidence };
|
|
135
|
+
case 'closed':
|
|
136
|
+
return { state: 'failed', reason: 'client-closed', evidence };
|
|
137
|
+
case 'failed':
|
|
138
|
+
return {
|
|
139
|
+
state: 'failed',
|
|
140
|
+
reason: connection.reason === 'gave-up' ? 'gave-up' : 'client-failed',
|
|
141
|
+
evidence,
|
|
142
|
+
};
|
|
143
|
+
case 'connected':
|
|
144
|
+
break;
|
|
145
|
+
default:
|
|
146
|
+
// 未知取值:宿主比我们新,退回观测值推导,不硬判。
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
if (hostState === 'connected') {
|
|
150
|
+
// 宿主说连着,但「测试连接」失败 / 端口拒绝仍然算不可达:那是更具体的证据。
|
|
151
|
+
const probeDisagrees = probe !== undefined && probe.ok === false;
|
|
152
|
+
const asserted = probeDisagrees && (reachable !== true || now - (probe.at ?? 0) < probeAssertMs);
|
|
153
|
+
if (asserted) return { state: 'unreachable', reason: 'probe-failed', evidence };
|
|
154
|
+
if (reachable === false) return { state: 'unreachable', reason: 'tcp-refused', evidence };
|
|
155
|
+
if (toolCount === 0) return { state: 'idle', reason: 'no-tools', evidence };
|
|
156
|
+
return { state: 'connected', reason: 'connected', evidence };
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
107
160
|
const probeFailed = probe !== undefined && probe.ok === false;
|
|
108
161
|
const probeAsserted = probeFailed && (reachable !== true || now - (probe.at ?? 0) < probeAssertMs);
|
|
109
162
|
if (probeAsserted) return { state: 'unreachable', reason: 'probe-failed', evidence };
|
|
@@ -141,10 +194,18 @@ export function decideGuard({ toolName, row, snapshotAt, now = Date.now(), confi
|
|
|
141
194
|
if (config.guardUnreachable === false) return undefined;
|
|
142
195
|
if (row === undefined || row === null) return undefined;
|
|
143
196
|
// 只拦「有证据的不可用」:pending/connecting 只是还没起来,可能下一秒就连上。
|
|
144
|
-
|
|
197
|
+
const guarded = row.state === 'unreachable' || row.state === 'failed' || row.state === 'reconnecting';
|
|
198
|
+
if (!guarded) return undefined;
|
|
145
199
|
if (now - snapshotAt > config.refreshMs * 2) return undefined;
|
|
146
200
|
|
|
201
|
+
const connection = row.connection ?? undefined;
|
|
147
202
|
const detail = row.probe?.error
|
|
203
|
+
?? (connection?.state === 'reconnecting'
|
|
204
|
+
? `the MCP client is reconnecting (attempt ${connection.attempt ?? '?'} of ${connection.maxAttempts ?? '?'})`
|
|
205
|
+
: null)
|
|
206
|
+
?? (row.reason === 'gave-up' && connection !== undefined
|
|
207
|
+
? `the MCP client gave up after ${connection.maxAttempts ?? '?'} failed reconnect attempts`
|
|
208
|
+
: null)
|
|
148
209
|
?? (row.reachDetail === 'timeout' ? `TCP connect to ${row.target} timed out` : null)
|
|
149
210
|
?? (row.reachDetail === 'refused' ? `TCP connect to ${row.target} refused` : null)
|
|
150
211
|
?? (row.state === 'failed' ? 'the MCP client failed to load' : 'not connected');
|
|
@@ -164,6 +225,7 @@ export function buildHealthText(snapshot, { now = Date.now(), maxRows = 6, maxCh
|
|
|
164
225
|
? ''
|
|
165
226
|
: `, checked ${Math.max(0, Math.round((now - row.checkedAt) / 1000))}s ago`;
|
|
166
227
|
const detail = row.probe?.error
|
|
228
|
+
?? (row.reason === 'gave-up' ? 'reconnect gave up — tools unregistered' : null)
|
|
167
229
|
?? (row.reachDetail === 'refused' ? 'TCP connect refused' : row.reachDetail === 'timeout' ? 'TCP connect timed out' : row.state);
|
|
168
230
|
return `- ${row.serverName} (${row.target || 'unknown target'}): ${row.state} — ${detail}${age}.`;
|
|
169
231
|
});
|
package/package.json
CHANGED
package/test/status.test.mjs
CHANGED
|
@@ -198,7 +198,134 @@ const cases = [
|
|
|
198
198
|
});
|
|
199
199
|
}],
|
|
200
200
|
|
|
201
|
-
//
|
|
201
|
+
// ------------------------------------------------- host connection status
|
|
202
|
+
|
|
203
|
+
['resolveStatus: host connecting → pending/client-connecting', () => {
|
|
204
|
+
const result = resolveStatus({
|
|
205
|
+
fiberState: FIBER_ACTIVE,
|
|
206
|
+
connection: { state: 'connecting' },
|
|
207
|
+
toolCount: 0,
|
|
208
|
+
now: NOW,
|
|
209
|
+
});
|
|
210
|
+
assert.equal(result.state, 'pending');
|
|
211
|
+
assert.equal(result.reason, 'client-connecting');
|
|
212
|
+
}],
|
|
213
|
+
|
|
214
|
+
['resolveStatus: host reconnecting → reconnecting + attempt in evidence', () => {
|
|
215
|
+
const result = resolveStatus({
|
|
216
|
+
fiberState: FIBER_ACTIVE,
|
|
217
|
+
connection: { state: 'reconnecting', attempt: 3, maxAttempts: 10 },
|
|
218
|
+
toolCount: 0,
|
|
219
|
+
now: NOW,
|
|
220
|
+
});
|
|
221
|
+
assert.equal(result.state, 'reconnecting');
|
|
222
|
+
assert.equal(result.reason, 'client-reconnecting');
|
|
223
|
+
assert.deepEqual(result.evidence.at(-1), {
|
|
224
|
+
signal: 'client',
|
|
225
|
+
value: 'reconnecting',
|
|
226
|
+
at: null,
|
|
227
|
+
detail: '3/10',
|
|
228
|
+
});
|
|
229
|
+
}],
|
|
230
|
+
|
|
231
|
+
['resolveStatus: host gave up wins over a successful probe (no more fake green)', () => {
|
|
232
|
+
const result = resolveStatus({
|
|
233
|
+
fiberState: FIBER_ACTIVE,
|
|
234
|
+
connection: { state: 'failed', reason: 'gave-up', maxAttempts: 10, lastError: 'connect ECONNREFUSED' },
|
|
235
|
+
toolCount: 0,
|
|
236
|
+
reachable: true,
|
|
237
|
+
reachableAt: NOW,
|
|
238
|
+
probe: { ok: true, at: NOW, toolsCount: 49 },
|
|
239
|
+
now: NOW,
|
|
240
|
+
});
|
|
241
|
+
assert.equal(result.state, 'failed');
|
|
242
|
+
assert.equal(result.reason, 'gave-up');
|
|
243
|
+
}],
|
|
244
|
+
|
|
245
|
+
['resolveStatus: host failed (other reasons) → failed/client-failed', () => {
|
|
246
|
+
for (const reason of ['unclosed-generation', 'reconnect-disabled', undefined]) {
|
|
247
|
+
const result = resolveStatus({
|
|
248
|
+
fiberState: FIBER_ACTIVE,
|
|
249
|
+
connection: reason === undefined ? { state: 'failed' } : { state: 'failed', reason },
|
|
250
|
+
toolCount: 2,
|
|
251
|
+
now: NOW,
|
|
252
|
+
});
|
|
253
|
+
assert.equal(result.state, 'failed', `reason=${String(reason)}`);
|
|
254
|
+
assert.equal(result.reason, 'client-failed', `reason=${String(reason)}`);
|
|
255
|
+
}
|
|
256
|
+
}],
|
|
257
|
+
|
|
258
|
+
['resolveStatus: host closed / waiting-credentials → failed', () => {
|
|
259
|
+
const closed = resolveStatus({
|
|
260
|
+
fiberState: FIBER_ACTIVE, connection: { state: 'closed' }, toolCount: 0, now: NOW,
|
|
261
|
+
});
|
|
262
|
+
assert.equal(closed.state, 'failed');
|
|
263
|
+
assert.equal(closed.reason, 'client-closed');
|
|
264
|
+
|
|
265
|
+
const waiting = resolveStatus({
|
|
266
|
+
fiberState: FIBER_ACTIVE, connection: { state: 'waiting-credentials' }, toolCount: 0, now: NOW,
|
|
267
|
+
});
|
|
268
|
+
assert.equal(waiting.state, 'failed');
|
|
269
|
+
assert.equal(waiting.reason, 'waiting-credentials');
|
|
270
|
+
}],
|
|
271
|
+
|
|
272
|
+
['resolveStatus: host connected + tools → connected, client evidence present', () => {
|
|
273
|
+
const result = resolveStatus({
|
|
274
|
+
fiberState: FIBER_ACTIVE,
|
|
275
|
+
connection: { state: 'connected' },
|
|
276
|
+
toolCount: 49,
|
|
277
|
+
reachable: true,
|
|
278
|
+
reachDetail: 'ok',
|
|
279
|
+
reachableAt: NOW,
|
|
280
|
+
now: NOW,
|
|
281
|
+
});
|
|
282
|
+
assert.equal(result.state, 'connected');
|
|
283
|
+
assert.equal(result.reason, 'connected');
|
|
284
|
+
assert.equal(result.evidence.at(-1).signal, 'client');
|
|
285
|
+
}],
|
|
286
|
+
|
|
287
|
+
['resolveStatus: host connected but a fresh failed probe still means unreachable', () => {
|
|
288
|
+
const result = resolveStatus({
|
|
289
|
+
fiberState: FIBER_ACTIVE,
|
|
290
|
+
connection: { state: 'connected' },
|
|
291
|
+
toolCount: 3,
|
|
292
|
+
reachable: true,
|
|
293
|
+
reachDetail: 'ok',
|
|
294
|
+
reachableAt: NOW,
|
|
295
|
+
probe: { ok: false, at: NOW, error: 'handshake failed' },
|
|
296
|
+
now: NOW,
|
|
297
|
+
probeAssertMs: PROBE_ASSERT_MS,
|
|
298
|
+
});
|
|
299
|
+
assert.equal(result.state, 'unreachable');
|
|
300
|
+
assert.equal(result.reason, 'probe-failed');
|
|
301
|
+
}],
|
|
302
|
+
|
|
303
|
+
['resolveStatus: host connected + 0 tools → idle/no-tools', () => {
|
|
304
|
+
const result = resolveStatus({
|
|
305
|
+
fiberState: FIBER_ACTIVE,
|
|
306
|
+
connection: { state: 'connected' },
|
|
307
|
+
toolCount: 0,
|
|
308
|
+
now: NOW,
|
|
309
|
+
});
|
|
310
|
+
assert.equal(result.state, 'idle');
|
|
311
|
+
assert.equal(result.reason, 'no-tools');
|
|
312
|
+
}],
|
|
313
|
+
|
|
314
|
+
['resolveStatus: unknown host state falls back to observational derivation', () => {
|
|
315
|
+
const result = resolveStatus({
|
|
316
|
+
fiberState: FIBER_ACTIVE,
|
|
317
|
+
connection: { state: 'some-future-state' },
|
|
318
|
+
toolCount: 4,
|
|
319
|
+
reachable: true,
|
|
320
|
+
reachDetail: 'ok',
|
|
321
|
+
reachableAt: NOW,
|
|
322
|
+
now: NOW,
|
|
323
|
+
});
|
|
324
|
+
assert.equal(result.state, 'connected');
|
|
325
|
+
assert.equal(result.reason, 'connected');
|
|
326
|
+
}],
|
|
327
|
+
|
|
328
|
+
// ---------------------------------------------------------- serverNameFromTool
|
|
202
329
|
|
|
203
330
|
['serverNameFromTool: extracts the server segment of an MCP tool name', () => {
|
|
204
331
|
assert.equal(serverNameFromTool('mcp__unityMCP__manage_scene'), 'unityMCP');
|
|
@@ -278,6 +405,42 @@ const cases = [
|
|
|
278
405
|
assert.ok(!message.includes('\n'), 'guard message must stay one line');
|
|
279
406
|
}],
|
|
280
407
|
|
|
408
|
+
['decideGuard: reconnecting row is refused with the attempt count', () => {
|
|
409
|
+
const message = decideGuard({
|
|
410
|
+
toolName: 'mcp__unityMCP__manage_scene',
|
|
411
|
+
row: {
|
|
412
|
+
serverName: 'unityMCP',
|
|
413
|
+
target: 'http://127.0.0.1:9/mcp',
|
|
414
|
+
state: 'reconnecting',
|
|
415
|
+
connection: { state: 'reconnecting', attempt: 4, maxAttempts: 10 },
|
|
416
|
+
},
|
|
417
|
+
snapshotAt: NOW - 1000,
|
|
418
|
+
now: NOW,
|
|
419
|
+
config: DEFAULT_CONFIG,
|
|
420
|
+
});
|
|
421
|
+
assert.equal(typeof message, 'string');
|
|
422
|
+
assert.ok(message.includes('reconnecting'), message);
|
|
423
|
+
assert.ok(message.includes('4 of 10'), message);
|
|
424
|
+
}],
|
|
425
|
+
|
|
426
|
+
['decideGuard: gave-up row explains the attempt limit', () => {
|
|
427
|
+
const message = decideGuard({
|
|
428
|
+
toolName: 'mcp__unityMCP__manage_scene',
|
|
429
|
+
row: {
|
|
430
|
+
serverName: 'unityMCP',
|
|
431
|
+
target: 'http://127.0.0.1:9/mcp',
|
|
432
|
+
state: 'failed',
|
|
433
|
+
reason: 'gave-up',
|
|
434
|
+
connection: { state: 'failed', reason: 'gave-up', maxAttempts: 10 },
|
|
435
|
+
},
|
|
436
|
+
snapshotAt: NOW - 1000,
|
|
437
|
+
now: NOW,
|
|
438
|
+
config: DEFAULT_CONFIG,
|
|
439
|
+
});
|
|
440
|
+
assert.equal(typeof message, 'string');
|
|
441
|
+
assert.ok(message.includes('gave up after 10'), message);
|
|
442
|
+
}],
|
|
443
|
+
|
|
281
444
|
// ------------------------------------------------------------ buildHealthText
|
|
282
445
|
|
|
283
446
|
['buildHealthText: no unhealthy rows → empty string', () => {
|
|
@@ -333,6 +496,21 @@ const cases = [
|
|
|
333
496
|
assert.ok(text.endsWith('…'), text);
|
|
334
497
|
}],
|
|
335
498
|
|
|
499
|
+
['buildHealthText: gave-up row says the client stopped reconnecting', () => {
|
|
500
|
+
const text = buildHealthText({
|
|
501
|
+
servers: [{
|
|
502
|
+
serverName: 'unityMCP',
|
|
503
|
+
target: 'http://127.0.0.1:8080/mcp',
|
|
504
|
+
state: 'failed',
|
|
505
|
+
reason: 'gave-up',
|
|
506
|
+
toolCount: 0,
|
|
507
|
+
checkedAt: NOW,
|
|
508
|
+
}],
|
|
509
|
+
}, { now: NOW });
|
|
510
|
+
assert.ok(text.includes('reconnect gave up'), text);
|
|
511
|
+
assert.ok(text.includes('unityMCP'), text);
|
|
512
|
+
}],
|
|
513
|
+
|
|
336
514
|
// ------------------------------------------------------------- normalizeConfig
|
|
337
515
|
|
|
338
516
|
['normalizeConfig: defaults, floors, type guards and unknown keys', () => {
|