dsh-mcp-manager-plus 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js ADDED
@@ -0,0 +1,1602 @@
1
+ // Browser half of dsh-mcp-manager-plus: the "MCP 管理" page inside Settings.
2
+ //
3
+ // Hand-written in the lazy-CJS bundle protocol
4
+ // (`window.__ModuleLoader__.load` with a factory returning cordis-plugin
5
+ // exports), so there is no build step. Everything it needs at runtime is
6
+ // already in the shell's frozen module table: React, plus the shared UI
7
+ // packages it declares under `dsh.client.external`.
8
+ //
9
+ // The page is deliberately self-contained: it renders its own markup and CSS
10
+ // rather than depending on product-internal components, so it keeps working
11
+ // across harness versions that rearrange those components. What it does depend
12
+ // on is one stable contract — `settings.section`, the additive settings page
13
+ // seat — and the HTTP API of its own host half.
14
+ //
15
+ // The host half owns the truth (the profile's patch file). This half renders
16
+ // it, collects form input, and polls briefly after a write, because a
17
+ // configuration change reaches the loader through the profile's file watcher:
18
+ // the write returns before the MCP server has mounted, so the tool list and
19
+ // connection phase settle a moment later.
20
+ window.__ModuleLoader__.load({
21
+ id: 'dsh-mcp-manager-plus',
22
+ factory: (require) => {
23
+ var module = { exports: {} };
24
+ var exports = module.exports;
25
+
26
+ var react = require('react');
27
+
28
+ var h = react.createElement;
29
+ var useState = react.useState;
30
+ var useEffect = react.useEffect;
31
+ var useCallback = react.useCallback;
32
+ var useRef = react.useRef;
33
+
34
+ var NS = 'dsh-mcp-manager-plus';
35
+
36
+ /** Attribute this plugin stamps on its own settings nav row (see markNavRow). */
37
+ var NAV_ROW_FLAG = 'data-mcpmp-nav';
38
+
39
+ /** The dictionary, keyed for the two locales the harness ships. */
40
+ var DICT = {
41
+ zh: {
42
+ nav: 'MCP 管理',
43
+ title: 'MCP Servers 管理',
44
+ description: '管理您已添加的 MCP 服务器,可启用、配置或添加新的工具能力。',
45
+ refresh: '刷新',
46
+ add: '添加',
47
+ loading: '正在加载…',
48
+ loadFailed: '加载失败',
49
+ retry: '重试',
50
+ empty: '还没有添加任何 MCP 服务器。',
51
+ emptyHint: '点击右上角「添加」,粘贴任意工具的 MCP 配置(Claude Code / Cursor / VS Code / Codex / OpenCode 等)即可接入。',
52
+ manualTitle: '手动配置',
53
+ manualHint:
54
+ '直接粘贴其它工具的 MCP 配置即可,无需改写:Claude Code、Cursor、VS Code、Codex、OpenCode、Continue、Pi、Cherry Studio、Windsurf、Qoder、CodeBuddy、TRAE、ZCode、DeepSeek Harness 的格式都能识别(含 TOML 与带注释的 JSON)。',
55
+ manualPlaceholder:
56
+ '// 示例:Claude Code / Cursor / Windsurf / Qoder 等\n{\n "mcpServers": {\n "example-server": {\n "command": "npx",\n "args": ["-y", "mcp-server-example"]\n }\n }\n}\n\n// VS Code 用 "servers",Codex 用 TOML 的 [mcp_servers.x],\n// OpenCode 用 "mcp" + type:"local"/"remote" —— 都可以直接粘贴。',
57
+ manualWarn: '配置前请确认来源,甄别风险',
58
+ editJsonTitle: '编辑 MCP 服务器(JSON)',
59
+ editJsonHint: '直接编辑该服务器的 JSON 配置。改服务名即为重命名,原有行与其启用/停用状态都会保留;修改后可切回表单模式查看。',
60
+ modeLabel: '配置模式',
61
+ modeForm: '表单',
62
+ modeJson: 'JSON',
63
+ formatsSummary: '支持粘贴以下工具的 MCP 配置(点开查看容器键)',
64
+ formatsFooter: '键名不同也能识别,无需改写;支持 JSON 注释与尾逗号。',
65
+ cancel: '取消',
66
+ close: '关闭',
67
+ confirm: '确认',
68
+ saving: '保存中…',
69
+ edit: '编辑',
70
+ restart: '重启',
71
+ remove: '删除',
72
+ removeConfirm: '确定要删除「{name}」吗?此操作会从配置文件中移除该服务器。',
73
+ editTitle: '编辑 MCP 服务器',
74
+ addTitle: '添加 MCP 服务器',
75
+ name: '服务名',
76
+ nameHint: '仅字母、数字、下划线和连字符,1–32 个字符。工具名前缀为 mcp__<名称>__。',
77
+ transport: '连接方式',
78
+ transportStdio: 'STDIO(本地命令)',
79
+ transportHttp: 'Streamable HTTP(远程地址)',
80
+ command: '命令',
81
+ commandHint: '例如 npx、uvx,或可执行文件的绝对路径。',
82
+ args: '参数',
83
+ argsHint: '每行一个参数。',
84
+ env: '环境变量',
85
+ envHint: '每行一个 KEY=VALUE。',
86
+ cwd: '工作目录',
87
+ cwdHint: '可选;留空则继承当前工作目录。',
88
+ url: 'URL',
89
+ urlHint: '例如 http://localhost:3000/mcp',
90
+ headers: '请求头',
91
+ headersHint: '每行一个 KEY=VALUE。',
92
+ toolCount: '{n} 个工具',
93
+ phaseActive: '已连接',
94
+ phasePending: '等待中',
95
+ phaseLoading: '连接中',
96
+ phaseFailed: '连接失败',
97
+ phaseDisabled: '已停用',
98
+ phaseUnloading: '卸载中',
99
+ sourceUser: '配置文件',
100
+ sourceBundle: '部署内置',
101
+ sourceBuiltin: '内置能力',
102
+ notWritable: '配置文件不可写,改动无法保存:{path}',
103
+ issues: '配置提示',
104
+ saved: '已保存',
105
+ removed: '已删除',
106
+ imported: '已导入',
107
+ restartDone: '已重启 {name}',
108
+ noTools: '暂无工具(服务器可能未连接,或未提供任何工具)',
109
+ expand: '展开',
110
+ collapse: '收起',
111
+ langLabel: '语言',
112
+ langAuto: '自动',
113
+ },
114
+ en: {
115
+ nav: 'MCP',
116
+ title: 'MCP Servers',
117
+ description: 'Manage the MCP servers you have added — enable, configure, or add new tool capabilities.',
118
+ refresh: 'Refresh',
119
+ add: 'Add',
120
+ loading: 'Loading…',
121
+ loadFailed: 'Failed to load',
122
+ retry: 'Retry',
123
+ empty: 'No MCP servers added yet.',
124
+ emptyHint: 'Use “Add” to paste an MCP configuration from any tool (Claude Code, Cursor, VS Code, Codex, OpenCode, …).',
125
+ manualTitle: 'Manual configuration',
126
+ manualHint:
127
+ 'Paste an MCP configuration from any of these tools as-is — no rewriting: Claude Code, Cursor, VS Code, Codex, OpenCode, Continue, Pi, Cherry Studio, Windsurf, Qoder, CodeBuddy, TRAE, ZCode and DeepSeek Harness (TOML and JSON-with-comments included).',
128
+ manualPlaceholder:
129
+ '// Example: Claude Code / Cursor / Windsurf / Qoder etc.\n{\n "mcpServers": {\n "example-server": {\n "command": "npx",\n "args": ["-y", "mcp-server-example"]\n }\n }\n}\n\n// VS Code uses "servers", Codex uses TOML [mcp_servers.x],\n// OpenCode uses "mcp" with type:"local"/"remote" — paste any of them.',
130
+ manualWarn: 'Verify the source and assess the risk before configuring.',
131
+ editJsonTitle: 'Edit MCP server (JSON)',
132
+ editJsonHint: 'Edit this server’s JSON configuration directly. Renaming it here renames the row, keeping its id and its enabled/disabled state; switch back to the form to review it.',
133
+ modeLabel: 'Configuration mode',
134
+ modeForm: 'Form',
135
+ modeJson: 'JSON',
136
+ formatsSummary: 'Accepts MCP configuration pasted from these tools (expand to see the container key)',
137
+ formatsFooter: 'Different key names are understood as-is — no rewriting needed. JSON comments and trailing commas are fine too.',
138
+ cancel: 'Cancel',
139
+ close: 'Close',
140
+ confirm: 'Confirm',
141
+ saving: 'Saving…',
142
+ edit: 'Edit',
143
+ restart: 'Restart',
144
+ remove: 'Delete',
145
+ removeConfirm: 'Delete “{name}”? This removes the server from the configuration file.',
146
+ editTitle: 'Edit MCP server',
147
+ addTitle: 'Add MCP server',
148
+ name: 'Server name',
149
+ nameHint: 'Letters, digits, underscore and hyphen only, 1–32 characters. Prefixes tools as mcp__<name>__.',
150
+ transport: 'Transport',
151
+ transportStdio: 'STDIO (local command)',
152
+ transportHttp: 'Streamable HTTP (remote URL)',
153
+ command: 'Command',
154
+ commandHint: 'For example npx, uvx, or an absolute executable path.',
155
+ args: 'Arguments',
156
+ argsHint: 'One argument per line.',
157
+ env: 'Environment',
158
+ envHint: 'One KEY=VALUE per line.',
159
+ cwd: 'Working directory',
160
+ cwdHint: 'Optional; inherits the current directory when empty.',
161
+ url: 'URL',
162
+ urlHint: 'For example http://localhost:3000/mcp',
163
+ headers: 'Headers',
164
+ headersHint: 'One KEY=VALUE per line.',
165
+ toolCount: '{n} tools',
166
+ phaseActive: 'Connected',
167
+ phasePending: 'Pending',
168
+ phaseLoading: 'Connecting',
169
+ phaseFailed: 'Failed',
170
+ phaseDisabled: 'Disabled',
171
+ phaseUnloading: 'Unloading',
172
+ sourceUser: 'Config file',
173
+ sourceBundle: 'Deployment',
174
+ sourceBuiltin: 'Built-in',
175
+ notWritable: 'The configuration file is not writable, so changes cannot be saved: {path}',
176
+ issues: 'Notes',
177
+ saved: 'Saved',
178
+ removed: 'Removed',
179
+ imported: 'Imported',
180
+ restartDone: 'Restarted {name}',
181
+ noTools: 'No tools yet (the server may be disconnected, or exposes none).',
182
+ expand: 'Expand',
183
+ collapse: 'Collapse',
184
+ langLabel: 'Language',
185
+ langAuto: 'Auto',
186
+ },
187
+ };
188
+
189
+ /** Translate one key, interpolating `{name}` placeholders. */
190
+ function makeT(locale) {
191
+ var table = DICT[locale === 'en' ? 'en' : 'zh'];
192
+ return function t(key, params) {
193
+ var text = table[key] !== undefined ? table[key] : DICT.zh[key] !== undefined ? DICT.zh[key] : key;
194
+ if (params === undefined) return text;
195
+ return text.replace(/\{(\w+)\}/g, function (match, name) {
196
+ return params[name] !== undefined ? String(params[name]) : match;
197
+ });
198
+ };
199
+ }
200
+
201
+ // The settings shell picks a nav-row icon from its own hard-coded table
202
+ // keyed by section id, and every id it does not know — `mcp` included —
203
+ // falls through to the same generic gear `general` uses. The two chain
204
+ // links below are the shell's own `IconLinkOutline16` geometry, copied
205
+ // verbatim so the row matches the rest of the sidebar's visual language.
206
+ // They are filled (not stroked) because that is how the shipped icon draws.
207
+ var NAV_ICON_PATHS = [
208
+ 'M9.94133 6.50173C11.3218 7.99603 11.3218 10.3011 9.94128 11.7954C9.88691 11.8542 9.82125 11.9196 9.72099 12.0198L7.75707 13.9838C7.65709 14.0838 7.592 14.1491 7.53334 14.2034C6.03906 15.5843 3.7327 15.5854 2.23827 14.2048C2.17933 14.1503 2.11374 14.0844 2.01315 13.9838C1.91318 13.8839 1.84922 13.8188 1.79495 13.7601C0.413857 12.2657 0.413909 9.95948 1.795 8.46503C1.84923 8.4064 1.91335 8.34115 2.01321 8.24129L3.79275 6.46313C3.71814 7.08101 3.75236 7.71445 3.90115 8.33518L3.00344 9.23151C2.89398 9.34097 2.8535 9.38307 2.82251 9.41658C1.93771 10.3744 1.93704 11.8514 2.82179 12.8092C2.85279 12.8427 2.89383 12.884 3.0034 12.9936C3.11272 13.1029 3.15429 13.1442 3.18777 13.1752C4.14561 14.0603 5.62381 14.0608 6.58178 13.1758C6.61532 13.1448 6.65722 13.1032 6.76685 12.9935L8.73077 11.0296C8.83999 10.9204 8.88142 10.8787 8.91238 10.8452C9.79744 9.88728 9.7969 8.40911 8.91173 7.45124C8.88074 7.41775 8.83944 7.3762 8.73011 7.26687C8.62082 7.15757 8.58061 7.11623 8.54712 7.08526C8.37347 6.92477 8.18243 6.79361 7.98088 6.69165L9.00289 5.66964C9.17506 5.78373 9.34035 5.91265 9.49663 6.05703C9.55538 6.11135 9.62026 6.17652 9.72036 6.27662C9.82094 6.3772 9.88686 6.4428 9.94133 6.50173Z',
209
+ 'M6.06816 9.49196C4.68626 7.99724 4.68667 5.68942 6.06885 4.19487C6.12268 4.13671 6.18789 4.07306 6.28706 3.9739L8.24541 2.01416C8.34478 1.91479 8.41018 1.85055 8.46845 1.79665C9.96301 0.414902 12.2689 0.414922 13.7635 1.79665C13.8217 1.85051 13.8866 1.91559 13.9858 2.01486C14.0849 2.11394 14.1502 2.17769 14.204 2.23583C15.5861 3.7304 15.5866 6.03823 14.2047 7.53291C14.1508 7.59125 14.0854 7.65638 13.9858 7.75595L12.1994 9.54098C12.2614 8.92982 12.2185 8.30587 12.0634 7.69657L12.9956 6.76573C13.1044 6.65692 13.1458 6.61529 13.1765 6.58205C14.0621 5.62404 14.0621 4.1454 13.1765 3.18738C13.1458 3.15419 13.104 3.1135 12.9956 3.00508C12.8877 2.89716 12.8471 2.85551 12.814 2.82485C11.8559 1.9389 10.376 1.93886 9.41794 2.82485C9.38479 2.85554 9.34381 2.89622 9.23564 3.00439L7.27728 4.96413C7.16875 5.07265 7.12708 5.11322 7.09636 5.14643C6.21074 6.10441 6.21153 7.58236 7.09705 8.5404C7.12775 8.57357 7.16826 8.61575 7.27659 8.72408C7.38456 8.83205 7.42647 8.87227 7.45958 8.90293C7.62849 9.0591 7.81309 9.1881 8.00856 9.28894L6.98795 10.3095C6.82111 10.1978 6.66052 10.0715 6.50872 9.93114C6.45057 9.87733 6.38547 9.81341 6.28637 9.71431C6.1871 9.61504 6.12202 9.55018 6.06816 9.49196Z',
210
+ ];
211
+
212
+ /** The one stylesheet the page injects, using the theme's alias tokens. */
213
+ var CSS = [
214
+ '.mcpmp-root{display:flex;flex-direction:column;gap:16px;padding:4px 2px 24px;color:var(--dsw-alias-label-primary);font-size:13px;line-height:1.5}',
215
+ '.mcpmp-head{display:flex;align-items:flex-start;justify-content:space-between;gap:16px}',
216
+ '.mcpmp-head h2{margin:0 0 4px;font-size:15px;font-weight:600}',
217
+ '.mcpmp-head p{margin:0;color:var(--dsw-alias-label-secondary);font-size:12px}',
218
+ '.mcpmp-lang{display:inline-flex;align-items:center;gap:2px;height:30px;padding:0 2px 0 8px;border-radius:8px;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);font-size:12px;color:var(--dsw-alias-label-secondary)}',
219
+ '.mcpmp-lang-glyph{font-size:11px;letter-spacing:-1px;white-space:nowrap}',
220
+ '.mcpmp-lang select{border:none;background:transparent;color:inherit;font:inherit;height:26px;outline:none;cursor:pointer}',
221
+ '.mcpmp-btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;height:30px;padding:0 12px;border-radius:8px;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font-size:12px;cursor:pointer;white-space:nowrap}',
222
+ '.mcpmp-btn:hover:not(:disabled){background:var(--dsw-alias-bg-layer-2)}',
223
+ '.mcpmp-btn:disabled{opacity:.5;cursor:not-allowed}',
224
+ '.mcpmp-btn-primary{background:var(--dsw-alias-brand-primary);border-color:transparent;color:#fff}',
225
+ '.mcpmp-btn-primary:hover:not(:disabled){filter:brightness(1.08);background:var(--dsw-alias-brand-primary)}',
226
+ '.mcpmp-btn-danger{color:var(--dsw-alias-state-error-primary)}',
227
+ '.mcpmp-btn-sm{height:26px;padding:0 9px;font-size:12px}',
228
+ '.mcpmp-icon{width:30px;padding:0}',
229
+ '.mcpmp-list{display:flex;flex-direction:column;gap:8px}',
230
+ '.mcpmp-card{border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-1);overflow:hidden}',
231
+ '.mcpmp-row{display:flex;align-items:center;gap:10px;padding:10px 12px;min-height:52px}',
232
+ '.mcpmp-avatar{width:26px;height:26px;border-radius:7px;display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:700;color:#fff;flex:0 0 auto;text-transform:uppercase}',
233
+ '.mcpmp-name{display:flex;align-items:center;gap:6px;font-weight:500;min-width:0}',
234
+ '.mcpmp-name span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
235
+ '.mcpmp-meta{color:var(--dsw-alias-label-secondary);font-size:12px;display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-top:2px}',
236
+ '.mcpmp-grow{flex:1 1 auto;min-width:0}',
237
+ '.mcpmp-tag{display:inline-flex;align-items:center;height:18px;padding:0 6px;border-radius:5px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);font-size:11px}',
238
+ '.mcpmp-dot{width:6px;height:6px;border-radius:50%;display:inline-block;flex:0 0 auto;background:var(--dsw-alias-label-secondary)}',
239
+ '.mcpmp-dot-active{background:var(--dsw-alias-state-success-primary)}',
240
+ '.mcpmp-dot-failed{background:var(--dsw-alias-state-error-primary)}',
241
+ '.mcpmp-dot-loading,.mcpmp-dot-pending{background:var(--dsw-alias-state-warn-primary)}',
242
+ '.mcpmp-switch{position:relative;width:38px;height:22px;border-radius:11px;border:none;background:var(--dsw-alias-border-l2);cursor:pointer;padding:0;flex:0 0 auto;transition:background .15s ease}',
243
+ '.mcpmp-switch[data-on="true"]{background:var(--dsw-alias-state-success-primary)}',
244
+ '.mcpmp-switch:disabled{opacity:.5;cursor:not-allowed}',
245
+ '.mcpmp-switch i{position:absolute;top:2px;left:2px;width:18px;height:18px;border-radius:50%;background:#fff;transition:transform .15s ease}',
246
+ '.mcpmp-switch[data-on="true"] i{transform:translateX(16px)}',
247
+ '.mcpmp-caret{width:20px;height:20px;padding:0;border:none;background:transparent;color:var(--dsw-alias-label-secondary);cursor:pointer;display:flex;align-items:center;justify-content:center;flex:0 0 auto;transition:transform .15s ease}',
248
+ '.mcpmp-tools{border-top:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-base);max-height:320px;overflow:auto}',
249
+ '.mcpmp-tool{display:grid;grid-template-columns:minmax(140px,220px) 1fr;gap:12px;padding:7px 14px;border-bottom:1px solid var(--dsw-alias-border-l1)}',
250
+ '.mcpmp-tool:last-child{border-bottom:none}',
251
+ '.mcpmp-tool code{font-size:12px;color:var(--dsw-alias-label-primary);word-break:break-all}',
252
+ '.mcpmp-tool p{margin:0;color:var(--dsw-alias-label-secondary);font-size:12px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
253
+ '.mcpmp-tools-empty{padding:10px 14px;color:var(--dsw-alias-label-secondary);font-size:12px}',
254
+ '.mcpmp-note{padding:9px 12px;border-radius:8px;background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);font-size:12px}',
255
+ '.mcpmp-note-warn{color:var(--dsw-alias-state-warn-primary)}',
256
+ '.mcpmp-note-error{color:var(--dsw-alias-state-error-primary)}',
257
+ '.mcpmp-overlay{position:fixed;inset:0;z-index:60;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.32);padding:24px}',
258
+ '.mcpmp-modal{width:min(640px,100%);max-height:86vh;display:flex;flex-direction:column;border-radius:12px;background:var(--dsw-alias-bg-overlay);border:1px solid var(--dsw-alias-border-l1);box-shadow:0 12px 40px rgba(0,0,0,.28)}',
259
+ '.mcpmp-modal-head{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:14px 16px;border-bottom:1px solid var(--dsw-alias-border-l1)}',
260
+ '.mcpmp-modal-head h3{margin:0;font-size:14px;font-weight:600;flex:1;min-width:0}',
261
+ // Mode switch: a segmented control with a sliding pill. The pill is a
262
+ // separate element so it can animate, and each option keeps its own
263
+ // size so the labels never shift while the pill moves.
264
+ '.mcpmp-seg{position:relative;display:inline-flex;flex:none;padding:3px;gap:0;border-radius:9px;background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l1)}',
265
+ '.mcpmp-seg-pill{position:absolute;top:3px;bottom:3px;left:3px;width:calc((100% - 6px)/2);border-radius:6px;background:var(--dsw-alias-bg-overlay);box-shadow:0 1px 3px rgba(0,0,0,.10);transition:transform .18s cubic-bezier(.4,0,.2,1)}',
266
+ '.mcpmp-seg[data-index="1"] .mcpmp-seg-pill{transform:translateX(100%)}',
267
+ '.mcpmp-seg-btn{position:relative;z-index:1;display:inline-flex;align-items:center;justify-content:center;gap:5px;flex:1;border:none;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;line-height:18px;padding:4px 12px;border-radius:6px;cursor:pointer;white-space:nowrap;transition:color .18s ease}',
268
+ '.mcpmp-seg-btn:hover{color:var(--dsw-alias-label-primary)}',
269
+ '.mcpmp-seg-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}',
270
+ '.mcpmp-seg-on,.mcpmp-seg-on:hover{color:var(--dsw-alias-label-primary);font-weight:500}',
271
+ // Accepted paste formats: collapsed by default so the box stays the
272
+ // focus, expanded for anyone who needs the per-tool container key.
273
+ '.mcpmp-formats{flex:none;border:1px solid var(--dsw-alias-border-l1);border-radius:8px;background:var(--dsw-alias-bg-layer-1);font-size:12px}',
274
+ '.mcpmp-formats>summary{display:flex;align-items:center;gap:6px;padding:7px 10px;cursor:pointer;color:var(--dsw-alias-label-secondary);list-style:none}',
275
+ '.mcpmp-formats>summary::-webkit-details-marker{display:none}',
276
+ '.mcpmp-formats>summary:hover{color:var(--dsw-alias-label-primary)}',
277
+ '.mcpmp-formats>summary svg{transition:transform .18s ease;flex:none}',
278
+ '.mcpmp-formats[open]>summary svg{transform:rotate(180deg)}',
279
+ '.mcpmp-formats[open]>summary{border-bottom:1px solid var(--dsw-alias-border-l1)}',
280
+ '.mcpmp-formats-grid{display:flex;flex-direction:column;gap:1px;padding:6px 10px}',
281
+ '.mcpmp-format{display:grid;grid-template-columns:1fr auto auto;align-items:baseline;gap:8px;padding:3px 0}',
282
+ '.mcpmp-format-tools{color:var(--dsw-alias-label-primary);font-size:12px}',
283
+ '.mcpmp-format code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:11px;padding:1px 5px;border-radius:4px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);white-space:nowrap}',
284
+ '.mcpmp-format em{color:var(--dsw-alias-label-secondary);font-size:11px;font-style:normal;white-space:nowrap}',
285
+ '.mcpmp-formats-foot{margin:0;padding:7px 10px;border-top:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);font-size:11px}',
286
+ '.mcpmp-modal-body{padding:14px 16px;overflow:auto;display:flex;flex-direction:column;gap:12px}',
287
+ '.mcpmp-modal-body p{margin:0;color:var(--dsw-alias-label-secondary);font-size:12px}',
288
+ '.mcpmp-modal-foot{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:12px 16px;border-top:1px solid var(--dsw-alias-border-l1)}',
289
+ '.mcpmp-field{display:flex;flex-direction:column;gap:5px}',
290
+ '.mcpmp-field label{font-size:12px;font-weight:500}',
291
+ '.mcpmp-field small{color:var(--dsw-alias-label-secondary);font-size:11px}',
292
+ '.mcpmp-input,.mcpmp-select,.mcpmp-textarea{width:100%;box-sizing:border-box;border-radius:8px;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-primary);font-size:12px;padding:7px 9px;font-family:inherit}',
293
+ '.mcpmp-textarea{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;line-height:1.55;resize:vertical}',
294
+ '.mcpmp-input:focus,.mcpmp-select:focus,.mcpmp-textarea:focus{outline:none;border-color:var(--dsw-alias-brand-primary)}',
295
+ '@media (max-width:640px){.mcpmp-tool{grid-template-columns:1fr;gap:2px}}',
296
+ // ── settings nav row icon ────────────────────────────────────────────
297
+ // The shell draws a generic gear for any section id it does not know,
298
+ // and offers no way to supply a different one. Our row is tagged with
299
+ // NAV_ROW_FLAG by markNavRow; hide the shell's gear in that row and
300
+ // paint the chain-link glyph instead. The glyph rides a mask so it
301
+ // inherits `currentColor` exactly like every other nav icon, in both
302
+ // themes, with no extra element to keep in sync.
303
+ 'button[' + NAV_ROW_FLAG + ']>svg:first-child{display:none}',
304
+ 'button[' + NAV_ROW_FLAG + ']::before{content:"";flex:none;width:16px;height:16px;background-color:currentColor;'
305
+ + '-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;-webkit-mask-position:center;mask-position:center;'
306
+ + '-webkit-mask-size:16px 16px;mask-size:16px 16px;'
307
+ + '-webkit-mask-image:url("' + navIconDataUrl() + '");mask-image:url("' + navIconDataUrl() + '")}',
308
+ ].join('\n');
309
+
310
+ /**
311
+ * The nav glyph as a data-URL mask image.
312
+ *
313
+ * A mask (rather than a background image) is what lets the glyph take the
314
+ * row's own text colour — including the active and hover states the shell
315
+ * styles — without hard-coding a colour per theme.
316
+ * @returns a `url("data:…")` value holding the link icon.
317
+ */
318
+ function navIconDataUrl() {
319
+ var svg =
320
+ '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none">'
321
+ + NAV_ICON_PATHS.map(function (d) {
322
+ return '<path d="' + d + '" fill="#000"/>';
323
+ }).join('')
324
+ + '</svg>';
325
+ // encodeURIComponent keeps the payload readable and quote-safe.
326
+ return 'data:image/svg+xml,' + encodeURIComponent(svg);
327
+ }
328
+
329
+ /** Insert the page stylesheet once per client module instance. */
330
+ function installStyles() {
331
+ var id = NS + '-styles';
332
+ if (document.getElementById(id) !== null) return;
333
+ var tag = document.createElement('style');
334
+ tag.id = id;
335
+ tag.textContent = CSS;
336
+ document.head.appendChild(tag);
337
+ }
338
+
339
+ /**
340
+ * Render one server as the `mcpServers` JSON everyone pastes.
341
+ *
342
+ * The JSON editor opens on the server being edited, so the starting point
343
+ * has to be that server's own configuration rather than an empty box or a
344
+ * generic sample. Only the fields the server actually uses are emitted, so
345
+ * a stdio server does not open with an empty `url` beside it.
346
+ * @param server - one inventory row.
347
+ * @returns pretty-printed JSON text.
348
+ */
349
+ function serverToJson(server) {
350
+ var entry = {};
351
+ if (server.transport === 'streamable-http') {
352
+ entry.url = server.url || '';
353
+ if (server.headers && Object.keys(server.headers).length > 0) entry.headers = server.headers;
354
+ } else {
355
+ entry.command = server.command || '';
356
+ if (server.args && server.args.length > 0) entry.args = server.args;
357
+ if (server.env && Object.keys(server.env).length > 0) entry.env = server.env;
358
+ if (server.cwd) entry.cwd = server.cwd;
359
+ }
360
+ var document = { mcpServers: {} };
361
+ document.mcpServers[server.serverName] = entry;
362
+ return JSON.stringify(document, null, 2);
363
+ }
364
+
365
+ /** A stable avatar colour per server name, so rows stay recognisable. */
366
+ function avatarColor(name) {
367
+ var palette = ['#E8A33D', '#4C7EF3', '#3BB273', '#C4553C', '#8B5CF6', '#0EA5E9'];
368
+ var sum = 0;
369
+ for (var i = 0; i < name.length; i += 1) sum = (sum * 31 + name.charCodeAt(i)) % 997;
370
+ return palette[sum % palette.length];
371
+ }
372
+
373
+ /** The avatar letter for a name (its first alphanumeric character). */
374
+ function avatarLetter(name) {
375
+ var match = /[A-Za-z0-9]/.exec(name);
376
+ return match === null ? '?' : match[0];
377
+ }
378
+
379
+ /** Split a textarea's lines into a string array, dropping empties. */
380
+ function linesToArray(text) {
381
+ return String(text)
382
+ .split(/\r?\n/)
383
+ .map(function (line) {
384
+ return line.trim();
385
+ })
386
+ .filter(function (line) {
387
+ return line !== '';
388
+ });
389
+ }
390
+
391
+ /** Parse KEY=VALUE lines into a map; a line without `=` is dropped. */
392
+ function linesToMap(text) {
393
+ var map = {};
394
+ linesToArray(text).forEach(function (line) {
395
+ var index = line.indexOf('=');
396
+ if (index <= 0) return;
397
+ map[line.slice(0, index).trim()] = line.slice(index + 1).trim();
398
+ });
399
+ return map;
400
+ }
401
+
402
+ /** Render a map back to KEY=VALUE lines, including host-masked values. */
403
+ function mapToLines(map) {
404
+ if (map === null || typeof map !== 'object') return '';
405
+ return Object.keys(map)
406
+ .map(function (key) {
407
+ return key + '=' + String(map[key]);
408
+ })
409
+ .join('\n');
410
+ }
411
+
412
+ /** The HTTP API prefix this plugin's host half registers. */
413
+ var API_PREFIX = '/mcp-manager-plus';
414
+
415
+ /**
416
+ * Call the host half over its loopback HTTP API. A regular client plugin
417
+ * talks to its host through `fetch` (the `host.call` bridge belongs to
418
+ * dynamic Cordis Packages); the route is same-origin, so no credential or
419
+ * proxy handling is involved.
420
+ * @param route - API route without the prefix, e.g. `servers`.
421
+ * @param body - JSON body; a GET is issued when it is absent.
422
+ * @returns the decoded JSON response.
423
+ */
424
+ function api(route, body) {
425
+ var isRead = body === undefined;
426
+ // Host-side messages follow the page's effective language.
427
+ var query = '?lang=' + (localeRef.current === 'en' ? 'en' : 'zh');
428
+ return fetch(API_PREFIX + '/' + route + query, {
429
+ method: isRead ? 'GET' : 'POST',
430
+ headers: isRead ? undefined : { 'content-type': 'application/json' },
431
+ body: isRead ? undefined : JSON.stringify(body),
432
+ }).then(function (response) {
433
+ return response
434
+ .json()
435
+ .catch(function () {
436
+ return {};
437
+ })
438
+ .then(function (payload) {
439
+ if (!response.ok) throw new Error(payload.error || 'HTTP ' + response.status);
440
+ return payload;
441
+ });
442
+ });
443
+ }
444
+
445
+ // ── small presentational pieces ────────────────────────────────────────
446
+
447
+ /** Inline SVG icon: one path, stroked in the current text colour. */
448
+ function Icon(props) {
449
+ return h(
450
+ 'svg',
451
+ {
452
+ width: props.size || 14,
453
+ height: props.size || 14,
454
+ viewBox: '0 0 16 16',
455
+ fill: 'none',
456
+ stroke: 'currentColor',
457
+ strokeWidth: 1.5,
458
+ strokeLinecap: 'round',
459
+ strokeLinejoin: 'round',
460
+ 'aria-hidden': 'true',
461
+ },
462
+ props.path,
463
+ );
464
+ }
465
+
466
+ var ICON_PATH = {
467
+ plus: h('path', { d: 'M8 3v10M3 8h10' }),
468
+ refresh: h('path', { d: 'M13.5 8a5.5 5.5 0 1 1-1.6-3.9M13.5 2.5V5H11' }),
469
+ chevron: h('path', { d: 'M4 6l4 4 4-4' }),
470
+ close: h('path', { d: 'M4 4l8 8M12 4l-8 8' }),
471
+ // Mode-switch glyphs: a form (label rows) and code brackets. Each is a
472
+ // single <path> with several subpaths, so no React `key` is needed —
473
+ // `key` is not forwarded to the DOM, but avoiding it keeps the elements
474
+ // simple and the preview faithful.
475
+ form: h('path', { d: 'M2.5 4h3M2.5 8h3M2.5 12h3M7.5 4h6M7.5 8h6M7.5 12h6' }),
476
+ code: h('path', { d: 'M6 4L2.5 8 6 12M10 4l3.5 4L10 12' }),
477
+ };
478
+
479
+ /**
480
+ * Mark this plugin's own nav row so the stylesheet can swap its icon.
481
+ *
482
+ * The shell renders nav rows without any id or data attribute, so the row
483
+ * cannot be selected from CSS directly. The page it renders is mounted
484
+ * inside that very row's panel, which gives a stable way back: walk up
485
+ * from the page element to the settings panel, then tag the nav cell whose
486
+ * label matches this page's own nav text. Tagging (rather than an
487
+ * `:nth-child` guess) keeps working when another plugin inserts a section
488
+ * at a neighbouring order, and it never touches a row that is not ours.
489
+ *
490
+ * @param root - the mounted page element.
491
+ * @returns a disposer that removes the marker.
492
+ */
493
+ function markNavRow(root) {
494
+ if (root === null || typeof root.closest !== 'function') return function () {};
495
+ var label = makeT(localeRef.current)('nav');
496
+ // The page is mounted inside the settings panel, so the panel is the
497
+ // shortest scope that still contains the nav list this row belongs to.
498
+ var panel = root.closest('[class*="panel"]');
499
+ var scope = panel === null ? document : panel;
500
+ var cells = scope.querySelectorAll('button[class*="navCell"]');
501
+ var row = null;
502
+ for (var i = 0; i < cells.length; i += 1) {
503
+ var text = cells[i].textContent;
504
+ if (text !== null && text.trim() === label) {
505
+ row = cells[i];
506
+ break;
507
+ }
508
+ }
509
+ if (row === null) return function () {};
510
+ row.setAttribute(NAV_ROW_FLAG, '');
511
+ return function () {
512
+ row.removeAttribute(NAV_ROW_FLAG);
513
+ };
514
+ }
515
+
516
+ /**
517
+ * Flag this plugin's nav row as soon as the shell renders it.
518
+ *
519
+ * markNavRow can only run once this page mounts — after the user first
520
+ * clicks the row — so until then the row still wears the shell's default
521
+ * gear. The shell offers no hook for "nav list rendered", so watch the
522
+ * document instead: whenever nodes change, tag the nav cell whose label
523
+ * matches this page's nav text. The page-level effect stays as a fallback
524
+ * for environments without MutationObserver; here a missing flag is only
525
+ * ever set, never removed, so mutations cannot ping-pong.
526
+ *
527
+ * @returns a disposer that disconnects the observer.
528
+ */
529
+ function watchNavRow() {
530
+ if (typeof MutationObserver === 'undefined' || typeof document === 'undefined') {
531
+ return function () {};
532
+ }
533
+ var scheduled = false;
534
+ function scan() {
535
+ scheduled = false;
536
+ var label = makeT(localeRef.current)('nav');
537
+ var cells = document.querySelectorAll('button[class*="navCell"]');
538
+ for (var i = 0; i < cells.length; i += 1) {
539
+ var text = cells[i].textContent;
540
+ if (text !== null && text.trim() === label && !cells[i].hasAttribute(NAV_ROW_FLAG)) {
541
+ cells[i].setAttribute(NAV_ROW_FLAG, '');
542
+ }
543
+ }
544
+ }
545
+ function schedule() {
546
+ if (scheduled) return;
547
+ scheduled = true;
548
+ setTimeout(scan, 100);
549
+ }
550
+ var observer = new MutationObserver(schedule);
551
+ observer.observe(document.documentElement, { childList: true, subtree: true });
552
+ schedule();
553
+ return function () {
554
+ observer.disconnect();
555
+ };
556
+ }
557
+
558
+ /** The row switch, styled as the pill toggle the rest of the UI uses. */
559
+ function Switch(props) {
560
+ return h(
561
+ 'button',
562
+ {
563
+ type: 'button',
564
+ className: 'mcpmp-switch',
565
+ 'data-on': props.checked ? 'true' : 'false',
566
+ role: 'switch',
567
+ 'aria-checked': props.checked,
568
+ 'aria-label': props.label,
569
+ disabled: props.disabled,
570
+ onClick: props.onChange,
571
+ },
572
+ h('i', null),
573
+ );
574
+ }
575
+
576
+ /** One expandable server row, with its tool list beneath it. */
577
+ function ServerCard(props) {
578
+ var t = props.t;
579
+ var server = props.server;
580
+ var busy = props.busy;
581
+ var expanded = props.expanded;
582
+ var live = server.live || {};
583
+ var phase = live.phase || 'pending';
584
+ var phaseLabel =
585
+ {
586
+ active: t('phaseActive'),
587
+ loading: t('phaseLoading'),
588
+ pending: t('phasePending'),
589
+ failed: t('phaseFailed'),
590
+ disabled: t('phaseDisabled'),
591
+ unloading: t('phaseUnloading'),
592
+ }[phase] || phase;
593
+ var tools = Array.isArray(live.tools) ? live.tools : [];
594
+ var sourceLabel =
595
+ server.source === 'user'
596
+ ? t('sourceUser')
597
+ : server.source === 'builtin'
598
+ ? t('sourceBuiltin')
599
+ : t('sourceBundle');
600
+
601
+ var actions = [];
602
+ if (server.editable) {
603
+ actions.push(
604
+ h(
605
+ 'button',
606
+ { key: 'edit', type: 'button', className: 'mcpmp-btn mcpmp-btn-sm', disabled: busy, onClick: props.onEdit },
607
+ t('edit'),
608
+ ),
609
+ );
610
+ }
611
+ if (live.mounted) {
612
+ actions.push(
613
+ h(
614
+ 'button',
615
+ {
616
+ key: 'restart',
617
+ type: 'button',
618
+ className: 'mcpmp-btn mcpmp-btn-sm',
619
+ disabled: busy,
620
+ onClick: props.onRestart,
621
+ },
622
+ t('restart'),
623
+ ),
624
+ );
625
+ }
626
+ if (server.removable) {
627
+ actions.push(
628
+ h(
629
+ 'button',
630
+ {
631
+ key: 'remove',
632
+ type: 'button',
633
+ className: 'mcpmp-btn mcpmp-btn-sm mcpmp-btn-danger',
634
+ disabled: busy,
635
+ onClick: props.onRemove,
636
+ },
637
+ t('remove'),
638
+ ),
639
+ );
640
+ }
641
+
642
+ return h(
643
+ 'div',
644
+ { className: 'mcpmp-card' },
645
+ h(
646
+ 'div',
647
+ { className: 'mcpmp-row' },
648
+ h(
649
+ 'button',
650
+ {
651
+ type: 'button',
652
+ className: 'mcpmp-caret',
653
+ 'aria-expanded': expanded,
654
+ 'aria-label': expanded ? t('collapse') : t('expand'),
655
+ onClick: props.onExpand,
656
+ style: { transform: expanded ? 'rotate(0deg)' : 'rotate(-90deg)' },
657
+ },
658
+ h(Icon, { path: ICON_PATH.chevron, size: 13 }),
659
+ ),
660
+ h(
661
+ 'div',
662
+ { className: 'mcpmp-avatar', style: { background: avatarColor(server.serverName) } },
663
+ avatarLetter(server.serverName),
664
+ ),
665
+ h(
666
+ 'div',
667
+ { className: 'mcpmp-grow' },
668
+ h(
669
+ 'div',
670
+ { className: 'mcpmp-name' },
671
+ h('span', { title: server.serverName }, server.displayName || server.serverName),
672
+ server.enabled ? h('span', { style: { color: 'var(--dsw-alias-state-success-primary)' } }, '✓') : null,
673
+ ),
674
+ h(
675
+ 'div',
676
+ { className: 'mcpmp-meta' },
677
+ h('span', { className: 'mcpmp-dot mcpmp-dot-' + phase }),
678
+ h('span', null, phaseLabel),
679
+ h('span', { className: 'mcpmp-tag' }, t('toolCount', { n: tools.length })),
680
+ h('span', { className: 'mcpmp-tag' }, sourceLabel),
681
+ ),
682
+ ),
683
+ actions.length > 0 ? h('div', { style: { display: 'flex', gap: 6 } }, actions) : null,
684
+ h(Switch, {
685
+ checked: server.enabled,
686
+ disabled: busy || server.id === '',
687
+ label: server.serverName,
688
+ onChange: props.onToggle,
689
+ }),
690
+ ),
691
+ expanded
692
+ ? h(
693
+ 'div',
694
+ { className: 'mcpmp-tools' },
695
+ tools.length === 0
696
+ ? h('div', { className: 'mcpmp-tools-empty' }, t('noTools'))
697
+ : tools.map(function (tool) {
698
+ return h(
699
+ 'div',
700
+ { className: 'mcpmp-tool', key: tool.fullName || tool.name },
701
+ h('code', { title: tool.fullName }, tool.name),
702
+ h('p', { title: tool.description }, tool.description),
703
+ );
704
+ }),
705
+ )
706
+ : null,
707
+ );
708
+ }
709
+
710
+ /**
711
+ * A two-option segmented control.
712
+ *
713
+ * Used for the edit dialog's mode switch. It is a radiogroup rather than
714
+ * two buttons so the current mode is announced correctly, and so arrow keys
715
+ * work the way a keyboard user expects.
716
+ */
717
+ /**
718
+ * The clipboard formats this box accepts, grouped by the container key a
719
+ * user actually sees in their other tool's file. Kept in step with the
720
+ * parser in `lib/import.js`; `test/client.test.mjs` asserts they agree.
721
+ */
722
+ var FORMAT_ROWS = [
723
+ {
724
+ tools: 'Claude Code · Cursor · Windsurf · Qoder · Cherry Studio · CodeBuddy · TRAE · ZCode',
725
+ key: 'mcpServers',
726
+ note: null,
727
+ },
728
+ { tools: 'DeepSeek Harness', key: 'mcpServers', note: null },
729
+ { tools: 'VS Code', key: 'servers', note: null },
730
+ { tools: 'Codex', key: 'mcp_servers', note: 'TOML' },
731
+ { tools: 'OpenCode', key: 'mcp', note: 'type: local / remote' },
732
+ { tools: 'Continue', key: 'mcpServers', note: 'array' },
733
+ { tools: 'Pi', key: 'mcpServers', note: 'settings ignored' },
734
+ ];
735
+
736
+ /**
737
+ * A two-option segmented switch with a sliding indicator.
738
+ *
739
+ * Used for the edit dialog's mode switch. It is a radiogroup rather than
740
+ * two buttons so the current mode is announced correctly and arrow keys
741
+ * work as a keyboard user expects; the sliding pill is a separate element
742
+ * (not a background on the active button) so it can animate between the two
743
+ * without either option changing size.
744
+ */
745
+ function Segmented(props) {
746
+ var index = props.options.findIndex(function (option) {
747
+ return option.value === props.value;
748
+ });
749
+ if (index < 0) index = 0;
750
+ return h(
751
+ 'div',
752
+ {
753
+ className: 'mcpmp-seg',
754
+ role: 'radiogroup',
755
+ 'aria-label': props.label,
756
+ 'data-index': String(index),
757
+ 'data-count': String(props.options.length),
758
+ },
759
+ h('span', { className: 'mcpmp-seg-pill', 'aria-hidden': 'true' }),
760
+ props.options.map(function (option) {
761
+ var active = option.value === props.value;
762
+ return h(
763
+ 'button',
764
+ {
765
+ key: option.value,
766
+ type: 'button',
767
+ role: 'radio',
768
+ 'aria-checked': active,
769
+ tabIndex: active ? 0 : -1,
770
+ className: 'mcpmp-seg-btn' + (active ? ' mcpmp-seg-on' : ''),
771
+ onClick: function () {
772
+ props.onChange(option.value);
773
+ },
774
+ // Arrow keys move between the two options, as a radiogroup does.
775
+ onKeyDown: function (event) {
776
+ if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') return;
777
+ event.preventDefault();
778
+ var step = event.key === 'ArrowRight' ? 1 : -1;
779
+ var next = (index + step + props.options.length) % props.options.length;
780
+ props.onChange(props.options[next].value);
781
+ },
782
+ },
783
+ option.icon === undefined ? null : h(Icon, { path: option.icon, size: 13 }),
784
+ h('span', null, option.label),
785
+ );
786
+ }),
787
+ );
788
+ }
789
+
790
+ /** A modal shell with a title, a body and a footer. */
791
+ function Modal(props) {
792
+ var onClose = props.onClose;
793
+ useEffect(
794
+ function () {
795
+ function onKey(event) {
796
+ if (event.key === 'Escape') onClose();
797
+ }
798
+ document.addEventListener('keydown', onKey);
799
+ return function () {
800
+ document.removeEventListener('keydown', onKey);
801
+ };
802
+ },
803
+ [onClose],
804
+ );
805
+ return h(
806
+ 'div',
807
+ {
808
+ className: 'mcpmp-overlay',
809
+ onMouseDown: function (event) {
810
+ if (event.target === event.currentTarget) onClose();
811
+ },
812
+ },
813
+ h(
814
+ 'div',
815
+ { className: 'mcpmp-modal', role: 'dialog', 'aria-modal': 'true', 'aria-label': props.title },
816
+ h(
817
+ 'div',
818
+ { className: 'mcpmp-modal-head' },
819
+ h('h3', null, props.title),
820
+ // Optional control between the title and the close button (the
821
+ // edit dialog puts its form/JSON switch here).
822
+ props.headerExtra !== undefined ? props.headerExtra : null,
823
+ h(
824
+ 'button',
825
+ {
826
+ type: 'button',
827
+ className: 'mcpmp-btn mcpmp-btn-sm mcpmp-icon',
828
+ onClick: onClose,
829
+ 'aria-label': props.closeLabel,
830
+ },
831
+ h(Icon, { path: ICON_PATH.close, size: 13 }),
832
+ ),
833
+ ),
834
+ h('div', { className: 'mcpmp-modal-body' }, props.children),
835
+ h('div', { className: 'mcpmp-modal-foot' }, props.footer),
836
+ ),
837
+ );
838
+ }
839
+
840
+ /**
841
+ * Which tools' configurations this box accepts, and the one thing a user
842
+ * needs to know about each: the container key differs, so a paste that
843
+ * "looks wrong" usually is not.
844
+ *
845
+ * Rendered as a compact grid rather than a paragraph because the useful
846
+ * information is per-tool, and a wall of names is what makes people give up
847
+ * and hand-edit the JSON instead.
848
+ */
849
+ function FormatHint(props) {
850
+ var t = props.t;
851
+ return h(
852
+ 'details',
853
+ { className: 'mcpmp-formats' },
854
+ h(
855
+ 'summary',
856
+ null,
857
+ h(Icon, { path: ICON_PATH.chevron, size: 12 }),
858
+ t('formatsSummary'),
859
+ ),
860
+ h(
861
+ 'div',
862
+ { className: 'mcpmp-formats-grid' },
863
+ FORMAT_ROWS.map(function (row) {
864
+ return h(
865
+ 'div',
866
+ { className: 'mcpmp-format', key: row.tools },
867
+ h('span', { className: 'mcpmp-format-tools' }, row.tools),
868
+ h('code', null, row.key),
869
+ row.note === null ? null : h('em', null, row.note),
870
+ );
871
+ }),
872
+ ),
873
+ h('p', { className: 'mcpmp-formats-foot' }, t('formatsFooter')),
874
+ );
875
+ }
876
+
877
+ /** The paste-a-configuration dialog. */
878
+ /**
879
+ * The raw-JSON dialog, used both to add servers and to edit one.
880
+ *
881
+ * Editing passes `server`, which seeds the box with that server's own
882
+ * configuration and makes the submit an in-place update: the row keeps its
883
+ * id and its overrides, and renaming inside the JSON renames the row rather
884
+ * than leaving a stray copy behind.
885
+ */
886
+ function ManualConfigDialog(props) {
887
+ var t = props.t;
888
+ var editing = props.server !== null && props.server !== undefined;
889
+ var [text, setText] = useState(function () {
890
+ return editing ? serverToJson(props.server) : '';
891
+ });
892
+ var [error, setError] = useState(null);
893
+ var [busy, setBusy] = useState(false);
894
+
895
+ function submit() {
896
+ if (busy) return;
897
+ if (text.trim() === '') {
898
+ setError(t('manualHint'));
899
+ return;
900
+ }
901
+ setBusy(true);
902
+ setError(null);
903
+ api('import', {
904
+ json: text,
905
+ originalName: editing ? props.server.serverName : undefined,
906
+ })
907
+ .then(function (result) {
908
+ setBusy(false);
909
+ props.onDone(result);
910
+ })
911
+ .catch(function (failure) {
912
+ setBusy(false);
913
+ setError(String((failure && failure.message) || failure));
914
+ });
915
+ }
916
+
917
+ return h(
918
+ Modal,
919
+ {
920
+ title: editing ? t('editJsonTitle') : t('manualTitle'),
921
+ closeLabel: t('close'),
922
+ onClose: props.onClose,
923
+ // The mirror of the form dialog's switch, so the two modes are
924
+ // reachable from each other rather than one-way.
925
+ headerExtra: editing
926
+ ? h(Segmented, {
927
+ label: t('modeLabel'),
928
+ value: 'json',
929
+ options: [
930
+ { value: 'form', label: t('modeForm'), icon: ICON_PATH.form },
931
+ { value: 'json', label: t('modeJson'), icon: ICON_PATH.code },
932
+ ],
933
+ onChange: function (mode) {
934
+ if (mode === 'form') props.onSwitchToForm();
935
+ },
936
+ })
937
+ : undefined,
938
+ footer: h(
939
+ 'div',
940
+ {
941
+ style: {
942
+ display: 'flex',
943
+ alignItems: 'center',
944
+ justifyContent: 'space-between',
945
+ width: '100%',
946
+ gap: 12,
947
+ },
948
+ },
949
+ h('span', { className: 'mcpmp-note-warn', style: { fontSize: 12 } }, '⚠ ' + t('manualWarn')),
950
+ h(
951
+ 'div',
952
+ { style: { display: 'flex', gap: 8 } },
953
+ h('button', { type: 'button', className: 'mcpmp-btn', onClick: props.onClose }, t('cancel')),
954
+ h(
955
+ 'button',
956
+ { type: 'button', className: 'mcpmp-btn mcpmp-btn-primary', disabled: busy, onClick: submit },
957
+ busy ? t('saving') : t('confirm'),
958
+ ),
959
+ ),
960
+ ),
961
+ },
962
+ h('p', null, editing ? t('editJsonHint') : t('manualHint')),
963
+ h(FormatHint, { t: t }),
964
+ h('textarea', {
965
+ className: 'mcpmp-textarea',
966
+ rows: 12,
967
+ spellCheck: false,
968
+ 'aria-label': editing ? t('editJsonTitle') : t('manualTitle'),
969
+ value: text,
970
+ placeholder: t('manualPlaceholder'),
971
+ onChange: function (event) {
972
+ setText(event.target.value);
973
+ },
974
+ }),
975
+ error !== null ? h('div', { className: 'mcpmp-note mcpmp-note-error' }, error) : null,
976
+ );
977
+ }
978
+
979
+ /** The add/edit form for one server. */
980
+ function ServerFormDialog(props) {
981
+ var t = props.t;
982
+ var editing = props.server !== null && props.server !== undefined;
983
+ var server = props.server || {};
984
+ var [form, setForm] = useState(function () {
985
+ return {
986
+ serverName: server.serverName || '',
987
+ transport: server.transport === 'streamable-http' ? 'streamable-http' : 'stdio',
988
+ command: server.command || '',
989
+ args: (server.args || []).join('\n'),
990
+ env: mapToLines(server.env),
991
+ cwd: server.cwd || '',
992
+ url: server.url || '',
993
+ headers: mapToLines(server.headers),
994
+ };
995
+ });
996
+ var [error, setError] = useState(null);
997
+ var [busy, setBusy] = useState(false);
998
+
999
+ function field(key) {
1000
+ return function (event) {
1001
+ var value = event.target.value;
1002
+ setForm(function (previous) {
1003
+ var next = Object.assign({}, previous);
1004
+ next[key] = value;
1005
+ return next;
1006
+ });
1007
+ };
1008
+ }
1009
+
1010
+ function submit() {
1011
+ if (busy) return;
1012
+ setBusy(true);
1013
+ setError(null);
1014
+ var http = form.transport === 'streamable-http';
1015
+ // `originalName` is sent only for an edit: it is what distinguishes
1016
+ // updating an existing row from creating one, and an accidental value
1017
+ // on a create would be rejected as an unknown server.
1018
+ api('save', {
1019
+ serverName: form.serverName,
1020
+ originalName: editing ? server.serverName : undefined,
1021
+ transport: form.transport,
1022
+ command: http ? '' : form.command,
1023
+ args: http ? [] : linesToArray(form.args),
1024
+ env: http ? {} : linesToMap(form.env),
1025
+ cwd: http ? '' : form.cwd,
1026
+ url: http ? form.url : '',
1027
+ headers: http ? linesToMap(form.headers) : {},
1028
+ })
1029
+ .then(function (result) {
1030
+ setBusy(false);
1031
+ props.onDone(result);
1032
+ })
1033
+ .catch(function (failure) {
1034
+ setBusy(false);
1035
+ setError(String((failure && failure.message) || failure));
1036
+ });
1037
+ }
1038
+
1039
+ function textField(key, label, hint, extra) {
1040
+ return h(
1041
+ 'div',
1042
+ { className: 'mcpmp-field' },
1043
+ h('label', null, label),
1044
+ h(
1045
+ 'input',
1046
+ Object.assign(
1047
+ {
1048
+ className: 'mcpmp-input',
1049
+ value: form[key],
1050
+ onChange: field(key),
1051
+ spellCheck: false,
1052
+ 'aria-label': label,
1053
+ },
1054
+ extra || {},
1055
+ ),
1056
+ ),
1057
+ hint ? h('small', null, hint) : null,
1058
+ );
1059
+ }
1060
+
1061
+ function areaField(key, label, hint) {
1062
+ return h(
1063
+ 'div',
1064
+ { className: 'mcpmp-field' },
1065
+ h('label', null, label),
1066
+ h('textarea', {
1067
+ className: 'mcpmp-textarea',
1068
+ rows: 4,
1069
+ spellCheck: false,
1070
+ 'aria-label': label,
1071
+ value: form[key],
1072
+ onChange: field(key),
1073
+ }),
1074
+ hint ? h('small', null, hint) : null,
1075
+ );
1076
+ }
1077
+
1078
+ var http = form.transport === 'streamable-http';
1079
+ return h(
1080
+ Modal,
1081
+ {
1082
+ title: editing ? t('editTitle') : t('addTitle'),
1083
+ closeLabel: t('close'),
1084
+ onClose: props.onClose,
1085
+ // Only an existing server can be reopened as JSON: the JSON editor
1086
+ // updates one named row, so it needs a row to name.
1087
+ headerExtra: editing
1088
+ ? h(Segmented, {
1089
+ label: t('modeLabel'),
1090
+ value: 'form',
1091
+ options: [
1092
+ { value: 'form', label: t('modeForm'), icon: ICON_PATH.form },
1093
+ { value: 'json', label: t('modeJson'), icon: ICON_PATH.code },
1094
+ ],
1095
+ onChange: function (mode) {
1096
+ if (mode === 'json') props.onSwitchToJson();
1097
+ },
1098
+ })
1099
+ : undefined,
1100
+ footer: h(
1101
+ 'div',
1102
+ { style: { display: 'flex', justifyContent: 'flex-end', gap: 8, width: '100%' } },
1103
+ h('button', { type: 'button', className: 'mcpmp-btn', onClick: props.onClose }, t('cancel')),
1104
+ h(
1105
+ 'button',
1106
+ { type: 'button', className: 'mcpmp-btn mcpmp-btn-primary', disabled: busy, onClick: submit },
1107
+ busy ? t('saving') : t('confirm'),
1108
+ ),
1109
+ ),
1110
+ },
1111
+ h(
1112
+ 'div',
1113
+ { className: 'mcpmp-field' },
1114
+ h('label', null, t('name')),
1115
+ h('input', {
1116
+ className: 'mcpmp-input',
1117
+ value: form.serverName,
1118
+ spellCheck: false,
1119
+ disabled: editing,
1120
+ 'aria-label': t('name'),
1121
+ onChange: field('serverName'),
1122
+ placeholder: 'my-server',
1123
+ }),
1124
+ h('small', null, t('nameHint')),
1125
+ ),
1126
+ h(
1127
+ 'div',
1128
+ { className: 'mcpmp-field' },
1129
+ h('label', null, t('transport')),
1130
+ h(
1131
+ 'select',
1132
+ {
1133
+ className: 'mcpmp-select',
1134
+ value: form.transport,
1135
+ 'aria-label': t('transport'),
1136
+ onChange: field('transport'),
1137
+ },
1138
+ h('option', { value: 'stdio' }, t('transportStdio')),
1139
+ h('option', { value: 'streamable-http' }, t('transportHttp')),
1140
+ ),
1141
+ ),
1142
+ http
1143
+ ? h(
1144
+ react.Fragment,
1145
+ null,
1146
+ textField('url', t('url'), t('urlHint'), { placeholder: 'http://localhost:3000/mcp' }),
1147
+ areaField('headers', t('headers'), t('headersHint')),
1148
+ )
1149
+ : h(
1150
+ react.Fragment,
1151
+ null,
1152
+ textField('command', t('command'), t('commandHint'), { placeholder: 'npx' }),
1153
+ areaField('args', t('args'), t('argsHint')),
1154
+ areaField('env', t('env'), t('envHint')),
1155
+ textField('cwd', t('cwd'), t('cwdHint')),
1156
+ ),
1157
+ error !== null ? h('div', { className: 'mcpmp-note mcpmp-note-error' }, error) : null,
1158
+ );
1159
+ }
1160
+
1161
+ /**
1162
+ * Language preference plumbing.
1163
+ *
1164
+ * The page supports three modes: "auto" (follow the harness locale, falling
1165
+ * back to the browser's language when the locale service is unreachable)
1166
+ * or a pinned language. The choice persists in localStorage so it survives
1167
+ * reloads. `localeRef.current` always holds the EFFECTIVE language; the
1168
+ * nav-row watcher and every API call read it.
1169
+ */
1170
+ var LANG_KEY = 'dsh-mcp-manager-plus:lang';
1171
+ var LANG_MODES = ['auto', 'zh', 'en'];
1172
+
1173
+ /** The persisted preference, defaulting to "auto". */
1174
+ function readLangPref() {
1175
+ try {
1176
+ var stored = localStorage.getItem(LANG_KEY);
1177
+ return LANG_MODES.indexOf(stored) !== -1 ? stored : 'auto';
1178
+ } catch (error) {
1179
+ return 'auto';
1180
+ }
1181
+ }
1182
+
1183
+ /** Persist a preference; a failing store only loses persistence. */
1184
+ function writeLangPref(mode) {
1185
+ try {
1186
+ localStorage.setItem(LANG_KEY, mode);
1187
+ } catch (error) {
1188
+ // ignore — the switch itself still works for this session
1189
+ }
1190
+ }
1191
+
1192
+ /** The browser's own language, used when the locale service is absent. */
1193
+ function browserLocale() {
1194
+ try {
1195
+ var languages = navigator.languages || [navigator.language];
1196
+ for (var i = 0; i < languages.length; i += 1) {
1197
+ var code = typeof languages[i] === 'string' ? languages[i].slice(0, 2).toLowerCase() : '';
1198
+ if (code === 'zh') return 'zh';
1199
+ if (code === 'en') return 'en';
1200
+ }
1201
+ } catch (error) {
1202
+ // fall through
1203
+ }
1204
+ return 'zh';
1205
+ }
1206
+
1207
+ var langPrefRef = { current: readLangPref() };
1208
+ /**
1209
+ * The harness locale as reported by the locale service, when reachable —
1210
+ * the resolution of "auto" prefers it over the browser guess.
1211
+ */
1212
+ var shellLocaleRef = { current: null };
1213
+ var localeRef = {
1214
+ current: langPrefRef.current === 'auto' ? browserLocale() : langPrefRef.current,
1215
+ };
1216
+
1217
+ /** The settings page itself. */
1218
+ function McpManagerPage() {
1219
+ // locale drives re-renders; localeRef mirrors it for non-React readers
1220
+ // (nav-row matching, api()).
1221
+ var [locale, setLocaleState] = useState(localeRef.current);
1222
+ var t = makeT(locale);
1223
+ var [state, setState] = useState({ status: 'loading', data: null, error: null });
1224
+ var [busyId, setBusyId] = useState(null);
1225
+ var [expanded, setExpanded] = useState({});
1226
+ var [dialog, setDialog] = useState(null);
1227
+ var [notice, setNotice] = useState(null);
1228
+ var settleTimer = useRef(null);
1229
+ var pageRef = useRef(null);
1230
+
1231
+ // Swap this page's settings nav-row icon. watchNavRow already keeps the
1232
+ // row flagged from registration time, so this is only a fallback for
1233
+ // environments where the observer is unavailable.
1234
+ useEffect(function () {
1235
+ return markNavRow(pageRef.current);
1236
+ }, []);
1237
+
1238
+ /** Fetch the inventory, optionally keeping the current view while it loads. */
1239
+ var load = useCallback(function (quiet) {
1240
+ if (!quiet) setState({ status: 'loading', data: null, error: null });
1241
+ return api('servers')
1242
+ .then(function (data) {
1243
+ setState({ status: 'ready', data: data, error: null });
1244
+ return data;
1245
+ })
1246
+ .catch(function (failure) {
1247
+ setState({ status: 'error', data: null, error: String((failure && failure.message) || failure) });
1248
+ });
1249
+ }, []);
1250
+
1251
+ useEffect(
1252
+ function () {
1253
+ load(false);
1254
+ return function () {
1255
+ if (settleTimer.current !== null) clearTimeout(settleTimer.current);
1256
+ };
1257
+ },
1258
+ [load],
1259
+ );
1260
+
1261
+ /**
1262
+ * After a write, the loader converges on its own schedule (the profile's
1263
+ * file watcher), so poll a few times rather than reporting a tool list
1264
+ * that is still one generation stale.
1265
+ */
1266
+ function settle() {
1267
+ if (settleTimer.current !== null) clearTimeout(settleTimer.current);
1268
+ var attempts = 0;
1269
+ function tick() {
1270
+ attempts += 1;
1271
+ load(true).then(function () {
1272
+ if (attempts < 5) settleTimer.current = setTimeout(tick, 450);
1273
+ else settleTimer.current = null;
1274
+ });
1275
+ }
1276
+ settleTimer.current = setTimeout(tick, 350);
1277
+ }
1278
+
1279
+ /**
1280
+ * Switch the page language. "auto" resolves to the harness locale when
1281
+ * the locale service reported one, else the browser's language. The
1282
+ * choice persists and re-renders the whole page; api() picks the change
1283
+ * up for host-side messages on the next request.
1284
+ */
1285
+ function setLang(mode) {
1286
+ writeLangPref(mode);
1287
+ langPrefRef.current = mode;
1288
+ var next =
1289
+ mode === 'auto'
1290
+ ? shellLocaleRef.current !== null
1291
+ ? shellLocaleRef.current
1292
+ : browserLocale()
1293
+ : mode;
1294
+ localeRef.current = next;
1295
+ setLocaleState(next);
1296
+ }
1297
+
1298
+ /** Run one mutation, folding the returned state back into the page. */
1299
+ function run(id, promise, successMessage) {
1300
+ setBusyId(id);
1301
+ return promise
1302
+ .then(function (result) {
1303
+ setBusyId(null);
1304
+ if (result && result.state) setState({ status: 'ready', data: result.state, error: null });
1305
+ if (successMessage !== undefined) setNotice(successMessage);
1306
+ settle();
1307
+ return result;
1308
+ })
1309
+ .catch(function (failure) {
1310
+ setBusyId(null);
1311
+ setNotice(String((failure && failure.message) || failure));
1312
+ return null;
1313
+ });
1314
+ }
1315
+
1316
+ var data = state.data;
1317
+ var servers = data !== null && Array.isArray(data.servers) ? data.servers : [];
1318
+ var issues = data !== null && Array.isArray(data.issues) ? data.issues : [];
1319
+ var readOnly = data !== null && data.writable === false;
1320
+
1321
+ var transfer = null;
1322
+ if (state.status === 'loading') {
1323
+ transfer = h('div', { className: 'mcpmp-note' }, t('loading'));
1324
+ } else if (state.status === 'error') {
1325
+ transfer = h(
1326
+ 'div',
1327
+ { className: 'mcpmp-note mcpmp-note-error' },
1328
+ t('loadFailed') + ':' + state.error,
1329
+ ' ',
1330
+ h(
1331
+ 'button',
1332
+ {
1333
+ type: 'button',
1334
+ className: 'mcpmp-btn mcpmp-btn-sm',
1335
+ onClick: function () {
1336
+ load(false);
1337
+ },
1338
+ },
1339
+ t('retry'),
1340
+ ),
1341
+ );
1342
+ } else if (servers.length === 0) {
1343
+ transfer = h(
1344
+ 'div',
1345
+ { className: 'mcpmp-note' },
1346
+ h('div', null, t('empty')),
1347
+ h('div', { style: { marginTop: 2 } }, t('emptyHint')),
1348
+ );
1349
+ } else {
1350
+ transfer = h(
1351
+ 'div',
1352
+ { className: 'mcpmp-list' },
1353
+ servers.map(function (server) {
1354
+ return h(ServerCard, {
1355
+ key: server.id + ':' + server.serverName,
1356
+ t: t,
1357
+ server: server,
1358
+ busy: busyId === server.id,
1359
+ expanded: expanded[server.serverName] === true,
1360
+ onExpand: function () {
1361
+ setExpanded(function (previous) {
1362
+ var next = Object.assign({}, previous);
1363
+ next[server.serverName] = !(previous[server.serverName] === true);
1364
+ return next;
1365
+ });
1366
+ },
1367
+ onToggle: function () {
1368
+ run(server.id, api('toggle', { id: server.id, enabled: !server.enabled, source: server.source }));
1369
+ },
1370
+ onRestart: function () {
1371
+ run(server.id, api('restart', { id: server.id }), t('restartDone', { name: server.serverName }));
1372
+ },
1373
+ onRemove: function () {
1374
+ if (!window.confirm(t('removeConfirm', { name: server.serverName }))) return;
1375
+ run(server.id, api('remove', { id: server.id }), t('removed') + ':' + server.serverName);
1376
+ },
1377
+ onEdit: function () {
1378
+ setDialog({ kind: 'form', server: server });
1379
+ },
1380
+ });
1381
+ }),
1382
+ );
1383
+ }
1384
+
1385
+ return h(
1386
+ 'div',
1387
+ { className: 'mcpmp-root', ref: pageRef },
1388
+ h(
1389
+ 'div',
1390
+ { className: 'mcpmp-head' },
1391
+ h('div', null, h('h2', null, t('title')), h('p', null, t('description'))),
1392
+ h(
1393
+ 'div',
1394
+ { style: { display: 'flex', gap: 8, alignItems: 'center' } },
1395
+ h(
1396
+ 'label',
1397
+ { className: 'mcpmp-lang', title: t('langLabel') },
1398
+ h('span', { className: 'mcpmp-lang-glyph', 'aria-hidden': 'true' }, '文A'),
1399
+ h(
1400
+ 'select',
1401
+ {
1402
+ value: langPrefRef.current,
1403
+ onChange: function (event) {
1404
+ setLang(event.target.value);
1405
+ },
1406
+ 'aria-label': t('langLabel'),
1407
+ },
1408
+ h('option', { value: 'auto' }, t('langAuto')),
1409
+ h('option', { value: 'zh' }, '中文'),
1410
+ h('option', { value: 'en' }, 'English'),
1411
+ ),
1412
+ ),
1413
+ h(
1414
+ 'button',
1415
+ {
1416
+ type: 'button',
1417
+ className: 'mcpmp-btn mcpmp-btn-sm mcpmp-icon',
1418
+ title: t('refresh'),
1419
+ 'aria-label': t('refresh'),
1420
+ disabled: state.status === 'loading',
1421
+ onClick: function () {
1422
+ api('refresh', {}).then(function (next) {
1423
+ setState({ status: 'ready', data: next, error: null });
1424
+ });
1425
+ },
1426
+ },
1427
+ h(Icon, { path: ICON_PATH.refresh, size: 14 }),
1428
+ ),
1429
+ h(
1430
+ 'button',
1431
+ {
1432
+ type: 'button',
1433
+ className: 'mcpmp-btn mcpmp-btn-primary',
1434
+ disabled: readOnly,
1435
+ onClick: function () {
1436
+ setDialog({ kind: 'manual' });
1437
+ },
1438
+ },
1439
+ h(Icon, { path: ICON_PATH.plus, size: 13 }),
1440
+ t('add'),
1441
+ ),
1442
+ ),
1443
+ ),
1444
+
1445
+ readOnly
1446
+ ? h('div', { className: 'mcpmp-note mcpmp-note-warn' }, t('notWritable', { path: data.patchPath }))
1447
+ : null,
1448
+
1449
+ issues.length > 0
1450
+ ? h(
1451
+ 'div',
1452
+ { className: 'mcpmp-note mcpmp-note-warn' },
1453
+ h('div', { style: { fontWeight: 500, marginBottom: 4 } }, t('issues')),
1454
+ issues.map(function (issue, index) {
1455
+ return h('div', { key: index }, '• ' + issue);
1456
+ }),
1457
+ )
1458
+ : null,
1459
+
1460
+ notice !== null
1461
+ ? h(
1462
+ 'div',
1463
+ {
1464
+ className: 'mcpmp-note',
1465
+ style: { display: 'flex', justifyContent: 'space-between', gap: 12, alignItems: 'center' },
1466
+ },
1467
+ h('span', null, notice),
1468
+ h(
1469
+ 'button',
1470
+ {
1471
+ type: 'button',
1472
+ className: 'mcpmp-btn mcpmp-btn-sm',
1473
+ onClick: function () {
1474
+ setNotice(null);
1475
+ },
1476
+ },
1477
+ t('close'),
1478
+ ),
1479
+ )
1480
+ : null,
1481
+
1482
+ transfer,
1483
+
1484
+ dialog !== null && dialog.kind === 'manual'
1485
+ ? h(ManualConfigDialog, {
1486
+ t: t,
1487
+ server: dialog.server,
1488
+ onClose: function () {
1489
+ setDialog(null);
1490
+ },
1491
+ onDone: function (result) {
1492
+ setDialog(null);
1493
+ setNotice(t('imported') + ':' + (result.message || ''));
1494
+ settle();
1495
+ },
1496
+ // Switching back keeps the same server, so the form reopens
1497
+ // seeded from the row as it is on disk rather than from whatever
1498
+ // was half-typed in the JSON box.
1499
+ onSwitchToForm: dialog.server
1500
+ ? function () {
1501
+ var server = dialog.server;
1502
+ setDialog({ kind: 'form', server: server });
1503
+ }
1504
+ : undefined,
1505
+ })
1506
+ : null,
1507
+
1508
+ dialog !== null && dialog.kind === 'form'
1509
+ ? h(ServerFormDialog, {
1510
+ t: t,
1511
+ server: dialog.server,
1512
+ onClose: function () {
1513
+ setDialog(null);
1514
+ },
1515
+ onDone: function (result) {
1516
+ setDialog(null);
1517
+ if (result && result.state) setState({ status: 'ready', data: result.state, error: null });
1518
+ setNotice(t('saved') + ':' + (result.serverName || ''));
1519
+ settle();
1520
+ },
1521
+ onSwitchToJson: dialog.server
1522
+ ? function () {
1523
+ var server = dialog.server;
1524
+ setDialog({ kind: 'manual', server: server });
1525
+ }
1526
+ : undefined,
1527
+ })
1528
+ : null,
1529
+ );
1530
+ }
1531
+
1532
+ exports.name = 'dsh-mcp-manager-plus';
1533
+ // `slots` must be DECLARED, not merely looked up. A declared service is
1534
+ // resolved before apply() runs and parks the plugin until its provider
1535
+ // exists; `ctx.get('slots')` with an empty inject list resolves to
1536
+ // `undefined` even while the service is live, so the page would never
1537
+ // register. `locale` stays optional (ctx.get) because it is a
1538
+ // nice-to-have: the page falls back to its built-in dictionary.
1539
+ exports.inject = ['slots'];
1540
+
1541
+ exports.apply = function apply(ctx) {
1542
+ installStyles();
1543
+
1544
+ var locale = ctx.get('locale');
1545
+ if (locale !== undefined && typeof locale.register === 'function') {
1546
+ ctx.effect(
1547
+ function () {
1548
+ return locale.register(NS, { zh: DICT.zh, en: DICT.en });
1549
+ },
1550
+ 'dsh-mcp-manager-plus: dictionaries',
1551
+ );
1552
+ // Track the active locale so "auto" mode follows the UI language. A
1553
+ // pinned language ignores the harness locale entirely.
1554
+ try {
1555
+ var read = function () {
1556
+ var id = locale.getLocale().id === 'en' ? 'en' : 'zh';
1557
+ shellLocaleRef.current = id;
1558
+ if (langPrefRef.current === 'auto') localeRef.current = id;
1559
+ };
1560
+ read();
1561
+ ctx.effect(function () {
1562
+ return locale.subscribe(read);
1563
+ }, 'dsh-mcp-manager-plus: locale mirror');
1564
+ } catch (error) {
1565
+ console.warn('[dsh-mcp-manager-plus] locale mirror skipped:', error);
1566
+ }
1567
+ }
1568
+
1569
+ // `slots` is declared in `inject`, so it is present by the time apply()
1570
+ // runs. A registration failure is reported by throwing: a settings page
1571
+ // that silently never appears is the one failure mode this plugin must
1572
+ // not have.
1573
+ var slots = ctx.slots;
1574
+ if (slots === undefined) {
1575
+ throw new Error(
1576
+ '[dsh-mcp-manager-plus] the slots service is unavailable, so the settings page cannot be registered',
1577
+ );
1578
+ }
1579
+ ctx.effect(function () {
1580
+ return slots.inject('settings.section', function () {
1581
+ return slots.register(
1582
+ {
1583
+ name: 'settings.section',
1584
+ id: 'mcp',
1585
+ order: 35,
1586
+ label: function () {
1587
+ return makeT(localeRef.current)('nav');
1588
+ },
1589
+ },
1590
+ McpManagerPage,
1591
+ );
1592
+ });
1593
+ }, 'dsh-mcp-manager-plus: settings section');
1594
+
1595
+ // Flag the nav row from the moment the shell first renders it, so the
1596
+ // link icon shows before the page is ever opened.
1597
+ ctx.effect(watchNavRow, 'dsh-mcp-manager-plus: nav row icon watch');
1598
+ };
1599
+
1600
+ return module.exports;
1601
+ },
1602
+ });