dsh-mcp-connector 0.2.97 → 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 +15 -0
- package/README.en.md +2 -2
- package/README.md +2 -2
- package/docs/screenshots/01-market-overview.jpg +0 -0
- package/docs/screenshots/02-connector-detail.jpg +0 -0
- package/docs/screenshots/03-tool-discovery.jpg +0 -0
- package/docs/screenshots/04-json-import.jpg +0 -0
- package/docs/screenshots/05-unified-tool-search.png +0 -0
- package/docs/screenshots/06-tool-parameters.png +0 -0
- package/docs/screenshots/07-connection-diagnostics.png +0 -0
- package/docs/screenshots/08-ten-recommendations.jpg +0 -0
- package/docs/screenshots/README.md +1 -1
- package/docs/screenshots/assets.json +30 -30
- package/docs/screenshots/en/01-market-overview.jpg +0 -0
- package/docs/screenshots/en/02-connector-detail.jpg +0 -0
- package/docs/screenshots/en/03-tool-discovery.jpg +0 -0
- package/docs/screenshots/en/04-json-import.jpg +0 -0
- package/docs/screenshots/en/05-unified-tool-search.png +0 -0
- package/docs/screenshots/en/06-tool-parameters.png +0 -0
- package/docs/screenshots/en/07-connection-diagnostics.png +0 -0
- package/docs/screenshots/en/08-ten-recommendations.jpg +0 -0
- package/docs/screenshots/en/assets.json +30 -30
- package/docs/screenshots/en/demo.gif +0 -0
- package/docs/tutorials/FIRST-SUCCESS-SCENARIOS.md +1 -1
- package/lib/diagnostics.js +4 -1
- package/lib/index.js +66 -17
- package/lib/mcp-http.js +27 -3
- package/lib/mcp-sse.js +48 -0
- package/lib/mcp-validation.js +5 -28
- package/package.json +2 -2
- package/ui/index.html +164 -24
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
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
|
+
|
|
11
|
+
## 0.2.98
|
|
12
|
+
|
|
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.
|
|
14
|
+
- Add a first successful connection handoff to discovered tools and example prompts without claiming authorization, tool execution, or business-call success.
|
|
15
|
+
- Add bounded, local-browser guidance counters for Quick start, recommendations, first connector setup and tool discovery. No data is uploaded and the UI explicitly avoids calculating a conversion rate across mixed denominators.
|
|
16
|
+
- Refresh the bilingual credential-free Mock screenshots and GIFs so the storefront matches the current two-column UI and does not display a reauthorization state.
|
|
17
|
+
|
|
3
18
|
## 0.2.97
|
|
4
19
|
|
|
5
20
|
- Bind remote catalog caches and ETags to catalogUrl. Changing the source fetches the new catalog immediately, including while the old cache TTL is fresh; failed requests do not expose entries from another source (#219).
|
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
|
|  | |
|
|
116
116
|
|
|
117
|
-
<!-- generated:media -->English UI screenshots and GIF were captured from v0.2.
|
|
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.
|
|
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
|
|  | |
|
|
130
130
|
|
|
131
|
-
<!-- generated:media -->截图与 GIF 采集自 v0.2.
|
|
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.
|
|
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
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 产品截图与演示的来源及更新
|
|
2
2
|
|
|
3
|
-
<!-- generated:media -->本组 8 张截图和 GIF 均从 v0.2.
|
|
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
|
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"capture": {
|
|
4
4
|
"locale": "zh-CN",
|
|
5
|
-
"capturedOn": "2026-11-
|
|
6
|
-
"sourceVersion": "0.2.
|
|
7
|
-
"sourceFingerprint": "
|
|
5
|
+
"capturedOn": "2026-11-10",
|
|
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": "
|
|
20
|
+
"sha256": "84589ad5fa2ed5b228dec616f30c74002db00d961002848003d6b3177ac5d490",
|
|
21
21
|
"width": 1280,
|
|
22
22
|
"height": 720,
|
|
23
|
-
"capturedOn": "2026-11-
|
|
24
|
-
"sourceVersion": "0.2.
|
|
23
|
+
"capturedOn": "2026-11-10",
|
|
24
|
+
"sourceVersion": "0.2.99"
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
27
|
"path": "docs/screenshots/02-connector-detail.jpg",
|
|
28
|
-
"sha256": "
|
|
28
|
+
"sha256": "69a89d4d7d3ddf825007255fa911154d911306e7c172887901ff96c16d7e7cd1",
|
|
29
29
|
"width": 1280,
|
|
30
30
|
"height": 720,
|
|
31
|
-
"capturedOn": "2026-11-
|
|
32
|
-
"sourceVersion": "0.2.
|
|
31
|
+
"capturedOn": "2026-11-10",
|
|
32
|
+
"sourceVersion": "0.2.99"
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
35
|
"path": "docs/screenshots/03-tool-discovery.jpg",
|
|
36
|
-
"sha256": "
|
|
36
|
+
"sha256": "0540269514a6c6bd9ba17d96ca219afe854be637d4528e0dc6c37c9f47760dbc",
|
|
37
37
|
"width": 1280,
|
|
38
38
|
"height": 720,
|
|
39
|
-
"capturedOn": "2026-11-
|
|
40
|
-
"sourceVersion": "0.2.
|
|
39
|
+
"capturedOn": "2026-11-10",
|
|
40
|
+
"sourceVersion": "0.2.99"
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
43
|
"path": "docs/screenshots/04-json-import.jpg",
|
|
44
|
-
"sha256": "
|
|
44
|
+
"sha256": "724de44513ac6302530e6ad5d89f6a3c7d23a9b564af8b276fb36890adcebbaf",
|
|
45
45
|
"width": 1280,
|
|
46
46
|
"height": 720,
|
|
47
|
-
"capturedOn": "2026-11-
|
|
48
|
-
"sourceVersion": "0.2.
|
|
47
|
+
"capturedOn": "2026-11-10",
|
|
48
|
+
"sourceVersion": "0.2.99"
|
|
49
49
|
},
|
|
50
50
|
{
|
|
51
51
|
"path": "docs/screenshots/05-unified-tool-search.png",
|
|
52
|
-
"sha256": "
|
|
52
|
+
"sha256": "b9b230492e0fc2e9bbe85dd652c118de468ca4481748d8a8cce2337abd3332b1",
|
|
53
53
|
"width": 1280,
|
|
54
54
|
"height": 720,
|
|
55
|
-
"capturedOn": "2026-11-
|
|
56
|
-
"sourceVersion": "0.2.
|
|
55
|
+
"capturedOn": "2026-11-10",
|
|
56
|
+
"sourceVersion": "0.2.99"
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
59
|
"path": "docs/screenshots/06-tool-parameters.png",
|
|
60
|
-
"sha256": "
|
|
60
|
+
"sha256": "b10f6e3b7e2e935f0fcc0c11529421070612db3f182a59f5928281e90b9c83b1",
|
|
61
61
|
"width": 1280,
|
|
62
62
|
"height": 720,
|
|
63
|
-
"capturedOn": "2026-11-
|
|
64
|
-
"sourceVersion": "0.2.
|
|
63
|
+
"capturedOn": "2026-11-10",
|
|
64
|
+
"sourceVersion": "0.2.99"
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
67
|
"path": "docs/screenshots/07-connection-diagnostics.png",
|
|
68
|
-
"sha256": "
|
|
68
|
+
"sha256": "7dab4e1f8557cb9e14ca20668fc8bc390e0819e06b3b6e7f1291c82137e285bd",
|
|
69
69
|
"width": 1280,
|
|
70
70
|
"height": 720,
|
|
71
|
-
"capturedOn": "2026-11-
|
|
72
|
-
"sourceVersion": "0.2.
|
|
71
|
+
"capturedOn": "2026-11-10",
|
|
72
|
+
"sourceVersion": "0.2.99"
|
|
73
73
|
},
|
|
74
74
|
{
|
|
75
75
|
"path": "docs/screenshots/08-ten-recommendations.jpg",
|
|
76
|
-
"sha256": "
|
|
76
|
+
"sha256": "c86c448277e80505659a8dc7faef8efd1dcf254b3cbeb93aab0c95640226537f",
|
|
77
77
|
"width": 1280,
|
|
78
78
|
"height": 1400,
|
|
79
79
|
"browserViewport": {
|
|
@@ -81,17 +81,17 @@
|
|
|
81
81
|
"height": 1400
|
|
82
82
|
},
|
|
83
83
|
"panelHeight": 1280,
|
|
84
|
-
"capturedOn": "2026-11-
|
|
85
|
-
"sourceVersion": "0.2.
|
|
84
|
+
"capturedOn": "2026-11-10",
|
|
85
|
+
"sourceVersion": "0.2.99"
|
|
86
86
|
}
|
|
87
87
|
],
|
|
88
88
|
"demo": {
|
|
89
89
|
"path": "docs/demo.gif",
|
|
90
|
-
"sha256": "
|
|
90
|
+
"sha256": "d3bef144cc3236a3965e1ffed668319fdead5073836ac664cc8059073692cf1f",
|
|
91
91
|
"width": 960,
|
|
92
92
|
"height": 540,
|
|
93
|
-
"capturedOn": "2026-11-
|
|
94
|
-
"sourceVersion": "0.2.
|
|
93
|
+
"capturedOn": "2026-11-10",
|
|
94
|
+
"sourceVersion": "0.2.99",
|
|
95
95
|
"durationSeconds": 36
|
|
96
96
|
}
|
|
97
97
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"capture": {
|
|
4
4
|
"locale": "en",
|
|
5
|
-
"capturedOn": "2026-11-
|
|
6
|
-
"sourceVersion": "0.2.
|
|
7
|
-
"sourceFingerprint": "
|
|
5
|
+
"capturedOn": "2026-11-10",
|
|
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": "
|
|
20
|
+
"sha256": "fabe58bc533ce3c3a917f3ef8ea0c45c44b66038aab8d3d45733f87010947375",
|
|
21
21
|
"width": 1280,
|
|
22
22
|
"height": 720,
|
|
23
|
-
"capturedOn": "2026-11-
|
|
24
|
-
"sourceVersion": "0.2.
|
|
23
|
+
"capturedOn": "2026-11-10",
|
|
24
|
+
"sourceVersion": "0.2.99"
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
27
|
"path": "docs/screenshots/en/02-connector-detail.jpg",
|
|
28
|
-
"sha256": "
|
|
28
|
+
"sha256": "6caae572c2f56d78617ca1137ae3473c5bd6f8f2e05acada25a18d90c4a4aef8",
|
|
29
29
|
"width": 1280,
|
|
30
30
|
"height": 720,
|
|
31
|
-
"capturedOn": "2026-11-
|
|
32
|
-
"sourceVersion": "0.2.
|
|
31
|
+
"capturedOn": "2026-11-10",
|
|
32
|
+
"sourceVersion": "0.2.99"
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
35
|
"path": "docs/screenshots/en/03-tool-discovery.jpg",
|
|
36
|
-
"sha256": "
|
|
36
|
+
"sha256": "29668029ceee6223a1efe9c405cc573c6bed868737a964f18d6bc01f65cdfd9d",
|
|
37
37
|
"width": 1280,
|
|
38
38
|
"height": 720,
|
|
39
|
-
"capturedOn": "2026-11-
|
|
40
|
-
"sourceVersion": "0.2.
|
|
39
|
+
"capturedOn": "2026-11-10",
|
|
40
|
+
"sourceVersion": "0.2.99"
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
43
|
"path": "docs/screenshots/en/04-json-import.jpg",
|
|
44
|
-
"sha256": "
|
|
44
|
+
"sha256": "e5f496baace32174a876ee83f9c1d42e0d577f60718d18a23158b86d9d4babb1",
|
|
45
45
|
"width": 1280,
|
|
46
46
|
"height": 720,
|
|
47
|
-
"capturedOn": "2026-11-
|
|
48
|
-
"sourceVersion": "0.2.
|
|
47
|
+
"capturedOn": "2026-11-10",
|
|
48
|
+
"sourceVersion": "0.2.99"
|
|
49
49
|
},
|
|
50
50
|
{
|
|
51
51
|
"path": "docs/screenshots/en/05-unified-tool-search.png",
|
|
52
|
-
"sha256": "
|
|
52
|
+
"sha256": "e11b2d53cd47cc32166777c73b39b0f408c74e420e04a9cc755ca15eedad7cb5",
|
|
53
53
|
"width": 1280,
|
|
54
54
|
"height": 720,
|
|
55
|
-
"capturedOn": "2026-11-
|
|
56
|
-
"sourceVersion": "0.2.
|
|
55
|
+
"capturedOn": "2026-11-10",
|
|
56
|
+
"sourceVersion": "0.2.99"
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
59
|
"path": "docs/screenshots/en/06-tool-parameters.png",
|
|
60
|
-
"sha256": "
|
|
60
|
+
"sha256": "1b005dfb87014c88aef488ca4441ebc98b2d93acbb2dfa9ea44d4eb855478138",
|
|
61
61
|
"width": 1280,
|
|
62
62
|
"height": 720,
|
|
63
|
-
"capturedOn": "2026-11-
|
|
64
|
-
"sourceVersion": "0.2.
|
|
63
|
+
"capturedOn": "2026-11-10",
|
|
64
|
+
"sourceVersion": "0.2.99"
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
67
|
"path": "docs/screenshots/en/07-connection-diagnostics.png",
|
|
68
|
-
"sha256": "
|
|
68
|
+
"sha256": "7a3810e60d182495f30994c1e4cf47459759f5d28543c8e82f39ede3b911d8b3",
|
|
69
69
|
"width": 1280,
|
|
70
70
|
"height": 720,
|
|
71
|
-
"capturedOn": "2026-11-
|
|
72
|
-
"sourceVersion": "0.2.
|
|
71
|
+
"capturedOn": "2026-11-10",
|
|
72
|
+
"sourceVersion": "0.2.99"
|
|
73
73
|
},
|
|
74
74
|
{
|
|
75
75
|
"path": "docs/screenshots/en/08-ten-recommendations.jpg",
|
|
76
|
-
"sha256": "
|
|
76
|
+
"sha256": "58d34d5977e36c832e7b3820e7557ac42346e05e79948108301a5662d9a40b7c",
|
|
77
77
|
"width": 1280,
|
|
78
78
|
"height": 1400,
|
|
79
79
|
"browserViewport": {
|
|
@@ -81,17 +81,17 @@
|
|
|
81
81
|
"height": 1400
|
|
82
82
|
},
|
|
83
83
|
"panelHeight": 1280,
|
|
84
|
-
"capturedOn": "2026-11-
|
|
85
|
-
"sourceVersion": "0.2.
|
|
84
|
+
"capturedOn": "2026-11-10",
|
|
85
|
+
"sourceVersion": "0.2.99"
|
|
86
86
|
}
|
|
87
87
|
],
|
|
88
88
|
"demo": {
|
|
89
89
|
"path": "docs/screenshots/en/demo.gif",
|
|
90
|
-
"sha256": "
|
|
90
|
+
"sha256": "7315138b5c61f3c847353cdfd9a12696ba98479a1eb65a9378938ec71e1c1cba",
|
|
91
91
|
"width": 960,
|
|
92
92
|
"height": 540,
|
|
93
|
-
"capturedOn": "2026-11-
|
|
94
|
-
"sourceVersion": "0.2.
|
|
93
|
+
"capturedOn": "2026-11-10",
|
|
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.
|
|
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` |
|
package/lib/diagnostics.js
CHANGED
|
@@ -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 [
|
|
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
|
|
1237
|
-
|
|
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
|
|
1312
|
-
state.health.
|
|
1313
|
-
|
|
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
|
|
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 =
|
|
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,
|
|
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
|
|
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
|
+
}
|
package/lib/mcp-validation.js
CHANGED
|
@@ -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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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.
|
|
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
|
@@ -90,6 +90,11 @@
|
|
|
90
90
|
.toolbar .search-box { flex: 1; width: auto; min-width: 80px; }
|
|
91
91
|
.toolbar .icon-btn { white-space: nowrap; padding-inline: 10px; min-height: 34px; }
|
|
92
92
|
.toolbar .compact-action { width: 34px; flex-shrink: 0; padding: 4px; font-size: 18px; }
|
|
93
|
+
.toolbar .first-use-action {
|
|
94
|
+
flex-shrink: 0; border-color: var(--accent);
|
|
95
|
+
background: var(--accent-light); color: var(--accent); font-weight: 650;
|
|
96
|
+
}
|
|
97
|
+
.toolbar .first-use-action:hover { border-color: var(--accent); color: var(--accent); }
|
|
93
98
|
.language-switch { display: inline-flex; gap: 3px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
|
|
94
99
|
.language-switch { flex-shrink: 0; }
|
|
95
100
|
.language-switch button { min-height: 28px; padding: 3px 7px; border: 0; border-radius: 7px; background: transparent; color: var(--text-2); font: inherit; font-size: 12px; cursor: pointer; }
|
|
@@ -222,6 +227,13 @@
|
|
|
222
227
|
|
|
223
228
|
/* Empty */
|
|
224
229
|
.empty { text-align: center; color: var(--muted); padding: 80px 0; font-size: 15px; }
|
|
230
|
+
.empty-action-card {
|
|
231
|
+
max-width: 640px; margin: 28px auto; padding: 24px; text-align: center;
|
|
232
|
+
border: 1px solid var(--line); background: var(--card); border-radius: 14px;
|
|
233
|
+
}
|
|
234
|
+
.empty-action-card strong { display: block; margin-bottom: 6px; color: var(--text); font-size: 16px; }
|
|
235
|
+
.empty-action-card p { margin: 0; color: var(--text-2); font-size: 13px; line-height: 1.6; }
|
|
236
|
+
.empty-action-card .actions { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
|
|
225
237
|
.migration-banner { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; padding: 12px 14px; border: 1px solid #fbbf24; background: var(--warn-bg); border-radius: 10px; color: var(--text-2); }
|
|
226
238
|
.migration-banner .copy { flex: 1; min-width: 0; font-size: 12px; }
|
|
227
239
|
.migration-banner strong { display: block; color: var(--text); font-size: 13px; }
|
|
@@ -232,6 +244,14 @@
|
|
|
232
244
|
.community-cta-close { border: 0; background: transparent; color: var(--muted); cursor: pointer; font: inherit; font-size: 16px; line-height: 1; padding: 2px 4px; }
|
|
233
245
|
.community-cta-close:hover { color: var(--text); }
|
|
234
246
|
.community-cta-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
|
|
247
|
+
.first-use-banner {
|
|
248
|
+
display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
|
|
249
|
+
margin-bottom: 18px; padding: 14px 16px; border: 1px solid var(--accent);
|
|
250
|
+
background: var(--accent-light); border-radius: 12px; color: var(--text-2);
|
|
251
|
+
}
|
|
252
|
+
.first-use-banner .copy { flex: 1 1 360px; min-width: 0; font-size: 12px; line-height: 1.55; }
|
|
253
|
+
.first-use-banner strong { display: block; margin-bottom: 2px; color: var(--text); font-size: 14px; }
|
|
254
|
+
.first-use-banner .actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
235
255
|
|
|
236
256
|
/* Detail Overlay */
|
|
237
257
|
.detail-overlay {
|
|
@@ -515,7 +535,7 @@
|
|
|
515
535
|
</div>
|
|
516
536
|
<button class="icon-btn primary" id="add-connection" type="button">+ 添加连接</button>
|
|
517
537
|
<button class="icon-btn compact-action" id="refresh" type="button" title="刷新连接器目录" aria-label="刷新连接器目录">↻</button>
|
|
518
|
-
<button class="icon-btn
|
|
538
|
+
<button class="icon-btn first-use-action" id="first-use" type="button" title="快速开始" aria-label="快速开始">▶ 快速开始</button>
|
|
519
539
|
</div>
|
|
520
540
|
<div class="market-nav" id="market-nav" aria-label="市场分类导航"></div>
|
|
521
541
|
</header>
|
|
@@ -643,6 +663,23 @@
|
|
|
643
663
|
"打开新会话失败,请检查工作区后重试": "Failed to open a new session. Check the workspace and retry.",
|
|
644
664
|
"本机连接统计": "Local connection statistics",
|
|
645
665
|
"首次使用": "Getting started",
|
|
666
|
+
"快速开始": "Quick start",
|
|
667
|
+
"▶ 快速开始": "▶ Quick start",
|
|
668
|
+
"第一次使用 MCP连接器?": "New to MCP Connector?",
|
|
669
|
+
"先从推荐连接器开始,查看详情并按服务商要求完成授权;连接成功后即可发现工具并在会话中使用。": "Start with a recommended connector, review its details, and complete provider authorization. Once connected, its tools become available in your sessions.",
|
|
670
|
+
"查看推荐连接器": "View recommended connectors",
|
|
671
|
+
"浏览推荐连接器": "Browse recommended connectors",
|
|
672
|
+
"查看首次使用步骤": "View getting-started steps",
|
|
673
|
+
"还没有连接任何 MCP": "No MCP connections yet",
|
|
674
|
+
"先选择一个推荐连接器,完成授权后即可在会话中发现并使用工具。": "Choose a recommended connector first. After authorization, its tools can be discovered and used in your sessions.",
|
|
675
|
+
"连接流程已完成": "Connection setup completed",
|
|
676
|
+
"下一步确认工具发现结果,再选择一个示例 Prompt。实际业务成功以工具真实返回为准。": "Next, confirm tool discovery and choose an example prompt. Actual business success requires a real tool result.",
|
|
677
|
+
"检查已发现工具": "Check discovered tools",
|
|
678
|
+
"查看示例 Prompt": "View example prompts",
|
|
679
|
+
"本机引导路径(不计算转化率)": "Local guidance path (no conversion rate)",
|
|
680
|
+
"快速开始打开 {count} 次 · 推荐入口打开 {recommended} 次": "Quick start opened {count} times · recommendations opened {recommended} times",
|
|
681
|
+
"本浏览器首次连接 {connected} 张卡片 · 已发现工具 {discovered} 张卡片": "First connection in this browser: {connected} cards · tools discovered: {discovered} cards",
|
|
682
|
+
"入口次数与卡片去重数口径不同,只用于本机排查,不上传且不计算转化率。": "Entry counts and deduplicated card counts use different denominators. They are for local troubleshooting only, are not uploaded, and are not used to calculate a conversion rate.",
|
|
646
683
|
"Host 未确认草稿写入": "The Host did not confirm the draft",
|
|
647
684
|
"读取状态失败,请稍后重试;不能据此判断授权或业务调用成功。": "Failed to read status. Retry later; this does not confirm authorization or a successful business call.",
|
|
648
685
|
"当前范围没有连接。请先到市场选择服务,或添加你自己的连接,并按服务商要求完成授权。": "No connections in this scope. Select a service in the market or add your own connection and complete provider authorization.",
|
|
@@ -1217,6 +1254,50 @@
|
|
|
1217
1254
|
},
|
|
1218
1255
|
}, null, 2);
|
|
1219
1256
|
|
|
1257
|
+
const LOCAL_CONVERSION_STORAGE_KEY = 'mcp-connector.local-conversion-v1';
|
|
1258
|
+
const emptyLocalConversion = () => ({ quickStartOpened: 0, recommendedOpened: 0, connectedConnectorIds: [], discoveredConnectorIds: [] });
|
|
1259
|
+
function readLocalConversion() {
|
|
1260
|
+
try {
|
|
1261
|
+
const raw = JSON.parse(window.localStorage.getItem(LOCAL_CONVERSION_STORAGE_KEY) || '{}');
|
|
1262
|
+
const count = (value) => Number.isSafeInteger(value) && value >= 0 ? Math.min(value, 1_000_000) : 0;
|
|
1263
|
+
const ids = (value) => [...new Set((Array.isArray(value) ? value : [])
|
|
1264
|
+
.filter((id) => typeof id === 'string' && id.length > 0 && id.length <= 256))].slice(0, 256);
|
|
1265
|
+
return {
|
|
1266
|
+
quickStartOpened: count(raw.quickStartOpened),
|
|
1267
|
+
recommendedOpened: count(raw.recommendedOpened),
|
|
1268
|
+
connectedConnectorIds: ids(raw.connectedConnectorIds),
|
|
1269
|
+
discoveredConnectorIds: ids(raw.discoveredConnectorIds),
|
|
1270
|
+
};
|
|
1271
|
+
} catch { return emptyLocalConversion(); }
|
|
1272
|
+
}
|
|
1273
|
+
function writeLocalConversion(value) {
|
|
1274
|
+
try { window.localStorage.setItem(LOCAL_CONVERSION_STORAGE_KEY, JSON.stringify(value)); return true; }
|
|
1275
|
+
catch { return false; }
|
|
1276
|
+
}
|
|
1277
|
+
function recordLocalConversion(stage, connectorId = '') {
|
|
1278
|
+
const value = readLocalConversion();
|
|
1279
|
+
if (stage === 'quickStartOpened') value.quickStartOpened = Math.min(1_000_000, value.quickStartOpened + 1);
|
|
1280
|
+
else if (stage === 'recommendedOpened') value.recommendedOpened = Math.min(1_000_000, value.recommendedOpened + 1);
|
|
1281
|
+
else if (['connectionSucceeded', 'toolDiscoverySucceeded'].includes(stage)) {
|
|
1282
|
+
const id = String(connectorId || '').trim();
|
|
1283
|
+
if (!id || id.length > 256) return false;
|
|
1284
|
+
const field = stage === 'connectionSucceeded' ? 'connectedConnectorIds' : 'discoveredConnectorIds';
|
|
1285
|
+
if (value[field].includes(id)) return false;
|
|
1286
|
+
if (value[field].length >= 256) return false;
|
|
1287
|
+
value[field].push(id);
|
|
1288
|
+
} else return false;
|
|
1289
|
+
return writeLocalConversion(value);
|
|
1290
|
+
}
|
|
1291
|
+
function localConversionSnapshot() {
|
|
1292
|
+
const value = readLocalConversion();
|
|
1293
|
+
return {
|
|
1294
|
+
quickStartOpened: value.quickStartOpened,
|
|
1295
|
+
recommendedOpened: value.recommendedOpened,
|
|
1296
|
+
connectedConnectors: value.connectedConnectorIds.length,
|
|
1297
|
+
discoveredConnectors: value.discoveredConnectorIds.length,
|
|
1298
|
+
};
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1220
1301
|
let view = 'market';
|
|
1221
1302
|
let marketItems = {};
|
|
1222
1303
|
let searchQuery = '';
|
|
@@ -1644,6 +1725,17 @@
|
|
|
1644
1725
|
await window.__mcp.showDetail(connectorId);
|
|
1645
1726
|
}
|
|
1646
1727
|
|
|
1728
|
+
function openPostConnectionSuccess(connectorId) {
|
|
1729
|
+
openModal(t('连接流程已完成'), `<p>${t('下一步确认工具发现结果,再选择一个示例 Prompt。实际业务成功以工具真实返回为准。')}</p><div class="m-actions"><button class="btn ghost" type="button" onclick="window.__mcp.openConnectedTools(${jsString(connectorId)})">${t('检查已发现工具')}</button><button class="btn" type="button" onclick="window.__mcp.openConnectedPrompts(${jsString(connectorId)})">${t('查看示例 Prompt')}</button></div>`);
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
async function completeCatalogConnection(connectorId, { healthCheck = false } = {}) {
|
|
1733
|
+
const firstLocalSuccess = recordLocalConversion('connectionSucceeded', connectorId);
|
|
1734
|
+
if (healthCheck) await call('healthCheck', { connectorId });
|
|
1735
|
+
await refreshConnectionUi(connectorId);
|
|
1736
|
+
if (firstLocalSuccess) openPostConnectionSuccess(connectorId);
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1647
1739
|
// 详情主按钮:状态未知且已有连接记录时优先提供「重新连接」(Host 侧可能已放弃重连)
|
|
1648
1740
|
function detailTryLabel(fallback) {
|
|
1649
1741
|
return detailReconnectKey ? t('🔄 重新连接') : fallback;
|
|
@@ -2163,6 +2255,14 @@
|
|
|
2163
2255
|
document.querySelector('.community-cta')?.remove();
|
|
2164
2256
|
}
|
|
2165
2257
|
|
|
2258
|
+
function firstUseBannerHtml() {
|
|
2259
|
+
return `<aside class="first-use-banner" aria-label="${t('快速开始')}"><div class="copy"><strong>${t('第一次使用 MCP连接器?')}</strong>${t('先从推荐连接器开始,查看详情并按服务商要求完成授权;连接成功后即可发现工具并在会话中使用。')}</div><div class="actions"><button class="btn" type="button" data-first-use-action="recommended">${t('查看推荐连接器')}</button><button class="btn ghost" type="button" data-first-use-action="guide">${t('查看首次使用步骤')}</button></div></aside>`;
|
|
2260
|
+
}
|
|
2261
|
+
|
|
2262
|
+
function installedEmptyHtml() {
|
|
2263
|
+
return `<section class="empty-action-card"><strong>${t('还没有连接任何 MCP')}</strong><p>${t('先选择一个推荐连接器,完成授权后即可在会话中发现并使用工具。')}</p><div class="actions"><button class="btn" type="button" data-first-use-action="recommended">${t('浏览推荐连接器')}</button><button class="btn ghost" type="button" data-first-use-action="guide">${t('查看首次使用步骤')}</button></div></section>`;
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2166
2266
|
function marketSectionHtml(value, label, items) {
|
|
2167
2267
|
if (!items.length) return '';
|
|
2168
2268
|
const expanded = value === 'recommended' || expandedMarketSections.has(value);
|
|
@@ -2212,7 +2312,8 @@
|
|
|
2212
2312
|
: filtered.length > 0
|
|
2213
2313
|
? `<div class="grid">${filtered.map(cardHtml).join('')}</div>`
|
|
2214
2314
|
: `<div class="empty">${t('没有匹配当前筛选条件的连接器')}</div>`;
|
|
2215
|
-
|
|
2315
|
+
const firstUseBanner = status.ok && (status.detail?.items ?? []).length === 0 && !marketCategory && !searchQuery ? firstUseBannerHtml() : '';
|
|
2316
|
+
main.innerHTML = `${firstUseBanner}${resultHtml}`;
|
|
2216
2317
|
if (preserveScroll) main.scrollTop = previousScrollTop;
|
|
2217
2318
|
if (checkHealth && !initialHealthCheckStarted && items.some((item) => item.connected?.length > 0)) {
|
|
2218
2319
|
initialHealthCheckStarted = true;
|
|
@@ -2290,6 +2391,11 @@
|
|
|
2290
2391
|
const explorerStatusLabel = (status) => t(EXPLORER_STATUS[status] || status);
|
|
2291
2392
|
const formatObserved = (value) => value ? new Date(value).toLocaleString(t.locale, { hour12: false }) : t('尚无记录');
|
|
2292
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
|
+
|
|
2293
2399
|
async function loadToolExplorer() {
|
|
2294
2400
|
const render = beginViewRender();
|
|
2295
2401
|
try {
|
|
@@ -2312,7 +2418,7 @@
|
|
|
2312
2418
|
$('#explorer-server').value = explorerFilter.serverName;
|
|
2313
2419
|
$('#explorer-status').value = explorerFilter.status;
|
|
2314
2420
|
$('#explorer-summary').textContent = t('{scope} · {connections} 条连接 · 匹配 {tools} 个工具 · 显示 {shown} 个', { scope: explorerData.scopeLabel, connections: connections.length, tools: total, shown: items.length });
|
|
2315
|
-
$('#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>${
|
|
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>`;
|
|
2316
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>`;
|
|
2317
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>`;
|
|
2318
2424
|
} finally { finishViewRender(render); }
|
|
@@ -2375,7 +2481,7 @@
|
|
|
2375
2481
|
const pendingMigration = migration.ok ? migration.detail?.pendingCount || 0 : 0;
|
|
2376
2482
|
const migrationHtml = pendingMigration > 0 ? `<div class="migration-banner"><div class="copy"><strong>${t('发现旧企查查 MCP 授权')}</strong>${t('可安全复制 {count} 组授权到 MCP连接器;不会删除旧插件或原凭据。', { count: pendingMigration })}</div><button class="btn" type="button" onclick="window.__mcp.migrateLegacy()">${t('迁移')}</button></div>` : '';
|
|
2377
2483
|
if (!items.length) {
|
|
2378
|
-
main.innerHTML = `${migrationHtml}<div class="stats"><span class="count">${t('可从旧企查查 OAuth 插件复制已有授权')}</span><button class="btn ghost" type="button" onclick="window.__mcp.openConnectionStatistics()">${t('本机连接统计')}</button><button class="btn ghost" id="config-backup" type="button" onclick="window.__mcp.openConfigBackup()">${t('配置备份')}</button><button class="btn ghost" type="button" title="${t('扫描企查查旧 OAuth 插件;不会删除旧插件或原凭据')}" onclick="window.__mcp.scanLegacy()">${t('检测企查查旧授权')}</button></div
|
|
2484
|
+
main.innerHTML = `${migrationHtml}<div class="stats"><span class="count">${t('可从旧企查查 OAuth 插件复制已有授权')}</span><button class="btn ghost" type="button" onclick="window.__mcp.openConnectionStatistics()">${t('本机连接统计')}</button><button class="btn ghost" id="config-backup" type="button" onclick="window.__mcp.openConfigBackup()">${t('配置备份')}</button><button class="btn ghost" type="button" title="${t('扫描企查查旧 OAuth 插件;不会删除旧插件或原凭据')}" onclick="window.__mcp.scanLegacy()">${t('检测企查查旧授权')}</button></div>${installedEmptyHtml()}`;
|
|
2379
2485
|
if (preserveScroll) main.scrollTop = previousScrollTop;
|
|
2380
2486
|
return;
|
|
2381
2487
|
}
|
|
@@ -2709,8 +2815,7 @@
|
|
|
2709
2815
|
if (r.ok) {
|
|
2710
2816
|
markCommunityCtaEligible();
|
|
2711
2817
|
closeModal();
|
|
2712
|
-
await
|
|
2713
|
-
await refreshConnectionUi(connectorId);
|
|
2818
|
+
await completeCatalogConnection(connectorId, { healthCheck: true });
|
|
2714
2819
|
}
|
|
2715
2820
|
},
|
|
2716
2821
|
confirmConnect() {
|
|
@@ -2881,12 +2986,30 @@
|
|
|
2881
2986
|
openModal(t('本机连接统计'), `<p>${t("统计暂不可用,不影响连接。请检查 Host 日志。")}</p>`);
|
|
2882
2987
|
return;
|
|
2883
2988
|
}
|
|
2989
|
+
const local = localConversionSnapshot();
|
|
2884
2990
|
openModal(t('本机连接统计'), `<div class="form-note">${t('仅统计当前 profile,不是社区总量或独立用户数。数据保存在本机,不向外上传。')}${d.persistent ? '' : t('当前未启用持久化,重启后计数清空。')}</div>
|
|
2885
2991
|
<p>${t('成功连接过的卡片数')} <strong>${esc(d.cumulativeSuccessfulConnections)}</strong> · ${t('近 30 天首次连接的新卡片')} <strong>${esc(d.newSuccessfulConnections30d)}</strong></p>
|
|
2886
2992
|
<p>${t('历史已有连接基线:{count} 张卡片,未验证前不计成功,验证后也不计新增。', { count: esc(d.historicalBaseline) })}</p>
|
|
2887
2993
|
<p>${t("同一卡片只计一次;重启、升级、重新授权和重连不重复增加,断开不扣减。此处成功指连接流程完成,不代表业务调用成功。")}</p>
|
|
2994
|
+
<hr><p><strong>${t('本机引导路径(不计算转化率)')}</strong></p>
|
|
2995
|
+
<p>${t('快速开始打开 {count} 次 · 推荐入口打开 {recommended} 次', { count: esc(local.quickStartOpened), recommended: esc(local.recommendedOpened) })}</p>
|
|
2996
|
+
<p>${t('本浏览器首次连接 {connected} 张卡片 · 已发现工具 {discovered} 张卡片', { connected: esc(local.connectedConnectors), discovered: esc(local.discoveredConnectors) })}</p>
|
|
2997
|
+
<p class="field-help">${t('入口次数与卡片去重数口径不同,只用于本机排查,不上传且不计算转化率。')}</p>
|
|
2888
2998
|
<div>${(d.items || []).map(x => `<p><strong>${esc(x.connectorId)}</strong>:${x.cumulativeSuccessfulConnections ? t('已记录成功') : t('历史配置,待验证')}${x.historicalBaseline ? t(' · 历史基线') : ''}</p>`).join('') || t('尚无统计记录。')}</div>`);
|
|
2889
2999
|
},
|
|
3000
|
+
async openConnectedTools(connectorId) {
|
|
3001
|
+
closeModal();
|
|
3002
|
+
await window.__mcp.showDetail(connectorId);
|
|
3003
|
+
const disclosure = $('#tools-disclosure');
|
|
3004
|
+
if (disclosure) { disclosure.open = true; disclosure.scrollIntoView({ block: 'start' }); }
|
|
3005
|
+
$('#tools-search')?.focus();
|
|
3006
|
+
},
|
|
3007
|
+
async openConnectedPrompts(connectorId) {
|
|
3008
|
+
closeModal();
|
|
3009
|
+
await window.__mcp.showDetail(connectorId);
|
|
3010
|
+
$('#detail-prompts')?.scrollIntoView({ block: 'center' });
|
|
3011
|
+
$('#detail-prompts button')?.focus();
|
|
3012
|
+
},
|
|
2890
3013
|
async openConfigBackup() { await openConfigBackup(); },
|
|
2891
3014
|
async copyBackup() {
|
|
2892
3015
|
const text = $('#backup-json')?.value || '';
|
|
@@ -2968,7 +3091,7 @@
|
|
|
2968
3091
|
if (!r.ok) { showModalError(r.message); return; }
|
|
2969
3092
|
closeModal();
|
|
2970
3093
|
markCommunityCtaEligible();
|
|
2971
|
-
showToast(r.message, true); await
|
|
3094
|
+
showToast(r.message, true); await completeCatalogConnection(connectorId);
|
|
2972
3095
|
return;
|
|
2973
3096
|
}
|
|
2974
3097
|
const name = $('#cfg-name').value.trim();
|
|
@@ -3131,9 +3254,9 @@
|
|
|
3131
3254
|
syncGovernanceBar();
|
|
3132
3255
|
if (!toolsResult.ok) {
|
|
3133
3256
|
detailFailureState = toolsResult.detail?.connectionState || detailFailureState || 'unavailable';
|
|
3134
|
-
detailNeedsReconfigure =
|
|
3257
|
+
detailNeedsReconfigure = detailFailureState !== 'healthy';
|
|
3135
3258
|
detailReconnectKey = detailFailureState === 'unknown' && d.connected?.length > 0 ? d.connected[0] : '';
|
|
3136
|
-
const diagnostic = toolsResult.detail?.diagnostic;
|
|
3259
|
+
const diagnostic = toolsResult.detail?.discoveryDiagnostic || toolsResult.detail?.diagnostic;
|
|
3137
3260
|
$('#tools-summary').textContent = t(detailFailureState === 'unknown' ? '工具状态未知' : '工具加载失败');
|
|
3138
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>`;
|
|
3139
3262
|
detailToolServers = toolsResult.detail?.servers || [];
|
|
@@ -3145,7 +3268,7 @@
|
|
|
3145
3268
|
}
|
|
3146
3269
|
const failureLabel = detailFailureState === 'reauth'
|
|
3147
3270
|
? t(d.authMode === 'oauth2-pkce' ? '授权已失效' : '凭据已失效')
|
|
3148
|
-
: t(detailFailureState === 'unknown' ? '状态尚未确认' : '当前连接异常');
|
|
3271
|
+
: t(detailFailureState === 'healthy' ? '已连接' : detailFailureState === 'unknown' ? '状态尚未确认' : '当前连接异常');
|
|
3149
3272
|
$('#detail-vendor').textContent = d.vendor ? `${d.vendor} · ${failureLabel}` : failureLabel;
|
|
3150
3273
|
$('#detail-try-btn').textContent = detailTryLabel(d.authMode === 'oauth2-pkce' && detailFailureState === 'reauth'
|
|
3151
3274
|
? t('🔐 重新授权')
|
|
@@ -3163,6 +3286,7 @@
|
|
|
3163
3286
|
$('#detail-try-btn').textContent = detailTryLabel(incomplete ? (d.authMode === 'oauth2-pkce' ? t('upgradeOauth') : t('completeSetup')) : t('try'));
|
|
3164
3287
|
renderPromptPage();
|
|
3165
3288
|
detailToolServers = toolsResult.detail?.servers || [];
|
|
3289
|
+
if (detailToolServers.some((server) => (server.tools || []).length > 0)) recordLocalConversion('toolDiscoverySucceeded', connectorId);
|
|
3166
3290
|
updateToolsSummary();
|
|
3167
3291
|
renderTools();
|
|
3168
3292
|
},
|
|
@@ -3278,8 +3402,7 @@
|
|
|
3278
3402
|
showToast(r.message, r.ok);
|
|
3279
3403
|
if (r.ok) {
|
|
3280
3404
|
markCommunityCtaEligible();
|
|
3281
|
-
await
|
|
3282
|
-
await refreshConnectionUi(id);
|
|
3405
|
+
await completeCatalogConnection(id, { healthCheck: true });
|
|
3283
3406
|
}
|
|
3284
3407
|
return;
|
|
3285
3408
|
}
|
|
@@ -3289,8 +3412,7 @@
|
|
|
3289
3412
|
showToast(r.message, r.ok);
|
|
3290
3413
|
if (r.ok) {
|
|
3291
3414
|
markCommunityCtaEligible();
|
|
3292
|
-
await
|
|
3293
|
-
await refreshConnectionUi(id);
|
|
3415
|
+
await completeCatalogConnection(id, { healthCheck: true });
|
|
3294
3416
|
}
|
|
3295
3417
|
return;
|
|
3296
3418
|
}
|
|
@@ -3352,13 +3474,10 @@
|
|
|
3352
3474
|
detailToolServers = result.detail.servers;
|
|
3353
3475
|
renderTools();
|
|
3354
3476
|
const pending = detailToolServers.some((server) => server.pending);
|
|
3355
|
-
|
|
3356
|
-
const
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
: available > 0 ? '部分服务可用' : '当前连接异常');
|
|
3360
|
-
detailFailureState = pending ? 'unknown' : available > 0 ? 'healthy' : 'unavailable';
|
|
3361
|
-
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';
|
|
3362
3481
|
detailReconnectKey = '';
|
|
3363
3482
|
$('#detail-vendor').textContent = detailConnector.vendor ? `${detailConnector.vendor} · ${label}` : label;
|
|
3364
3483
|
$('#detail-try-btn').textContent = detailTryLabel(detailNeedsReconfigure ? t('🔄 重新检查') : t('try'));
|
|
@@ -3440,7 +3559,27 @@
|
|
|
3440
3559
|
}
|
|
3441
3560
|
});
|
|
3442
3561
|
new ResizeObserver(updateCategoryArrows).observe($('#market-nav'));
|
|
3562
|
+
function showRecommendedMarket() {
|
|
3563
|
+
recordLocalConversion('recommendedOpened');
|
|
3564
|
+
view = 'market'; marketCategory = 'recommended';
|
|
3565
|
+
searchQuery = ''; searchInput.value = '';
|
|
3566
|
+
pendingViewScroll = null; main.scrollTop = 0;
|
|
3567
|
+
explorerSequence++; explorerDetailSequence++;
|
|
3568
|
+
syncTabs();
|
|
3569
|
+
loadMarket({ checkHealth: false });
|
|
3570
|
+
}
|
|
3571
|
+
|
|
3443
3572
|
main.addEventListener('click', (event) => {
|
|
3573
|
+
const firstUseAction = event.target.closest('[data-first-use-action]');
|
|
3574
|
+
if (firstUseAction?.dataset.firstUseAction === 'recommended') {
|
|
3575
|
+
showRecommendedMarket();
|
|
3576
|
+
return;
|
|
3577
|
+
}
|
|
3578
|
+
if (firstUseAction?.dataset.firstUseAction === 'guide') {
|
|
3579
|
+
recordLocalConversion('quickStartOpened');
|
|
3580
|
+
openFirstUse();
|
|
3581
|
+
return;
|
|
3582
|
+
}
|
|
3444
3583
|
const sectionToggle = event.target.closest('[data-section-toggle]');
|
|
3445
3584
|
if (sectionToggle) {
|
|
3446
3585
|
const section = sectionToggle.dataset.sectionToggle;
|
|
@@ -3489,8 +3628,9 @@
|
|
|
3489
3628
|
setText('#tab-installed', '已安装');
|
|
3490
3629
|
setText('#tab-tools', '工具');
|
|
3491
3630
|
setText('#add-connection', '+ 添加连接');
|
|
3492
|
-
|
|
3493
|
-
$('#first-use').
|
|
3631
|
+
setText('#first-use', '▶ 快速开始');
|
|
3632
|
+
$('#first-use').title = t('快速开始');
|
|
3633
|
+
$('#first-use').setAttribute('aria-label', t('快速开始'));
|
|
3494
3634
|
setText('#prompt-title', '试试这样用');
|
|
3495
3635
|
setText('#prompt-next', '换一批');
|
|
3496
3636
|
setText('#tools-title', '工具详情');
|
|
@@ -3530,7 +3670,7 @@
|
|
|
3530
3670
|
window.location.assign(url.href);
|
|
3531
3671
|
});
|
|
3532
3672
|
syncTabs();
|
|
3533
|
-
$('#first-use').addEventListener('click', openFirstUse);
|
|
3673
|
+
$('#first-use').addEventListener('click', () => { recordLocalConversion('quickStartOpened'); openFirstUse(); });
|
|
3534
3674
|
if (viewStateReady) restoreViewState();
|
|
3535
3675
|
requestWorkspaceContext();
|
|
3536
3676
|
connectStatusEvents();
|