dsh-mcp-connector 0.2.98 → 0.2.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.99
4
+
5
+ - Finish tool discovery when a streamable-HTTP server keeps the SSE response open after initialize or tools/list, instead of waiting for EOF and reporting a timeout (#218).
6
+ - Ignore notifications and unrelated request ids while consuming SSE events; preserve authentication error classification.
7
+ - Share a line-based SSE reader between connection validation and tool discovery, including mixed LF/CRLF/CR endings and UTF-8 fragments (#218).
8
+ - Keep handshake health separate from tool-discovery failures. Preserve per-connection checks, show discovery diagnostics independently, and retain real handshake/authentication failures (#218).
9
+ - Maintainer revalidation passed for #218 and the previously released catalog TTL, background refresh and source-isolation fixes for #219. Both issues remain open for tracking.
10
+
3
11
  ## 0.2.98
4
12
 
5
13
  - Replace the hidden first-use question mark with a bilingual Quick start action and a zero-connection guidance card that leads directly to recommended connectors or the existing read-only getting-started flow.
package/README.en.md CHANGED
@@ -114,7 +114,7 @@ As of 2026-10-24, the public Registry publishes 112 connector descriptors. After
114
114
  | Connection diagnostics and last-success cache | |
115
115
  | ![Connection diagnostics](https://raw.githubusercontent.com/duhu2000/dsh-mcp-connector/main/docs/screenshots/en/07-connection-diagnostics.png) | |
116
116
 
117
- <!-- generated:media -->English UI screenshots and GIF were captured from v0.2.98 (2026-11-10), using the credential-free Mock harness. Provider content retains its original language. They demonstrate UI, not real business acceptance; counts are fixtures. See [asset provenance](docs/screenshots/README.md).<!-- /generated:media -->
117
+ <!-- generated:media -->English UI screenshots and GIF were captured from v0.2.99 (2026-11-10), using the credential-free Mock harness. Provider content retains its original language. They demonstrate UI, not real business acceptance; counts are fixtures. See [asset provenance](docs/screenshots/README.md).<!-- /generated:media -->
118
118
 
119
119
  ## Installation
120
120
 
@@ -245,7 +245,7 @@ npm run dev:ui
245
245
 
246
246
  Every Registry merge regenerates `catalog-stats.json`; an hourly workflow in this repository synchronizes the Chinese and English product copy plus a local stats snapshot. The static npm README updates with package releases, while the live badges above read the Registry directly and therefore stay current without another npm release.
247
247
 
248
- <!-- generated:version -->The current public version is [`dsh-mcp-connector@0.2.98`](https://www.npmjs.com/package/dsh-mcp-connector), with [GitHub Release v0.2.98](https://github.com/duhu2000/dsh-mcp-connector/releases/tag/v0.2.98).<!-- /generated:version -->
248
+ <!-- generated:version -->The current public version is [`dsh-mcp-connector@0.2.99`](https://www.npmjs.com/package/dsh-mcp-connector), with [GitHub Release v0.2.99](https://github.com/duhu2000/dsh-mcp-connector/releases/tag/v0.2.99).<!-- /generated:version -->
249
249
 
250
250
  See [CHANGELOG.md](CHANGELOG.md) for version history and [docs/DESKTOP-E2E.md](docs/DESKTOP-E2E.md) for the Desktop release checklist.
251
251
 
package/README.md CHANGED
@@ -128,7 +128,7 @@ Desktop 需要完全退出并重新启动应用;Web 需要停止原 `dsh web`
128
128
  | 连接诊断与最后成功缓存 | |
129
129
  | ![连接诊断](https://raw.githubusercontent.com/duhu2000/dsh-mcp-connector/main/docs/screenshots/07-connection-diagnostics.png) | |
130
130
 
131
- <!-- generated:media -->截图与 GIF 采集自 v0.2.98(2026-11-10)无凭据 Mock 页面,展示界面而非真实业务验收;市场数量是测试夹具。来源与更新方法见 [素材说明](docs/screenshots/README.md)。<!-- /generated:media -->
131
+ <!-- generated:media -->截图与 GIF 采集自 v0.2.99(2026-11-10)无凭据 Mock 页面,展示界面而非真实业务验收;市场数量是测试夹具。来源与更新方法见 [素材说明](docs/screenshots/README.md)。<!-- /generated:media -->
132
132
 
133
133
  ## 安装
134
134
 
@@ -252,7 +252,7 @@ npm run dev:ui
252
252
 
253
253
  公共 Registry 每次合并后会生成 `catalog-stats.json`;本仓库的定时工作流每小时同步中英文介绍和统计快照。npm 页面中的静态正文随版本发布更新,上方动态统计徽标则直接读取 Registry,可在不发布新 npm 版本时保持实时数量一致。
254
254
 
255
- <!-- generated:version -->当前公开版本为 [`dsh-mcp-connector@0.2.98`](https://www.npmjs.com/package/dsh-mcp-connector),对应 [GitHub Release v0.2.98](https://github.com/duhu2000/dsh-mcp-connector/releases/tag/v0.2.98)。<!-- /generated:version -->
255
+ <!-- generated:version -->当前公开版本为 [`dsh-mcp-connector@0.2.99`](https://www.npmjs.com/package/dsh-mcp-connector),对应 [GitHub Release v0.2.99](https://github.com/duhu2000/dsh-mcp-connector/releases/tag/v0.2.99)。<!-- /generated:version -->
256
256
 
257
257
  版本能力与变更记录见 [CHANGELOG.md](CHANGELOG.md)。
258
258
  Desktop 发版回归见 [docs/DESKTOP-E2E.md](docs/DESKTOP-E2E.md)。
Binary file
@@ -1,6 +1,6 @@
1
1
  # 产品截图与演示的来源及更新
2
2
 
3
- <!-- generated:media -->本组 8 张截图和 GIF 均从 v0.2.98 于 2026-11-10 重新采集,未修改截图中的版本文字。<!-- /generated:media -->
3
+ <!-- generated:media -->本组 8 张截图和 GIF 均从 v0.2.99 于 2026-11-10 重新采集,未修改截图中的版本文字。<!-- /generated:media -->
4
4
 
5
5
  前七张素材由真实产品 UI 的无凭据 Mock harness 渲染:1280×720 浏览器视口、800px 产品面板、桌面两列卡片。顶部保留“无凭据 Mock”标识;目录数、连接数与工具数是演示夹具,不代表生产统计或真实授权、业务验收。不会读取用户 profile、调用服务商或上传业务数据。
6
6
 
@@ -3,8 +3,8 @@
3
3
  "capture": {
4
4
  "locale": "zh-CN",
5
5
  "capturedOn": "2026-11-10",
6
- "sourceVersion": "0.2.98",
7
- "sourceFingerprint": "82d95b2a17d76f195db9afc1cfc1881ce25ff26c389797b396b28b6af34f68cd",
6
+ "sourceVersion": "0.2.99",
7
+ "sourceFingerprint": "b36089cc721fa8b15a923c1e5bcf0003fc74da608710c046a5444301b6d324ae",
8
8
  "browserViewport": {
9
9
  "width": 1280,
10
10
  "height": 720
@@ -17,63 +17,63 @@
17
17
  "screenshots": [
18
18
  {
19
19
  "path": "docs/screenshots/01-market-overview.jpg",
20
- "sha256": "9832c299de24c484f2e32bfe2d83925e7b3fbe897c0b914f03d78332f6c5daec",
20
+ "sha256": "84589ad5fa2ed5b228dec616f30c74002db00d961002848003d6b3177ac5d490",
21
21
  "width": 1280,
22
22
  "height": 720,
23
23
  "capturedOn": "2026-11-10",
24
- "sourceVersion": "0.2.98"
24
+ "sourceVersion": "0.2.99"
25
25
  },
26
26
  {
27
27
  "path": "docs/screenshots/02-connector-detail.jpg",
28
- "sha256": "4f42dfb09df6228e6ec7514fc96a5861504a71d3d7daebd02d54219b31f65af7",
28
+ "sha256": "69a89d4d7d3ddf825007255fa911154d911306e7c172887901ff96c16d7e7cd1",
29
29
  "width": 1280,
30
30
  "height": 720,
31
31
  "capturedOn": "2026-11-10",
32
- "sourceVersion": "0.2.98"
32
+ "sourceVersion": "0.2.99"
33
33
  },
34
34
  {
35
35
  "path": "docs/screenshots/03-tool-discovery.jpg",
36
- "sha256": "c2d267375103c5b739e2f830c40fa0824e55f619450b4748b9c1192300cf2d2a",
36
+ "sha256": "0540269514a6c6bd9ba17d96ca219afe854be637d4528e0dc6c37c9f47760dbc",
37
37
  "width": 1280,
38
38
  "height": 720,
39
39
  "capturedOn": "2026-11-10",
40
- "sourceVersion": "0.2.98"
40
+ "sourceVersion": "0.2.99"
41
41
  },
42
42
  {
43
43
  "path": "docs/screenshots/04-json-import.jpg",
44
- "sha256": "0eb7221f036871bba1e284836cb400bec84e27f9ee52df5fcce539e86ee16f0f",
44
+ "sha256": "724de44513ac6302530e6ad5d89f6a3c7d23a9b564af8b276fb36890adcebbaf",
45
45
  "width": 1280,
46
46
  "height": 720,
47
47
  "capturedOn": "2026-11-10",
48
- "sourceVersion": "0.2.98"
48
+ "sourceVersion": "0.2.99"
49
49
  },
50
50
  {
51
51
  "path": "docs/screenshots/05-unified-tool-search.png",
52
- "sha256": "6b8dab1027dd074e3cc4edffd11ccfff9fb01dc94ab709a2c671b735cafb537d",
52
+ "sha256": "b9b230492e0fc2e9bbe85dd652c118de468ca4481748d8a8cce2337abd3332b1",
53
53
  "width": 1280,
54
54
  "height": 720,
55
55
  "capturedOn": "2026-11-10",
56
- "sourceVersion": "0.2.98"
56
+ "sourceVersion": "0.2.99"
57
57
  },
58
58
  {
59
59
  "path": "docs/screenshots/06-tool-parameters.png",
60
- "sha256": "9b1506c8eba96e304c279c6f70770637ceae608dc3c62c9c69e4b3b849d875fe",
60
+ "sha256": "b10f6e3b7e2e935f0fcc0c11529421070612db3f182a59f5928281e90b9c83b1",
61
61
  "width": 1280,
62
62
  "height": 720,
63
63
  "capturedOn": "2026-11-10",
64
- "sourceVersion": "0.2.98"
64
+ "sourceVersion": "0.2.99"
65
65
  },
66
66
  {
67
67
  "path": "docs/screenshots/07-connection-diagnostics.png",
68
- "sha256": "40f0daaff46204c31b61ca96d6fc30322830dba72d53fa22c469da0d4c0283d7",
68
+ "sha256": "7dab4e1f8557cb9e14ca20668fc8bc390e0819e06b3b6e7f1291c82137e285bd",
69
69
  "width": 1280,
70
70
  "height": 720,
71
71
  "capturedOn": "2026-11-10",
72
- "sourceVersion": "0.2.98"
72
+ "sourceVersion": "0.2.99"
73
73
  },
74
74
  {
75
75
  "path": "docs/screenshots/08-ten-recommendations.jpg",
76
- "sha256": "d7cbc112bb97972a2831be8f91e9bd61d32fa9d5a5ebffcd44431b30ca489846",
76
+ "sha256": "c86c448277e80505659a8dc7faef8efd1dcf254b3cbeb93aab0c95640226537f",
77
77
  "width": 1280,
78
78
  "height": 1400,
79
79
  "browserViewport": {
@@ -82,16 +82,16 @@
82
82
  },
83
83
  "panelHeight": 1280,
84
84
  "capturedOn": "2026-11-10",
85
- "sourceVersion": "0.2.98"
85
+ "sourceVersion": "0.2.99"
86
86
  }
87
87
  ],
88
88
  "demo": {
89
89
  "path": "docs/demo.gif",
90
- "sha256": "b69146e9b9286d417d9f88d3cda5bbd126adc061b314f4e66a1cd953c94f7a22",
90
+ "sha256": "d3bef144cc3236a3965e1ffed668319fdead5073836ac664cc8059073692cf1f",
91
91
  "width": 960,
92
92
  "height": 540,
93
93
  "capturedOn": "2026-11-10",
94
- "sourceVersion": "0.2.98",
94
+ "sourceVersion": "0.2.99",
95
95
  "durationSeconds": 36
96
96
  }
97
97
  }
@@ -3,8 +3,8 @@
3
3
  "capture": {
4
4
  "locale": "en",
5
5
  "capturedOn": "2026-11-10",
6
- "sourceVersion": "0.2.98",
7
- "sourceFingerprint": "82d95b2a17d76f195db9afc1cfc1881ce25ff26c389797b396b28b6af34f68cd",
6
+ "sourceVersion": "0.2.99",
7
+ "sourceFingerprint": "b36089cc721fa8b15a923c1e5bcf0003fc74da608710c046a5444301b6d324ae",
8
8
  "browserViewport": {
9
9
  "width": 1280,
10
10
  "height": 720
@@ -17,63 +17,63 @@
17
17
  "screenshots": [
18
18
  {
19
19
  "path": "docs/screenshots/en/01-market-overview.jpg",
20
- "sha256": "084a8002c8c0c93de4504804acb58e9c9ac2aede8865292f0913e66435e0cc56",
20
+ "sha256": "fabe58bc533ce3c3a917f3ef8ea0c45c44b66038aab8d3d45733f87010947375",
21
21
  "width": 1280,
22
22
  "height": 720,
23
23
  "capturedOn": "2026-11-10",
24
- "sourceVersion": "0.2.98"
24
+ "sourceVersion": "0.2.99"
25
25
  },
26
26
  {
27
27
  "path": "docs/screenshots/en/02-connector-detail.jpg",
28
- "sha256": "ac9c12d8ae9b662a095a5834a433a6c54000d0f00cbc9a9fda919efb73712353",
28
+ "sha256": "6caae572c2f56d78617ca1137ae3473c5bd6f8f2e05acada25a18d90c4a4aef8",
29
29
  "width": 1280,
30
30
  "height": 720,
31
31
  "capturedOn": "2026-11-10",
32
- "sourceVersion": "0.2.98"
32
+ "sourceVersion": "0.2.99"
33
33
  },
34
34
  {
35
35
  "path": "docs/screenshots/en/03-tool-discovery.jpg",
36
- "sha256": "679d59e40ad9ae53c4d09ad2295c4e87971b35d3e4f211fec412b70e5a20be9a",
36
+ "sha256": "29668029ceee6223a1efe9c405cc573c6bed868737a964f18d6bc01f65cdfd9d",
37
37
  "width": 1280,
38
38
  "height": 720,
39
39
  "capturedOn": "2026-11-10",
40
- "sourceVersion": "0.2.98"
40
+ "sourceVersion": "0.2.99"
41
41
  },
42
42
  {
43
43
  "path": "docs/screenshots/en/04-json-import.jpg",
44
- "sha256": "025750e844ec1c6fdf68391a099fc81894f3c21f980c1971556bf061f4ac7cd2",
44
+ "sha256": "e5f496baace32174a876ee83f9c1d42e0d577f60718d18a23158b86d9d4babb1",
45
45
  "width": 1280,
46
46
  "height": 720,
47
47
  "capturedOn": "2026-11-10",
48
- "sourceVersion": "0.2.98"
48
+ "sourceVersion": "0.2.99"
49
49
  },
50
50
  {
51
51
  "path": "docs/screenshots/en/05-unified-tool-search.png",
52
- "sha256": "5f7777eba34c4c9328b9451e10bcfef133da3f47c0bb9bd74150c36e59d8047a",
52
+ "sha256": "e11b2d53cd47cc32166777c73b39b0f408c74e420e04a9cc755ca15eedad7cb5",
53
53
  "width": 1280,
54
54
  "height": 720,
55
55
  "capturedOn": "2026-11-10",
56
- "sourceVersion": "0.2.98"
56
+ "sourceVersion": "0.2.99"
57
57
  },
58
58
  {
59
59
  "path": "docs/screenshots/en/06-tool-parameters.png",
60
- "sha256": "567f6286633c98fccbbd390e6188375e67ceee6f865ad129842116dc38a9ddfd",
60
+ "sha256": "1b005dfb87014c88aef488ca4441ebc98b2d93acbb2dfa9ea44d4eb855478138",
61
61
  "width": 1280,
62
62
  "height": 720,
63
63
  "capturedOn": "2026-11-10",
64
- "sourceVersion": "0.2.98"
64
+ "sourceVersion": "0.2.99"
65
65
  },
66
66
  {
67
67
  "path": "docs/screenshots/en/07-connection-diagnostics.png",
68
- "sha256": "f0435d733038163da255109b272ec153083ad99ce00f704018419212c2769bcd",
68
+ "sha256": "7a3810e60d182495f30994c1e4cf47459759f5d28543c8e82f39ede3b911d8b3",
69
69
  "width": 1280,
70
70
  "height": 720,
71
71
  "capturedOn": "2026-11-10",
72
- "sourceVersion": "0.2.98"
72
+ "sourceVersion": "0.2.99"
73
73
  },
74
74
  {
75
75
  "path": "docs/screenshots/en/08-ten-recommendations.jpg",
76
- "sha256": "3b36eaa0533f667ed47ae44f89cf5514c396f7b7d29ca40635ebd0411310037e",
76
+ "sha256": "58d34d5977e36c832e7b3820e7557ac42346e05e79948108301a5662d9a40b7c",
77
77
  "width": 1280,
78
78
  "height": 1400,
79
79
  "browserViewport": {
@@ -82,16 +82,16 @@
82
82
  },
83
83
  "panelHeight": 1280,
84
84
  "capturedOn": "2026-11-10",
85
- "sourceVersion": "0.2.98"
85
+ "sourceVersion": "0.2.99"
86
86
  }
87
87
  ],
88
88
  "demo": {
89
89
  "path": "docs/screenshots/en/demo.gif",
90
- "sha256": "77d04fbdcb3dc6352f172920827f02a345ad4af2b0eded70af2d706873019a41",
90
+ "sha256": "7315138b5c61f3c847353cdfd9a12696ba98479a1eb65a9378938ec71e1c1cba",
91
91
  "width": 960,
92
92
  "height": 540,
93
93
  "capturedOn": "2026-11-10",
94
- "sourceVersion": "0.2.98",
94
+ "sourceVersion": "0.2.99",
95
95
  "durationSeconds": 36
96
96
  }
97
97
  }
Binary file
@@ -8,7 +8,7 @@
8
8
 
9
9
  | 项目 | 验收要求 |
10
10
  |---|---|
11
- | 前提 | <!-- generated:version -->正式 `dsh-mcp-connector@0.2.98`<!-- /generated:version -->;当前 Workspace;企查查 OAuth 可用;测试账号具有目标企业数据权限 |
11
+ | 前提 | <!-- generated:version -->正式 `dsh-mcp-connector@0.2.99`<!-- /generated:version -->;当前 Workspace;企查查 OAuth 可用;测试账号具有目标企业数据权限 |
12
12
  | 权限/管理员 | 账号权限、组织授权和可见字段由服务商控制;企业组织可能需要管理员开通,当前文档不能替代审批 |
13
13
  | 费用 | 可能受套餐、次数或字段权限影响;MCP连接器无法确认本次费用,调用前在服务商侧核对 |
14
14
  | 运行/数据去向 | 远程 MCP Server;企业名称、查询参数和调用结果经 DSH Host 发送到/返回自 `agent.qcc.com` |
@@ -52,6 +52,7 @@ const FAILURE_GUIDANCE = Object.freeze({
52
52
  'host-tools-pending': ['host-observation', '查看 Host 日志并重新检查;可用性确认前保持未知'],
53
53
  'host-status-unavailable': ['host-observation', '升级或重启 DSH Host,待注册状态可见后重新检查'],
54
54
  'host-status-error': ['host-observation', '查看 Host 日志并重新检查工具注册状态'],
55
+ 'not-checked': ['host-observation', '运行健康检查以确认连接状态'],
55
56
  'tool-list': ['tool-discovery', '检查 Server 工具权限和服务状态后重试'],
56
57
  });
57
58
 
@@ -144,7 +145,9 @@ function resultDiagnostic(t, result, checkedAt, previous) {
144
145
  }
145
146
 
146
147
  const code = result.code || result.kind || 'network';
147
- const [stage, action] = FAILURE_GUIDANCE[code] || FAILURE_GUIDANCE.network;
148
+ const [defaultStage, defaultAction] = FAILURE_GUIDANCE[code] || FAILURE_GUIDANCE.network;
149
+ const stage = result.stage || defaultStage;
150
+ const action = stage === 'tool-discovery' ? FAILURE_GUIDANCE['tool-list'][1] : defaultAction;
148
151
  return {
149
152
  state: failureState(result.kind),
150
153
  stage,
package/lib/index.js CHANGED
@@ -1233,12 +1233,8 @@ export async function apply(ctx, config) {
1233
1233
  const plan = discoveryPlans.get(record.key);
1234
1234
  const currentPlan = plan?.record === record ? plan : null;
1235
1235
  const check = connectionChecks.get(record.key);
1236
- const diagnostic = check?.record === record && (!view || check.at >= view.at)
1237
- ? check.summary.diagnostic
1238
- : server ? buildHealthSummary({ connectorId: record.connectorId, records: [record], results: [{
1239
- ok: server.ok || server.unknown, kind: server.unknown ? 'managed' : server.ok ? 'connected' : server.errorKind || 'network',
1240
- code: server.diagnosticCode, serverName: record.serverName, serverKey: record.serverKey, message: server.error,
1241
- }], checkedAt: view.at }).diagnostic : null;
1236
+ const diagnostic = check?.record === record ? check.summary.diagnostic : null;
1237
+ const discoveryDiagnostic = server ? discoveryHealth(record.connectorId, [record], [server], view.at).diagnostic : null;
1242
1238
  const status = !server ? 'pending' : server.unknown ? 'unknown' : server.ok ? 'success' : 'failed';
1243
1239
  return {
1244
1240
  connectionKey: record.key, connectionName: record.name, connectorId: record.connectorId,
@@ -1247,7 +1243,7 @@ export async function apply(ctx, config) {
1247
1243
  checkedAt: view?.record === record ? view.at : null,
1248
1244
  observedAt: cache?.observedAt || null, stale: cache?.stale || false,
1249
1245
  toolCount: cache?.entry.tools.length || 0, cacheTruncated: cache?.entry.truncated === true,
1250
- diagnostic, nextDiscoveryAt: currentPlan?.nextAt ?? null,
1246
+ diagnostic, discoveryDiagnostic, nextDiscoveryAt: currentPlan?.nextAt ?? null,
1251
1247
  retryReason: currentPlan?.reason || null,
1252
1248
  };
1253
1249
  }
@@ -1307,10 +1303,52 @@ export async function apply(ctx, config) {
1307
1303
  return cached ?? healthSummary(connectorId, records, [], null);
1308
1304
  }
1309
1305
 
1306
+ function observedHealth(connectorId, records, previous = state.health.get(connectorId) ?? null) {
1307
+ const enabled = records.filter((record) => record.enabled !== false);
1308
+ const checks = enabled.map((record) => {
1309
+ const check = connectionChecks.get(record.key);
1310
+ return check?.record === record ? check : null;
1311
+ });
1312
+ return buildHealthSummary({
1313
+ connectorId, records, previous,
1314
+ checkedAt: checks.some(Boolean) ? Math.max(...checks.filter(Boolean).map((check) => check.at)) : null,
1315
+ results: enabled.map((record, index) => grantFailure(record) ?? checks[index]?.summary.results[0] ?? {
1316
+ ok: true, kind: 'managed', code: 'not-checked', serverKey: record.serverKey, serverName: record.serverName,
1317
+ message: t('已保存配置,但本进程尚未观察到可用性检查结果'),
1318
+ }),
1319
+ });
1320
+ }
1321
+
1322
+ function discoveryHealth(connectorId, records, servers, checkedAt = Date.now()) {
1323
+ return buildHealthSummary({ connectorId, records, checkedAt, results: servers.map((server) => ({
1324
+ ok: server.ok || server.unknown, kind: server.unknown ? 'managed' : server.ok ? 'connected' : server.errorKind ?? 'network',
1325
+ serverKey: server.serverKey, serverName: server.serverName, code: server.diagnosticCode,
1326
+ stage: server.errorStage === 'tool-discovery' || server.ok ? 'tool-discovery' : undefined, message: server.error,
1327
+ })) });
1328
+ }
1329
+
1310
1330
  function cacheHealth(connectorId, records, results) {
1311
- const summary = healthSummary(connectorId, records, results);
1312
- state.health.set(connectorId, summary);
1313
- return summary;
1331
+ const now = Date.now();
1332
+ const previous = state.health.get(connectorId) ?? null;
1333
+ for (const record of records) {
1334
+ if (state.connections.get(record.key) !== record || record.enabled === false) continue;
1335
+ const result = results.find((item) => item.serverName === record.serverName)
1336
+ ?? results.find((item) => item.serverKey === record.serverKey);
1337
+ if (!result) continue;
1338
+ const at = result.checkedAt ?? now;
1339
+ const prior = connectionChecks.get(record.key);
1340
+ // With millisecond clocks, a tied discovery observation must also yield to
1341
+ // an explicit check already recorded while tools/list was in flight.
1342
+ if (prior?.record === record && (prior.at > at || (prior.at === at && result.checkedAt !== undefined))) continue;
1343
+ const summary = buildHealthSummary({
1344
+ connectorId, records: [record], results: [result], checkedAt: at,
1345
+ previous: prior?.record === record ? prior.summary : previous,
1346
+ });
1347
+ connectionChecks.set(record.key, { record, summary, at });
1348
+ }
1349
+ // Scoped checks merge only their records; other connections keep their own observations.
1350
+ state.health.set(connectorId, observedHealth(connectorId, [...state.connections.values()].filter((record) => record.connectorId === connectorId), previous));
1351
+ return observedHealth(connectorId, records, previous);
1314
1352
  }
1315
1353
 
1316
1354
  function resolveCredentialValues(connector, params = {}) {
@@ -2514,7 +2552,10 @@ export async function apply(ctx, config) {
2514
2552
  async status({ workspaceId } = {}) {
2515
2553
  const items = [];
2516
2554
  for (const [key, record] of state.connections) {
2517
- const health = record.connectorId ? connectorHealth(record.connectorId) : null;
2555
+ const check = connectionChecks.get(key);
2556
+ const failure = grantFailure(record);
2557
+ const health = failure ? healthSummary(record.connectorId, [record], [failure])
2558
+ : check?.record === record ? check.summary : record.connectorId ? connectorHealth(record.connectorId) : null;
2518
2559
  const recordHealth = health?.results?.find((result) => result.serverKey === record.serverKey || result.serverName === record.serverName);
2519
2560
  const diagnostic = diagnosticForRecord(health, recordHealth);
2520
2561
  let grantInfo = null;
@@ -2643,10 +2684,8 @@ export async function apply(ctx, config) {
2643
2684
  });
2644
2685
  checkedResults = validation.detail.results;
2645
2686
  }
2646
- const summary = scoped ? healthSummary(id, records, [...immediateResults, ...checkedResults], Date.now())
2647
- : cacheHealth(id, records, [...immediateResults, ...checkedResults]);
2687
+ const summary = cacheHealth(id, records, [...immediateResults, ...checkedResults]);
2648
2688
  if (connectionKey && state.connections.get(connectionKey) === records[0]) {
2649
- connectionChecks.set(connectionKey, { record: records[0], summary, at: Date.now() });
2650
2689
  const outcome = [...immediateResults, ...checkedResults][0];
2651
2690
  if (outcome && !outcome.ok) {
2652
2691
  const prior = discoveryPlans.get(connectionKey);
@@ -3308,6 +3347,7 @@ export async function apply(ctx, config) {
3308
3347
  unknown: !current || current.unknown === true,
3309
3348
  pending: current?.pending === true || (!current && !cached),
3310
3349
  error: current?.error || (!cached && !current ? t('正在后台发现工具,请稍候') : undefined),
3350
+ errorKind: current?.errorKind, errorStage: current?.errorStage, diagnosticCode: current?.diagnosticCode,
3311
3351
  policy: serverPolicy(record),
3312
3352
  ...(cached ? { cacheObservedAt: cached.observedAt, cacheAgeMs: cached.cacheAgeMs, stale: cached.stale } : {}),
3313
3353
  tools: (cached?.entry.tools || []).map((tool) => decorateToolPolicy(record, {
@@ -3315,9 +3355,12 @@ export async function apply(ctx, config) {
3315
3355
  })),
3316
3356
  };
3317
3357
  });
3358
+ const health = observedHealth(connectorId, records);
3318
3359
  return { ok: servers.some((server) => server.ok), message: t('最近工具发现状态'), detail: {
3319
3360
  connectorId, servers, totalTools: servers.reduce((sum, server) => sum + server.tools.length, 0),
3320
3361
  source: 'last-success-cache',
3362
+ connectionState: health.connectionState, diagnostic: health.diagnostic,
3363
+ discoveryDiagnostic: discoveryHealth(connectorId, records, servers).diagnostic,
3321
3364
  } };
3322
3365
  }
3323
3366
  if (!records.length) {
@@ -3419,6 +3462,7 @@ export async function apply(ctx, config) {
3419
3462
  serverKey: record.serverKey || record.name,
3420
3463
  serverName: record.serverName,
3421
3464
  ok: true,
3465
+ connectionCheckedAt: listed.connectionCheckedAt,
3422
3466
  policy: serverPolicy(record),
3423
3467
  tools: listed.tools.map((t) => decorateToolPolicy(record, {
3424
3468
  name: t.name,
@@ -3447,6 +3491,8 @@ export async function apply(ctx, config) {
3447
3491
  ok: false,
3448
3492
  error: error.message,
3449
3493
  errorKind: error.kind,
3494
+ errorStage: error.stage,
3495
+ connectionCheckedAt: error.connectionCheckedAt,
3450
3496
  retryAfterMs: error.retryAfterMs,
3451
3497
  policy: serverPolicy(record),
3452
3498
  ...cachedFields,
@@ -3454,7 +3500,8 @@ export async function apply(ctx, config) {
3454
3500
  continue;
3455
3501
  }
3456
3502
  const classified = classifyConnectionError(error);
3457
- servers.push({ serverKey: record.serverKey || record.name, serverName: record.serverName, ok: false, error: classified.message, errorKind: classified.kind, policy: serverPolicy(record), ...cachedFields });
3503
+ servers.push({ serverKey: record.serverKey || record.name, serverName: record.serverName, ok: false, error: classified.message, errorKind: classified.kind,
3504
+ errorStage: error.stage, connectionCheckedAt: error.connectionCheckedAt, policy: serverPolicy(record), ...cachedFields });
3458
3505
  }
3459
3506
  }
3460
3507
 
@@ -3475,8 +3522,8 @@ export async function apply(ctx, config) {
3475
3522
  const failedServers = servers.length - availableServers - unknownServers;
3476
3523
  const pendingManagedServers = unknownServers;
3477
3524
  const cachedServers = servers.filter((server) => server.cached).length;
3478
- const health = cacheHealth(connectorId, records, servers.map((server) => server.ok
3479
- ? { ok: true, kind: 'connected', serverKey: server.serverKey, serverName: server.serverName }
3525
+ const health = cacheHealth(connectorId, records, servers.map((server) => server.ok || server.connectionCheckedAt !== undefined
3526
+ ? { ok: true, kind: 'connected', serverKey: server.serverKey, serverName: server.serverName, checkedAt: server.connectionCheckedAt }
3480
3527
  : server.unknown
3481
3528
  ? {
3482
3529
  ok: true,
@@ -3487,6 +3534,7 @@ export async function apply(ctx, config) {
3487
3534
  message: server.error,
3488
3535
  }
3489
3536
  : { ok: false, kind: server.errorKind ?? 'network', serverKey: server.serverKey, serverName: server.serverName, message: server.error }));
3537
+ const discovery = discoveryHealth(connectorId, records, servers);
3490
3538
  const failureSummary = servers.filter((server) => !server.ok && !server.unknown).slice(0, 3)
3491
3539
  .map((server) => `${server.serverName || server.serverKey}${t(':')}${server.error}`).join(t(';'));
3492
3540
  const unknownSummary = servers.filter((server) => server.unknown).slice(0, 3)
@@ -3518,6 +3566,7 @@ export async function apply(ctx, config) {
3518
3566
  connectionState: health.connectionState,
3519
3567
  lastSuccessfulAt: health.lastSuccessfulAt,
3520
3568
  diagnostic: health.diagnostic,
3569
+ discoveryDiagnostic: discovery.diagnostic,
3521
3570
  governance: {
3522
3571
  revision: governancePolicies.snapshot().revision,
3523
3572
  connectionPolicy: directPolicyEffect('connection', connectorId),
package/lib/mcp-http.js CHANGED
@@ -8,6 +8,7 @@
8
8
  import { MCP_PROTOCOL_VERSION } from './constants.js';
9
9
  import { authHeaders } from './mcp-provision.js';
10
10
  import { parseRetryAfter } from './discovery-policy.js';
11
+ import { readSseResponse } from './mcp-sse.js';
11
12
  import { DEFAULT_LOCALE, createTranslator } from './i18n/index.js';
12
13
 
13
14
  /** 缺省译文:中文(既有调用点与测试无需改动)。 */
@@ -95,6 +96,20 @@ function requestHeaders(record, grants, { sessionId, protocolVersion } = {}) {
95
96
  };
96
97
  }
97
98
 
99
+ // A streamable-HTTP response may stay open after the matching JSON-RPC reply
100
+ // (persistent SSE). Consume complete events until that reply arrives instead of
101
+ // waiting for EOF, and ignore notifications / unrelated request ids.
102
+ async function readResponsePayload(response, { id, t = tZh } = {}) {
103
+ const contentType = (response.headers.get('content-type') ?? '').toLowerCase();
104
+ if (id === undefined || !contentType.includes('text/event-stream')) {
105
+ const text = await readLimitedText(response, MAX_RESPONSE_BYTES, { t });
106
+ return { text, payload: parseMcpPayload(text, contentType) };
107
+ }
108
+ return readSseResponse(response, {
109
+ id, maxBytes: MAX_RESPONSE_BYTES, tooLarge: () => new McpHttpError(t('MCP 响应过大')),
110
+ });
111
+ }
112
+
98
113
  async function post(record, payload, { grants, sessionId, protocolVersion, signal, fetchImpl, t = tZh }) {
99
114
  const response = await fetchImpl(record.url, {
100
115
  method: 'POST',
@@ -103,8 +118,7 @@ async function post(record, payload, { grants, sessionId, protocolVersion, signa
103
118
  signal,
104
119
  redirect: 'follow',
105
120
  });
106
- const text = await readLimitedText(response, MAX_RESPONSE_BYTES, { t });
107
- const parsed = parseMcpPayload(text, response.headers.get('content-type') ?? '');
121
+ const { text, payload: parsed } = await readResponsePayload(response, { id: payload?.id, t });
108
122
  return { response, text, payload: parsed };
109
123
  }
110
124
 
@@ -134,6 +148,8 @@ async function listMcpToolsOnce(record, {
134
148
  const timer = setTimeout(() => controller.abort(new Error('timeout')), timeoutMs);
135
149
  let sessionId = '';
136
150
  let protocolVersion = MCP_PROTOCOL_VERSION;
151
+ let stage = 'mcp-initialize';
152
+ let connectionCheckedAt;
137
153
  try {
138
154
  const initialized = await post(record, {
139
155
  jsonrpc: '2.0',
@@ -163,6 +179,8 @@ async function listMcpToolsOnce(record, {
163
179
  throw responseError(notification.response, notification.payload, notification.text, { t });
164
180
  }
165
181
 
182
+ connectionCheckedAt = Date.now();
183
+ stage = 'tool-discovery';
166
184
  const tools = [];
167
185
  const seenCursors = new Set();
168
186
  let cursor;
@@ -185,7 +203,7 @@ async function listMcpToolsOnce(record, {
185
203
 
186
204
  const nextCursor = listed.payload?.result?.nextCursor;
187
205
  if (typeof nextCursor !== 'string' || nextCursor.length === 0) {
188
- return { tools, protocolVersion, sessionful: Boolean(sessionId), pages: page + 1 };
206
+ return { tools, protocolVersion, sessionful: Boolean(sessionId), pages: page + 1, connectionCheckedAt };
189
207
  }
190
208
  if (seenCursors.has(nextCursor)) {
191
209
  throw new McpHttpError(t('MCP tools/list 返回了重复分页游标'));
@@ -194,6 +212,12 @@ async function listMcpToolsOnce(record, {
194
212
  cursor = nextCursor;
195
213
  }
196
214
  throw new McpHttpError(t('MCP tools/list 分页超过安全上限({maxPages} 页)', { maxPages: MAX_TOOL_PAGES }));
215
+ } catch (error) {
216
+ // Keep transport errors and their causes intact for retry/error classification.
217
+ const failure = error instanceof Error ? error : new Error(String(error));
218
+ failure.stage = stage;
219
+ failure.connectionCheckedAt = connectionCheckedAt;
220
+ throw failure;
197
221
  } finally {
198
222
  clearTimeout(timer);
199
223
  await closeSession(record, { grants, sessionId, protocolVersion, fetchImpl });
package/lib/mcp-sse.js ADDED
@@ -0,0 +1,48 @@
1
+ /** Read the first complete SSE event matching a JSON-RPC request, without waiting for EOF. */
2
+ export async function readSseResponse(response, { id, maxBytes, tooLarge }) {
3
+ if (!response.body) return { text: '', payload: undefined };
4
+ const reader = response.body.getReader();
5
+ const decoder = new TextDecoder();
6
+ let line = '';
7
+ let data = [];
8
+ let skipLF = false;
9
+ let total = 0;
10
+ try {
11
+ for (;;) {
12
+ const { done, value } = await reader.read();
13
+ // EOF does not dispatch an event lacking its final blank line.
14
+ if (done) return { text: '', payload: undefined };
15
+ total += value.byteLength;
16
+ if (total > maxBytes) throw tooLarge();
17
+ const text = decoder.decode(value, { stream: true });
18
+ if (!text) continue;
19
+ let start = skipLF && text.startsWith('\n') ? 1 : 0;
20
+ skipLF = text.endsWith('\r');
21
+ const endings = /\r\n|\r|\n/g;
22
+ endings.lastIndex = start;
23
+ let ending;
24
+ while ((ending = endings.exec(text))) {
25
+ line += text.slice(start, ending.index);
26
+ start = endings.lastIndex;
27
+ if (line === '') {
28
+ const event = data.join('\n');
29
+ data = [];
30
+ let payload;
31
+ try { payload = JSON.parse(event); } catch { continue; }
32
+ if (payload?.jsonrpc === '2.0' && payload.id === id && ('result' in payload || 'error' in payload)) {
33
+ return { text: event, payload };
34
+ }
35
+ } else {
36
+ if (line === 'data') data.push('');
37
+ else if (line.startsWith('data:')) data.push(line.slice(5).replace(/^ /, ''));
38
+ line = '';
39
+ }
40
+ }
41
+ line += text.slice(start);
42
+ }
43
+ } finally {
44
+ // A server or stream adapter may never resolve cancellation; do not await it.
45
+ void reader.cancel().catch(() => {});
46
+ reader.releaseLock();
47
+ }
48
+ }
@@ -6,6 +6,7 @@ import { MCP_PROTOCOL_VERSION } from './constants.js';
6
6
  import { DEFAULT_LOCALE, createTranslator } from './i18n/index.js';
7
7
  import { authHeaders } from './mcp-provision.js';
8
8
  import { parseRetryAfter } from './discovery-policy.js';
9
+ import { readSseResponse } from './mcp-sse.js';
9
10
 
10
11
  /** 缺省译文:中文(既有调用点与测试无需改动)。 */
11
12
  const tZh = createTranslator(DEFAULT_LOCALE);
@@ -18,34 +19,10 @@ async function readInitializePayload(response, { t }) {
18
19
  if (!(response.headers.get('content-type') ?? '').toLowerCase().includes('text/event-stream')) {
19
20
  return parseMcpPayload(await readLimitedText(response, MAX_RESPONSE_BYTES, { t }));
20
21
  }
21
- if (!response.body) return undefined;
22
- const reader = response.body.getReader();
23
- const decoder = new TextDecoder();
24
- let buffer = '';
25
- let total = 0;
26
- try {
27
- for (;;) {
28
- const { done, value } = await reader.read();
29
- if (done) return undefined;
30
- total += value.byteLength;
31
- if (total > MAX_RESPONSE_BYTES) throw new Error(t('MCP 响应过大'));
32
- buffer += decoder.decode(value, { stream: true });
33
- let boundary;
34
- while ((boundary = /\r\n\r\n|\n\n|\r\r/.exec(buffer))) {
35
- const event = buffer.slice(0, boundary.index);
36
- buffer = buffer.slice(boundary.index + boundary[0].length);
37
- const data = event.split(/\r\n|\n|\r/).filter(line => line.startsWith('data:'))
38
- .map(line => line.slice(5).replace(/^ /, '')).join('\n');
39
- let payload;
40
- try { payload = JSON.parse(data); } catch { continue; }
41
- if (payload?.jsonrpc === '2.0' && payload.id === 1 && ('result' in payload || 'error' in payload)) return payload;
42
- }
43
- }
44
- } finally {
45
- // Cancellation must not await a server closing its persistent stream.
46
- void reader.cancel().catch(() => {});
47
- reader.releaseLock();
48
- }
22
+ const { payload } = await readSseResponse(response, {
23
+ id: 1, maxBytes: MAX_RESPONSE_BYTES, tooLarge: () => new Error(t('MCP 响应过大')),
24
+ });
25
+ return payload;
49
26
  }
50
27
 
51
28
  async function readLimitedText(response, maxBytes = MAX_RESPONSE_BYTES, { t = tZh } = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mcp-connector",
3
- "version": "0.2.98",
3
+ "version": "0.2.99",
4
4
  "description": "MCP Connector for DeepSeek Harness: a data marketplace connecting enterprise, financial, legal, patent and research data. Manage authorization, search tools and troubleshoot MCP connections. Supports OAuth, API keys and HTTP/stdio.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -49,7 +49,7 @@
49
49
  ],
50
50
  "scripts": {
51
51
  "test": "node --test",
52
- "lint": "node --check lib/discovery-policy.js && node --check lib/index.js && node --check lib/web.js && node --check lib/client.js && node --check lib/settings.js && node --check lib/version-status.js && node --check lib/schema.js && node --check lib/catalog.js && node --check lib/prompts.js && node --check lib/probe.js && node --check lib/diagnostics.js && node --check lib/connection-backup.js && node --check lib/shareable-connection-template.js && node --check lib/connection-editor.js && node --check lib/connection-scopes.js && node --check lib/governance.js && node --check lib/session-injection.js && node --check lib/tool-catalog-cache.js && node --check lib/status-events.js && node --check lib/mcp-validation.js && node --check lib/mcp-http.js && node --check lib/migration.js && node --check lib/stores.js && node --check lib/grant-journal.js && node --check lib/oauth.js && node --check lib/grant-lifecycle.js && node --check lib/callback-server.js && node --check lib/mcp-provision.js && node --check lib/stdio-startup-guard.js && node --check lib/cli-providers.js && node --check lib/util.js && node --check lib/constants.js && node --check lib/tools.js && node --check lib/connectors/oauth-connector.js && node --check lib/connectors/manual-connector.js && node --check lib/connectors/json-connector.js && node --check ui/sharing-experience.js && node --check ui/connection-template-sharing.js && node --check scripts/probe-connector.mjs && node --check scripts/cli-bridge.mjs && node --check scripts/build-registry.mjs && node --check scripts/ui-harness.mjs && node --check scripts/check-market-registration.mjs && node --check scripts/check-distribution-sync.mjs && node --check scripts/check-readme-version.mjs && node --check scripts/check-first-use-docs.mjs && node --check scripts/check-marketing-metadata.mjs && node --check scripts/check-storefront-screenshots.mjs && node --check scripts/sync-registry-stats.mjs && node --check scripts/verify-pack.mjs && node --check scripts/check-tutorial-links.mjs",
52
+ "lint": "node --check lib/discovery-policy.js && node --check lib/index.js && node --check lib/web.js && node --check lib/client.js && node --check lib/settings.js && node --check lib/version-status.js && node --check lib/schema.js && node --check lib/catalog.js && node --check lib/prompts.js && node --check lib/probe.js && node --check lib/diagnostics.js && node --check lib/connection-backup.js && node --check lib/shareable-connection-template.js && node --check lib/connection-editor.js && node --check lib/connection-scopes.js && node --check lib/governance.js && node --check lib/session-injection.js && node --check lib/tool-catalog-cache.js && node --check lib/status-events.js && node --check lib/mcp-validation.js && node --check lib/mcp-http.js && node --check lib/mcp-sse.js && node --check lib/migration.js && node --check lib/stores.js && node --check lib/grant-journal.js && node --check lib/oauth.js && node --check lib/grant-lifecycle.js && node --check lib/callback-server.js && node --check lib/mcp-provision.js && node --check lib/stdio-startup-guard.js && node --check lib/cli-providers.js && node --check lib/util.js && node --check lib/constants.js && node --check lib/tools.js && node --check lib/connectors/oauth-connector.js && node --check lib/connectors/manual-connector.js && node --check lib/connectors/json-connector.js && node --check ui/sharing-experience.js && node --check ui/connection-template-sharing.js && node --check scripts/probe-connector.mjs && node --check scripts/cli-bridge.mjs && node --check scripts/build-registry.mjs && node --check scripts/ui-harness.mjs && node --check scripts/check-market-registration.mjs && node --check scripts/check-distribution-sync.mjs && node --check scripts/check-readme-version.mjs && node --check scripts/check-first-use-docs.mjs && node --check scripts/check-marketing-metadata.mjs && node --check scripts/check-storefront-screenshots.mjs && node --check scripts/sync-registry-stats.mjs && node --check scripts/verify-pack.mjs && node --check scripts/check-tutorial-links.mjs",
53
53
  "registry:build": "node scripts/build-registry.mjs",
54
54
  "registry:validate": "node scripts/probe-connector.mjs catalog/catalog.json --validate-only",
55
55
  "dev:ui": "node scripts/ui-harness.mjs",
package/ui/index.html CHANGED
@@ -2391,6 +2391,11 @@
2391
2391
  const explorerStatusLabel = (status) => t(EXPLORER_STATUS[status] || status);
2392
2392
  const formatObserved = (value) => value ? new Date(value).toLocaleString(t.locale, { hour12: false }) : t('尚无记录');
2393
2393
 
2394
+ function explorerDiagnosticsHtml(connection) {
2395
+ return [connection.diagnostic, connection.discoveryDiagnostic].filter(Boolean).map((diagnostic) =>
2396
+ `<div>${t('{stage}:{message}', { stage: esc(diagnostic.stageLabel), message: esc(diagnostic.message) })}<br>${t('建议:{action}', { action: esc(diagnostic.action) })}</div>`).join('');
2397
+ }
2398
+
2394
2399
  async function loadToolExplorer() {
2395
2400
  const render = beginViewRender();
2396
2401
  try {
@@ -2413,7 +2418,7 @@
2413
2418
  $('#explorer-server').value = explorerFilter.serverName;
2414
2419
  $('#explorer-status').value = explorerFilter.status;
2415
2420
  $('#explorer-summary').textContent = t('{scope} · {connections} 条连接 · 匹配 {tools} 个工具 · 显示 {shown} 个', { scope: explorerData.scopeLabel, connections: connections.length, tools: total, shown: items.length });
2416
- $('#explorer-connections').innerHTML = `<details ${explorerFilter.connectionKey || !total ? 'open' : ''}><summary>${t('连接状态与故障处理({count})', { count: selectedConnections.length })}</summary>${selectedConnections.map((c) => `<div class="explorer-card"><strong>${esc(c.connectionName)}</strong><div>${esc(c.serverName)} · ${esc(explorerStatusLabel(c.status))} · ${t('缓存 {count} 个工具', { count: c.toolCount })}</div><div class="hint">${t('最近发现:{observed};最后成功:{success}{stale}{truncated}', { observed: esc(formatObserved(c.checkedAt)), success: esc(formatObserved(c.observedAt)), stale: c.stale ? t(' · 缓存超过 24 小时') : '', truncated: c.cacheTruncated ? t(' · 缓存清单已截断') : '' })}</div>${c.diagnostic ? `<div>${t('{stage}:{message}', { stage: esc(c.diagnostic.stageLabel), message: esc(c.diagnostic.message) })}<br>${t('建议:{action}', { action: esc(c.diagnostic.action) })}</div>` : ''}${c.retryReason === 'auth' ? `<p>${t('鉴权失败已暂停后台重试,请到已安装页更新凭据或重新授权。')}</p>` : c.nextDiscoveryAt ? `<p class="hint">${t('下次后台发现不早于:{at}(页面保持连接时)', { at: esc(formatObserved(c.nextDiscoveryAt)) })}</p>` : ''}<div class="m-actions"><button class="btn ghost" data-explorer-action="discover" data-key="${esc(c.connectionKey)}" ${explorerBusy.has(c.connectionKey) ? 'disabled' : ''}>${t('重新发现工具')}</button><button class="btn ghost" data-explorer-action="check" data-key="${esc(c.connectionKey)}" ${explorerBusy.has(c.connectionKey) ? 'disabled' : ''}>${t('检查连接')}</button></div></div>`).join('') || `<p>${t('当前筛选下没有连接。')}</p>`}</details>`;
2421
+ $('#explorer-connections').innerHTML = `<details ${explorerFilter.connectionKey || !total ? 'open' : ''}><summary>${t('连接状态与故障处理({count})', { count: selectedConnections.length })}</summary>${selectedConnections.map((c) => `<div class="explorer-card"><strong>${esc(c.connectionName)}</strong><div>${esc(c.serverName)} · ${esc(explorerStatusLabel(c.status))} · ${t('缓存 {count} 个工具', { count: c.toolCount })}</div><div class="hint">${t('最近发现:{observed};最后成功:{success}{stale}{truncated}', { observed: esc(formatObserved(c.checkedAt)), success: esc(formatObserved(c.observedAt)), stale: c.stale ? t(' · 缓存超过 24 小时') : '', truncated: c.cacheTruncated ? t(' · 缓存清单已截断') : '' })}</div>${explorerDiagnosticsHtml(c)}${c.retryReason === 'auth' ? `<p>${t('鉴权失败已暂停后台重试,请到已安装页更新凭据或重新授权。')}</p>` : c.nextDiscoveryAt ? `<p class="hint">${t('下次后台发现不早于:{at}(页面保持连接时)', { at: esc(formatObserved(c.nextDiscoveryAt)) })}</p>` : ''}<div class="m-actions"><button class="btn ghost" data-explorer-action="discover" data-key="${esc(c.connectionKey)}" ${explorerBusy.has(c.connectionKey) ? 'disabled' : ''}>${t('重新发现工具')}</button><button class="btn ghost" data-explorer-action="check" data-key="${esc(c.connectionKey)}" ${explorerBusy.has(c.connectionKey) ? 'disabled' : ''}>${t('检查连接')}</button></div></div>`).join('') || `<p>${t('当前筛选下没有连接。')}</p>`}</details>`;
2417
2422
  $('#explorer-results').innerHTML = items.map((item, index) => `<article class="explorer-card"><strong>${esc(item.name)}</strong>${item.title !== item.name ? `<div>${esc(item.title)}</div>` : ''}<p>${esc(item.description || t('暂无描述'))}</p><div class="hint">${t('来源:{connector} / {connection} / {server}', { connector: esc(item.connection.connectorName), connection: esc(item.connection.connectionName), server: esc(item.serverName) })}<br>${esc(explorerStatusLabel(item.connection.status))} · ${t('最后成功缓存 {at}', { at: esc(formatObserved(item.observedAt)) })}${item.stale ? t(' · 已超过 24 小时') : ''}</div><button class="btn ghost" data-explorer-detail="${index}">${t('参数详情')}</button></article>`).join('') || `<p class="empty">${t(connections.length ? '没有匹配工具。请调整关键词或筛选;也可展开连接状态检查是否尚未发现或读取失败。' : '当前范围没有已启用连接。请先添加连接,或选择对应工作区。')}</p>`;
2418
2423
  $('#explorer-pages').innerHTML = `<button class="btn ghost" data-explorer-page="prev" ${explorerOffset === 0 ? 'disabled' : ''}>${t('上一页')}</button><span>${Math.floor(explorerOffset / 20) + 1} / ${Math.max(1, Math.ceil(total / 20))}</span><button class="btn ghost" data-explorer-page="next" ${explorerOffset + 20 >= total ? 'disabled' : ''}>${t('下一页')}</button>`;
2419
2424
  } finally { finishViewRender(render); }
@@ -3249,9 +3254,9 @@
3249
3254
  syncGovernanceBar();
3250
3255
  if (!toolsResult.ok) {
3251
3256
  detailFailureState = toolsResult.detail?.connectionState || detailFailureState || 'unavailable';
3252
- detailNeedsReconfigure = true;
3257
+ detailNeedsReconfigure = detailFailureState !== 'healthy';
3253
3258
  detailReconnectKey = detailFailureState === 'unknown' && d.connected?.length > 0 ? d.connected[0] : '';
3254
- const diagnostic = toolsResult.detail?.diagnostic;
3259
+ const diagnostic = toolsResult.detail?.discoveryDiagnostic || toolsResult.detail?.diagnostic;
3255
3260
  $('#tools-summary').textContent = t(detailFailureState === 'unknown' ? '工具状态未知' : '工具加载失败');
3256
3261
  const failureHtml = `<div class="tools-error">${esc(toolsResult.message)}${diagnostic ? `<br><br>${esc(t('{stage} · {code}:{message}', { stage: diagnostic.stageLabel || diagnostic.stage, code: diagnostic.code, message: diagnostic.message }))}<br>${esc(t('建议:{action}', { action: diagnostic.action }))}${diagnostic.lastSuccessfulAt ? `<br>${esc(t('最近成功:{at}', { at: new Date(diagnostic.lastSuccessfulAt).toLocaleString(t.locale, { hour12: false }) }))}` : ''}` : ''}</div>`;
3257
3262
  detailToolServers = toolsResult.detail?.servers || [];
@@ -3263,7 +3268,7 @@
3263
3268
  }
3264
3269
  const failureLabel = detailFailureState === 'reauth'
3265
3270
  ? t(d.authMode === 'oauth2-pkce' ? '授权已失效' : '凭据已失效')
3266
- : t(detailFailureState === 'unknown' ? '状态尚未确认' : '当前连接异常');
3271
+ : t(detailFailureState === 'healthy' ? '已连接' : detailFailureState === 'unknown' ? '状态尚未确认' : '当前连接异常');
3267
3272
  $('#detail-vendor').textContent = d.vendor ? `${d.vendor} · ${failureLabel}` : failureLabel;
3268
3273
  $('#detail-try-btn').textContent = detailTryLabel(d.authMode === 'oauth2-pkce' && detailFailureState === 'reauth'
3269
3274
  ? t('🔐 重新授权')
@@ -3469,13 +3474,10 @@
3469
3474
  detailToolServers = result.detail.servers;
3470
3475
  renderTools();
3471
3476
  const pending = detailToolServers.some((server) => server.pending);
3472
- const unknown = detailToolServers.some((server) => server.unknown);
3473
- const available = detailToolServers.filter((server) => server.ok).length;
3474
- const label = t(pending ? '正在后台发现工具' : unknown && available === 0 ? '工具状态尚未确认'
3475
- : available === detailToolServers.length ? '已连接'
3476
- : available > 0 ? '部分服务可用' : '当前连接异常');
3477
- detailFailureState = pending ? 'unknown' : available > 0 ? 'healthy' : 'unavailable';
3478
- detailNeedsReconfigure = !pending && available === 0;
3477
+ detailFailureState = result.detail.connectionState || 'unknown';
3478
+ const label = t(detailFailureState === 'healthy' ? '已连接' : detailFailureState === 'reauth' ? '凭据已失效'
3479
+ : detailFailureState === 'unknown' ? '状态尚未确认' : detailFailureState === 'degraded' ? '部分服务可用' : '当前连接异常');
3480
+ detailNeedsReconfigure = !pending && detailFailureState !== 'healthy';
3479
3481
  detailReconnectKey = '';
3480
3482
  $('#detail-vendor').textContent = detailConnector.vendor ? `${detailConnector.vendor} · ${label}` : label;
3481
3483
  $('#detail-try-btn').textContent = detailTryLabel(detailNeedsReconfigure ? t('🔄 重新检查') : t('try'));