dsh-mcp-manager-plus 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.en.md +24 -4
- package/README.md +15 -3
- package/lib/client.js +125 -14
- package/lib/index.js +320 -20
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,41 @@
|
|
|
5
5
|
|
|
6
6
|
0.3.1 之前的开发发生在公开仓库建立之前,历史没有保留。
|
|
7
7
|
|
|
8
|
+
## [0.5.2] - 2026-11-21
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **连接彻底失败的行仍显示「已连接」,与「0 个工具」自相矛盾**
|
|
13
|
+
([#6](https://github.com/appthin/dsh-mcp-manager-plus/issues/6)):状态徽章原来取的是
|
|
14
|
+
Cordis fiber 的生命周期(`FIBER_PHASE[2] = 'active'`),它只回答「插件条目挂载
|
|
15
|
+
成功了吗」。MCP 子进程是条目加载**之后**才 spawn 的,进程起不来、握手失败、
|
|
16
|
+
鉴权失败都不会回头改 `fiber.state`,于是 `chrome-devtools-mcp` 这种「Node 版本
|
|
17
|
+
不满足 engines、npx 一启动就退出」的服务器稳定显示「已连接 · 0 个工具」,而宿主
|
|
18
|
+
侧实际报 `server is disconnected`。
|
|
19
|
+
- 现在优先读 `dsh-mcp-client` 自己的连接状态(`connectionStatusOf(fiber)` →
|
|
20
|
+
`failed` / `closed` / `connecting` / `reconnecting` / `waiting-credentials` /
|
|
21
|
+
`connected`),映射成「连接失败 / 已断开 / 连接中 / 重连中 / 缺少凭据 / 已连接」,
|
|
22
|
+
失败原因与重连进度作为悬停提示。状态单元是 `WeakMap` 按 fiber 存的,所以按
|
|
23
|
+
**裸导入 → loader 内部 import → 各解析锚点(profile、插件目录、`app.asar/dsh`)**
|
|
24
|
+
依次尝试,拿到哪个副本就用哪个;**新旧两代 `dsh-mcp-client` 都能兼容**(老副本
|
|
25
|
+
没有这个导出,直接跳过)。
|
|
26
|
+
- 读不到状态时按工具数兜底:**已启用 + 已挂载 + 0 个工具**降级为「可能未连接」
|
|
27
|
+
(黄点),不再声称已连接;已有工具的行不加这个字段,因为工具注册本身已证明
|
|
28
|
+
握手成功过。
|
|
29
|
+
- 顺带修掉两处同源的矛盾:「已启用 ✓」在连接确认断开时不再绘制(原来它和
|
|
30
|
+
「连接失败」并排出现);展开后的空态在握手已确认时改用「服务器已连接,但未提供
|
|
31
|
+
任何工具」,不再用「可能未连接」的含糊说法。
|
|
32
|
+
- `live.phase` 的含义与取值**保持不变**(仍是对条目生命周期的回答),新增的
|
|
33
|
+
真实状态放在 `live.connection`,旧前端与旧测试不受影响。
|
|
34
|
+
- 回归用例 7 项(测试总数 149 → 157):握手失败但 fiber 为 `active`、确认连接且
|
|
35
|
+
0 工具不降级、无状态可读且 0 工具的兜底、有工具时不加字段、已停用行不报连接
|
|
36
|
+
问题,以及客户端侧的状态映射、勾选条件与空态文案。测试通过
|
|
37
|
+
`DSH_MCP_MANAGER_STATUS_MODULE` 注入一个假的桥接模块,不依赖真机安装的包。
|
|
38
|
+
- **行预览工具丢掉 `style` 对象**(仅开发脚本 `tools/preview-row.mjs`):序列化
|
|
39
|
+
JSX 树时把 `style={{...}}` 整个跳过,头像的底色是行内样式,于是预览页渲染成
|
|
40
|
+
白字白底,任何按预览页做对比度检查都会误报 1:1。现在会把样式对象写成内联
|
|
41
|
+
CSS,预览与真实渲染一致。
|
|
42
|
+
|
|
8
43
|
## [0.5.0] - 2026-11-11
|
|
9
44
|
|
|
10
45
|
### Added
|
|
@@ -245,6 +280,9 @@
|
|
|
245
280
|
JSON 编辑、宿主路由、bundle 加载、profile 组合与真实 profile 只读验证;
|
|
246
281
|
另附 e2e 导入、往返校验、图标预览等辅助脚本
|
|
247
282
|
|
|
283
|
+
[0.5.2]: https://github.com/appthin/dsh-mcp-manager-plus/compare/v0.5.0...v0.5.2
|
|
284
|
+
[0.5.0]: https://github.com/appthin/dsh-mcp-manager-plus/compare/v0.4.5...v0.5.0
|
|
285
|
+
[0.4.5]: https://github.com/appthin/dsh-mcp-manager-plus/compare/v0.4.4...v0.4.5
|
|
248
286
|
[0.4.4]: https://github.com/appthin/dsh-mcp-manager-plus/compare/v0.4.3...v0.4.4
|
|
249
287
|
[0.4.3]: https://github.com/appthin/dsh-mcp-manager-plus/compare/v0.4.2...v0.4.3
|
|
250
288
|
[0.4.2]: https://github.com/appthin/dsh-mcp-manager-plus/compare/v0.4.1...v0.4.2
|
package/README.en.md
CHANGED
|
@@ -129,11 +129,31 @@ bottom:
|
|
|
129
129
|
- the **square avatar** holds the server name's first letter, coloured from the
|
|
130
130
|
name — a different name gets a different colour, which makes a long list
|
|
131
131
|
scannable;
|
|
132
|
-
- **dbx ✓** is the server name; the check means it is enabled
|
|
132
|
+
- **dbx ✓** is the server name; the check means it is enabled (it is withheld
|
|
133
|
+
while the connection is known to be down — see below);
|
|
133
134
|
- the second line carries the **connection state** (Connected / Connecting /
|
|
134
|
-
Pending / Failed /
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
Reconnecting / Pending / Failed / Disconnected / Missing credentials / May be
|
|
136
|
+
disconnected / Unloading / Disabled), the **tool count**, and the
|
|
137
|
+
**project-binding state** (`All projects`, or `Bound to N project(s)`). A bound
|
|
138
|
+
row paints that chip's **text** green, and hovering it lists the bound
|
|
139
|
+
directories;
|
|
140
|
+
- the badge reports the **MCP handshake**, not "the plugin entry mounted". A
|
|
141
|
+
child process that never starts, a failed handshake or a failed auth all happen
|
|
142
|
+
after the entry loaded, so the entry stays `active` forever — which is how a
|
|
143
|
+
row could claim "Connected · 0 tools"
|
|
144
|
+
([#6](https://github.com/appthin/dsh-mcp-manager-plus/issues/6)). The order is
|
|
145
|
+
now:
|
|
146
|
+
1. use the connection state from `dsh-mcp-client` when it can be read:
|
|
147
|
+
`failed` → Failed, `closed` → Disconnected, `connecting` / `reconnecting` →
|
|
148
|
+
Connecting / Reconnecting, `waiting-credentials` → Missing credentials,
|
|
149
|
+
`connected` → Connected;
|
|
150
|
+
2. when it cannot be read, an **enabled, mounted row exposing zero tools**
|
|
151
|
+
degrades to "May be disconnected" (amber dot) instead of claiming a
|
|
152
|
+
connection; a row with tools gets no such field, because registered tools
|
|
153
|
+
already prove the handshake happened.
|
|
154
|
+
|
|
155
|
+
Failure details (`spawn ENOENT` and friends) and reconnect progress go in the
|
|
156
|
+
badge's hover title.
|
|
137
157
|
- the far right is the **enable/disable switch**, preceded by up to four icon
|
|
138
158
|
buttons (which ones a row has depends on what it can do, see the table):
|
|
139
159
|
|
package/README.md
CHANGED
|
@@ -108,10 +108,22 @@ MCP 服务器行会原样保留——它们是你的配置数据,不会被连
|
|
|
108
108
|
|
|
109
109
|
- **⌄** 展开 / 收起该服务器的工具列表;
|
|
110
110
|
- **方头像**里是服务名的首字母,颜色由服务名决定,换一个名字换一种颜色,便于扫视;
|
|
111
|
-
- **dbx ✓**
|
|
112
|
-
- 第二行依次是**连接状态**(已连接 / 连接中 /
|
|
113
|
-
|
|
111
|
+
- **dbx ✓** 是服务名,后面那个勾表示已启用(连接已确认断开时不画这个勾,见下);
|
|
112
|
+
- 第二行依次是**连接状态**(已连接 / 连接中 / 重连中 / 等待中 / 连接失败 /
|
|
113
|
+
已断开 / 缺少凭据 / 可能未连接 / 卸载中 / 已停用)、**工具数**、以及
|
|
114
|
+
**项目绑定状态**(`全局可用` 或 `仅限 N 个项目`)。
|
|
114
115
|
已绑定时这个标签的**文字**会变成绿色,鼠标悬停可直接看到绑定的目录;
|
|
116
|
+
- 状态徽章读的是 **MCP 握手结果**,不是「插件条目挂载成功」。进程没起来、
|
|
117
|
+
握手失败、鉴权失败都发生在条目加载之后,条目本身一直是 `active`,所以
|
|
118
|
+
只按条目判断会出现「已连接 · 0 个工具」这种自相矛盾的行(
|
|
119
|
+
[#6](https://github.com/appthin/dsh-mcp-manager-plus/issues/6))。现在的取值顺序是:
|
|
120
|
+
1. 能读到 `dsh-mcp-client` 的连接状态就用它:`failed` → 连接失败、
|
|
121
|
+
`closed` → 已断开、`connecting` / `reconnecting` → 连接中 / 重连中、
|
|
122
|
+
`waiting-credentials` → 缺少凭据、`connected` → 已连接;
|
|
123
|
+
2. 读不到时,**已启用、已挂载、但工具数为 0** 的行降级为「可能未连接」
|
|
124
|
+
(黄点),不再声称已连接;有工具的行不加这个字段,因为工具已注册本身
|
|
125
|
+
就证明握手成功过。
|
|
126
|
+
失败原因(`spawn ENOENT` 之类)与重连进度写在徽章的悬停提示里。
|
|
115
127
|
- 行的最右边是**启用开关**;开关左边最多四个图标按钮(取决于该行能做什么,见下表):
|
|
116
128
|
|
|
117
129
|
| 图标 | 动作 | 说明 |
|
package/lib/client.js
CHANGED
|
@@ -114,6 +114,15 @@ window.__ModuleLoader__.load({
|
|
|
114
114
|
phaseFailed: '连接失败',
|
|
115
115
|
phaseDisabled: '已停用',
|
|
116
116
|
phaseUnloading: '卸载中',
|
|
117
|
+
phaseReconnecting: '重连中',
|
|
118
|
+
phaseClosed: '已断开',
|
|
119
|
+
phaseCredentials: '缺少凭据',
|
|
120
|
+
phaseUnverified: '可能未连接',
|
|
121
|
+
reasonGaveUp: '已放弃重连',
|
|
122
|
+
reasonReconnectDisabled: '自动重连已关闭',
|
|
123
|
+
reasonUnclosed: '上一代连接未关闭',
|
|
124
|
+
reconnectDetail: '第 {attempt}/{max} 次重连',
|
|
125
|
+
noToolsConnected: '服务器已连接,但未提供任何工具。',
|
|
117
126
|
sourceBundle: '部署内置',
|
|
118
127
|
sourceBuiltin: '内置能力',
|
|
119
128
|
notWritable: '配置文件不可写,改动无法保存:{path}',
|
|
@@ -197,6 +206,15 @@ window.__ModuleLoader__.load({
|
|
|
197
206
|
phaseFailed: 'Failed',
|
|
198
207
|
phaseDisabled: 'Disabled',
|
|
199
208
|
phaseUnloading: 'Unloading',
|
|
209
|
+
phaseReconnecting: 'Reconnecting',
|
|
210
|
+
phaseClosed: 'Disconnected',
|
|
211
|
+
phaseCredentials: 'Missing credentials',
|
|
212
|
+
phaseUnverified: 'May be disconnected',
|
|
213
|
+
reasonGaveUp: 'Gave up reconnecting',
|
|
214
|
+
reasonReconnectDisabled: 'Automatic reconnect is off',
|
|
215
|
+
reasonUnclosed: 'Previous connection was not closed',
|
|
216
|
+
reconnectDetail: 'Reconnect attempt {attempt}/{max}',
|
|
217
|
+
noToolsConnected: 'Connected, but the server exposes no tools.',
|
|
200
218
|
sourceBundle: 'Deployment',
|
|
201
219
|
sourceBuiltin: 'Built-in',
|
|
202
220
|
notWritable: 'The configuration file is not writable, so changes cannot be saved: {path}',
|
|
@@ -716,15 +734,86 @@ window.__ModuleLoader__.load({
|
|
|
716
734
|
var expanded = props.expanded;
|
|
717
735
|
var live = server.live || {};
|
|
718
736
|
var phase = live.phase || 'pending';
|
|
719
|
-
var
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
737
|
+
var connection =
|
|
738
|
+
live.connection !== null && typeof live.connection === 'object' ? live.connection : null;
|
|
739
|
+
var connectionState =
|
|
740
|
+
connection !== null && typeof connection.state === 'string' ? connection.state : '';
|
|
741
|
+
// The bridge's own state is the truthful badge once it exists: the loader
|
|
742
|
+
// phase only proves the plugin mounted, and a crashed MCP handshake leaves
|
|
743
|
+
// that phase active forever. Lifecycle states still win — a disabled or
|
|
744
|
+
// failed entry has no live bridge to report.
|
|
745
|
+
var CONNECTION_LABEL = {
|
|
746
|
+
connected: 'phaseActive',
|
|
747
|
+
connecting: 'phaseLoading',
|
|
748
|
+
reconnecting: 'phaseReconnecting',
|
|
749
|
+
failed: 'phaseFailed',
|
|
750
|
+
closed: 'phaseClosed',
|
|
751
|
+
'waiting-credentials': 'phaseCredentials',
|
|
752
|
+
unknown: 'phaseUnverified',
|
|
753
|
+
};
|
|
754
|
+
var CONNECTION_DOT = {
|
|
755
|
+
connected: 'active',
|
|
756
|
+
connecting: 'loading',
|
|
757
|
+
reconnecting: 'loading',
|
|
758
|
+
failed: 'failed',
|
|
759
|
+
closed: 'failed',
|
|
760
|
+
'waiting-credentials': 'pending',
|
|
761
|
+
unknown: 'pending',
|
|
762
|
+
};
|
|
763
|
+
var REASON_LABEL = {
|
|
764
|
+
'gave-up': t('reasonGaveUp'),
|
|
765
|
+
'reconnect-disabled': t('reasonReconnectDisabled'),
|
|
766
|
+
'unclosed-generation': t('reasonUnclosed'),
|
|
767
|
+
};
|
|
768
|
+
var phaseLabel;
|
|
769
|
+
var dotPhase = phase;
|
|
770
|
+
if (phase === 'active' && connectionState !== '') {
|
|
771
|
+
phaseLabel =
|
|
772
|
+
CONNECTION_LABEL[connectionState] !== undefined
|
|
773
|
+
? t(CONNECTION_LABEL[connectionState])
|
|
774
|
+
: connectionState;
|
|
775
|
+
dotPhase = CONNECTION_DOT[connectionState] || 'pending';
|
|
776
|
+
} else {
|
|
777
|
+
phaseLabel =
|
|
778
|
+
{
|
|
779
|
+
active: t('phaseActive'),
|
|
780
|
+
loading: t('phaseLoading'),
|
|
781
|
+
pending: t('phasePending'),
|
|
782
|
+
failed: t('phaseFailed'),
|
|
783
|
+
disabled: t('phaseDisabled'),
|
|
784
|
+
unloading: t('phaseUnloading'),
|
|
785
|
+
}[phase] || phase;
|
|
786
|
+
}
|
|
787
|
+
var statusTitle = '';
|
|
788
|
+
if (connection !== null) {
|
|
789
|
+
var reason =
|
|
790
|
+
typeof connection.reason === 'string'
|
|
791
|
+
? REASON_LABEL[connection.reason] || connection.reason
|
|
792
|
+
: '';
|
|
793
|
+
statusTitle = [reason, connection.cleanupError, connection.lastError]
|
|
794
|
+
.filter(function (part) {
|
|
795
|
+
return typeof part === 'string' && part !== '';
|
|
796
|
+
})
|
|
797
|
+
.join(' · ');
|
|
798
|
+
if (
|
|
799
|
+
statusTitle === '' &&
|
|
800
|
+
connection.state === 'reconnecting' &&
|
|
801
|
+
typeof connection.attempt === 'number'
|
|
802
|
+
) {
|
|
803
|
+
statusTitle = t('reconnectDetail', {
|
|
804
|
+
attempt: connection.attempt,
|
|
805
|
+
max: typeof connection.maxAttempts === 'number' ? connection.maxAttempts : '?',
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
// A green tick next to "连接失败" is the contradiction this row used to
|
|
810
|
+
// show. Keep the enabled mark only while the connection is not known to be
|
|
811
|
+
// down; the switch itself still reports the configured on/off state.
|
|
812
|
+
var connectionDown =
|
|
813
|
+
connectionState === 'failed' ||
|
|
814
|
+
connectionState === 'closed' ||
|
|
815
|
+
connectionState === 'unknown';
|
|
816
|
+
var showEnabledTick = server.enabled && phase !== 'failed' && !connectionDown;
|
|
728
817
|
var tools = Array.isArray(live.tools) ? live.tools : [];
|
|
729
818
|
// Only non-user rows wear this tag now; a user row's origin is the
|
|
730
819
|
// "config file" text this row used to spend a chip on.
|
|
@@ -834,14 +923,27 @@ window.__ModuleLoader__.load({
|
|
|
834
923
|
'div',
|
|
835
924
|
{ className: 'mcpmp-name' },
|
|
836
925
|
h('span', { title: server.serverName }, server.displayName || server.serverName),
|
|
837
|
-
|
|
926
|
+
showEnabledTick ? h('span', { style: { color: 'var(--dsw-alias-state-success-primary)' } }, '✓') : null,
|
|
838
927
|
),
|
|
839
928
|
h(
|
|
840
929
|
'div',
|
|
841
930
|
{ className: 'mcpmp-meta' },
|
|
842
|
-
h('span', {
|
|
843
|
-
|
|
844
|
-
|
|
931
|
+
h('span', {
|
|
932
|
+
className: 'mcpmp-dot mcpmp-dot-' + dotPhase,
|
|
933
|
+
title: statusTitle || undefined,
|
|
934
|
+
}),
|
|
935
|
+
h('span', { title: statusTitle || undefined }, phaseLabel),
|
|
936
|
+
h(
|
|
937
|
+
'span',
|
|
938
|
+
{
|
|
939
|
+
className: 'mcpmp-tag',
|
|
940
|
+
title:
|
|
941
|
+
connectionState === 'connected' && tools.length === 0
|
|
942
|
+
? t('noToolsConnected')
|
|
943
|
+
: undefined,
|
|
944
|
+
},
|
|
945
|
+
t('toolCount', { n: tools.length }),
|
|
946
|
+
),
|
|
845
947
|
// The binding state sits where the source tag used to be. A
|
|
846
948
|
// user-managed server is the overwhelmingly common row, so its
|
|
847
949
|
// "config file" label was noise that pushed the useful state onto
|
|
@@ -890,7 +992,16 @@ window.__ModuleLoader__.load({
|
|
|
890
992
|
: h('span', { className: 'mcpmp-binding-all' }, t('bindScopeAll')),
|
|
891
993
|
),
|
|
892
994
|
tools.length === 0
|
|
893
|
-
? h(
|
|
995
|
+
? h(
|
|
996
|
+
'div',
|
|
997
|
+
{ className: 'mcpmp-tools-empty' },
|
|
998
|
+
// Once the handshake is confirmed the old "may be
|
|
999
|
+
// disconnected" hint is misleading, and so is the warning
|
|
1000
|
+
// tone: say plainly that the server exposes nothing.
|
|
1001
|
+
connectionState === 'connected'
|
|
1002
|
+
? t('noToolsConnected')
|
|
1003
|
+
: t('noTools'),
|
|
1004
|
+
)
|
|
894
1005
|
: tools.map(function (tool) {
|
|
895
1006
|
return h(
|
|
896
1007
|
'div',
|
package/lib/index.js
CHANGED
|
@@ -34,8 +34,9 @@ import {
|
|
|
34
34
|
statSync,
|
|
35
35
|
writeFileSync,
|
|
36
36
|
} from 'node:fs';
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
37
|
+
import { createRequire } from 'node:module';
|
|
38
|
+
import { dirname, isAbsolute, join, resolve as resolvePath } from 'node:path';
|
|
39
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
39
40
|
import { homedir } from 'node:os';
|
|
40
41
|
import {
|
|
41
42
|
MCP_CLIENT_PACKAGE,
|
|
@@ -760,6 +761,293 @@ function phaseOf(entry, disabled) {
|
|
|
760
761
|
return FIBER_PHASE[fiber.state] ?? null;
|
|
761
762
|
}
|
|
762
763
|
|
|
764
|
+
/** Longest diagnostic string copied out of a live bridge status. */
|
|
765
|
+
const STATUS_TEXT_LIMIT = 600;
|
|
766
|
+
/**
|
|
767
|
+
* Diagnostic override for the module that reports connection state. Set it to a
|
|
768
|
+
* file path or `file:` URL to read a nonstandard bridge copy; tests use it to
|
|
769
|
+
* inject a fake without requiring the real package.
|
|
770
|
+
*/
|
|
771
|
+
const STATUS_OVERRIDE_ENV = 'DSH_MCP_MANAGER_STATUS_MODULE';
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Resolved status readers, one promise per host context. Resolution imports
|
|
775
|
+
* code (slow, and it may legitimately fail), so a listing burst must not retry
|
|
776
|
+
* it; the readers themselves are stateless probes over live fibers.
|
|
777
|
+
*/
|
|
778
|
+
const STATUS_READERS = new WeakMap();
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* The `connectionStatusOf` export of a bridge module, or `null` when this copy
|
|
782
|
+
* predates the status API. Older bridges export no such function at all — that
|
|
783
|
+
* is the case the tool-count fallback exists for.
|
|
784
|
+
* @param mod - a module namespace.
|
|
785
|
+
* @returns the function, or null.
|
|
786
|
+
*/
|
|
787
|
+
function connectionStatusFunction(mod) {
|
|
788
|
+
if (mod === null || (typeof mod !== 'object' && typeof mod !== 'function')) return null;
|
|
789
|
+
if (typeof mod.connectionStatusOf === 'function') return mod.connectionStatusOf;
|
|
790
|
+
const fallback = mod.default;
|
|
791
|
+
if (
|
|
792
|
+
fallback !== null &&
|
|
793
|
+
typeof fallback === 'object' &&
|
|
794
|
+
typeof fallback.connectionStatusOf === 'function'
|
|
795
|
+
) {
|
|
796
|
+
return fallback.connectionStatusOf;
|
|
797
|
+
}
|
|
798
|
+
return null;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/** Bound diagnostic text: error strings can carry a whole child-process dump. */
|
|
802
|
+
function statusText(value) {
|
|
803
|
+
const text = typeof value === 'string' ? value : value instanceof Error ? value.message : '';
|
|
804
|
+
if (text === '') return '';
|
|
805
|
+
return text.length > STATUS_TEXT_LIMIT ? `${text.slice(0, STATUS_TEXT_LIMIT)}…` : text;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* Copy a bridge status into plain data. Only known fields are copied, so a
|
|
810
|
+
* future bridge state cannot smuggle an arbitrary object graph into the HTTP
|
|
811
|
+
* response, and every field is validated before the browser sees it.
|
|
812
|
+
* @param status - one `McpConnectionStatus` value.
|
|
813
|
+
* @returns the snapshot sent as `live.connection`.
|
|
814
|
+
*/
|
|
815
|
+
function snapshotConnection(status) {
|
|
816
|
+
const snapshot = { state: status.state };
|
|
817
|
+
if (typeof status.toolCount === 'number' && Number.isFinite(status.toolCount)) {
|
|
818
|
+
snapshot.toolCount = status.toolCount;
|
|
819
|
+
}
|
|
820
|
+
if (typeof status.connectedAt === 'number' && Number.isFinite(status.connectedAt)) {
|
|
821
|
+
snapshot.connectedAt = status.connectedAt;
|
|
822
|
+
}
|
|
823
|
+
if (typeof status.attempt === 'number' && Number.isFinite(status.attempt)) {
|
|
824
|
+
snapshot.attempt = status.attempt;
|
|
825
|
+
}
|
|
826
|
+
if (typeof status.maxAttempts === 'number' && Number.isFinite(status.maxAttempts)) {
|
|
827
|
+
snapshot.maxAttempts = status.maxAttempts;
|
|
828
|
+
}
|
|
829
|
+
if (typeof status.nextRetryAtMs === 'number' && Number.isFinite(status.nextRetryAtMs)) {
|
|
830
|
+
snapshot.nextRetryAtMs = status.nextRetryAtMs;
|
|
831
|
+
}
|
|
832
|
+
if (typeof status.reason === 'string' && status.reason !== '') {
|
|
833
|
+
snapshot.reason = status.reason;
|
|
834
|
+
}
|
|
835
|
+
const lastError = statusText(status.lastError);
|
|
836
|
+
if (lastError !== '') snapshot.lastError = lastError;
|
|
837
|
+
if (status.result !== null && typeof status.result === 'object') {
|
|
838
|
+
if (typeof status.result.closeConfirmed === 'boolean') {
|
|
839
|
+
snapshot.closeConfirmed = status.result.closeConfirmed;
|
|
840
|
+
}
|
|
841
|
+
const cleanupError = statusText(status.result.cleanupError);
|
|
842
|
+
if (cleanupError !== '') snapshot.cleanupError = cleanupError;
|
|
843
|
+
}
|
|
844
|
+
return snapshot;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* Ask every resolved bridge copy for this entry's connection status.
|
|
849
|
+
*
|
|
850
|
+
* The bridge keeps status cells in a `WeakMap` keyed by the live fiber, so a
|
|
851
|
+
* handle exists only in the module instance that actually applied the entry.
|
|
852
|
+
* Probing all copies is what makes the read independent of which copy the
|
|
853
|
+
* loader picked. A fake fiber (tests) has no `ctx.fiber` and makes the probe
|
|
854
|
+
* throw — that is caught and treated as "this copy does not own the entry".
|
|
855
|
+
* @param entry - the live loader entry.
|
|
856
|
+
* @param readers - resolved `connectionStatusOf` functions.
|
|
857
|
+
* @returns a snapshot, or null when no copy owns the entry.
|
|
858
|
+
*/
|
|
859
|
+
function connectionOf(entry, readers) {
|
|
860
|
+
if (!Array.isArray(readers) || readers.length === 0) return null;
|
|
861
|
+
const fiber = entry?.fiber;
|
|
862
|
+
if (fiber === undefined) return null;
|
|
863
|
+
for (const reader of readers) {
|
|
864
|
+
let handle;
|
|
865
|
+
try {
|
|
866
|
+
handle = reader.connectionStatusOf(fiber);
|
|
867
|
+
} catch {
|
|
868
|
+
continue;
|
|
869
|
+
}
|
|
870
|
+
if (handle === null || typeof handle !== 'object') continue;
|
|
871
|
+
if (typeof handle.current !== 'function') continue;
|
|
872
|
+
let status;
|
|
873
|
+
try {
|
|
874
|
+
status = handle.current();
|
|
875
|
+
} catch {
|
|
876
|
+
continue;
|
|
877
|
+
}
|
|
878
|
+
if (status === null || typeof status !== 'object') continue;
|
|
879
|
+
if (typeof status.state !== 'string' || status.state === '') continue;
|
|
880
|
+
return snapshotConnection(status);
|
|
881
|
+
}
|
|
882
|
+
return null;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
/**
|
|
886
|
+
* The connection projection for one row.
|
|
887
|
+
*
|
|
888
|
+
* A loader phase of `active` only proves the bridge plugin mounted; the MCP
|
|
889
|
+
* child process starts afterwards, so a crashed handshake leaves the fiber
|
|
890
|
+
* active forever. The bridge's own status is the authoritative answer when it
|
|
891
|
+
* can be read. When it cannot, a mounted, enabled server exposing zero tools is
|
|
892
|
+
* reported as `unknown` rather than `connected` — the two facts contradict each
|
|
893
|
+
* other, and the honest reading is that the handshake was not observed.
|
|
894
|
+
* @param entry - the live loader entry, when mounted.
|
|
895
|
+
* @param phase - the projected loader phase.
|
|
896
|
+
* @param disabled - whether the row is disabled by the patch layer.
|
|
897
|
+
* @param toolCount - registered tool count for this server.
|
|
898
|
+
* @param readers - resolved bridge status readers.
|
|
899
|
+
* @returns `live.connection`, or null when there is nothing to say.
|
|
900
|
+
*/
|
|
901
|
+
function liveConnectionOf(entry, phase, disabled, toolCount, readers) {
|
|
902
|
+
if (disabled || phase !== 'active') return null;
|
|
903
|
+
const observed = connectionOf(entry, readers);
|
|
904
|
+
if (observed !== null) return observed;
|
|
905
|
+
return toolCount === 0 ? { state: 'unknown' } : null;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
/** Normalize a diagnostic override into an importable URL. */
|
|
909
|
+
function statusOverrideUrl(specifier) {
|
|
910
|
+
// An absolute path has to win over the scheme test: on Windows `C:\bridge.mjs`
|
|
911
|
+
// starts with a colon-terminated run of letters, which reads as the `c:`
|
|
912
|
+
// scheme, and importing it as a URL fails rather than loading the file.
|
|
913
|
+
if (isAbsolute(specifier)) return pathToFileURL(specifier).href;
|
|
914
|
+
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/u.test(specifier)) return specifier;
|
|
915
|
+
return pathToFileURL(resolvePath(process.cwd(), specifier)).href;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
/**
|
|
919
|
+
* The anchors a bridge module is resolved through, in order.
|
|
920
|
+
*
|
|
921
|
+
* The profile anchor is the one that matches the loader's own view; the
|
|
922
|
+
* bundled Electron tree is the copy that carries the status API when the
|
|
923
|
+
* profile's hoisted copy is older; the rest cover a CLI install and a linked
|
|
924
|
+
* development checkout.
|
|
925
|
+
* @param profileDir - the profile directory, when known.
|
|
926
|
+
* @returns candidate directories.
|
|
927
|
+
*/
|
|
928
|
+
function statusResolutionAnchors(profileDir) {
|
|
929
|
+
const anchors = [];
|
|
930
|
+
const add = (value) => {
|
|
931
|
+
if (typeof value === 'string' && value !== '' && !anchors.includes(value)) {
|
|
932
|
+
anchors.push(value);
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
add(profileDir);
|
|
936
|
+
add(process.cwd());
|
|
937
|
+
const pluginLib = dirname(fileURLToPath(import.meta.url));
|
|
938
|
+
add(dirname(pluginLib));
|
|
939
|
+
add(pluginLib);
|
|
940
|
+
const home = dshHome();
|
|
941
|
+
if (home !== '') add(join(home, 'profiles'));
|
|
942
|
+
const resources = typeof process.resourcesPath === 'string' ? process.resourcesPath : '';
|
|
943
|
+
if (resources !== '') {
|
|
944
|
+
add(join(resources, 'app.asar', 'dsh'));
|
|
945
|
+
add(join(resources, 'app.asar', 'dsh', 'node_modules', '@deepseek-ai', 'dsh-mcp-client'));
|
|
946
|
+
}
|
|
947
|
+
const entrypoint = process.argv[1];
|
|
948
|
+
if (typeof entrypoint === 'string' && entrypoint !== '') add(dirname(entrypoint));
|
|
949
|
+
return anchors;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
* Resolve every importable copy of the MCP bridge that exposes
|
|
954
|
+
* `connectionStatusOf`.
|
|
955
|
+
*
|
|
956
|
+
* Four routes are tried because the running tree differs by deployment: a bare
|
|
957
|
+
* import (a Vite-backed loader may rewrite it), the loader's own internal
|
|
958
|
+
* importer (the exact module instance it applied), the profile/bundled anchors,
|
|
959
|
+
* and finally nothing — in which case the tool-count fallback still keeps the
|
|
960
|
+
* badge honest.
|
|
961
|
+
* @param ctx - host context.
|
|
962
|
+
* @param profileDir - the profile directory, when known.
|
|
963
|
+
* @returns `[{ source, connectionStatusOf }]`.
|
|
964
|
+
*/
|
|
965
|
+
async function loadStatusReaders(ctx, profileDir) {
|
|
966
|
+
const readers = [];
|
|
967
|
+
/** @param mod - candidate module. @param source - where it came from. */
|
|
968
|
+
const add = (mod, source) => {
|
|
969
|
+
const fn = connectionStatusFunction(mod);
|
|
970
|
+
if (fn === null) return false;
|
|
971
|
+
if (readers.some((reader) => reader.connectionStatusOf === fn)) return true;
|
|
972
|
+
readers.push({ source, connectionStatusOf: fn });
|
|
973
|
+
return true;
|
|
974
|
+
};
|
|
975
|
+
|
|
976
|
+
// A diagnostic/test override wins outright when it works: the caller asked
|
|
977
|
+
// for exactly one module, and mixing it with guessed copies would make the
|
|
978
|
+
// answer non-deterministic.
|
|
979
|
+
const override = process.env[STATUS_OVERRIDE_ENV];
|
|
980
|
+
if (typeof override === 'string' && override.trim() !== '') {
|
|
981
|
+
try {
|
|
982
|
+
if (add(await import(statusOverrideUrl(override.trim())), 'override')) return readers;
|
|
983
|
+
} catch {
|
|
984
|
+
// Fall through to the normal resolution routes.
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
try {
|
|
989
|
+
add(await import(MCP_CLIENT_PACKAGE), 'bare');
|
|
990
|
+
} catch {
|
|
991
|
+
// Older Node resolution cannot see the profile's copy.
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
const loader = ctx.get('loader');
|
|
995
|
+
const internal = loader?.internal;
|
|
996
|
+
if (internal !== undefined && typeof internal.import === 'function') {
|
|
997
|
+
const bases = new Set();
|
|
998
|
+
if (typeof ctx.baseUrl === 'string' && ctx.baseUrl !== '') bases.add(ctx.baseUrl);
|
|
999
|
+
if (loader !== undefined && typeof loader.entries === 'function') {
|
|
1000
|
+
try {
|
|
1001
|
+
for (const entry of loader.entries()) {
|
|
1002
|
+
const baseUrl = entry?.fiber?.ctx?.baseUrl;
|
|
1003
|
+
if (typeof baseUrl === 'string' && baseUrl !== '') bases.add(baseUrl);
|
|
1004
|
+
}
|
|
1005
|
+
} catch {
|
|
1006
|
+
// A loader that cannot enumerate entries still answers for itself.
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
for (const baseUrl of bases) {
|
|
1010
|
+
try {
|
|
1011
|
+
add(await internal.import(MCP_CLIENT_PACKAGE, baseUrl, {}), `loader:${baseUrl}`);
|
|
1012
|
+
} catch {
|
|
1013
|
+
// The internal importer only accepts bases it can resolve from.
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
for (const anchor of statusResolutionAnchors(profileDir)) {
|
|
1019
|
+
let resolved;
|
|
1020
|
+
try {
|
|
1021
|
+
resolved = createRequire(join(anchor, 'package.json')).resolve(MCP_CLIENT_PACKAGE);
|
|
1022
|
+
} catch {
|
|
1023
|
+
continue;
|
|
1024
|
+
}
|
|
1025
|
+
try {
|
|
1026
|
+
add(await import(pathToFileURL(resolved).href), resolved);
|
|
1027
|
+
} catch {
|
|
1028
|
+
// Resolvable but not importable (a native-only or broken copy).
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
return readers;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
/**
|
|
1036
|
+
* Resolve (and cache) the status readers for one host context. Resolution is
|
|
1037
|
+
* asynchronous, so callers await this before projecting the inventory; later
|
|
1038
|
+
* projections reuse the same readers.
|
|
1039
|
+
* @param ctx - host context.
|
|
1040
|
+
* @param profileDir - the profile directory, when known.
|
|
1041
|
+
* @returns the reader list (possibly empty).
|
|
1042
|
+
*/
|
|
1043
|
+
function prepareStatusReaders(ctx, profileDir) {
|
|
1044
|
+
const cached = STATUS_READERS.get(ctx);
|
|
1045
|
+
if (cached !== undefined) return cached;
|
|
1046
|
+
const pending = loadStatusReaders(ctx, profileDir).catch(() => []);
|
|
1047
|
+
STATUS_READERS.set(ctx, pending);
|
|
1048
|
+
return pending;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
763
1051
|
/** Every model-facing tool schema, defensively read. */
|
|
764
1052
|
function schemasOf(ctx) {
|
|
765
1053
|
const tools = ctx.get('tools');
|
|
@@ -832,9 +1120,10 @@ function toolsOfBuiltin(ctx, key) {
|
|
|
832
1120
|
* @param ctx - host context.
|
|
833
1121
|
* @param document - the parsed patch document.
|
|
834
1122
|
* @param lang - response language for issue strings and display labels.
|
|
1123
|
+
* @param statusReaders - resolved bridge status readers, when available.
|
|
835
1124
|
* @returns `{ servers, issues }`.
|
|
836
1125
|
*/
|
|
837
|
-
function buildInventory(ctx, document, lang = 'zh') {
|
|
1126
|
+
function buildInventory(ctx, document, lang = 'zh', statusReaders = null) {
|
|
838
1127
|
const issues = [...document.issues];
|
|
839
1128
|
const servers = [];
|
|
840
1129
|
const claimed = new Set();
|
|
@@ -856,6 +1145,15 @@ function buildInventory(ctx, document, lang = 'zh') {
|
|
|
856
1145
|
const disabled = document.overrides.disabled.get(row.id) === true;
|
|
857
1146
|
const entry = findEntry(ctx, serverName);
|
|
858
1147
|
const tools = disabled ? [] : toolsOfServer(ctx, serverName);
|
|
1148
|
+
const phase = phaseOf(entry, disabled);
|
|
1149
|
+
const live = {
|
|
1150
|
+
mounted: entry !== undefined,
|
|
1151
|
+
phase,
|
|
1152
|
+
toolCount: tools.length,
|
|
1153
|
+
tools,
|
|
1154
|
+
};
|
|
1155
|
+
const connection = liveConnectionOf(entry, phase, disabled, tools.length, statusReaders);
|
|
1156
|
+
if (connection !== null) live.connection = connection;
|
|
859
1157
|
servers.push({
|
|
860
1158
|
id: row.id,
|
|
861
1159
|
serverName,
|
|
@@ -873,12 +1171,7 @@ function buildInventory(ctx, document, lang = 'zh') {
|
|
|
873
1171
|
url: typeof config.url === 'string' ? config.url : '',
|
|
874
1172
|
headers: maskMap(config.headers),
|
|
875
1173
|
binding: bindingsOf(serverName),
|
|
876
|
-
live
|
|
877
|
-
mounted: entry !== undefined,
|
|
878
|
-
phase: phaseOf(entry, disabled),
|
|
879
|
-
toolCount: tools.length,
|
|
880
|
-
tools,
|
|
881
|
-
},
|
|
1174
|
+
live,
|
|
882
1175
|
});
|
|
883
1176
|
}
|
|
884
1177
|
|
|
@@ -899,6 +1192,15 @@ function buildInventory(ctx, document, lang = 'zh') {
|
|
|
899
1192
|
const id = typeof options.id === 'string' ? options.id : '';
|
|
900
1193
|
const off = entry.disabled === true || (id !== '' && document.overrides.disabled.get(id) === true);
|
|
901
1194
|
const tools = off ? [] : toolsOfServer(ctx, serverName);
|
|
1195
|
+
const phase = phaseOf(entry, off);
|
|
1196
|
+
const live = {
|
|
1197
|
+
mounted: entry.fiber !== undefined,
|
|
1198
|
+
phase,
|
|
1199
|
+
toolCount: tools.length,
|
|
1200
|
+
tools,
|
|
1201
|
+
};
|
|
1202
|
+
const connection = liveConnectionOf(entry, phase, off, tools.length, statusReaders);
|
|
1203
|
+
if (connection !== null) live.connection = connection;
|
|
902
1204
|
servers.push({
|
|
903
1205
|
id,
|
|
904
1206
|
serverName,
|
|
@@ -916,12 +1218,7 @@ function buildInventory(ctx, document, lang = 'zh') {
|
|
|
916
1218
|
url: typeof config.url === 'string' ? config.url : '',
|
|
917
1219
|
headers: maskMap(config.headers),
|
|
918
1220
|
binding: bindingsOf(serverName),
|
|
919
|
-
live
|
|
920
|
-
mounted: entry.fiber !== undefined,
|
|
921
|
-
phase: phaseOf(entry, off),
|
|
922
|
-
toolCount: tools.length,
|
|
923
|
-
tools,
|
|
924
|
-
},
|
|
1221
|
+
live,
|
|
925
1222
|
});
|
|
926
1223
|
}
|
|
927
1224
|
}
|
|
@@ -1232,10 +1529,11 @@ async function remountEntry(entry, serverName, lang) {
|
|
|
1232
1529
|
async function restartServer(ctx, input, lang = 'zh') {
|
|
1233
1530
|
const id = typeof input.id === 'string' ? input.id : '';
|
|
1234
1531
|
if (id === '') throw new Error(tr(lang, 'rowMissingId'));
|
|
1235
|
-
const { patchPath } = resolvePatchPath(ctx);
|
|
1532
|
+
const { patchPath, profileDir } = resolvePatchPath(ctx);
|
|
1236
1533
|
const { yaml, schema } = await loadYaml(ctx);
|
|
1237
1534
|
const document = readDocument(readPatchText(patchPath), yaml, schema);
|
|
1238
|
-
const
|
|
1535
|
+
const statusReaders = await prepareStatusReaders(ctx, profileDir);
|
|
1536
|
+
const inventory = buildInventory(ctx, document, lang, statusReaders);
|
|
1239
1537
|
const server = inventory.servers.find((entry) => entry.id === id);
|
|
1240
1538
|
if (server === undefined) throw new Error(tr(lang, 'restartTargetMissing', { id }));
|
|
1241
1539
|
if (!server.enabled) throw new Error(tr(lang, 'restartDisabled', { name: server.serverName }));
|
|
@@ -1266,10 +1564,11 @@ async function bindServer(ctx, input, lang = 'zh') {
|
|
|
1266
1564
|
const invalid = validateServerName(serverName, lang);
|
|
1267
1565
|
if (invalid !== null) throw new Error(invalid);
|
|
1268
1566
|
|
|
1269
|
-
const { patchPath } = resolvePatchPath(ctx);
|
|
1567
|
+
const { patchPath, profileDir } = resolvePatchPath(ctx);
|
|
1270
1568
|
const { yaml, schema } = await loadYaml(ctx);
|
|
1271
1569
|
const document = readDocument(readPatchText(patchPath), yaml, schema);
|
|
1272
|
-
const
|
|
1570
|
+
const statusReaders = await prepareStatusReaders(ctx, profileDir);
|
|
1571
|
+
const known = buildInventory(ctx, document, lang, statusReaders).servers.some(
|
|
1273
1572
|
(server) => server.serverName === serverName,
|
|
1274
1573
|
);
|
|
1275
1574
|
if (!known) throw new Error(tr(lang, 'bindUnknownServer', { name: serverName }));
|
|
@@ -1485,7 +1784,8 @@ export function apply(ctx) {
|
|
|
1485
1784
|
}
|
|
1486
1785
|
const { yaml, schema, degraded, source } = await loadYaml(ctx);
|
|
1487
1786
|
const document = readDocument(readPatchText(patchPath), yaml, schema);
|
|
1488
|
-
const
|
|
1787
|
+
const statusReaders = await prepareStatusReaders(ctx, profileDir);
|
|
1788
|
+
const inventory = buildInventory(ctx, document, lang, statusReaders);
|
|
1489
1789
|
// Say so rather than silently parsing with a weaker engine: the user's
|
|
1490
1790
|
// patch file is still fully managed, but a report that mentions it saves a
|
|
1491
1791
|
// round trip.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mcp-manager-plus",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "MCP manager settings page for DeepSeek Harness: list, enable, configure and add MCP servers from the browser, written durably to the profile's user patch layer.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"icon": "./icon.svg",
|