@tachec/dsh-mcp-manage 0.0.0-stage → 1.2.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/client.js ADDED
@@ -0,0 +1,2354 @@
1
+ /**
2
+ * dsh-mcp-manage — browser half.
3
+ *
4
+ * A Settings section (Settings → MCP) that manages every MCP server the
5
+ * Harness can run:
6
+ *
7
+ * - managed servers in `@deepseek-ai/dsh-mcp-manager` (add, edit, enable,
8
+ * disable, probe, restart, delete) with a form or pasted JSON;
9
+ * - statically composed `@deepseek-ai/dsh-mcp-client` rows (view, enable,
10
+ * disable, edit, tool list);
11
+ * - MCP servers found in other agent tools' configuration on this machine,
12
+ * with one-click import.
13
+ *
14
+ * The Host half owns persistence and validation; this module only renders the
15
+ * snapshot and posts actions to `/dsh-mcp-manage/api`. Plain ModuleLoader bundle:
16
+ * no build step, React from the page's module table.
17
+ */
18
+
19
+ window.__ModuleLoader__.load({
20
+ id: 'dsh-mcp-manage',
21
+ factory: (require) => {
22
+ const module = { exports: {} }
23
+ const exports = module.exports
24
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
25
+
26
+ const React = require('react')
27
+ const h = React.createElement
28
+ const { useCallback, useEffect, useRef, useState } = React
29
+
30
+ const name = 'dsh-mcp-manage'
31
+ const inject = ['slots', 'locale']
32
+ const NS = 'settings.mcpHub'
33
+ const ROUTE = '/dsh-mcp-manage/api'
34
+ const NAME_PATTERN = /^[A-Za-z0-9_-]{1,32}$/
35
+ const POLL_MS = 5000
36
+ const SHORTCUT_KEY = 'dsh-mcp-manage.sidebarShortcut'
37
+
38
+ /** The sidebar preference as this page last saw it; synchronous at boot. */
39
+ function readLocalShortcut() {
40
+ try {
41
+ if (typeof localStorage === 'undefined') return true
42
+ const stored = localStorage.getItem(SHORTCUT_KEY)
43
+ if (stored === '0') return false
44
+ if (stored === '1') return true
45
+ } catch { /* storage denied: fall back to the default */ }
46
+ return true
47
+ }
48
+
49
+ function writeLocalShortcut(enabled) {
50
+ try {
51
+ if (typeof localStorage === 'undefined') return
52
+ localStorage.setItem(SHORTCUT_KEY, enabled === true ? '1' : '0')
53
+ } catch { /* the Host preference remains authoritative */ }
54
+ }
55
+
56
+ // =========================================================================
57
+ // Locale
58
+ // =========================================================================
59
+
60
+ const zh = {
61
+ nav: 'MCP',
62
+ title: 'MCP 服务器',
63
+ lead: '集中管理这个 Harness 接入的 MCP 服务器。保存后立即生效,无需重启。',
64
+ refresh: '刷新',
65
+ add: '添加服务器',
66
+ loading: '正在读取 MCP 配置…',
67
+ failed: '操作失败',
68
+ retry: '重试',
69
+ scan: '重新扫描',
70
+ 'summary.all': '共 {count} 个托管服务器',
71
+ 'summary.connected': '{count} 个已连接',
72
+ 'summary.disabled': '{count} 个已停用',
73
+ 'summary.static': '静态接入 {count} 个',
74
+ 'summary.found': '本机发现 {count} 个可导入',
75
+ 'empty.title': '还没有托管服务器',
76
+ 'empty.hint': '添加一个 stdio 或 Streamable HTTP 服务器,它的工具会立刻出现在 Agent 的工具列表里。',
77
+ 'transport.stdio': 'STDIO',
78
+ 'transport.http': 'HTTP',
79
+ 'origin.base': '基础配置',
80
+ 'origin.profile': '本页添加',
81
+ 'origin.override': '已覆盖',
82
+ 'status.connected': '已连接 · {count} 个工具',
83
+ 'status.connectedAt': '连接于 {time}',
84
+ 'status.connecting': '连接中…',
85
+ 'status.reconnecting': '重连中({attempt}/{max})',
86
+ 'status.waiting': '等待凭据',
87
+ 'status.failed': '连接失败',
88
+ 'status.disabled': '已停用',
89
+ 'status.closed': '已关闭',
90
+ 'status.unknown': '状态未知',
91
+ 'status.rowFailed': '插件行加载失败',
92
+ 'status.noTools': '运行中,暂无工具',
93
+ 'tools.title': '已注册工具',
94
+ 'tools.none': '连接后这里会列出服务器提供的工具。',
95
+ 'tools.more': '还有 {count} 个',
96
+ 'action.probe': '探测',
97
+ 'action.restart': '重启',
98
+ 'action.edit': '编辑',
99
+ 'action.delete': '删除',
100
+ 'action.deleteDisabled': '来自基础配置的服务器不能删除,只能停用。',
101
+ 'action.import': '导入',
102
+ 'action.close': '关闭',
103
+ 'action.cancel': '取消',
104
+ 'action.save': '保存',
105
+ 'action.saving': '保存中…',
106
+ 'action.config': '查看配置',
107
+ 'action.enable': '启用',
108
+ 'action.disable': '停用',
109
+ 'status.restarting': '正在重启…',
110
+ 'form.close': '关闭超时(毫秒)',
111
+ 'form.jsonRequired': '请粘贴 JSON 配置。',
112
+ 'form.jsonReplace': 'JSON 会替换这个服务器的完整配置(名称保持不变)。',
113
+ 'form.jsonSingleName': '单独写一个服务器对象时需要 "name" 字段。',
114
+ 'errors.invalid-name': '名称 “{name}” 不合法:只能使用字母、数字、下划线或连字符,长度 1–32。',
115
+ 'errors.duplicate': '服务器 “{name}” 已存在,请换一个名称或直接编辑它。',
116
+ 'errors.static-collision': '名字 “{name}” 已被静态配置的 MCP 行占用;请换一个名字,或先停用那一行。',
117
+ 'errors.transport-required': '请选择传输方式:stdio 或 streamable-http。',
118
+ 'errors.command-required': 'stdio 服务器必须填写启动命令。',
119
+ 'errors.url-required': 'streamable-http 服务器必须填写以 http:// 或 https:// 开头的地址。',
120
+ 'errors.sse-unsupported': '不支持旧的 SSE 传输;请改用 Streamable HTTP。',
121
+ 'errors.invalid-json': 'JSON 格式不正确。',
122
+ 'errors.name-required': '单个服务器对象需要一个 name 或 serverName 字段。',
123
+ 'errors.invalid-server': '服务器配置格式不正确。',
124
+ 'errors.not-found': '找不到服务器 “{name}”。',
125
+ 'errors.inherited-readonly': '来自基础配置的服务器不能删除,只能停用。',
126
+ 'errors.manager-missing': '当前 profile 没有挂载 MCP 管理器,无法保存托管服务器。',
127
+ 'errors.manager-disabled': 'MCP 管理器当前被停用,无法保存托管服务器。',
128
+ 'errors.manager-unavailable': 'MCP 管理器还没有就绪,请稍后重试。',
129
+ 'errors.settings-missing': '设置服务未就绪,无法保存 MCP 配置。',
130
+ 'errors.loader-unavailable': '读取插件清单失败。',
131
+ 'errors.disabled': '这个静态 MCP 行已停用,请先启用再编辑。',
132
+ 'errors.not-mcp-client': '这个插件行不是 MCP 客户端。',
133
+ 'errors.config-editor-missing': '配置编辑服务不可用,无法保存静态 MCP 行。',
134
+ 'errors.plugin-manager-missing': '插件管理服务不可用,无法启停静态 MCP 行。',
135
+ 'errors.server-required': '缺少服务器配置。',
136
+ 'errors.json-name-mismatch': 'JSON 中没有对应的服务器配置。',
137
+ 'errors.empty': '没有要添加的服务器。',
138
+ 'errors.unknown-action': '未知操作。',
139
+ 'errors.body-too-large': '请求体过大。',
140
+ 'errors.invalid-body': '请求体格式不正确。',
141
+ 'errors.SETTINGS_CONFLICT': '配置已被其他页面修改,请刷新后重试。',
142
+ 'errors.invalid-preference': '偏好值不合法。',
143
+ 'errors.preferences-write-failed': '保存页面偏好失败。',
144
+ 'errors.error': '操作失败,请查看 Host 日志。',
145
+ 'notice.saved': '已保存',
146
+ 'notice.imported': '已导入',
147
+ 'notice.refreshed': '已刷新',
148
+ 'notice.restartRequired': '已保存,重启 DSH 后生效。',
149
+ 'notice.secrets': '环境变量与请求头会明文保存在 profile 中;密钥请使用 ${credential:REF} 模板,由凭据服务解析。',
150
+ 'version.label': '界面版本 1.5',
151
+ 'shortcut.title': '左侧栏快捷入口',
152
+ 'shortcut.hint': '在 DSH 左侧栏显示 MCP 图标,点击直接打开本页。',
153
+ 'confirm.deleteTitle': '删除服务器',
154
+ 'confirm.deleteBody': '删除 “{name}” 后,它的工具会立即从 Agent 中移除,配置也会从当前 profile 中删除。',
155
+ 'confirm.enableTitle': '启用静态 MCP 行',
156
+ 'confirm.enableBody': '启用 “{name}” 会立即挂载这一行并连接服务器。继续?',
157
+ 'confirm.disableTitle': '停用静态 MCP 行',
158
+ 'confirm.disableBody': '停用 “{name}” 会立即断开并移除它的工具,配置仍保留在 profile 中。继续?',
159
+ 'probe.running': '探测中…',
160
+ 'probe.ok': '连接成功 · {count} 个工具 · {ms} ms',
161
+ 'probe.truncated': '工具列表已截断',
162
+ 'probe.failed': '{stage}阶段失败:{message}({ms} ms)',
163
+ 'probe.stage.connect': '连接',
164
+ 'probe.stage.list': '列出工具',
165
+ 'probe.cleanup': '关闭时有告警:{message}',
166
+ 'form.addTitle': '添加 MCP 服务器',
167
+ 'form.editTitle': '编辑 {name}',
168
+ 'form.staticTitle': '编辑静态 MCP 行 {name}',
169
+ 'form.lead': 'stdio 服务器由本机命令启动;Streamable HTTP 服务器通过 URL 连接。',
170
+ 'form.tabForm': '表单',
171
+ 'form.tabJson': 'JSON',
172
+ 'form.name': '名称',
173
+ 'form.nameHint': '用于工具前缀 mcp__<名称>__,只能包含字母、数字、下划线、连字符。',
174
+ 'form.transport': '传输方式',
175
+ 'form.command': '启动命令',
176
+ 'form.commandHint': '例如 npx、uvx,或可执行文件的绝对路径。',
177
+ 'form.args': '参数',
178
+ 'form.argsHint': '每行一个参数,不做 shell 展开。',
179
+ 'form.env': '环境变量',
180
+ 'form.envHint': '每行 KEY=VALUE;值支持 ${credential:REF} 模板。',
181
+ 'form.cwd': '工作目录',
182
+ 'form.cwdHint': '可选;留空使用 Harness 进程目录。',
183
+ 'form.url': '服务地址',
184
+ 'form.urlHint': 'Streamable HTTP 端点,例如 https://example.com/mcp。',
185
+ 'form.headers': '请求头',
186
+ 'form.headersHint': '每行 Key: Value;值支持 ${credential:REF} 模板。',
187
+ 'form.advanced': '高级选项',
188
+ 'form.startup': '启动超时(毫秒)',
189
+ 'form.call': '调用超时(毫秒)',
190
+ 'form.reconnect': '断线自动重连',
191
+ 'form.failOnStartup': '启动失败时让插件行加载失败',
192
+ 'form.jsonHint': '粘贴 Claude Desktop / Cursor 的 mcpServers 配置、DSH 的 servers 配置,或单个服务器对象;一次可以添加多个。',
193
+ 'form.jsonEditHint': '只修改当前服务器:可以只写一个服务器对象,名称保持为 “{name}”。',
194
+ 'form.jsonPlaceholder': '{\n "mcpServers": {\n "github": {\n "command": "npx",\n "args": ["-y", "@modelcontextprotocol/server-github"],\n "env": { "GITHUB_TOKEN": "..." }\n }\n }\n}',
195
+ 'form.requiredCommand': '请填写启动命令。',
196
+ 'form.requiredUrl': '请填写以 http:// 或 https:// 开头的地址。',
197
+ 'form.badName': '名称不合法:只能使用字母、数字、下划线或连字符,长度 1–32。',
198
+ 'form.nameTaken': '这个名称已经存在。',
199
+ 'form.advancedHint': '留空表示使用默认值。',
200
+ 'static.title': '静态接入',
201
+ 'static.lead': '这些服务器由 profile 或插件补丁里的 @deepseek-ai/dsh-mcp-client 行挂载。可以在这里启停、编辑或查看工具;删除需要在对应的补丁里移除。',
202
+ 'static.disabledHint': '这一行已停用;启用后才能编辑配置。',
203
+ 'static.conflict': '与托管服务器同名,可能无法同时运行。',
204
+ 'static.empty': '没有静态接入的 MCP 行。',
205
+ 'static.phase': '插件状态:{phase}',
206
+ 'phase.pending': '等待加载',
207
+ 'phase.loading': '加载中',
208
+ 'phase.active': '运行中',
209
+ 'phase.failed': '加载失败',
210
+ 'phase.unloading': '卸载中',
211
+ 'discover.title': '从本机其他应用导入',
212
+ 'discover.lead': '读取本机已有的 MCP 配置(只读),导入后由本页托管。',
213
+ 'discover.empty': '没有在本机常见 MCP 配置文件中找到服务器。',
214
+ 'discover.import': '导入',
215
+ 'discover.importing': '导入中…',
216
+ 'discover.found': '{count} 个服务器',
217
+ 'discover.fileError': '读取失败:{message}',
218
+ 'discover.rowError': '无法导入:{message}',
219
+ 'discover.already': '已在托管列表中',
220
+ 'note.title': '写入位置',
221
+ 'note.body': '托管服务器通过设置服务写入当前 profile 的 cordis.patch.yml;静态行通过配置编辑器与插件管理器修改。所有更改只影响当前 profile。',
222
+ 'manager.missing': '没有检测到 MCP 管理器(@deepseek-ai/dsh-mcp-manager),无法添加托管服务器。',
223
+ 'manager.disabled': 'MCP 管理器已被停用,托管服务器暂不可编辑。',
224
+ 'manager.unavailable': 'MCP 管理器尚未就绪,请稍后刷新。',
225
+ 'capability.unavailable': '静态行编辑不可用:缺少配置编辑或插件管理服务。',
226
+ 'warn.title': '提示',
227
+ 'env.title': '环境变量',
228
+ 'headers.title': '请求头',
229
+ 'config.transport': '传输',
230
+ 'config.command': '命令',
231
+ 'config.url': '地址',
232
+ 'config.cwd': '工作目录',
233
+ 'config.startup': '启动超时',
234
+ 'config.call': '调用超时',
235
+ 'config.reconnect': '自动重连',
236
+ 'config.enabled': '启用',
237
+ 'config.none': '无额外配置',
238
+ 'config.on': '开',
239
+ 'config.off': '关',
240
+ copy: '复制',
241
+ copied: '已复制',
242
+ 'error.http': 'Host 返回了 {status},MCP 管理页的后端可能还没有加载。',
243
+ }
244
+
245
+ const en = {
246
+ nav: 'MCP',
247
+ title: 'MCP servers',
248
+ lead: 'Every MCP server this Harness can use, in one place. Changes apply immediately; no restart needed.',
249
+ refresh: 'Refresh',
250
+ add: 'Add server',
251
+ loading: 'Reading MCP configuration…',
252
+ failed: 'Operation failed',
253
+ retry: 'Retry',
254
+ scan: 'Scan again',
255
+ 'summary.all': '{count} managed server(s)',
256
+ 'summary.connected': '{count} connected',
257
+ 'summary.disabled': '{count} disabled',
258
+ 'summary.static': '{count} statically composed',
259
+ 'summary.found': '{count} importable on this machine',
260
+ 'empty.title': 'No managed servers yet',
261
+ 'empty.hint': 'Add a stdio or Streamable HTTP server and its tools appear in the agent tool list right away.',
262
+ 'transport.stdio': 'STDIO',
263
+ 'transport.http': 'HTTP',
264
+ 'origin.base': 'base config',
265
+ 'origin.profile': 'added here',
266
+ 'origin.override': 'overridden',
267
+ 'status.connected': 'Connected · {count} tools',
268
+ 'status.connectedAt': 'connected at {time}',
269
+ 'status.connecting': 'Connecting…',
270
+ 'status.reconnecting': 'Reconnecting ({attempt}/{max})',
271
+ 'status.waiting': 'Waiting for credentials',
272
+ 'status.failed': 'Connection failed',
273
+ 'status.disabled': 'Disabled',
274
+ 'status.closed': 'Closed',
275
+ 'status.unknown': 'Unknown state',
276
+ 'status.rowFailed': 'Plugin row failed to load',
277
+ 'status.noTools': 'Running, no tools yet',
278
+ 'tools.title': 'Registered tools',
279
+ 'tools.none': 'Tools this server provides appear here once it connects.',
280
+ 'tools.more': '{count} more',
281
+ 'action.probe': 'Probe',
282
+ 'action.restart': 'Restart',
283
+ 'action.edit': 'Edit',
284
+ 'action.delete': 'Delete',
285
+ 'action.deleteDisabled': 'A base-config server cannot be deleted; disable it instead.',
286
+ 'action.import': 'Import',
287
+ 'action.close': 'Close',
288
+ 'action.cancel': 'Cancel',
289
+ 'action.save': 'Save',
290
+ 'action.saving': 'Saving…',
291
+ 'action.config': 'Configuration',
292
+ 'action.enable': 'Enable',
293
+ 'action.disable': 'Disable',
294
+ 'status.restarting': 'Restarting…',
295
+ 'form.close': 'Close timeout (ms)',
296
+ 'form.jsonRequired': 'Paste a JSON configuration.',
297
+ 'form.jsonReplace': 'JSON replaces this server’s whole configuration (the name stays).',
298
+ 'form.jsonSingleName': 'A standalone server object needs a "name" field.',
299
+ 'errors.invalid-name': 'Invalid name “{name}”: letters, digits, underscore or hyphen, 1–32 characters.',
300
+ 'errors.duplicate': 'Server “{name}” already exists; rename it or edit it instead.',
301
+ 'errors.static-collision': '“{name}” is used by a statically composed MCP row; pick another name or disable that row first.',
302
+ 'errors.transport-required': 'Choose a transport: stdio or streamable-http.',
303
+ 'errors.command-required': 'A stdio server needs a command.',
304
+ 'errors.url-required': 'A streamable-http server needs an http:// or https:// URL.',
305
+ 'errors.sse-unsupported': 'The legacy SSE transport is not supported; use Streamable HTTP.',
306
+ 'errors.invalid-json': 'The JSON is not valid.',
307
+ 'errors.name-required': 'A standalone server object needs a name or serverName field.',
308
+ 'errors.invalid-server': 'The server configuration has the wrong shape.',
309
+ 'errors.not-found': 'No server named “{name}”.',
310
+ 'errors.inherited-readonly': 'A base-config server cannot be deleted; disable it instead.',
311
+ 'errors.manager-missing': 'No MCP manager is composed in this profile, so managed servers cannot be saved.',
312
+ 'errors.manager-disabled': 'The MCP manager is disabled, so managed servers cannot be saved.',
313
+ 'errors.manager-unavailable': 'The MCP manager is not ready yet; try again in a moment.',
314
+ 'errors.settings-missing': 'The settings service is not ready; the MCP configuration cannot be saved.',
315
+ 'errors.loader-unavailable': 'The plugin list could not be read.',
316
+ 'errors.disabled': 'This static MCP row is disabled; enable it before editing.',
317
+ 'errors.not-mcp-client': 'That plugin row is not an MCP client.',
318
+ 'errors.config-editor-missing': 'The config editor is unavailable; the static MCP row cannot be saved.',
319
+ 'errors.plugin-manager-missing': 'The plugin manager is unavailable; the static MCP row cannot be toggled.',
320
+ 'errors.server-required': 'The server configuration is missing.',
321
+ 'errors.json-name-mismatch': 'The JSON holds no configuration for this server.',
322
+ 'errors.empty': 'There is no server to add.',
323
+ 'errors.unknown-action': 'Unknown operation.',
324
+ 'errors.body-too-large': 'The request body is too large.',
325
+ 'errors.invalid-body': 'The request body is malformed.',
326
+ 'errors.SETTINGS_CONFLICT': 'The configuration changed in another page; refresh and try again.',
327
+ 'errors.invalid-preference': 'That preference value is invalid.',
328
+ 'errors.preferences-write-failed': 'The page preference could not be saved.',
329
+ 'errors.error': 'The operation failed; check the Host log.',
330
+ 'notice.saved': 'Saved',
331
+ 'notice.imported': 'Imported',
332
+ 'notice.refreshed': 'Refreshed',
333
+ 'notice.restartRequired': 'Saved; restart DSH to apply.',
334
+ 'notice.secrets': 'Environment values and headers are stored in the profile as plain text; keep secrets in ${credential:REF} templates so the credentials service resolves them.',
335
+ 'version.label': 'UI build 1.5',
336
+ 'shortcut.title': 'Sidebar shortcut',
337
+ 'shortcut.hint': 'Show an MCP icon in the DSH sidebar that opens this page.',
338
+ 'confirm.deleteTitle': 'Delete server',
339
+ 'confirm.deleteBody': 'Deleting “{name}” removes its tools from the agent immediately and drops the configuration from this profile.',
340
+ 'confirm.enableTitle': 'Enable static MCP row',
341
+ 'confirm.enableBody': 'Enabling “{name}” mounts the row and connects the server immediately. Continue?',
342
+ 'confirm.disableTitle': 'Disable static MCP row',
343
+ 'confirm.disableBody': 'Disabling “{name}” disconnects it and removes its tools immediately. The configuration stays in the profile. Continue?',
344
+ 'probe.running': 'Probing…',
345
+ 'probe.ok': 'Connected · {count} tools · {ms} ms',
346
+ 'probe.truncated': 'tool list truncated',
347
+ 'probe.failed': 'Failed at {stage}: {message} ({ms} ms)',
348
+ 'probe.stage.connect': 'connect',
349
+ 'probe.stage.list': 'list',
350
+ 'probe.cleanup': 'Close reported: {message}',
351
+ 'form.addTitle': 'Add MCP server',
352
+ 'form.editTitle': 'Edit {name}',
353
+ 'form.staticTitle': 'Edit static MCP row {name}',
354
+ 'form.lead': 'stdio servers start a local command; Streamable HTTP servers connect to a URL.',
355
+ 'form.tabForm': 'Form',
356
+ 'form.tabJson': 'JSON',
357
+ 'form.name': 'Name',
358
+ 'form.nameHint': 'Used in tool names as mcp__<name>__; letters, digits, underscore and hyphen only.',
359
+ 'form.transport': 'Transport',
360
+ 'form.command': 'Command',
361
+ 'form.commandHint': 'For example npx, uvx, or an absolute path to an executable.',
362
+ 'form.args': 'Arguments',
363
+ 'form.argsHint': 'One argument per line; no shell expansion.',
364
+ 'form.env': 'Environment',
365
+ 'form.envHint': 'One KEY=VALUE per line; values may use ${credential:REF} templates.',
366
+ 'form.cwd': 'Working directory',
367
+ 'form.cwdHint': 'Optional; empty uses the Harness process directory.',
368
+ 'form.url': 'Endpoint URL',
369
+ 'form.urlHint': 'Streamable HTTP endpoint, for example https://example.com/mcp.',
370
+ 'form.headers': 'Headers',
371
+ 'form.headersHint': 'One Key: Value per line; values may use ${credential:REF} templates.',
372
+ 'form.advanced': 'Advanced',
373
+ 'form.startup': 'Startup timeout (ms)',
374
+ 'form.call': 'Call timeout (ms)',
375
+ 'form.reconnect': 'Reconnect automatically',
376
+ 'form.failOnStartup': 'Fail the plugin row when startup fails',
377
+ 'form.jsonHint': 'Paste a Claude Desktop / Cursor mcpServers document, a DSH servers document, or one server object; several servers may be added at once.',
378
+ 'form.jsonEditHint': 'Only this server is updated: one server object is enough, keep the name “{name}”.',
379
+ 'form.jsonPlaceholder': '{\n "mcpServers": {\n "github": {\n "command": "npx",\n "args": ["-y", "@modelcontextprotocol/server-github"],\n "env": { "GITHUB_TOKEN": "..." }\n }\n }\n}',
380
+ 'form.requiredCommand': 'Enter a command.',
381
+ 'form.requiredUrl': 'Enter an http:// or https:// URL.',
382
+ 'form.badName': 'Invalid name: letters, digits, underscore or hyphen, 1–32 characters.',
383
+ 'form.nameTaken': 'That name is already taken.',
384
+ 'form.advancedHint': 'Leave a field empty to use the default.',
385
+ 'static.title': 'Statically composed',
386
+ 'static.lead': 'These servers are mounted by @deepseek-ai/dsh-mcp-client rows in the profile or a plugin patch. Enable, disable, edit or inspect them here; removing the row belongs in that patch.',
387
+ 'static.disabledHint': 'This row is disabled; enable it before editing its configuration.',
388
+ 'static.conflict': 'Shares a name with a managed server; they may not run together.',
389
+ 'static.empty': 'No statically composed MCP rows.',
390
+ 'static.phase': 'Plugin state: {phase}',
391
+ 'phase.pending': 'pending',
392
+ 'phase.loading': 'loading',
393
+ 'phase.active': 'active',
394
+ 'phase.failed': 'failed',
395
+ 'phase.unloading': 'unloading',
396
+ 'discover.title': 'Import from other apps on this machine',
397
+ 'discover.lead': 'Reads existing MCP configuration files without writing them; imported servers are then managed here.',
398
+ 'discover.empty': 'No servers found in the usual MCP configuration files on this machine.',
399
+ 'discover.import': 'Import',
400
+ 'discover.importing': 'Importing…',
401
+ 'discover.found': '{count} servers',
402
+ 'discover.fileError': 'Read failed: {message}',
403
+ 'discover.rowError': 'Cannot import: {message}',
404
+ 'discover.already': 'Already managed',
405
+ 'note.title': 'Where changes are saved',
406
+ 'note.body': 'Managed servers are written to this profile’s cordis.patch.yml through the settings service; static rows through the config editor and plugin manager. Every change affects only this profile.',
407
+ 'manager.missing': 'No MCP manager (@deepseek-ai/dsh-mcp-manager) is composed, so managed servers cannot be added.',
408
+ 'manager.disabled': 'The MCP manager is disabled; managed servers cannot be edited.',
409
+ 'manager.unavailable': 'The MCP manager is not ready yet; refresh in a moment.',
410
+ 'capability.unavailable': 'Static rows are read-only: the config editor or plugin manager is unavailable.',
411
+ 'warn.title': 'Notices',
412
+ 'env.title': 'Environment',
413
+ 'headers.title': 'Headers',
414
+ 'config.transport': 'Transport',
415
+ 'config.command': 'Command',
416
+ 'config.url': 'URL',
417
+ 'config.cwd': 'Working directory',
418
+ 'config.startup': 'Startup timeout',
419
+ 'config.call': 'Call timeout',
420
+ 'config.reconnect': 'Reconnect',
421
+ 'config.enabled': 'Enabled',
422
+ 'config.none': 'No extra configuration',
423
+ 'config.on': 'on',
424
+ 'config.off': 'off',
425
+ copy: 'Copy',
426
+ copied: 'Copied',
427
+ 'error.http': 'The Host answered {status}; the MCP manager backend may not be loaded yet.',
428
+ }
429
+
430
+ let translate = (key) => key
431
+ let localeVersion = 0
432
+ const localeWatchers = new Set()
433
+ /** Assigned by apply; (un)registers the optional sidebar entry. */
434
+ let applySidebarShortcut = () => {}
435
+
436
+ function format(template, values) {
437
+ if (!values) return template
438
+ let text = template
439
+ for (const [key, value] of Object.entries(values)) {
440
+ text = text.split('{' + key + '}').join(String(value))
441
+ }
442
+ return text
443
+ }
444
+
445
+ function t(key, values) {
446
+ return format(translate(key), values)
447
+ }
448
+
449
+ function useLocaleVersion() {
450
+ const [, force] = useState(0)
451
+ useEffect(() => {
452
+ const update = () => { force((value) => value + 1) }
453
+ localeWatchers.add(update)
454
+ return () => { localeWatchers.delete(update) }
455
+ }, [])
456
+ // Read the counter so a locale change that happened before this mount still
457
+ // renders through the bound translator.
458
+ void localeVersion
459
+ }
460
+
461
+ // =========================================================================
462
+ // Host API
463
+ // =========================================================================
464
+
465
+ async function readJson(response, fallbackStatus) {
466
+ let data
467
+ try {
468
+ data = await response.json()
469
+ } catch {
470
+ throw new Error(t('error.http', { status: fallbackStatus ?? response.status }))
471
+ }
472
+ return data
473
+ }
474
+
475
+ async function loadState() {
476
+ const response = await fetch(ROUTE, { headers: { accept: 'application/json' } })
477
+ if (!response.ok) {
478
+ const data = await response.json().catch(() => undefined)
479
+ throw new Error(data?.error || t('error.http', { status: response.status }))
480
+ }
481
+ const data = await readJson(response)
482
+ if (data?.ok !== true) throw new Error(data?.error || t('error.http', { status: response.status }))
483
+ return data
484
+ }
485
+
486
+ async function callAction(action, payload) {
487
+ const response = await fetch(ROUTE, {
488
+ method: 'POST',
489
+ headers: { 'content-type': 'application/json' },
490
+ body: JSON.stringify({ action, ...(payload ?? {}) }),
491
+ })
492
+ const data = await readJson(response)
493
+ if (data?.ok !== true) {
494
+ const error = new Error(data?.error || t('error.http', { status: response.status }))
495
+ error.code = data?.code
496
+ error.details = data?.details
497
+ throw error
498
+ }
499
+ return data
500
+ }
501
+
502
+ /**
503
+ * A user-facing message for a failure. The Host answers every refusal with a
504
+ * stable machine code, so the page speaks its active language instead of
505
+ * echoing the Host's Chinese-only text; an unknown code keeps the diagnostic.
506
+ */
507
+ function errorText(failure) {
508
+ const code = failure?.code
509
+ if (typeof code === 'string') {
510
+ const key = 'errors.' + code
511
+ const template = translate(key)
512
+ if (template !== key) {
513
+ const name = failure?.details?.name
514
+ return template.split('{name}').join(typeof name === 'string' && name !== '' ? name : '?')
515
+ }
516
+ }
517
+ return failure?.message || String(failure)
518
+ }
519
+
520
+ // =========================================================================
521
+ // Utilities
522
+ // =========================================================================
523
+
524
+ function clock(ms) {
525
+ if (typeof ms !== 'number' || !Number.isFinite(ms)) return ''
526
+ try {
527
+ return new Date(ms).toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit', second: '2-digit' })
528
+ } catch {
529
+ return ''
530
+ }
531
+ }
532
+
533
+ function splitLines(text) {
534
+ return String(text ?? '')
535
+ .split(/\r?\n/)
536
+ .map((line) => line.trim())
537
+ .filter((line) => line !== '')
538
+ }
539
+
540
+ /** Parse `KEY=VALUE` lines (environment). */
541
+ function parsePairs(text, separator) {
542
+ const result = {}
543
+ for (const line of splitLines(text)) {
544
+ const index = line.indexOf(separator)
545
+ if (index <= 0) continue
546
+ const key = line.slice(0, index).trim()
547
+ const value = line.slice(index + separator.length).trim()
548
+ if (key !== '') result[key] = value
549
+ }
550
+ return result
551
+ }
552
+
553
+ function pairsText(map) {
554
+ if (map === null || typeof map !== 'object') return ''
555
+ return Object.entries(map).map(([key, value]) => `${key}=${value}`).join('\n')
556
+ }
557
+
558
+ function headersText(map) {
559
+ if (map === null || typeof map !== 'object') return ''
560
+ return Object.entries(map).map(([key, value]) => `${key}: ${value}`).join('\n')
561
+ }
562
+
563
+ function commandLine(server) {
564
+ if (server.transport === 'stdio') {
565
+ const args = Array.isArray(server.args) ? server.args : []
566
+ return [server.command, ...args].filter(Boolean).join(' ')
567
+ }
568
+ return server.url || ''
569
+ }
570
+
571
+ function transportLabel(server) {
572
+ return server.transport === 'streamable-http' || server.transport === 'http'
573
+ ? t('transport.http')
574
+ : t('transport.stdio')
575
+ }
576
+
577
+ function managerReasonKey(reason) {
578
+ if (reason === 'manager-disabled') return 'manager.disabled'
579
+ if (reason === 'settings-missing' || reason === 'descriptor-missing' || reason === 'manager-unavailable') {
580
+ return 'manager.unavailable'
581
+ }
582
+ return 'manager.missing'
583
+ }
584
+
585
+ function statusView(server, isStatic) {
586
+ if (isStatic) {
587
+ if (server.enabled === false) return { tone: 'idle', label: t('status.disabled') }
588
+ if (server.phase === 'failed') {
589
+ return { tone: 'error', label: t('status.rowFailed'), detail: t('static.phase', { phase: t('phase.failed') }) }
590
+ }
591
+ if (server.tools.length > 0) return { tone: 'ok', label: t('status.connected', { count: server.tools.length }) }
592
+ if (server.phase === 'active') return { tone: 'warn', label: t('status.noTools') }
593
+ return { tone: 'idle', label: t('status.unknown'), detail: server.phase ? t('static.phase', { phase: t('phase.' + server.phase) }) : '' }
594
+ }
595
+ if (server.enabled === false) return { tone: 'idle', label: t('status.disabled') }
596
+ const status = server.status
597
+ if (status === null || typeof status !== 'object') return { tone: 'idle', label: t('status.unknown') }
598
+ switch (status.state) {
599
+ case 'connected':
600
+ return {
601
+ tone: 'ok',
602
+ label: t('status.connected', { count: typeof status.toolCount === 'number' ? status.toolCount : server.tools.length }),
603
+ detail: t('status.connectedAt', { time: clock(status.connectedAt) }),
604
+ }
605
+ case 'connecting':
606
+ return { tone: 'warn', label: t('status.connecting') }
607
+ case 'reconnecting':
608
+ return {
609
+ tone: 'warn',
610
+ label: t('status.reconnecting', { attempt: status.attempt, max: status.maxAttempts }),
611
+ detail: status.lastError,
612
+ }
613
+ case 'waiting-credentials':
614
+ return { tone: 'warn', label: t('status.waiting'), detail: status.lastError }
615
+ case 'failed':
616
+ return { tone: 'error', label: t('status.failed'), detail: status.lastError || status.reason }
617
+ case 'disabled':
618
+ return { tone: 'idle', label: t('status.disabled') }
619
+ case 'closed':
620
+ return { tone: 'idle', label: t('status.closed') }
621
+ default:
622
+ return { tone: 'idle', label: t('status.unknown'), detail: status.state }
623
+ }
624
+ }
625
+
626
+ function probeView(probe) {
627
+ if (probe === null || typeof probe !== 'object') return null
628
+ const duration = typeof probe.durationMs === 'number' ? probe.durationMs : 0
629
+ const notes = []
630
+ if (probe.ok === true) {
631
+ const count = Array.isArray(probe.toolNames) ? probe.toolNames.length : 0
632
+ let label = t('probe.ok', { count, ms: duration })
633
+ if (probe.truncated === true) label += ' · ' + t('probe.truncated')
634
+ if (probe.closeConfirmed === false) notes.push(t('probe.cleanup', { message: probe.cleanupError || 'unconfirmed' }))
635
+ return { tone: 'ok', label, notes }
636
+ }
637
+ const stage = probe.stage === 'list' ? t('probe.stage.list') : t('probe.stage.connect')
638
+ return { tone: 'error', label: t('probe.failed', { stage, message: probe.message || '', ms: duration }), notes }
639
+ }
640
+
641
+ // =========================================================================
642
+ // Styles
643
+ // =========================================================================
644
+
645
+ const CSS = `
646
+ .mcp-manage {
647
+ --mcp-manage-radius: 10px;
648
+ display: flex;
649
+ flex-direction: column;
650
+ gap: 16px;
651
+ font-size: 14px;
652
+ line-height: 1.55;
653
+ color: var(--dsw-alias-label-primary, inherit);
654
+ min-width: 0;
655
+ }
656
+ .mcp-manage * { box-sizing: border-box; }
657
+ .mcp-manage h3, .mcp-manage h4 { margin: 0; font-weight: 600; }
658
+ .mcp-manage p { margin: 0; }
659
+ .mcp-manage code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
660
+
661
+ .mcp-manage-lead { color: var(--dsw-alias-label-secondary, inherit); max-width: 72ch; }
662
+
663
+ /* The global main panel reuses the same management surface. */
664
+ .mcp-manage-page {
665
+ height: 100%;
666
+ min-height: 0;
667
+ overflow-y: auto;
668
+ box-sizing: border-box;
669
+ /* The host main-panel column already clears the window chrome; this is the
670
+ page's own breathing room, matching other main-panel entries. */
671
+ padding: 20px 28px 40px;
672
+ }
673
+ .mcp-manage-page-inner {
674
+ display: flex;
675
+ flex-direction: column;
676
+ gap: 18px;
677
+ width: min(100%, 1040px);
678
+ margin: 0 auto;
679
+ }
680
+ .mcp-manage-page-head { display: flex; align-items: center; gap: 10px; }
681
+ .mcp-manage-page-glyph { display: inline-flex; color: var(--dsw-alias-state-business-primary, var(--dsw-static-blue-600, #2563eb)); }
682
+ .mcp-manage-page-title { margin: 0; font-size: 22px; line-height: 1.25; font-weight: 600; color: var(--dsw-alias-label-primary, inherit); }
683
+
684
+ /* Page preference row: one switch, host row geometry. */
685
+ .mcp-manage-pref {
686
+ display: flex; align-items: center; justify-content: space-between; gap: 16px;
687
+ padding: 11px 14px;
688
+ border: 1px solid var(--dsw-alias-border-l1, rgba(128,128,128,.28));
689
+ border-radius: 12px;
690
+ background: var(--dsw-alias-bg-layer-1, transparent);
691
+ }
692
+ .mcp-manage-pref-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
693
+
694
+ .mcp-manage-toolbar {
695
+ display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
696
+ }
697
+ .mcp-manage-chips { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
698
+ .mcp-manage-chip {
699
+ display: inline-flex; align-items: center; gap: 6px;
700
+ padding: 2px 9px; border-radius: 999px; font-size: 12px;
701
+ border: 1px solid var(--dsw-alias-border-l1, rgba(128,128,128,.28));
702
+ background: var(--dsw-alias-bg-layer-1, transparent);
703
+ color: var(--dsw-alias-label-secondary, inherit);
704
+ white-space: nowrap;
705
+ }
706
+ .mcp-manage-chip[data-tone="ok"] { color: var(--dsw-alias-state-success-primary, #2f9e44); }
707
+ .mcp-manage-chip[data-tone="warn"] { color: var(--dsw-alias-state-warn-primary, #b7791f); }
708
+ .mcp-manage-spacer { flex: 1 1 auto; }
709
+
710
+ .mcp-manage-btn {
711
+ display: inline-flex; align-items: center; justify-content: center; gap: 6px;
712
+ min-height: 30px; padding: 4px 11px;
713
+ border-radius: 8px; border: 1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.38));
714
+ background: transparent; color: inherit; font: inherit; font-size: 13px;
715
+ cursor: pointer; white-space: nowrap;
716
+ transition: background-color .12s ease, border-color .12s ease;
717
+ }
718
+ .mcp-manage-btn:hover:not(:disabled) { background: color-mix(in srgb, currentColor 8%, transparent); }
719
+ .mcp-manage-btn:active:not(:disabled) { background: color-mix(in srgb, currentColor 13%, transparent); }
720
+ .mcp-manage-btn:disabled { opacity: .5; cursor: default; }
721
+ .mcp-manage-btn[data-variant="primary"] {
722
+ /* A filled action keeps the plugin's blue identity in both palettes. The
723
+ palette's saturated blue is stable light/dark and takes white ink, while
724
+ brand-primary is a near-white contrast fill in dark mode and would hide
725
+ white text. The inline declarations set by Button are authoritative; these
726
+ remain as the stylesheet fallback. */
727
+ background: var(--dsw-static-blue-600, #2563eb) !important;
728
+ border-color: transparent !important;
729
+ color: var(--dsw-alias-label-on-color, #fff) !important;
730
+ }
731
+ .mcp-manage-btn[data-variant="primary"]:hover:not(:disabled) { filter: brightness(.9); }
732
+ .mcp-manage-btn[data-variant="primary"]:active:not(:disabled) { filter: brightness(.82); }
733
+ .mcp-manage-btn[data-variant="danger"] { color: var(--dsw-alias-state-error-primary, #c9342c); border-color: color-mix(in srgb, currentColor 45%, transparent); }
734
+ .mcp-manage-icon-btn {
735
+ display: inline-flex; align-items: center; justify-content: center;
736
+ width: 28px; height: 28px; padding: 0;
737
+ border-radius: 7px; border: 1px solid transparent;
738
+ background: transparent; color: var(--dsw-alias-label-secondary, inherit);
739
+ cursor: pointer;
740
+ }
741
+ .mcp-manage-icon-btn:hover:not(:disabled) { background: color-mix(in srgb, currentColor 10%, transparent); color: var(--dsw-alias-label-primary, inherit); }
742
+ .mcp-manage-icon-btn:disabled { opacity: .4; cursor: default; }
743
+ .mcp-manage-icon-btn[data-tone="danger"]:hover:not(:disabled) { color: var(--dsw-alias-state-error-primary, #c9342c); }
744
+
745
+ .mcp-manage :is(button, input, textarea, select, summary, a):focus-visible {
746
+ outline: 2px solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary, Highlight));
747
+ outline-offset: 2px;
748
+ }
749
+
750
+ /* Summary cards */
751
+ .mcp-manage-list { display: flex; flex-direction: column; gap: 10px; }
752
+ .mcp-manage-card {
753
+ display: flex; flex-direction: column; gap: 8px;
754
+ padding: 12px 14px;
755
+ border: 1px solid var(--dsw-alias-border-l1, rgba(128,128,128,.28));
756
+ border-radius: 12px;
757
+ background: var(--dsw-alias-bg-layer-1, transparent);
758
+ transition: border-color .12s ease, background-color .12s ease;
759
+ }
760
+ .mcp-manage-card:hover { border-color: var(--dsw-alias-border-l2, rgba(128,128,128,.45)); }
761
+ .mcp-manage-card-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; min-width: 0; }
762
+ .mcp-manage-dot { flex: 0 0 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--dsw-alias-state-idle-primary, GrayText); }
763
+ .mcp-manage-dot[data-tone="ok"] { background: var(--dsw-alias-state-success-primary, #2f9e44); }
764
+ .mcp-manage-dot[data-tone="warn"] { background: var(--dsw-alias-state-warn-primary, #b7791f); animation: mcp-manage-pulse 1.4s ease-in-out infinite; }
765
+ .mcp-manage-dot[data-tone="error"] { background: var(--dsw-alias-state-error-primary, #c9342c); }
766
+ @keyframes mcp-manage-pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
767
+ @media (prefers-reduced-motion: reduce) { .mcp-manage-dot[data-tone="warn"] { animation: none; } }
768
+ .mcp-manage-name { font-weight: 600; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13.5px; }
769
+ .mcp-manage-badge {
770
+ display: inline-flex; align-items: center;
771
+ padding: 0 6px; min-height: 18px; border-radius: 5px;
772
+ font-size: 10.5px; letter-spacing: .04em;
773
+ border: 1px solid var(--dsw-alias-border-l1, rgba(128,128,128,.3));
774
+ color: var(--dsw-alias-label-secondary, inherit);
775
+ background: color-mix(in srgb, currentColor 6%, transparent);
776
+ white-space: nowrap;
777
+ }
778
+ .mcp-manage-badge[data-tone="brand"] { color: var(--dsw-alias-state-business-primary, #4176e6); border-color: color-mix(in srgb, currentColor 40%, transparent); }
779
+ .mcp-manage-badge[data-tone="warn"] { color: var(--dsw-alias-state-warn-primary, #b7791f); border-color: color-mix(in srgb, currentColor 40%, transparent); }
780
+ .mcp-manage-status { font-size: 12px; color: var(--dsw-alias-label-secondary, inherit); min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
781
+ .mcp-manage-status[data-tone="ok"] { color: var(--dsw-alias-state-success-primary, #2f9e44); }
782
+ .mcp-manage-status[data-tone="warn"] { color: var(--dsw-alias-state-warn-primary, #b7791f); }
783
+ .mcp-manage-status[data-tone="error"] { color: var(--dsw-alias-state-error-primary, #c9342c); }
784
+ .mcp-manage-status-detail { font-size: 11.5px; color: var(--dsw-alias-label-secondary, inherit); opacity: .85; overflow-wrap: anywhere; word-break: break-word; }
785
+ .mcp-manage-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; flex-wrap: wrap; }
786
+ .mcp-manage-sub { display: flex; align-items: center; gap: 8px; min-width: 0; }
787
+ .mcp-manage-cmd {
788
+ display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
789
+ color: var(--dsw-alias-label-secondary, inherit);
790
+ background: color-mix(in srgb, currentColor 5%, transparent);
791
+ padding: 2px 7px; border-radius: 6px; max-width: 100%;
792
+ }
793
+ .mcp-manage-probe { font-size: 12px; padding: 5px 9px; border-radius: 7px; background: color-mix(in srgb, currentColor 6%, transparent); overflow-wrap: anywhere; word-break: break-word; }
794
+ .mcp-manage-probe[data-tone="ok"] { color: var(--dsw-alias-state-success-primary, #2f9e44); }
795
+ .mcp-manage-probe[data-tone="error"] { color: var(--dsw-alias-state-error-primary, #c9342c); }
796
+ .mcp-manage-probe[data-tone="running"] { color: var(--dsw-alias-label-secondary, inherit); }
797
+ .mcp-manage-probe-warn { color: var(--dsw-alias-state-warn-primary, #b7791f); font-size: 11.5px; display: block; }
798
+ .mcp-manage-card-error {
799
+ font-size: 12px; padding: 5px 9px; border-radius: 7px;
800
+ color: var(--dsw-alias-state-error-primary, #c9342c);
801
+ background: color-mix(in srgb, currentColor 8%, transparent);
802
+ overflow-wrap: anywhere; word-break: break-word;
803
+ }
804
+
805
+ .mcp-manage-more { border-top: 1px dashed var(--dsw-alias-border-l1, rgba(128,128,128,.25)); padding-top: 7px; }
806
+ .mcp-manage-more > summary {
807
+ display: inline-flex; align-items: center; gap: 5px;
808
+ cursor: pointer; color: var(--dsw-alias-label-secondary, inherit); font-size: 12px;
809
+ list-style: none;
810
+ }
811
+ .mcp-manage-more > summary::-webkit-details-marker { display: none; }
812
+ .mcp-manage-more[open] > summary { margin-bottom: 8px; }
813
+ .mcp-manage-more-grid { display: grid; grid-template-columns: minmax(96px, max-content) minmax(0, 1fr); gap: 4px 14px; font-size: 12px; }
814
+ .mcp-manage-more-grid dt { color: var(--dsw-alias-label-secondary, inherit); }
815
+ .mcp-manage-more-grid dd { margin: 0; min-width: 0; word-break: break-all; }
816
+ .mcp-manage-mono-block {
817
+ font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11.5px;
818
+ white-space: pre-wrap; word-break: break-all;
819
+ background: color-mix(in srgb, currentColor 6%, transparent);
820
+ border-radius: 6px; padding: 5px 7px;
821
+ }
822
+ .mcp-manage-tools { display: flex; flex-wrap: wrap; gap: 5px; }
823
+ .mcp-manage-tool {
824
+ font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px;
825
+ padding: 1px 7px; border-radius: 999px;
826
+ border: 1px solid var(--dsw-alias-border-l1, rgba(128,128,128,.3));
827
+ color: var(--dsw-alias-label-secondary, inherit);
828
+ }
829
+ .mcp-manage-tool-more { font-size: 11px; color: var(--dsw-alias-label-secondary, inherit); }
830
+ .mcp-manage-empty-tools { font-size: 12px; color: var(--dsw-alias-label-secondary, inherit); }
831
+ .mcp-manage-note { font-size: 12px; color: var(--dsw-alias-state-warn-primary, #b7791f); }
832
+
833
+ .mcp-manage-switch { position: relative; display: inline-flex; flex: 0 0 36px; width: 36px; height: 20px; cursor: pointer; }
834
+ .mcp-manage-switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: inherit; }
835
+ .mcp-manage-switch-track {
836
+ position: absolute; inset: 0; border-radius: 999px;
837
+ background: var(--dsw-alias-border-l2, GrayText);
838
+ transition: background-color .14s ease;
839
+ }
840
+ .mcp-manage-switch-track::after {
841
+ content: ""; position: absolute; top: 2px; left: 2px;
842
+ width: 16px; height: 16px; border-radius: 50%;
843
+ background: var(--dsw-alias-bg-base, Canvas);
844
+ transition: transform .14s ease;
845
+ }
846
+ .mcp-manage-switch input:checked + .mcp-manage-switch-track { background: var(--dsw-alias-state-business-primary, var(--dsw-static-blue-600, #2563eb)); }
847
+ .mcp-manage-switch input:checked + .mcp-manage-switch-track::after { transform: translateX(16px); }
848
+ .mcp-manage-switch input:disabled + .mcp-manage-switch-track { opacity: .5; }
849
+ .mcp-manage-switch input:focus-visible + .mcp-manage-switch-track { outline: 2px solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary, Highlight)); outline-offset: 2px; }
850
+
851
+ /* Sections */
852
+ .mcp-manage-section {
853
+ border: 1px solid var(--dsw-alias-border-l1, rgba(128,128,128,.28));
854
+ border-radius: 12px; padding: 12px 14px;
855
+ }
856
+ .mcp-manage-section > summary {
857
+ display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
858
+ cursor: pointer; list-style: none;
859
+ }
860
+ .mcp-manage-section > summary::-webkit-details-marker { display: none; }
861
+ .mcp-manage-section[open] > summary { margin-bottom: 10px; }
862
+ .mcp-manage-section-title { font-size: 14px; font-weight: 600; }
863
+ .mcp-manage-section-count { font-size: 12px; color: var(--dsw-alias-label-secondary, inherit); }
864
+ .mcp-manage-section-lead { font-size: 12px; color: var(--dsw-alias-label-secondary, inherit); margin-bottom: 10px; }
865
+ .mcp-manage-section-body { display: flex; flex-direction: column; gap: 8px; }
866
+ .mcp-manage-file { border: 1px solid var(--dsw-alias-border-l1, rgba(128,128,128,.22)); border-radius: 9px; padding: 9px 11px; }
867
+ .mcp-manage-file-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
868
+ .mcp-manage-file-path { font-size: 11px; color: var(--dsw-alias-label-secondary, inherit); word-break: break-all; flex: 1 1 100%; }
869
+ .mcp-manage-file-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 3px 0; }
870
+ .mcp-manage-file-row code { min-width: 0; }
871
+ .mcp-manage-file-error { font-size: 12px; color: var(--dsw-alias-state-error-primary, #c9342c); }
872
+ .mcp-manage-static-phase { font-size: 11.5px; color: var(--dsw-alias-label-secondary, inherit); }
873
+ .mcp-manage-warnings { font-size: 12px; color: var(--dsw-alias-state-warn-primary, #b7791f); display: flex; flex-direction: column; gap: 3px; }
874
+ .mcp-manage-error {
875
+ display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
876
+ font-size: 12.5px; color: var(--dsw-alias-state-error-primary, #c9342c);
877
+ background: color-mix(in srgb, currentColor 8%, transparent);
878
+ border: 1px solid color-mix(in srgb, currentColor 30%, transparent);
879
+ border-radius: 8px; padding: 7px 10px;
880
+ }
881
+ .mcp-manage-notice { font-size: 12px; color: var(--dsw-alias-state-success-primary, #2f9e44); }
882
+ .mcp-manage-footer-note { font-size: 11.5px; color: var(--dsw-alias-label-secondary, inherit); }
883
+ .mcp-manage-footer-note strong { color: var(--dsw-alias-label-primary, inherit); font-weight: 600; }
884
+
885
+ .mcp-manage-empty {
886
+ display: flex; flex-direction: column; align-items: center; gap: 6px;
887
+ padding: 26px 18px; text-align: center;
888
+ border: 1px dashed var(--dsw-alias-border-l2, rgba(128,128,128,.4));
889
+ border-radius: 12px;
890
+ color: var(--dsw-alias-label-secondary, inherit);
891
+ }
892
+ .mcp-manage-empty strong { color: var(--dsw-alias-label-primary, inherit); font-weight: 600; }
893
+
894
+ /* Dialogs: a native modal dialog owns the top layer, so the settings panel's
895
+ scroll container, transforms and stacking order cannot clip it. */
896
+ .mcp-manage-dialog {
897
+ width: min(680px, calc(100vw - 40px));
898
+ max-height: min(86vh, 820px);
899
+ padding: 0;
900
+ border: 1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.45));
901
+ border-radius: 14px;
902
+ background: var(--dsw-alias-bg-overlay, var(--dsw-alias-bg-layer-2, Canvas));
903
+ color: var(--dsw-alias-label-primary, inherit);
904
+ box-shadow: 0 24px 64px rgba(0,0,0,.38);
905
+ overflow: hidden;
906
+ }
907
+ .mcp-manage-dialog[open] { display: flex; flex-direction: column; }
908
+ .mcp-manage-dialog[data-size="sm"] { width: min(440px, calc(100vw - 40px)); }
909
+ .mcp-manage-dialog::backdrop { background: rgba(0,0,0,.44); }
910
+ .mcp-manage-dialog-head, .mcp-manage-dialog-foot { flex: 0 0 auto; }
911
+ .mcp-manage-dialog-body { flex: 1 1 auto; }
912
+ .mcp-manage-dialog-head {
913
+ display: flex; align-items: flex-start; gap: 10px;
914
+ padding: 16px 18px 10px;
915
+ }
916
+ .mcp-manage-dialog-heading { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
917
+ .mcp-manage-dialog-title { font-size: 15px; font-weight: 600; }
918
+ .mcp-manage-dialog-sub { font-size: 12px; color: var(--dsw-alias-label-secondary, inherit); }
919
+ .mcp-manage-dialog-body { padding: 4px 18px 14px; overflow: auto; min-height: 0; display: flex; flex-direction: column; gap: 13px; }
920
+ .mcp-manage-dialog-foot {
921
+ display: flex; align-items: center; gap: 8px; justify-content: flex-end;
922
+ padding: 11px 18px; border-top: 1px solid var(--dsw-alias-border-l1, rgba(128,128,128,.25));
923
+ background: color-mix(in srgb, var(--dsw-alias-label-primary, #000) 3%, transparent);
924
+ }
925
+ .mcp-manage-tabs { display: inline-flex; gap: 3px; padding: 3px; border-radius: 9px; background: color-mix(in srgb, currentColor 7%, transparent); align-self: flex-start; }
926
+ .mcp-manage-tab {
927
+ border: 0; border-radius: 7px; background: transparent; color: var(--dsw-alias-label-secondary, inherit);
928
+ font: inherit; font-size: 12.5px; padding: 4px 12px; cursor: pointer;
929
+ }
930
+ .mcp-manage-tab[data-active="true"] { background: var(--dsw-alias-bg-layer-1, Canvas); color: var(--dsw-alias-label-primary, inherit); box-shadow: 0 1px 3px rgba(0,0,0,.18); }
931
+ .mcp-manage-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
932
+ .mcp-manage-field-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
933
+ .mcp-manage-field-label { font-size: 12.5px; font-weight: 600; }
934
+ .mcp-manage-field-hint { font-size: 11.5px; color: var(--dsw-alias-label-secondary, inherit); }
935
+ .mcp-manage-input, .mcp-manage-textarea, .mcp-manage-select {
936
+ width: 100%; min-height: 32px; padding: 5px 9px;
937
+ border: 1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.45));
938
+ border-radius: 8px;
939
+ background: var(--dsw-alias-bg-layer-1, Canvas);
940
+ color: var(--dsw-alias-label-primary, inherit);
941
+ font: inherit; font-size: 13px;
942
+ }
943
+ .mcp-manage-textarea { min-height: 68px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; line-height: 1.5; }
944
+ .mcp-manage-input:disabled, .mcp-manage-textarea:disabled, .mcp-manage-select:disabled { opacity: .6; }
945
+ .mcp-manage-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
946
+ .mcp-manage-segmented { display: inline-flex; gap: 4px; padding: 3px; border-radius: 9px; background: color-mix(in srgb, currentColor 7%, transparent); align-self: flex-start; }
947
+ .mcp-manage-segment {
948
+ border: 1px solid transparent; border-radius: 7px; background: transparent;
949
+ color: var(--dsw-alias-label-secondary, inherit); font: inherit; font-size: 12.5px;
950
+ padding: 4px 14px; cursor: pointer;
951
+ }
952
+ .mcp-manage-segment[data-active="true"] {
953
+ background: var(--dsw-alias-bg-layer-1, Canvas);
954
+ border-color: var(--dsw-alias-border-l2, rgba(128,128,128,.4));
955
+ color: var(--dsw-alias-label-primary, inherit); font-weight: 600;
956
+ }
957
+ .mcp-manage-check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
958
+ .mcp-manage-check input { width: 15px; height: 15px; accent-color: var(--dsw-alias-state-business-primary, #4176e6); }
959
+ .mcp-manage-advanced > summary { cursor: pointer; font-size: 12.5px; color: var(--dsw-alias-label-secondary, inherit); list-style: none; display: inline-flex; align-items: center; gap: 5px; }
960
+ .mcp-manage-advanced > summary::-webkit-details-marker { display: none; }
961
+ .mcp-manage-advanced[open] > summary { margin-bottom: 10px; }
962
+ .mcp-manage-advanced-body { display: flex; flex-direction: column; gap: 11px; }
963
+ .mcp-manage-form-error { font-size: 12.5px; color: var(--dsw-alias-state-error-primary, #c9342c); }
964
+ .mcp-manage-dialog-note { font-size: 12px; color: var(--dsw-alias-label-secondary, inherit); }
965
+ .mcp-manage-confirm-body { font-size: 13px; color: var(--dsw-alias-label-secondary, inherit); }
966
+ `
967
+
968
+ function installStyles() {
969
+ if (typeof document === 'undefined') return
970
+ const existing = document.getElementById('dsh-mcp-manage-styles')
971
+ if (existing !== null) {
972
+ // A plugin reload re-applies this module without reloading the page;
973
+ // the old tag must receive the current rules instead of being reused.
974
+ existing.textContent = CSS
975
+ return
976
+ }
977
+ const tag = document.createElement('style')
978
+ tag.id = 'dsh-mcp-manage-styles'
979
+ tag.textContent = CSS
980
+ document.head.appendChild(tag)
981
+ }
982
+
983
+ // =========================================================================
984
+ // Primitives
985
+ // =========================================================================
986
+
987
+ const ICONS = {
988
+ plus: 'M8 3.5v9M3.5 8h9',
989
+ refresh: 'M13.2 8a5.2 5.2 0 1 1-1.6-3.8M13.3 2.6v3h-3',
990
+ pulse: 'M1.8 8h2.6l1.8-3.8L8.4 12l1.9-4h3.9',
991
+ edit: 'M3 13l.7-2.9 6.8-6.8 2.2 2.2-6.8 6.8L3 13z',
992
+ trash: 'M2.8 5h10.4M6 5V3.2h4V5M4.6 5l.8 8.2h4.7L11 5',
993
+ chevron: 'M5.5 6.2 8 8.7l2.5-2.5',
994
+ x: 'M4 4l8 8M12 4l-8 8',
995
+ external: 'M9 3h4v4M13 3 7.5 8.5M12 9.5V13H3V4h3.5',
996
+ }
997
+
998
+ function Icon({ name: iconName, size }) {
999
+ return h('svg', {
1000
+ viewBox: '0 0 16 16',
1001
+ width: size ?? 14,
1002
+ height: size ?? 14,
1003
+ fill: 'none',
1004
+ stroke: 'currentColor',
1005
+ strokeWidth: 1.5,
1006
+ strokeLinecap: 'round',
1007
+ strokeLinejoin: 'round',
1008
+ 'aria-hidden': 'true',
1009
+ }, h('path', { d: ICONS[iconName] ?? '' }))
1010
+ }
1011
+
1012
+ function Button({ children, icon, variant, onClick, disabled, title, type }) {
1013
+ // A host-wide button rule can outrank a class selector, so the two
1014
+ // call-to-action buttons pin their fill and ink as inline important
1015
+ // declarations — the only author level above every stylesheet selector.
1016
+ const pinPrimary = (element) => {
1017
+ if (variant !== 'primary' || element === null) return
1018
+ element.style.setProperty('background', 'var(--dsw-static-blue-600, #2563eb)', 'important')
1019
+ element.style.setProperty('color', 'var(--dsw-alias-label-on-color, #fff)', 'important')
1020
+ element.style.setProperty('border-color', 'transparent', 'important')
1021
+ }
1022
+ return h('button', {
1023
+ type: type ?? 'button',
1024
+ className: 'mcp-manage-btn',
1025
+ 'data-variant': variant,
1026
+ onClick,
1027
+ disabled,
1028
+ title,
1029
+ ref: variant === 'primary' ? pinPrimary : undefined,
1030
+ }, icon ? h(Icon, { name: icon, size: 13 }) : null, children ? h('span', null, children) : null)
1031
+ }
1032
+
1033
+ function IconButton({ icon, label, onClick, disabled, tone, title }) {
1034
+ return h('button', {
1035
+ type: 'button',
1036
+ className: 'mcp-manage-icon-btn',
1037
+ 'data-tone': tone,
1038
+ 'aria-label': label,
1039
+ title: title ?? label,
1040
+ onClick,
1041
+ disabled,
1042
+ }, h(Icon, { name: icon }))
1043
+ }
1044
+
1045
+ function Badge({ children, tone }) {
1046
+ return h('span', { className: 'mcp-manage-badge', 'data-tone': tone }, children)
1047
+ }
1048
+
1049
+ function Switch({ checked, onChange, disabled, label }) {
1050
+ return h('label', { className: 'mcp-manage-switch', title: label },
1051
+ h('input', {
1052
+ type: 'checkbox',
1053
+ role: 'switch',
1054
+ checked,
1055
+ disabled,
1056
+ 'aria-label': label,
1057
+ onChange: (event) => onChange(event.target.checked),
1058
+ }),
1059
+ h('span', { className: 'mcp-manage-switch-track', 'aria-hidden': 'true' }))
1060
+ }
1061
+
1062
+ function Field({ label, hint, children }) {
1063
+ const id = React.useId()
1064
+ const hintId = React.useId()
1065
+ const control = React.isValidElement(children)
1066
+ ? React.cloneElement(children, {
1067
+ id,
1068
+ 'aria-describedby': hint ? hintId : undefined,
1069
+ })
1070
+ : children
1071
+ return h('div', { className: 'mcp-manage-field' },
1072
+ h('div', { className: 'mcp-manage-field-head' },
1073
+ h('label', { className: 'mcp-manage-field-label', htmlFor: id }, label),
1074
+ hint ? h('span', { className: 'mcp-manage-field-hint', id: hintId }, hint) : null),
1075
+ control)
1076
+ }
1077
+
1078
+ function Modal({ title, subtitle, onClose, children, footer, size }) {
1079
+ const ref = useRef(null)
1080
+ const closeRef = useRef(onClose)
1081
+ closeRef.current = onClose
1082
+ useEffect(() => {
1083
+ const element = ref.current
1084
+ if (element === null) return undefined
1085
+ if (typeof element.showModal === 'function' && element.open !== true) {
1086
+ try { element.showModal() } catch { /* already open */ }
1087
+ }
1088
+ const onCancel = (event) => {
1089
+ event.preventDefault()
1090
+ closeRef.current()
1091
+ }
1092
+ element.addEventListener('cancel', onCancel)
1093
+ const target = element.querySelector('.mcp-manage-dialog-body input:not([type="checkbox"]):not([disabled]), .mcp-manage-dialog-body textarea:not([disabled]), .mcp-manage-dialog-body select:not([disabled])')
1094
+ ?? element.querySelector('.mcp-manage-dialog-foot button')
1095
+ if (target !== null && typeof target.focus === 'function') target.focus()
1096
+ return () => {
1097
+ element.removeEventListener('cancel', onCancel)
1098
+ if (element.open === true) element.close()
1099
+ }
1100
+ }, [])
1101
+ // A native modal dialog lives in the top layer: no ancestor transform,
1102
+ // overflow or z-index can clip it, and Escape/focus are the browser's.
1103
+ return h('dialog', {
1104
+ className: 'mcp-manage-dialog',
1105
+ 'data-size': size,
1106
+ 'aria-label': title,
1107
+ ref,
1108
+ onMouseDown: (event) => {
1109
+ if (event.target === ref.current) onClose()
1110
+ },
1111
+ }, [
1112
+ h('div', { key: 'head', className: 'mcp-manage-dialog-head' }, [
1113
+ h('div', { key: 'text', className: 'mcp-manage-dialog-heading' }, [
1114
+ h('span', { key: 'title', className: 'mcp-manage-dialog-title' }, title),
1115
+ subtitle ? h('span', { key: 'sub', className: 'mcp-manage-dialog-sub' }, subtitle) : null,
1116
+ ]),
1117
+ h('div', { key: 'spacer', style: { flex: '1 1 auto' } }),
1118
+ h(IconButton, { key: 'close', icon: 'x', label: t('action.close'), onClick: onClose }),
1119
+ ]),
1120
+ h('div', { key: 'body', className: 'mcp-manage-dialog-body' }, children),
1121
+ footer ? h('div', { key: 'foot', className: 'mcp-manage-dialog-foot' }, footer) : null,
1122
+ ])
1123
+ }
1124
+
1125
+ // =========================================================================
1126
+ // Server dialog
1127
+ // =========================================================================
1128
+
1129
+ function emptyForm() {
1130
+ return {
1131
+ name: '',
1132
+ transport: 'stdio',
1133
+ command: '',
1134
+ args: '',
1135
+ env: '',
1136
+ cwd: '',
1137
+ url: '',
1138
+ headers: '',
1139
+ startupTimeoutMs: '',
1140
+ toolCallTimeoutMs: '',
1141
+ closeTimeoutMs: '',
1142
+ reconnect: true,
1143
+ reconnectConfig: null,
1144
+ failOnStartupError: false,
1145
+ }
1146
+ }
1147
+
1148
+ function formFromServer(server, staticMode) {
1149
+ const form = emptyForm()
1150
+ if (server === null || server === undefined) return form
1151
+ const config = server.config ?? server
1152
+ form.name = server.name ?? config.serverName ?? ''
1153
+ form.transport = config.transport === 'streamable-http' || config.transport === 'http' ? 'streamable-http' : 'stdio'
1154
+ form.command = config.command ?? ''
1155
+ form.args = Array.isArray(config.args) ? config.args.join('\n') : ''
1156
+ form.env = pairsText(config.env)
1157
+ form.cwd = config.cwd ?? ''
1158
+ form.url = config.url ?? ''
1159
+ form.headers = headersText(config.headers)
1160
+ form.startupTimeoutMs = typeof config.startupTimeoutMs === 'number' ? String(config.startupTimeoutMs) : ''
1161
+ form.toolCallTimeoutMs = typeof config.toolCallTimeoutMs === 'number' ? String(config.toolCallTimeoutMs) : ''
1162
+ form.closeTimeoutMs = typeof config.closeTimeoutMs === 'number' ? String(config.closeTimeoutMs) : ''
1163
+ form.reconnect = !(config.reconnect !== null && typeof config.reconnect === 'object' && config.reconnect.enabled === false)
1164
+ form.reconnectConfig = config.reconnect !== null && typeof config.reconnect === 'object' ? { ...config.reconnect } : null
1165
+ form.failOnStartupError = config.failOnStartupError === true
1166
+ void staticMode
1167
+ return form
1168
+ }
1169
+
1170
+ function jsonFromServer(server) {
1171
+ if (server === null || server === undefined) return ''
1172
+ const source = server.config ?? server
1173
+ const config = {}
1174
+ for (const key of ['transport', 'command', 'args', 'env', 'cwd', 'url', 'headers', 'startupTimeoutMs', 'toolCallTimeoutMs', 'closeTimeoutMs', 'reconnect', 'failOnStartupError']) {
1175
+ if (source[key] !== undefined) config[key] = source[key]
1176
+ }
1177
+ return JSON.stringify(config, null, 2)
1178
+ }
1179
+
1180
+ function ServerDialog({ mode, initial, staticMode, knownNames, onClose, onSubmit }) {
1181
+ const [tab, setTab] = useState('form')
1182
+ const [form, setForm] = useState(() => formFromServer(initial, staticMode))
1183
+ const [json, setJson] = useState(() => (mode === 'edit' ? jsonFromServer(initial) : ''))
1184
+ const [error, setError] = useState('')
1185
+ const [submitting, setSubmitting] = useState(false)
1186
+ const t2 = t
1187
+ const isEdit = mode === 'edit'
1188
+ const title = staticMode && isEdit
1189
+ ? t2('form.staticTitle', { name: form.name || '' })
1190
+ : isEdit
1191
+ ? t2('form.editTitle', { name: form.name || '' })
1192
+ : t2('form.addTitle')
1193
+
1194
+ const update = (key) => (event) => {
1195
+ const value = event?.target?.value ?? event
1196
+ setForm((current) => ({ ...current, [key]: value }))
1197
+ }
1198
+
1199
+ function buildPayload() {
1200
+ if (tab === 'json') {
1201
+ if (json.trim() === '') throw new Error(t2('form.jsonRequired'))
1202
+ return { json }
1203
+ }
1204
+ const serverName = form.name.trim()
1205
+ if (!staticMode) {
1206
+ if (!NAME_PATTERN.test(serverName)) throw new Error(t2('form.badName'))
1207
+ if (!isEdit && knownNames.includes(serverName)) throw new Error(t2('form.nameTaken'))
1208
+ }
1209
+ const config = { transport: form.transport }
1210
+ if (form.transport === 'stdio') {
1211
+ const command = form.command.trim()
1212
+ if (command === '') throw new Error(t2('form.requiredCommand'))
1213
+ config.command = command
1214
+ const args = splitLines(form.args)
1215
+ if (args.length > 0) config.args = args
1216
+ const env = parsePairs(form.env, '=')
1217
+ if (Object.keys(env).length > 0) config.env = env
1218
+ const cwd = form.cwd.trim()
1219
+ if (cwd !== '') config.cwd = cwd
1220
+ } else {
1221
+ const url = form.url.trim()
1222
+ if (!/^https?:\/\/\S+$/i.test(url)) throw new Error(t2('form.requiredUrl'))
1223
+ config.url = url
1224
+ const headers = parsePairs(form.headers, ':')
1225
+ if (Object.keys(headers).length > 0) config.headers = headers
1226
+ }
1227
+ const startup = Number(form.startupTimeoutMs)
1228
+ if (Number.isFinite(startup) && startup > 0) config.startupTimeoutMs = Math.floor(startup)
1229
+ const call = Number(form.toolCallTimeoutMs)
1230
+ if (Number.isFinite(call) && call > 0) config.toolCallTimeoutMs = Math.floor(call)
1231
+ const close = Number(form.closeTimeoutMs)
1232
+ if (Number.isFinite(close) && close > 0) config.closeTimeoutMs = Math.floor(close)
1233
+ if (!staticMode) {
1234
+ const baseReconnect = form.reconnectConfig !== null && typeof form.reconnectConfig === 'object' ? form.reconnectConfig : {}
1235
+ config.reconnect = { ...baseReconnect, enabled: form.reconnect !== false }
1236
+ }
1237
+ if (staticMode) config.failOnStartupError = form.failOnStartupError === true
1238
+ return { name: staticMode ? initial?.name : serverName, server: config }
1239
+ }
1240
+
1241
+ const submit = async () => {
1242
+ let payload
1243
+ try {
1244
+ payload = buildPayload()
1245
+ } catch (failure) {
1246
+ setError(failure.message)
1247
+ return
1248
+ }
1249
+ setSubmitting(true)
1250
+ setError('')
1251
+ try {
1252
+ await onSubmit(payload)
1253
+ } catch (failure) {
1254
+ setError(errorText(failure))
1255
+ } finally {
1256
+ setSubmitting(false)
1257
+ }
1258
+ }
1259
+
1260
+ const transportToggle = h('div', { className: 'mcp-manage-segmented', role: 'group', 'aria-label': t2('form.transport') }, [
1261
+ h('button', {
1262
+ key: 'stdio',
1263
+ type: 'button',
1264
+ className: 'mcp-manage-segment',
1265
+ 'data-active': String(form.transport === 'stdio'),
1266
+ 'aria-pressed': form.transport === 'stdio',
1267
+ onClick: () => setForm((current) => ({ ...current, transport: 'stdio' })),
1268
+ }, 'stdio'),
1269
+ h('button', {
1270
+ key: 'http',
1271
+ type: 'button',
1272
+ className: 'mcp-manage-segment',
1273
+ 'data-active': String(form.transport === 'streamable-http'),
1274
+ 'aria-pressed': form.transport === 'streamable-http',
1275
+ onClick: () => setForm((current) => ({ ...current, transport: 'streamable-http' })),
1276
+ }, 'Streamable HTTP'),
1277
+ ])
1278
+
1279
+ const formView = h('div', { key: 'form', style: { display: 'flex', flexDirection: 'column', gap: '13px' } }, [
1280
+ staticMode
1281
+ ? null
1282
+ : h(Field, {
1283
+ key: 'name',
1284
+ label: t2('form.name'),
1285
+ hint: t2('form.nameHint'),
1286
+ }, h('input', {
1287
+ className: 'mcp-manage-input',
1288
+ value: form.name,
1289
+ disabled: isEdit,
1290
+ spellCheck: false,
1291
+ placeholder: 'github',
1292
+ onChange: update('name'),
1293
+ })),
1294
+ h(Field, { key: 'transport', label: t2('form.transport') }, transportToggle),
1295
+ form.transport === 'stdio'
1296
+ ? h(Field, {
1297
+ key: 'command',
1298
+ label: t2('form.command'),
1299
+ hint: t2('form.commandHint'),
1300
+ }, h('input', {
1301
+ className: 'mcp-manage-input',
1302
+ value: form.command,
1303
+ spellCheck: false,
1304
+ placeholder: 'npx',
1305
+ onChange: update('command'),
1306
+ }))
1307
+ : h(Field, {
1308
+ key: 'url',
1309
+ label: t2('form.url'),
1310
+ hint: t2('form.urlHint'),
1311
+ }, h('input', {
1312
+ className: 'mcp-manage-input',
1313
+ value: form.url,
1314
+ spellCheck: false,
1315
+ placeholder: 'https://example.com/mcp',
1316
+ onChange: update('url'),
1317
+ })),
1318
+ form.transport === 'stdio'
1319
+ ? h(Field, {
1320
+ key: 'args',
1321
+ label: t2('form.args'),
1322
+ hint: t2('form.argsHint'),
1323
+ }, h('textarea', {
1324
+ className: 'mcp-manage-textarea',
1325
+ value: form.args,
1326
+ spellCheck: false,
1327
+ placeholder: '-y\n@modelcontextprotocol/server-github',
1328
+ onChange: update('args'),
1329
+ }))
1330
+ : h(Field, {
1331
+ key: 'headers',
1332
+ label: t2('form.headers'),
1333
+ hint: t2('form.headersHint'),
1334
+ }, h('textarea', {
1335
+ className: 'mcp-manage-textarea',
1336
+ value: form.headers,
1337
+ spellCheck: false,
1338
+ placeholder: 'Authorization: Bearer ${credential:MCP_TOKEN}',
1339
+ onChange: update('headers'),
1340
+ })),
1341
+ form.transport === 'stdio'
1342
+ ? h(Field, {
1343
+ key: 'env',
1344
+ label: t2('form.env'),
1345
+ hint: t2('form.envHint'),
1346
+ }, h('textarea', {
1347
+ className: 'mcp-manage-textarea',
1348
+ value: form.env,
1349
+ spellCheck: false,
1350
+ placeholder: 'GITHUB_TOKEN=${credential:GITHUB_TOKEN}',
1351
+ onChange: update('env'),
1352
+ }))
1353
+ : null,
1354
+ h('details', { key: 'advanced', className: 'mcp-manage-advanced' }, [
1355
+ h('summary', { key: 'summary' }, h(Icon, { name: 'chevron', size: 12 }), t2('form.advanced')),
1356
+ h('div', { key: 'body', className: 'mcp-manage-advanced-body' }, [
1357
+ form.transport === 'stdio'
1358
+ ? h(Field, {
1359
+ key: 'cwd',
1360
+ label: t2('form.cwd'),
1361
+ hint: t2('form.cwdHint'),
1362
+ }, h('input', {
1363
+ className: 'mcp-manage-input',
1364
+ value: form.cwd,
1365
+ spellCheck: false,
1366
+ placeholder: 'C:\\projects\\server',
1367
+ onChange: update('cwd'),
1368
+ }))
1369
+ : null,
1370
+ h('div', { key: 'numbers', className: 'mcp-manage-row2' }, [
1371
+ h(Field, { key: 'startup', label: t2('form.startup'), hint: t2('form.advancedHint') }, h('input', {
1372
+ className: 'mcp-manage-input',
1373
+ value: form.startupTimeoutMs,
1374
+ inputMode: 'numeric',
1375
+ placeholder: '30000',
1376
+ onChange: update('startupTimeoutMs'),
1377
+ })),
1378
+ h(Field, { key: 'call', label: t2('form.call'), hint: t2('form.advancedHint') }, h('input', {
1379
+ className: 'mcp-manage-input',
1380
+ value: form.toolCallTimeoutMs,
1381
+ inputMode: 'numeric',
1382
+ placeholder: '60000',
1383
+ onChange: update('toolCallTimeoutMs'),
1384
+ })),
1385
+ ]),
1386
+ h(Field, { key: 'close', label: t2('form.close'), hint: t2('form.advancedHint') }, h('input', {
1387
+ className: 'mcp-manage-input',
1388
+ value: form.closeTimeoutMs,
1389
+ inputMode: 'numeric',
1390
+ placeholder: '5000',
1391
+ onChange: update('closeTimeoutMs'),
1392
+ })),
1393
+ staticMode
1394
+ ? h('label', { key: 'fail', className: 'mcp-manage-check' }, h('input', {
1395
+ type: 'checkbox',
1396
+ checked: form.failOnStartupError === true,
1397
+ onChange: (event) => setForm((current) => ({ ...current, failOnStartupError: event.target.checked })),
1398
+ }), t2('form.failOnStartup'))
1399
+ : h('label', { key: 'reconnect', className: 'mcp-manage-check' }, h('input', {
1400
+ type: 'checkbox',
1401
+ checked: form.reconnect !== false,
1402
+ onChange: (event) => setForm((current) => ({ ...current, reconnect: event.target.checked })),
1403
+ }), t2('form.reconnect')),
1404
+ ]),
1405
+ ]),
1406
+ ])
1407
+
1408
+ const jsonView = h('div', { key: 'json', style: { display: 'flex', flexDirection: 'column', gap: '8px' }, role: 'tabpanel' }, [
1409
+ h('p', { key: 'hint', className: 'mcp-manage-dialog-note' }, isEdit
1410
+ ? t2('form.jsonEditHint', { name: form.name || '' })
1411
+ : t2('form.jsonHint')),
1412
+ h('p', { key: 'replace', className: 'mcp-manage-dialog-note' }, isEdit ? t2('form.jsonReplace') : t2('form.jsonSingleName')),
1413
+ h('textarea', {
1414
+ key: 'area',
1415
+ className: 'mcp-manage-textarea',
1416
+ style: { minHeight: '240px' },
1417
+ value: json,
1418
+ spellCheck: false,
1419
+ 'aria-label': t2('form.tabJson'),
1420
+ placeholder: t2('form.jsonPlaceholder'),
1421
+ onChange: (event) => setJson(event.target.value),
1422
+ }),
1423
+ ])
1424
+
1425
+ return h(Modal, {
1426
+ title,
1427
+ subtitle: t2('form.lead'),
1428
+ onClose: submitting ? () => {} : onClose,
1429
+ footer: [
1430
+ h('button', {
1431
+ key: 'cancel',
1432
+ type: 'button',
1433
+ className: 'mcp-manage-btn',
1434
+ onClick: onClose,
1435
+ disabled: submitting,
1436
+ }, t2('action.cancel')),
1437
+ h(Button, {
1438
+ key: 'save',
1439
+ variant: 'primary',
1440
+ onClick: submit,
1441
+ disabled: submitting,
1442
+ }, submitting ? t2('action.saving') : t2('action.save')),
1443
+ ],
1444
+ }, [
1445
+ h('div', { key: 'tabs', className: 'mcp-manage-tabs', role: 'tablist', 'aria-label': t2('title') }, [
1446
+ h('button', {
1447
+ key: 'form',
1448
+ type: 'button',
1449
+ className: 'mcp-manage-tab',
1450
+ role: 'tab',
1451
+ 'aria-selected': tab === 'form',
1452
+ 'data-active': String(tab === 'form'),
1453
+ onClick: () => setTab('form'),
1454
+ }, t2('form.tabForm')),
1455
+ h('button', {
1456
+ key: 'json',
1457
+ type: 'button',
1458
+ className: 'mcp-manage-tab',
1459
+ role: 'tab',
1460
+ 'aria-selected': tab === 'json',
1461
+ 'data-active': String(tab === 'json'),
1462
+ onClick: () => setTab('json'),
1463
+ }, t2('form.tabJson')),
1464
+ ]),
1465
+ tab === 'form' ? formView : jsonView,
1466
+ error !== '' ? h('div', { key: 'error', className: 'mcp-manage-form-error', role: 'alert' }, error) : null,
1467
+ ])
1468
+ }
1469
+
1470
+ // =========================================================================
1471
+ // Server rows
1472
+ // =========================================================================
1473
+
1474
+ function ToolList({ tools }) {
1475
+ const [expanded, setExpanded] = useState(false)
1476
+ if (!Array.isArray(tools) || tools.length === 0) {
1477
+ return h('p', { className: 'mcp-manage-empty-tools' }, t('tools.none'))
1478
+ }
1479
+ const limit = expanded ? tools.length : Math.min(tools.length, 12)
1480
+ return h('div', { style: { display: 'flex', flexDirection: 'column', gap: '6px' } }, [
1481
+ h('div', { key: 'list', className: 'mcp-manage-tools' }, tools.slice(0, limit).map((tool) =>
1482
+ h('span', { key: tool, className: 'mcp-manage-tool', title: tool }, tool))),
1483
+ tools.length > limit
1484
+ ? h('button', {
1485
+ key: 'more',
1486
+ type: 'button',
1487
+ className: 'mcp-manage-btn',
1488
+ style: { alignSelf: 'flex-start', minHeight: '24px', padding: '1px 8px', fontSize: '11.5px' },
1489
+ onClick: () => setExpanded(true),
1490
+ }, t('tools.more', { count: tools.length - limit }))
1491
+ : null,
1492
+ ])
1493
+ }
1494
+
1495
+ function DetailsGrid({ rows }) {
1496
+ const visible = rows.filter((row) => row !== null && row !== undefined)
1497
+ if (visible.length === 0) return h('p', { className: 'mcp-manage-empty-tools' }, t('config.none'))
1498
+ return h('dl', { className: 'mcp-manage-more-grid' }, visible.map((row, index) =>
1499
+ h(React.Fragment, { key: index }, h('dt', null, row[0]), h('dd', null, row[1]))))
1500
+ }
1501
+
1502
+ function configRows(server) {
1503
+ const rows = []
1504
+ rows.push([t('config.transport'), server.transport === 'streamable-http' ? 'streamable-http' : 'stdio'])
1505
+ if (server.transport === 'stdio') {
1506
+ rows.push([t('config.command'), h('code', null, server.command || '—')])
1507
+ if (Array.isArray(server.args) && server.args.length > 0) rows.push([t('form.args'), h('span', { className: 'mcp-manage-mono-block' }, server.args.join('\n'))])
1508
+ if (server.cwd) rows.push([t('config.cwd'), h('code', null, server.cwd)])
1509
+ const envKeys = Object.keys(server.env ?? {})
1510
+ if (envKeys.length > 0) {
1511
+ rows.push([t('env.title'), h('span', { className: 'mcp-manage-mono-block' },
1512
+ envKeys.map((key) => `${key}=${server.env[key]}`).join('\n'))])
1513
+ }
1514
+ } else {
1515
+ rows.push([t('config.url'), h('code', null, server.url || '—')])
1516
+ const headerKeys = Object.keys(server.headers ?? {})
1517
+ if (headerKeys.length > 0) {
1518
+ rows.push([t('headers.title'), h('span', { className: 'mcp-manage-mono-block' },
1519
+ headerKeys.map((key) => `${key}: ${server.headers[key]}`).join('\n'))])
1520
+ }
1521
+ }
1522
+ if (server.startupTimeoutMs) rows.push([t('config.startup'), `${server.startupTimeoutMs} ms`])
1523
+ if (server.toolCallTimeoutMs) rows.push([t('config.call'), `${server.toolCallTimeoutMs} ms`])
1524
+ const reconnect = server.reconnect
1525
+ if (reconnect !== null && typeof reconnect === 'object') {
1526
+ rows.push([t('config.reconnect'), reconnect.enabled === false ? t('config.off') : t('config.on')])
1527
+ }
1528
+ return rows
1529
+ }
1530
+
1531
+ function ManagedCard({ server, busy, enabledOverride, activeKind, error, probe, onToggle, onRestart, onProbe, onEdit, onDelete }) {
1532
+ const baseView = statusView(server, false)
1533
+ const view = activeKind === 'restart' ? { tone: 'warn', label: t('status.restarting') } : baseView
1534
+ const probeInfo = probe?.state === 'done' ? probeView(probe.result) : null
1535
+ const isBase = server.origin === 'base'
1536
+ const checked = enabledOverride === undefined ? server.enabled !== false : enabledOverride
1537
+ const actions = []
1538
+ actions.push(h(Switch, {
1539
+ key: 'switch',
1540
+ checked,
1541
+ disabled: busy,
1542
+ label: checked ? t('action.disable') : t('action.enable'),
1543
+ onChange: (value) => onToggle(value),
1544
+ }))
1545
+ actions.push(h(IconButton, {
1546
+ key: 'probe',
1547
+ icon: 'pulse',
1548
+ label: t('action.probe'),
1549
+ disabled: busy,
1550
+ onClick: () => onProbe(),
1551
+ }))
1552
+ actions.push(h(IconButton, {
1553
+ key: 'restart',
1554
+ icon: 'refresh',
1555
+ label: t('action.restart'),
1556
+ disabled: busy || server.enabled === false,
1557
+ onClick: () => onRestart(),
1558
+ }))
1559
+ actions.push(h(IconButton, {
1560
+ key: 'edit',
1561
+ icon: 'edit',
1562
+ label: t('action.edit'),
1563
+ disabled: busy,
1564
+ onClick: () => onEdit(),
1565
+ }))
1566
+ actions.push(h(IconButton, {
1567
+ key: 'delete',
1568
+ icon: 'trash',
1569
+ tone: 'danger',
1570
+ label: t('action.delete'),
1571
+ title: isBase ? t('action.deleteDisabled') : t('action.delete'),
1572
+ disabled: busy || isBase,
1573
+ onClick: () => onDelete(),
1574
+ }))
1575
+
1576
+ return h('article', { className: 'mcp-manage-card', 'aria-busy': activeKind !== undefined }, [
1577
+ h('div', { key: 'head', className: 'mcp-manage-card-head' }, [
1578
+ h('span', { key: 'dot', className: 'mcp-manage-dot', 'data-tone': view.tone, 'aria-hidden': 'true' }),
1579
+ h('span', { key: 'name', className: 'mcp-manage-name' }, server.name),
1580
+ h(Badge, { key: 'transport' }, transportLabel(server)),
1581
+ isBase ? h(Badge, { key: 'origin', tone: 'brand' }, t('origin.base')) : null,
1582
+ server.origin === 'override' ? h(Badge, { key: 'override' }, t('origin.override')) : null,
1583
+ h('span', { key: 'status', className: 'mcp-manage-status', 'data-tone': view.tone, role: 'status' }, [
1584
+ h('span', { key: 'label' }, view.label),
1585
+ view.detail ? h('span', { key: 'detail', className: 'mcp-manage-status-detail' }, ' · ' + view.detail) : null,
1586
+ ]),
1587
+ h('div', { key: 'actions', className: 'mcp-manage-actions' }, actions),
1588
+ ]),
1589
+ h('div', { key: 'sub', className: 'mcp-manage-sub' },
1590
+ h('code', { className: 'mcp-manage-cmd', title: commandLine(server) }, commandLine(server) || '—')),
1591
+ isBase
1592
+ ? h('p', { key: 'base-hint', className: 'mcp-manage-footer-note' }, t('action.deleteDisabled'))
1593
+ : null,
1594
+ error !== undefined && error !== ''
1595
+ ? h('p', { key: 'error', className: 'mcp-manage-card-error', role: 'alert' }, error)
1596
+ : null,
1597
+ probe !== undefined && probe !== null
1598
+ ? h('div', {
1599
+ key: 'probe',
1600
+ className: 'mcp-manage-probe',
1601
+ 'data-tone': probe.state === 'running' ? 'running' : (probeInfo?.tone ?? 'error'),
1602
+ role: 'status',
1603
+ }, [
1604
+ h('span', { key: 'label' }, probe.state === 'running' ? t('probe.running') : (probe.state === 'error' ? probe.error : probeInfo?.label)),
1605
+ ...(probeInfo?.notes ?? []).map((note, index) => h('span', { key: `note${index}`, className: 'mcp-manage-probe-warn' }, note)),
1606
+ ])
1607
+ : null,
1608
+ h('details', { key: 'more', className: 'mcp-manage-more' }, [
1609
+ h('summary', { key: 'summary' }, h(Icon, { name: 'chevron', size: 12 }), t('action.config')),
1610
+ h('div', { key: 'body', style: { display: 'flex', flexDirection: 'column', gap: '8px' } }, [
1611
+ h('div', { key: 'tools' }, [
1612
+ h('div', { key: 'title', className: 'mcp-manage-field-label', style: { marginBottom: '5px' } }, t('tools.title')),
1613
+ h(ToolList, { key: 'list', tools: server.tools }),
1614
+ ]),
1615
+ h(DetailsGrid, { key: 'grid', rows: configRows(server) }),
1616
+ ]),
1617
+ ]),
1618
+ ])
1619
+ }
1620
+
1621
+ function StaticCard({ server, busy, canEdit, enabledOverride, activeKind, error, onToggle, onEdit }) {
1622
+ const view = statusView(server, true)
1623
+ const phaseText = server.phase ? t('phase.' + server.phase) : ''
1624
+ const checked = enabledOverride === undefined ? server.enabled !== false : enabledOverride
1625
+ const actions = [
1626
+ h(Switch, {
1627
+ key: 'switch',
1628
+ checked,
1629
+ disabled: busy || !canEdit,
1630
+ label: checked ? t('action.disable') : t('action.enable'),
1631
+ onChange: (value) => onToggle(value),
1632
+ }),
1633
+ h(IconButton, {
1634
+ key: 'edit',
1635
+ icon: 'edit',
1636
+ label: t('action.edit'),
1637
+ disabled: busy || !canEdit || server.enabled === false,
1638
+ onClick: () => onEdit(),
1639
+ }),
1640
+ ]
1641
+ return h('article', { className: 'mcp-manage-card', 'aria-busy': activeKind !== undefined }, [
1642
+ h('div', { key: 'head', className: 'mcp-manage-card-head' }, [
1643
+ h('span', { key: 'dot', className: 'mcp-manage-dot', 'data-tone': view.tone, 'aria-hidden': 'true' }),
1644
+ h('span', { key: 'name', className: 'mcp-manage-name' }, server.name || server.entryId),
1645
+ h(Badge, { key: 'transport' }, transportLabel(server)),
1646
+ h(Badge, { key: 'static', tone: 'brand' }, 'cordis'),
1647
+ h('span', { key: 'status', className: 'mcp-manage-status', 'data-tone': view.tone, role: 'status' }, [
1648
+ h('span', { key: 'label' }, view.label),
1649
+ phaseText ? h('span', { key: 'phase', className: 'mcp-manage-status-detail' }, ' · ' + t('static.phase', { phase: phaseText })) : null,
1650
+ ]),
1651
+ h('div', { key: 'actions', className: 'mcp-manage-actions' }, actions),
1652
+ ]),
1653
+ h('div', { key: 'sub', className: 'mcp-manage-sub' },
1654
+ h('code', { className: 'mcp-manage-cmd', title: commandLine(server) }, commandLine(server) || '—')),
1655
+ server.enabled === false
1656
+ ? h('p', { key: 'hint', className: 'mcp-manage-footer-note' }, t('static.disabledHint'))
1657
+ : null,
1658
+ server.conflict === true
1659
+ ? h('p', { key: 'conflict', className: 'mcp-manage-note' }, t('static.conflict'))
1660
+ : null,
1661
+ error !== undefined && error !== ''
1662
+ ? h('p', { key: 'error', className: 'mcp-manage-card-error', role: 'alert' }, error)
1663
+ : null,
1664
+ h('details', { key: 'more', className: 'mcp-manage-more' }, [
1665
+ h('summary', { key: 'summary' }, h(Icon, { name: 'chevron', size: 12 }), t('action.config')),
1666
+ h('div', { key: 'body', style: { display: 'flex', flexDirection: 'column', gap: '8px' } }, [
1667
+ h('div', { key: 'tools' }, [
1668
+ h('div', { key: 'title', className: 'mcp-manage-field-label', style: { marginBottom: '5px' } }, t('tools.title')),
1669
+ h(ToolList, { key: 'list', tools: server.tools }),
1670
+ ]),
1671
+ h(DetailsGrid, { key: 'grid', rows: configRows(server) }),
1672
+ ]),
1673
+ ]),
1674
+ ])
1675
+ }
1676
+
1677
+ // =========================================================================
1678
+ // Sections
1679
+ // =========================================================================
1680
+
1681
+ function DiscoverSection({ items, managedNames, busy, canManage, onImport, onScan }) {
1682
+ const total = items.reduce((count, item) => count + item.servers.length, 0)
1683
+ return h('details', { className: 'mcp-manage-section', open: false }, [
1684
+ h('summary', { key: 'summary' }, [
1685
+ h('span', { key: 'title', className: 'mcp-manage-section-title' }, t('discover.title')),
1686
+ h('span', { key: 'count', className: 'mcp-manage-section-count' }, total > 0 ? t('discover.found', { count: total }) : ''),
1687
+ h('span', { key: 'spacer', style: { flex: '1 1 auto' } }),
1688
+ h('button', {
1689
+ key: 'scan',
1690
+ type: 'button',
1691
+ className: 'mcp-manage-btn',
1692
+ style: { minHeight: '26px', padding: '1px 9px', fontSize: '12px' },
1693
+ disabled: busy,
1694
+ onClick: (event) => { event.preventDefault(); onScan() },
1695
+ }, t('scan')),
1696
+ ]),
1697
+ h('p', { key: 'lead', className: 'mcp-manage-section-lead' }, t('discover.lead')),
1698
+ items.length === 0
1699
+ ? h('p', { key: 'empty', className: 'mcp-manage-empty-tools' }, t('discover.empty'))
1700
+ : h('div', { key: 'files', className: 'mcp-manage-section-body' }, items.map((item) =>
1701
+ h('div', { key: item.id, className: 'mcp-manage-file' }, [
1702
+ h('div', { key: 'head', className: 'mcp-manage-file-head' }, [
1703
+ h('strong', { key: 'label', style: { fontSize: '13px' } }, item.label),
1704
+ h('span', { key: 'count', className: 'mcp-manage-section-count' }, t('discover.found', { count: item.servers.length })),
1705
+ ]),
1706
+ h('div', { key: 'path', className: 'mcp-manage-file-path' }, item.path),
1707
+ item.error
1708
+ ? h('p', { key: 'error', className: 'mcp-manage-file-error' }, t('discover.fileError', { message: item.error }))
1709
+ : null,
1710
+ ...item.servers.map((server) =>
1711
+ h('div', { key: server.name, className: 'mcp-manage-file-row' }, [
1712
+ h('code', { key: 'name' }, server.name),
1713
+ server.transport ? h(Badge, { key: 'transport' }, server.transport === 'streamable-http' ? t('transport.http') : t('transport.stdio')) : null,
1714
+ server.error
1715
+ ? h('span', { key: 'error', className: 'mcp-manage-file-error' }, t('discover.rowError', { message: server.error }))
1716
+ : managedNames.includes(server.name)
1717
+ ? h('span', { key: 'already', className: 'mcp-manage-section-count' }, t('discover.already'))
1718
+ : h('button', {
1719
+ key: 'import',
1720
+ type: 'button',
1721
+ className: 'mcp-manage-btn',
1722
+ style: { minHeight: '24px', padding: '1px 9px', fontSize: '11.5px' },
1723
+ disabled: busy || canManage !== true,
1724
+ onClick: () => onImport(server),
1725
+ }, t('discover.import')),
1726
+ ])),
1727
+ ])),
1728
+ ),
1729
+ ])
1730
+ }
1731
+
1732
+ // =========================================================================
1733
+ // Main panel and sidebar entry
1734
+ // =========================================================================
1735
+
1736
+ /** The compact sidebar glyph: the same hub mark, drawn in currentColor. */
1737
+ function HubGlyph({ size }) {
1738
+ const edge = size ?? 18
1739
+ return h('svg', {
1740
+ width: edge,
1741
+ height: edge,
1742
+ viewBox: '0 0 36 36',
1743
+ fill: 'none',
1744
+ 'aria-hidden': 'true',
1745
+ }, [
1746
+ h('g', { key: 'spokes', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round', opacity: 0.55 }, [
1747
+ h('path', { key: 'a', d: 'M15.1 15.1 9.4 9.4' }),
1748
+ h('path', { key: 'b', d: 'M21 14.6 25.4 10.2' }),
1749
+ h('path', { key: 'c', d: 'M18 21.4v5.4' }),
1750
+ ]),
1751
+ h('rect', { key: 'core', x: 12.6, y: 12.6, width: 10.8, height: 10.8, rx: 3.1, fill: 'currentColor' }),
1752
+ h('circle', { key: 'n1', cx: 7.6, cy: 7.6, r: 2.5, fill: 'currentColor' }),
1753
+ h('circle', { key: 'n2', cx: 27.8, cy: 8.6, r: 2.2, fill: 'currentColor' }),
1754
+ h('circle', { key: 'n3', cx: 18, cy: 29.4, r: 2.2, fill: 'currentColor' }),
1755
+ ])
1756
+ }
1757
+
1758
+ /** The MCP manager as a global main panel, opened from the sidebar entry. */
1759
+ function HubPage() {
1760
+ useLocaleVersion()
1761
+ return h('div', { className: 'mcp-manage-page' },
1762
+ h('div', { className: 'mcp-manage-page-inner' }, [
1763
+ h('header', { key: 'head', className: 'mcp-manage-page-head' }, [
1764
+ h('span', { key: 'glyph', className: 'mcp-manage-page-glyph' }, h(HubGlyph, { size: 22 })),
1765
+ h('h1', { key: 'title', className: 'mcp-manage-page-title' }, t('title')),
1766
+ ]),
1767
+ h(SettingsRoot, { key: 'root' }),
1768
+ ]))
1769
+ }
1770
+
1771
+ // =========================================================================
1772
+ // Root
1773
+ // =========================================================================
1774
+
1775
+ function SettingsRoot() {
1776
+ useLocaleVersion()
1777
+ const [state, setState] = useState(null)
1778
+ const [error, setError] = useState('')
1779
+ const [notice, setNotice] = useState('')
1780
+ const [busy, setBusy] = useState(false)
1781
+ const [probes, setProbes] = useState({})
1782
+ const [active, setActive] = useState({})
1783
+ const [cardErrors, setCardErrors] = useState({})
1784
+ const [optimistic, setOptimistic] = useState({})
1785
+ const [dialog, setDialog] = useState(null)
1786
+ const live = useRef(true)
1787
+ const inflight = useRef(0)
1788
+ const noticeTimer = useRef(null)
1789
+
1790
+ const flash = useCallback((message) => {
1791
+ setNotice(message)
1792
+ clearTimeout(noticeTimer.current)
1793
+ noticeTimer.current = setTimeout(() => { if (live.current) setNotice('') }, 2200)
1794
+ }, [])
1795
+
1796
+ const clearProbe = useCallback((key) => {
1797
+ setProbes((current) => {
1798
+ if (current[key] === undefined) return current
1799
+ const next = { ...current }
1800
+ delete next[key]
1801
+ return next
1802
+ })
1803
+ }, [])
1804
+
1805
+ const setCardError = useCallback((key, message) => {
1806
+ setCardErrors((current) => {
1807
+ const next = { ...current }
1808
+ if (message === undefined || message === '') delete next[key]
1809
+ else next[key] = message
1810
+ return next
1811
+ })
1812
+ }, [])
1813
+
1814
+ const load = useCallback((options) => {
1815
+ if (options?.silent !== true) setError('')
1816
+ loadState().then((next) => {
1817
+ if (!live.current) return
1818
+ setState(next)
1819
+ }).catch((failure) => {
1820
+ if (!live.current || options?.silent === true) return
1821
+ setError(errorText(failure))
1822
+ })
1823
+ }, [])
1824
+
1825
+ useEffect(() => {
1826
+ live.current = true
1827
+ load()
1828
+ const timer = setInterval(() => {
1829
+ if (!live.current || inflight.current > 0) return
1830
+ if (typeof document !== 'undefined' && document.visibilityState !== 'visible') return
1831
+ load({ silent: true })
1832
+ }, POLL_MS)
1833
+ return () => {
1834
+ live.current = false
1835
+ clearInterval(timer)
1836
+ clearTimeout(noticeTimer.current)
1837
+ }
1838
+ }, [load])
1839
+
1840
+ const run = useCallback(async (action, payload, options) => {
1841
+ const card = options?.card
1842
+ const surface = options?.surface ?? (card === undefined ? 'page' : 'card')
1843
+ inflight.current += 1
1844
+ if (card !== undefined) {
1845
+ setActive((current) => ({ ...current, [card]: action }))
1846
+ } else {
1847
+ setBusy(true)
1848
+ }
1849
+ if (surface === 'page') setError('')
1850
+ try {
1851
+ const data = await callAction(action, payload)
1852
+ if (!live.current) return data
1853
+ if (data.state) setState(data.state)
1854
+ return data
1855
+ } catch (failure) {
1856
+ if (live.current && surface === 'page') setError(errorText(failure))
1857
+ throw failure
1858
+ } finally {
1859
+ inflight.current -= 1
1860
+ if (card !== undefined) {
1861
+ setActive((current) => {
1862
+ if (current[card] !== action) return current
1863
+ const next = { ...current }
1864
+ delete next[card]
1865
+ return next
1866
+ })
1867
+ } else if (live.current) {
1868
+ setBusy(false)
1869
+ }
1870
+ }
1871
+ }, [])
1872
+
1873
+ const toggleManaged = useCallback(async (server, enabled) => {
1874
+ const key = server.name
1875
+ setOptimistic((current) => ({ ...current, [key]: enabled }))
1876
+ setCardError(key, '')
1877
+ try {
1878
+ await run('toggle', { name: key, enabled }, { card: key })
1879
+ clearProbe(key)
1880
+ flash(t('notice.saved'))
1881
+ } catch (failure) {
1882
+ setCardError(key, errorText(failure))
1883
+ } finally {
1884
+ setOptimistic((current) => {
1885
+ const next = { ...current }
1886
+ delete next[key]
1887
+ return next
1888
+ })
1889
+ }
1890
+ }, [run, flash, clearProbe, setCardError])
1891
+
1892
+ const restartManaged = useCallback(async (server) => {
1893
+ const key = server.name
1894
+ setCardError(key, '')
1895
+ try {
1896
+ await run('restart', { name: key }, { card: key })
1897
+ clearProbe(key)
1898
+ flash(t('notice.saved'))
1899
+ setTimeout(() => { if (live.current) load({ silent: true }) }, 900)
1900
+ } catch (failure) {
1901
+ setCardError(key, errorText(failure))
1902
+ }
1903
+ }, [run, flash, load, clearProbe, setCardError])
1904
+
1905
+ const probeManaged = useCallback(async (server) => {
1906
+ const key = server.name
1907
+ setProbes((current) => ({ ...current, [key]: { state: 'running' } }))
1908
+ inflight.current += 1
1909
+ setActive((current) => ({ ...current, [key]: 'probe' }))
1910
+ try {
1911
+ const data = await callAction('probe', { name: key })
1912
+ if (!live.current) return
1913
+ setProbes((current) => ({ ...current, [key]: { state: 'done', result: data.probe } }))
1914
+ } catch (failure) {
1915
+ if (live.current) {
1916
+ const result = failure?.message || String(failure)
1917
+ setProbes((current) => ({ ...current, [key]: { state: 'error', error: failure?.code ? errorText(failure) : result } }))
1918
+ }
1919
+ } finally {
1920
+ inflight.current -= 1
1921
+ if (live.current) {
1922
+ setActive((current) => {
1923
+ if (current[key] !== 'probe') return current
1924
+ const next = { ...current }
1925
+ delete next[key]
1926
+ return next
1927
+ })
1928
+ }
1929
+ }
1930
+ }, [])
1931
+
1932
+ const openConfirm = useCallback((options) => { setDialog({ kind: 'confirm', ...options }) }, [])
1933
+
1934
+ const submitServer = useCallback(async (payload) => {
1935
+ if (dialog === null) return
1936
+ if (dialog.kind === 'static') {
1937
+ await run('static-update', { entryId: dialog.entryId, ...(payload.json ? { json: payload.json } : { server: payload.server }) }, { surface: 'dialog' })
1938
+ if (dialog.initial?.name) clearProbe(dialog.initial.name)
1939
+ flash(t('notice.saved'))
1940
+ setDialog(null)
1941
+ return
1942
+ }
1943
+ if (dialog.mode === 'edit') {
1944
+ const key = dialog.initial.name
1945
+ await run('update', { name: key, ...(payload.json ? { json: payload.json } : { server: payload.server }) }, { surface: 'dialog' })
1946
+ clearProbe(key)
1947
+ setCardError(key, '')
1948
+ flash(t('notice.saved'))
1949
+ setDialog(null)
1950
+ return
1951
+ }
1952
+ const data = await run('create', payload.json ? { json: payload.json } : { name: payload.name, server: payload.server }, { surface: 'dialog' })
1953
+ for (const added of Array.isArray(data?.added) ? data.added : []) {
1954
+ clearProbe(added)
1955
+ setCardError(added, '')
1956
+ }
1957
+ flash(t('notice.saved'))
1958
+ if (Array.isArray(data?.added) && data.added.length > 1) flash(t('notice.imported'))
1959
+ setDialog(null)
1960
+ }, [dialog, run, flash, clearProbe, setCardError])
1961
+
1962
+ const importServer = useCallback(async (server) => {
1963
+ try {
1964
+ await run('create', { servers: { [server.name]: server.config } }, { surface: 'page' })
1965
+ clearProbe(server.name)
1966
+ setCardError(server.name, '')
1967
+ flash(t('notice.imported'))
1968
+ } catch { /* shown by the page banner */ }
1969
+ }, [run, flash, clearProbe, setCardError])
1970
+
1971
+ const setSidebarPreference = useCallback(async (enabled) => {
1972
+ const previous = state?.preferences?.sidebarShortcut === true
1973
+ writeLocalShortcut(enabled)
1974
+ applySidebarShortcut(enabled)
1975
+ try {
1976
+ await run('preferences', { sidebarShortcut: enabled }, { surface: 'page' })
1977
+ flash(t('notice.saved'))
1978
+ } catch {
1979
+ writeLocalShortcut(previous)
1980
+ applySidebarShortcut(previous)
1981
+ /* the page banner carries the failure */
1982
+ }
1983
+ }, [run, flash, state?.preferences?.sidebarShortcut])
1984
+
1985
+ useEffect(() => {
1986
+ if (state === null) return
1987
+ applySidebarShortcut(state.preferences?.sidebarShortcut === true)
1988
+ }, [state?.preferences?.sidebarShortcut])
1989
+
1990
+ const managedNames = state?.servers?.map((server) => server.name) ?? []
1991
+
1992
+ const body = []
1993
+
1994
+ if (state === null) {
1995
+ body.push(h('p', { key: 'loading', className: 'mcp-manage-lead', role: 'status' }, t('loading')))
1996
+ if (error !== '') {
1997
+ body.push(h('div', { key: 'error', className: 'mcp-manage-error' }, [
1998
+ h('span', { key: 'text' }, t('failed') + ':' + error),
1999
+ h('button', {
2000
+ key: 'retry',
2001
+ type: 'button',
2002
+ className: 'mcp-manage-btn',
2003
+ onClick: () => load(),
2004
+ }, t('retry')),
2005
+ ]))
2006
+ }
2007
+ return h('div', { className: 'mcp-manage' }, body)
2008
+ }
2009
+
2010
+ const servers = state.servers ?? []
2011
+ const staticServers = state.staticServers ?? []
2012
+ const discovered = state.discovered ?? []
2013
+ const connected = servers.filter((server) => {
2014
+ const view = statusView(server, false)
2015
+ return view.tone === 'ok'
2016
+ }).length
2017
+ const disabled = servers.filter((server) => server.enabled === false).length
2018
+ const importable = discovered.reduce((count, item) => count + item.servers.filter((server) => !server.error && !managedNames.includes(server.name)).length, 0)
2019
+ const managed = state.manager ?? {}
2020
+ const capabilities = state.capabilities ?? {}
2021
+
2022
+ const chips = [
2023
+ h('span', { key: 'all', className: 'mcp-manage-chip' }, t('summary.all', { count: servers.length })),
2024
+ ]
2025
+ if (connected > 0) chips.push(h('span', { key: 'connected', className: 'mcp-manage-chip', 'data-tone': 'ok' }, t('summary.connected', { count: connected })))
2026
+ if (disabled > 0) chips.push(h('span', { key: 'disabled', className: 'mcp-manage-chip' }, t('summary.disabled', { count: disabled })))
2027
+ if (staticServers.length > 0) chips.push(h('span', { key: 'static', className: 'mcp-manage-chip' }, t('summary.static', { count: staticServers.length })))
2028
+ if (importable > 0) chips.push(h('span', { key: 'found', className: 'mcp-manage-chip', 'data-tone': 'warn' }, t('summary.found', { count: importable })))
2029
+
2030
+ body.push(h('p', { key: 'lead', className: 'mcp-manage-lead' }, [
2031
+ h('span', { key: 'text' }, t('lead')),
2032
+ h('span', { key: 'version', style: { opacity: 0.55, marginLeft: '8px', fontSize: '11.5px' } }, '· ' + t('version.label')),
2033
+ ]))
2034
+
2035
+ body.push(h('div', { key: 'toolbar', className: 'mcp-manage-toolbar' }, [
2036
+ h('div', { key: 'chips', className: 'mcp-manage-chips' }, chips),
2037
+ h('span', { key: 'spacer', className: 'mcp-manage-spacer' }),
2038
+ h('button', {
2039
+ key: 'refresh',
2040
+ type: 'button',
2041
+ className: 'mcp-manage-btn',
2042
+ disabled: busy,
2043
+ onClick: () => { load(); flash(t('notice.refreshed')) },
2044
+ }, h(Icon, { name: 'refresh', size: 13 }), h('span', null, t('refresh'))),
2045
+ h(Button, {
2046
+ key: 'add',
2047
+ variant: 'primary',
2048
+ icon: 'plus',
2049
+ disabled: busy || capabilities.managed !== true,
2050
+ title: capabilities.managed === true ? undefined : t(managerReasonKey(managed.reason)),
2051
+ onClick: () => setDialog({ kind: 'server', mode: 'create' }),
2052
+ }, t('add')),
2053
+ ]))
2054
+
2055
+ body.push(h('div', { key: 'shortcut', className: 'mcp-manage-pref' }, [
2056
+ h('div', { key: 'text', className: 'mcp-manage-pref-text' }, [
2057
+ h('span', { key: 'title', className: 'mcp-manage-field-label' }, t('shortcut.title')),
2058
+ h('span', { key: 'hint', className: 'mcp-manage-field-hint' }, t('shortcut.hint')),
2059
+ ]),
2060
+ h(Switch, {
2061
+ key: 'switch',
2062
+ checked: state.preferences?.sidebarShortcut === true,
2063
+ disabled: busy,
2064
+ label: t('shortcut.title'),
2065
+ onChange: (value) => { void setSidebarPreference(value) },
2066
+ }),
2067
+ ]))
2068
+
2069
+ if (error !== '') {
2070
+ body.push(h('div', { key: 'error', className: 'mcp-manage-error', role: 'alert' }, [
2071
+ h('span', { key: 'text' }, t('failed') + ':' + error),
2072
+ h('button', { key: 'retry', type: 'button', className: 'mcp-manage-btn', onClick: () => load() }, t('refresh')),
2073
+ ]))
2074
+ }
2075
+ if (notice !== '') body.push(h('div', { key: 'notice', className: 'mcp-manage-notice', role: 'status' }, notice))
2076
+
2077
+ if (capabilities.managed !== true) {
2078
+ body.push(h('div', { key: 'manager', className: 'mcp-manage-note' }, t(managerReasonKey(managed.reason))))
2079
+ }
2080
+
2081
+ if (servers.length === 0) {
2082
+ body.push(h('div', { key: 'empty', className: 'mcp-manage-empty' }, [
2083
+ h('strong', { key: 'title' }, t('empty.title')),
2084
+ h('span', { key: 'hint' }, t('empty.hint')),
2085
+ capabilities.managed === true
2086
+ ? h(Button, { key: 'add', variant: 'primary', icon: 'plus', onClick: () => setDialog({ kind: 'server', mode: 'create' }) }, t('add'))
2087
+ : null,
2088
+ ]))
2089
+ } else {
2090
+ body.push(h('div', { key: 'list', className: 'mcp-manage-list' }, servers.map((server) =>
2091
+ h(ManagedCard, {
2092
+ key: server.name,
2093
+ server,
2094
+ busy: busy || active[server.name] !== undefined,
2095
+ activeKind: active[server.name],
2096
+ enabledOverride: optimistic[server.name],
2097
+ error: cardErrors[server.name],
2098
+ probe: probes[server.name],
2099
+ onToggle: (enabled) => { void toggleManaged(server, enabled) },
2100
+ onRestart: () => { void restartManaged(server) },
2101
+ onProbe: () => { void probeManaged(server) },
2102
+ onEdit: () => setDialog({ kind: 'server', mode: 'edit', initial: server }),
2103
+ onDelete: () => openConfirm({
2104
+ title: t('confirm.deleteTitle'),
2105
+ body: t('confirm.deleteBody', { name: server.name }),
2106
+ danger: true,
2107
+ confirmLabel: t('action.delete'),
2108
+ onConfirm: async () => {
2109
+ await run('remove', { name: server.name }, { surface: 'dialog' })
2110
+ clearProbe(server.name)
2111
+ setCardError(server.name, '')
2112
+ flash(t('notice.saved'))
2113
+ setDialog(null)
2114
+ },
2115
+ }),
2116
+ }))))
2117
+ }
2118
+
2119
+ if (staticServers.length > 0) {
2120
+ body.push(h('details', { key: 'static', className: 'mcp-manage-section' }, [
2121
+ h('summary', { key: 'summary' }, [
2122
+ h('span', { key: 'title', className: 'mcp-manage-section-title' }, t('static.title')),
2123
+ h('span', { key: 'count', className: 'mcp-manage-section-count' }, String(staticServers.length)),
2124
+ ]),
2125
+ h('p', { key: 'lead', className: 'mcp-manage-section-lead' }, t('static.lead')),
2126
+ capabilities.staticEditable === true
2127
+ ? null
2128
+ : h('p', { key: 'capability', className: 'mcp-manage-note' }, t('capability.unavailable')),
2129
+ h('div', { key: 'list', className: 'mcp-manage-list' }, staticServers.map((server) =>
2130
+ h(StaticCard, {
2131
+ key: server.entryId,
2132
+ server,
2133
+ busy: busy || active[server.entryId] !== undefined,
2134
+ activeKind: active[server.entryId],
2135
+ enabledOverride: optimistic[server.entryId],
2136
+ error: cardErrors[server.entryId],
2137
+ canEdit: capabilities.staticEditable === true,
2138
+ onToggle: (enabled) => openConfirm({
2139
+ title: enabled ? t('confirm.enableTitle') : t('confirm.disableTitle'),
2140
+ body: t(enabled ? 'confirm.enableBody' : 'confirm.disableBody', { name: server.name || server.entryId }),
2141
+ danger: !enabled,
2142
+ confirmLabel: enabled ? t('action.enable') : t('action.disable'),
2143
+ onConfirm: async () => {
2144
+ setOptimistic((current) => ({ ...current, [server.entryId]: enabled }))
2145
+ try {
2146
+ const data = await run('static-toggle', { entryId: server.entryId, enabled }, { surface: 'dialog' })
2147
+ setCardError(server.entryId, '')
2148
+ const application = data?.change?.application
2149
+ if (typeof application === 'string' && application !== 'applied') flash(t('notice.restartRequired'))
2150
+ else flash(t('notice.saved'))
2151
+ setDialog(null)
2152
+ } finally {
2153
+ setOptimistic((current) => {
2154
+ const next = { ...current }
2155
+ delete next[server.entryId]
2156
+ return next
2157
+ })
2158
+ }
2159
+ },
2160
+ }),
2161
+ onEdit: () => setDialog({ kind: 'static', entryId: server.entryId, initial: server }),
2162
+ }))),
2163
+ ]))
2164
+ } else {
2165
+ body.push(h('details', { key: 'static', className: 'mcp-manage-section' }, [
2166
+ h('summary', { key: 'summary' }, h('span', { key: 'title', className: 'mcp-manage-section-title' }, t('static.title'))),
2167
+ h('p', { key: 'empty', className: 'mcp-manage-empty-tools' }, t('static.empty')),
2168
+ ]))
2169
+ }
2170
+
2171
+ body.push(h(DiscoverSection, {
2172
+ key: 'discover',
2173
+ items: discovered,
2174
+ managedNames,
2175
+ busy,
2176
+ canManage: capabilities.managed === true,
2177
+ onImport: (server) => { void importServer(server) },
2178
+ onScan: () => { void run('refresh', {}).then(() => flash(t('notice.refreshed'))).catch(() => {}) },
2179
+ }))
2180
+
2181
+ if (Array.isArray(state.warnings) && state.warnings.length > 0) {
2182
+ body.push(h('div', { key: 'warnings', className: 'mcp-manage-warnings' }, [
2183
+ h('span', { key: 'title', style: { fontWeight: 600 } }, t('warn.title')),
2184
+ ...state.warnings.map((warning, index) => h('span', { key: index }, warning)),
2185
+ ]))
2186
+ }
2187
+
2188
+ body.push(h('div', { key: 'note', className: 'mcp-manage-footer-note' }, [
2189
+ h('div', { key: 'where' }, [
2190
+ h('strong', { key: 'title' }, t('note.title') + ':'),
2191
+ h('span', { key: 'text' }, t('note.body')),
2192
+ ]),
2193
+ h('div', { key: 'secrets' }, t('notice.secrets')),
2194
+ ]))
2195
+
2196
+ const overlay = []
2197
+ if (dialog !== null && (dialog.kind === 'server' || dialog.kind === 'static')) {
2198
+ overlay.push(h(ServerDialog, {
2199
+ key: 'server-dialog',
2200
+ mode: dialog.kind === 'static' ? 'edit' : dialog.mode,
2201
+ initial: dialog.initial ?? null,
2202
+ staticMode: dialog.kind === 'static',
2203
+ knownNames: managedNames,
2204
+ onClose: () => setDialog(null),
2205
+ onSubmit: submitServer,
2206
+ }))
2207
+ }
2208
+ if (dialog !== null && dialog.kind === 'confirm') {
2209
+ overlay.push(h(ConfirmDialog, {
2210
+ key: 'confirm-dialog',
2211
+ title: dialog.title,
2212
+ body: dialog.body,
2213
+ danger: dialog.danger,
2214
+ confirmLabel: dialog.confirmLabel,
2215
+ busy,
2216
+ onClose: () => setDialog(null),
2217
+ onConfirm: dialog.onConfirm,
2218
+ }))
2219
+ }
2220
+
2221
+ return h('div', { className: 'mcp-manage' }, [...body, ...overlay])
2222
+ }
2223
+
2224
+ function ConfirmDialog({ title, body, danger, confirmLabel, busy, onClose, onConfirm }) {
2225
+ const [error, setError] = useState('')
2226
+ const [working, setWorking] = useState(false)
2227
+ const confirm = async () => {
2228
+ setWorking(true)
2229
+ setError('')
2230
+ try {
2231
+ await onConfirm()
2232
+ } catch (failure) {
2233
+ setError(errorText(failure))
2234
+ } finally {
2235
+ setWorking(false)
2236
+ }
2237
+ }
2238
+ const disabled = working || busy
2239
+ return h(Modal, {
2240
+ title,
2241
+ size: 'sm',
2242
+ onClose: () => { if (!working) onClose() },
2243
+ footer: [
2244
+ h('button', {
2245
+ key: 'cancel',
2246
+ type: 'button',
2247
+ className: 'mcp-manage-btn',
2248
+ disabled,
2249
+ onClick: onClose,
2250
+ }, t('action.cancel')),
2251
+ h('button', {
2252
+ key: 'confirm',
2253
+ type: 'button',
2254
+ className: 'mcp-manage-btn',
2255
+ 'data-variant': danger ? 'danger' : 'primary',
2256
+ disabled,
2257
+ onClick: confirm,
2258
+ }, confirmLabel),
2259
+ ],
2260
+ }, [
2261
+ h('p', { key: 'body', className: 'mcp-manage-confirm-body' }, body),
2262
+ error !== '' ? h('div', { key: 'error', className: 'mcp-manage-form-error', role: 'alert' }, error) : null,
2263
+ ])
2264
+ }
2265
+
2266
+ // =========================================================================
2267
+ // Plugin
2268
+ // =========================================================================
2269
+
2270
+ function apply(ctx) {
2271
+ installStyles()
2272
+ ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'dsh-mcp-manage: dictionary')
2273
+ translate = ctx.locale.bind(NS)
2274
+ const bump = () => {
2275
+ localeVersion += 1
2276
+ translate = ctx.locale.bind(NS)
2277
+ for (const update of localeWatchers) update()
2278
+ }
2279
+ if (typeof ctx.locale.subscribe === 'function') {
2280
+ ctx.effect(() => {
2281
+ const off = ctx.locale.subscribe(bump)
2282
+ return () => { if (typeof off === 'function') off() }
2283
+ }, 'dsh-mcp-manage: locale changes')
2284
+ }
2285
+ ctx.slots.inject('settings.section', () => ctx.slots.register({
2286
+ name: 'settings.section',
2287
+ id: 'mcp-manage',
2288
+ order: 30,
2289
+ label: () => translate('nav'),
2290
+ locale: NS,
2291
+ }, SettingsRoot))
2292
+
2293
+ // The global panel is always composed; the sidebar entry that opens it
2294
+ // is the preference the user controls from the page.
2295
+ ctx.slots.inject('main', () => ctx.slots.register({ name: 'main', key: 'mcp-manage' }, HubPage))
2296
+
2297
+ let launcherDispose = null
2298
+ let launcherOn = false
2299
+ const setLauncher = (on) => {
2300
+ const next = on === true
2301
+ if (next === launcherOn) return
2302
+ launcherOn = next
2303
+ if (next) {
2304
+ launcherDispose = ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
2305
+ name: 'sidebar.panellist',
2306
+ id: 'mcp-manage',
2307
+ order: 25,
2308
+ label: () => translate('nav'),
2309
+ locale: NS,
2310
+ }, HubGlyph))
2311
+ } else if (launcherDispose !== null) {
2312
+ launcherDispose()
2313
+ launcherDispose = null
2314
+ }
2315
+ }
2316
+ applySidebarShortcut = setLauncher
2317
+ let shortcutAlive = true
2318
+ ctx.effect(() => () => {
2319
+ shortcutAlive = false
2320
+ applySidebarShortcut = () => {}
2321
+ if (launcherDispose !== null) {
2322
+ launcherDispose()
2323
+ launcherDispose = null
2324
+ }
2325
+ launcherOn = false
2326
+ }, 'dsh-mcp-manage: sidebar shortcut lifetime')
2327
+ // Register synchronously from the last browser-local choice, then
2328
+ // reconcile with the Host preference. The Host can still be starting
2329
+ // when a client row materializes, so the read retries for a moment.
2330
+ setLauncher(readLocalShortcut())
2331
+ const syncShortcut = (attempt) => {
2332
+ if (!shortcutAlive) return
2333
+ loadState().then((snapshot) => {
2334
+ if (!shortcutAlive) return
2335
+ const on = snapshot.preferences?.sidebarShortcut === true
2336
+ writeLocalShortcut(on)
2337
+ setLauncher(on)
2338
+ }).catch(() => {
2339
+ if (shortcutAlive && attempt < 6 && typeof window !== 'undefined') {
2340
+ setTimeout(() => { syncShortcut(attempt + 1) }, 500)
2341
+ }
2342
+ })
2343
+ }
2344
+ syncShortcut(0)
2345
+ }
2346
+
2347
+ exports.name = name
2348
+ exports.inject = inject
2349
+ exports.apply = apply
2350
+ // Test seam: the page's own harness renders these without a browser.
2351
+ exports.__parts = { SettingsRoot, ServerDialog, ManagedCard, StaticCard, DiscoverSection, ConfirmDialog, Field, HubPage, HubGlyph, setSidebarShortcut: (on) => applySidebarShortcut(on) }
2352
+ return module.exports
2353
+ },
2354
+ })