universal-plugin-hub 1.0.45 → 1.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/client.js +558 -446
- package/package.json +3 -2
- package/src/icons.js +132 -14
- package/src/install.js +111 -56
- package/src/parser.js +20 -0
- package/src/routes.js +1 -1
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"title": "Universal Plugin Hub",
|
|
4
4
|
"displayName": "Universal Plugin Hub",
|
|
5
5
|
"description": "在 DSH 中使用 Claude Code、Codex 等软件生态的插件,一站式管理插件、Skills 与 MCP。支持添加 Git 插件源和 marketplace、上传插件和 Skills、添加 MCP 服务器,自动扫描并开关本地 Skills,接入插件提供的子代理、MCP、Hooks 与 LSP。",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.50",
|
|
7
7
|
"engines": {
|
|
8
8
|
"dsh": ">=0.1.5-rc.1"
|
|
9
9
|
},
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@modelcontextprotocol/sdk": "1.32.1",
|
|
37
|
-
"js-yaml": "^5.3.0"
|
|
37
|
+
"js-yaml": "^5.3.0",
|
|
38
|
+
"pngjs": "7.0.0"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
41
|
"@deepseek-ai/cordis": ">=4.0.1 <5.0.0"
|
package/src/icons.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { statSync, realpathSync, readFileSync, readdirSync, openSync, readSync, closeSync } from 'node:fs'
|
|
1
|
+
import { statSync, realpathSync, readFileSync, readdirSync, openSync, readSync, closeSync, mkdirSync, writeFileSync, rmSync } from 'node:fs'
|
|
2
2
|
import { mkdir, readFile, writeFile, stat } from 'node:fs/promises'
|
|
3
3
|
import { join, relative, isAbsolute, posix } from 'node:path'
|
|
4
4
|
import { createHash } from 'node:crypto'
|
|
5
|
+
import { PNG } from 'pngjs'
|
|
5
6
|
import { marketRoot } from './store.js'
|
|
6
7
|
import { pluginPath } from './market.js'
|
|
7
8
|
|
|
@@ -160,17 +161,22 @@ function discoverIconFiles(dir, pluginName) {
|
|
|
160
161
|
return found.sort((a, b) => b.score - a.score || a.path.localeCompare(b.path))
|
|
161
162
|
}
|
|
162
163
|
|
|
163
|
-
//
|
|
164
|
-
//
|
|
165
|
-
//
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
// The inline set is a budget, not a rule: every icon carried in the list is
|
|
169
|
-
// paid again on each /state fetch, and the card renders at 38px. At 12KB the
|
|
170
|
-
// whole marketplace payload stays under 1MB and 67 rows still paint with no
|
|
171
|
-
// request; the rest keep the served URL, which is a local disk read.
|
|
164
|
+
// Small local artwork can travel in the row directly. Larger PNGs use a
|
|
165
|
+
// bounded 96px preview, cached separately from the original. Remote images
|
|
166
|
+
// only contribute a preview when bytes already exist in the proxy cache;
|
|
167
|
+
// parsing a catalog never waits on an upstream image request.
|
|
172
168
|
|
|
173
169
|
const INLINE_LIMIT = 12 * 1024
|
|
170
|
+
// A preview is carried once per URL rather than duplicated in both theme arrays.
|
|
171
|
+
// This covers ordinary raster logos while keeping large artwork out of list JSON.
|
|
172
|
+
const PREVIEW_LIMIT = 64 * 1024
|
|
173
|
+
// Decoding runs synchronously inside catalog parsing, once per row, so the
|
|
174
|
+
// bound has to cover the decode itself and not just the file size.
|
|
175
|
+
const PREVIEW_MAX_PIXELS = 262144
|
|
176
|
+
const PREVIEWS_DIR = 'previews'
|
|
177
|
+
const PREVIEW_CACHE_KEEP = 200
|
|
178
|
+
const previewMemory = new Map()
|
|
179
|
+
let lastPreviewPrune = 0
|
|
174
180
|
|
|
175
181
|
/** A local file's bytes as a data URL, or null when it is too big or unreadable. */
|
|
176
182
|
function inlineFile(file) {
|
|
@@ -183,6 +189,94 @@ function inlineFile(file) {
|
|
|
183
189
|
} catch { return null }
|
|
184
190
|
}
|
|
185
191
|
|
|
192
|
+
function inlinePreview(buffer) {
|
|
193
|
+
const contentType = imageContentType(buffer)
|
|
194
|
+
if (!contentType) return null
|
|
195
|
+
if (contentType === 'image/png' && buffer.length > INLINE_LIMIT) {
|
|
196
|
+
if (buffer.length < 24) return null
|
|
197
|
+
const w = buffer.readUInt32BE(16), h = buffer.readUInt32BE(20)
|
|
198
|
+
// Reject before decoding: the decode is the expensive part.
|
|
199
|
+
if (!w || !h || w * h > PREVIEW_MAX_PIXELS) return null
|
|
200
|
+
// Version the derived cache by content and algorithm, so replacing artwork
|
|
201
|
+
// cannot leave an old thumbnail behind. Originals are never overwritten.
|
|
202
|
+
const key = createHash('sha256').update(buffer).digest('hex')
|
|
203
|
+
const directory = join(marketRoot(), 'icons', PREVIEWS_DIR)
|
|
204
|
+
const file = join(directory, `96-v1-${key}.png`)
|
|
205
|
+
try {
|
|
206
|
+
const saved = readFileSync(file)
|
|
207
|
+
if (saved.length <= INLINE_LIMIT && imageContentType(saved) === 'image/png') return `data:image/png;base64,${saved.toString('base64')}`
|
|
208
|
+
} catch {}
|
|
209
|
+
let image
|
|
210
|
+
try { image = PNG.sync.read(buffer) } catch { return null }
|
|
211
|
+
const ratio = Math.min(1, 96 / Math.max(w, h))
|
|
212
|
+
const width = Math.max(1, Math.round(w * ratio)), height = Math.max(1, Math.round(h * ratio))
|
|
213
|
+
const data = Buffer.alloc(width * height * 4)
|
|
214
|
+
// Area sampling with premultiplied alpha preserves fine edges on both
|
|
215
|
+
// themes; simply averaging transparent RGB creates dark logo fringes.
|
|
216
|
+
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
217
|
+
const left = x * w / width, right = (x + 1) * w / width
|
|
218
|
+
const top = y * h / height, bottom = (y + 1) * h / height
|
|
219
|
+
let red = 0, green = 0, blue = 0, alpha = 0
|
|
220
|
+
for (let sy = Math.floor(top); sy < Math.ceil(bottom); sy++) for (let sx = Math.floor(left); sx < Math.ceil(right); sx++) {
|
|
221
|
+
const weight = (Math.min(right, sx + 1) - Math.max(left, sx)) * (Math.min(bottom, sy + 1) - Math.max(top, sy))
|
|
222
|
+
const i = (sy * w + sx) * 4, a = image.data[i + 3] / 255 * weight
|
|
223
|
+
alpha += a; red += image.data[i] * a; green += image.data[i + 1] * a; blue += image.data[i + 2] * a
|
|
224
|
+
}
|
|
225
|
+
const i = (y * width + x) * 4
|
|
226
|
+
if (alpha) { data[i] = Math.round(red / alpha); data[i + 1] = Math.round(green / alpha); data[i + 2] = Math.round(blue / alpha) }
|
|
227
|
+
data[i + 3] = Math.round(255 * alpha / ((right - left) * (bottom - top)))
|
|
228
|
+
}
|
|
229
|
+
const thumbnail = PNG.sync.write({ width, height, data }, { deflateLevel: 9, deflateStrategy: 0 })
|
|
230
|
+
if (thumbnail.length > INLINE_LIMIT) return null
|
|
231
|
+
try {
|
|
232
|
+
mkdirSync(directory, { recursive: true })
|
|
233
|
+
writeFileSync(file, thumbnail)
|
|
234
|
+
prunePreviewCache(directory)
|
|
235
|
+
} catch {}
|
|
236
|
+
return `data:image/png;base64,${thumbnail.toString('base64')}`
|
|
237
|
+
}
|
|
238
|
+
return buffer.length <= PREVIEW_LIMIT ? `data:${contentType};base64,${buffer.toString('base64')}` : null
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** Content-addressed thumbnails are never overwritten, so they need pruning. */
|
|
242
|
+
function prunePreviewCache(directory) {
|
|
243
|
+
const now = Date.now()
|
|
244
|
+
if (now - lastPreviewPrune < 60 * 60 * 1000) return
|
|
245
|
+
lastPreviewPrune = now
|
|
246
|
+
try {
|
|
247
|
+
const files = readdirSync(directory)
|
|
248
|
+
.map((entry) => {
|
|
249
|
+
try { const info = statSync(join(directory, entry)); return info.isFile() ? { entry, at: info.mtimeMs } : null } catch { return null }
|
|
250
|
+
})
|
|
251
|
+
.filter(Boolean)
|
|
252
|
+
.sort((a, b) => b.at - a.at)
|
|
253
|
+
for (const stale of files.slice(PREVIEW_CACHE_KEEP)) {
|
|
254
|
+
try { rmSync(join(directory, stale.entry), { force: true }) } catch {}
|
|
255
|
+
}
|
|
256
|
+
} catch {}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function previewFile(file) {
|
|
260
|
+
try {
|
|
261
|
+
const info = statSync(file)
|
|
262
|
+
if (!info.isFile() || info.size > MAX_BYTES) return null
|
|
263
|
+
const key = `${file}:${info.mtimeMs}:${info.size}`
|
|
264
|
+
if (previewMemory.has(key)) return previewMemory.get(key)
|
|
265
|
+
const preview = inlinePreview(readFileSync(file))
|
|
266
|
+
if (previewMemory.size >= 256) previewMemory.delete(previewMemory.keys().next().value)
|
|
267
|
+
previewMemory.set(key, preview)
|
|
268
|
+
return preview
|
|
269
|
+
} catch { return null }
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function cachedIconPreview(url) {
|
|
273
|
+
const cached = memory.get(url)
|
|
274
|
+
if (cached) {
|
|
275
|
+
try { return inlinePreview(cached.buffer) } catch { return null }
|
|
276
|
+
}
|
|
277
|
+
return previewFile(iconCacheFile(url))
|
|
278
|
+
}
|
|
279
|
+
|
|
186
280
|
/**
|
|
187
281
|
* Carry manifest assets through marketplace rows without exposing filesystem paths.
|
|
188
282
|
*
|
|
@@ -197,6 +291,7 @@ export function buildPluginIcons(meta, { sourceId, name, dir, source } = {}) {
|
|
|
197
291
|
// Local files are stat'd once here and the same File is reused for the inline
|
|
198
292
|
// copy, so discovering artwork and inlining it is one pass over the disk.
|
|
199
293
|
const files = new Map()
|
|
294
|
+
const previews = {}
|
|
200
295
|
const toUrl = (value) => {
|
|
201
296
|
if (typeof value !== 'string' || !value.trim()) return null
|
|
202
297
|
if (/^https?:\/\//i.test(value)) return proxy(value)
|
|
@@ -238,18 +333,41 @@ export function buildPluginIcons(meta, { sourceId, name, dir, source } = {}) {
|
|
|
238
333
|
: [ui.iconLight, ui.logoLight, meta?.iconLight, ...values('light'), ...plain, ...shade]
|
|
239
334
|
const urls = [...new Set(declared.map(toUrl).filter(Boolean))]
|
|
240
335
|
// The inline copy leads, so the first candidate needs no request at all.
|
|
241
|
-
// Only
|
|
242
|
-
//
|
|
336
|
+
// Only local files lead with their bytes. The separately carried preview
|
|
337
|
+
// never changes candidate priority or replaces the normal refresh request.
|
|
243
338
|
const inline = urls.map((url) => files.get(url) && inlineFile(files.get(url))).find(Boolean)
|
|
339
|
+
if (!inline && urls[0]) {
|
|
340
|
+
const first = urls[0]
|
|
341
|
+
const remote = first.startsWith('/universal-plugin-hub/api/icon?') ? new URL(first, 'http://localhost').searchParams.get('u') : null
|
|
342
|
+
const preview = files.has(first) ? previewFile(files.get(first)) : remote && cachedIconPreview(remote)
|
|
343
|
+
if (preview) previews[first] = preview
|
|
344
|
+
}
|
|
244
345
|
return inline ? [inline, ...urls.filter((url) => url !== inline)] : urls
|
|
245
346
|
}
|
|
246
347
|
const served = (paths) => [...new Set(paths.map(toUrl).filter(Boolean))]
|
|
247
348
|
// Reported apart from the tile candidates so the client can try them after
|
|
248
349
|
// the brand artwork it knows about, instead of leading every row with them.
|
|
350
|
+
const light = build('light')
|
|
351
|
+
const dark = build('dark')
|
|
352
|
+
// Avatar-only rows already have reusable bytes in the proxy's disk cache.
|
|
353
|
+
// Expose those as a preview without starting network work during parsing;
|
|
354
|
+
// the normal image request still refreshes expired cache entries.
|
|
355
|
+
if (!light.length || !dark.length) {
|
|
356
|
+
const githubOwner = (url) => typeof url === 'string' ? url.match(/github\.com\/([^/]+)/i)?.[1] : null
|
|
357
|
+
let owner = [source?.url || meta?.source?.url, meta?.homepage].map(githubOwner).find((value) => value && !value.toLowerCase().includes('anthropics'))
|
|
358
|
+
const author = (typeof meta?.author === 'string' ? meta.author : meta?.author?.name || '').trim().toLowerCase()
|
|
359
|
+
if (!owner && /^[a-z0-9_-]+$/i.test(author) && author !== 'anthropic') owner = author
|
|
360
|
+
if (owner) {
|
|
361
|
+
const url = `https://github.com/${encodeURIComponent(owner)}.png?size=80`
|
|
362
|
+
const preview = cachedIconPreview(url)
|
|
363
|
+
if (preview) previews[proxy(url)] = preview
|
|
364
|
+
}
|
|
365
|
+
}
|
|
249
366
|
return {
|
|
250
|
-
light
|
|
251
|
-
dark
|
|
367
|
+
light,
|
|
368
|
+
dark,
|
|
252
369
|
portrait: { light: served(portrait), dark: served(portrait) },
|
|
370
|
+
...(Object.keys(previews).length ? { previews } : {}),
|
|
253
371
|
}
|
|
254
372
|
}
|
|
255
373
|
|
package/src/install.js
CHANGED
|
@@ -1248,7 +1248,7 @@ export async function verifyConnectorAuth(pluginName, connectorName, payload) {
|
|
|
1248
1248
|
let result
|
|
1249
1249
|
try {
|
|
1250
1250
|
const controller = new AbortController()
|
|
1251
|
-
const timer = setTimeout(() => controller.abort(),
|
|
1251
|
+
const timer = setTimeout(() => controller.abort(), MCP_AUTH_TIMEOUT_MS)
|
|
1252
1252
|
const res = await fetch(url, {
|
|
1253
1253
|
method: 'POST',
|
|
1254
1254
|
headers: reqHeaders,
|
|
@@ -1293,22 +1293,23 @@ export async function verifyConnectorAuth(pluginName, connectorName, payload) {
|
|
|
1293
1293
|
if (e.name === 'AbortError') {
|
|
1294
1294
|
result = {
|
|
1295
1295
|
ok: false,
|
|
1296
|
-
message:
|
|
1296
|
+
message: `连接超时(${MCP_AUTH_TIMEOUT_MS / 1000} 秒未响应),请检查服务 URL 与网络`,
|
|
1297
1297
|
server: connectorName,
|
|
1298
1298
|
transport,
|
|
1299
1299
|
endpoint: url,
|
|
1300
|
-
errorDetails:
|
|
1300
|
+
errorDetails: `Connection timed out (${MCP_AUTH_TIMEOUT_MS / 1000}s limit)`,
|
|
1301
|
+
duration,
|
|
1302
|
+
}
|
|
1303
|
+
} else {
|
|
1304
|
+
result = {
|
|
1305
|
+
ok: false,
|
|
1306
|
+
message: `连接异常:${e.message}`,
|
|
1307
|
+
server: connectorName,
|
|
1308
|
+
transport,
|
|
1309
|
+
endpoint: url,
|
|
1310
|
+
errorDetails: e.message,
|
|
1301
1311
|
duration,
|
|
1302
1312
|
}
|
|
1303
|
-
}
|
|
1304
|
-
result = {
|
|
1305
|
-
ok: false,
|
|
1306
|
-
message: `连接异常:${e.message}`,
|
|
1307
|
-
server: connectorName,
|
|
1308
|
-
transport,
|
|
1309
|
-
endpoint: url,
|
|
1310
|
-
errorDetails: e.message,
|
|
1311
|
-
duration,
|
|
1312
1313
|
}
|
|
1313
1314
|
}
|
|
1314
1315
|
setRemoteVerification(pluginName, connectorName, { transport, url, headers: reqHeaders, oauth: payload?.oauth }, result.ok === true)
|
|
@@ -1389,9 +1390,10 @@ export function saveConnectorAuth(pluginName, connectorName, payload) {
|
|
|
1389
1390
|
writeMcpToolsState(savedState)
|
|
1390
1391
|
}
|
|
1391
1392
|
}
|
|
1392
|
-
if (
|
|
1393
|
-
|
|
1394
|
-
|
|
1393
|
+
if (result.ok) {
|
|
1394
|
+
MEMORY_TOOLS_CACHE.delete(toolsKey)
|
|
1395
|
+
// A probe still running against the old configuration must not be reused.
|
|
1396
|
+
MCP_TOOLS_INFLIGHT.delete(toolsKey)
|
|
1395
1397
|
}
|
|
1396
1398
|
return result
|
|
1397
1399
|
}
|
|
@@ -1466,6 +1468,14 @@ function quoteArgForShell(value) {
|
|
|
1466
1468
|
* an (possibly empty) tool list, so callers can tell "no tools" from "the
|
|
1467
1469
|
* probe never reached the server".
|
|
1468
1470
|
*/
|
|
1471
|
+
const MCP_STARTUP_TIMEOUT_MS = 180000
|
|
1472
|
+
const MCP_TOOLS_TIMEOUT_MS = 60000
|
|
1473
|
+
// A user-initiated connection test is not the same wait as a background probe.
|
|
1474
|
+
const MCP_AUTH_TIMEOUT_MS = 8000
|
|
1475
|
+
// Keep only the tail: a chatty server during a 180s startup window would
|
|
1476
|
+
// otherwise grow this string without bound (and `+=` copies it each time).
|
|
1477
|
+
const STDERR_TAIL_BYTES = 8192
|
|
1478
|
+
|
|
1469
1479
|
export function queryStdioToolsList(cmd, args, extraEnv = {}) {
|
|
1470
1480
|
return new Promise((resolve) => {
|
|
1471
1481
|
const argv = Array.isArray(args) ? args : []
|
|
@@ -1498,10 +1508,22 @@ export function queryStdioToolsList(cmd, args, extraEnv = {}) {
|
|
|
1498
1508
|
settled = true
|
|
1499
1509
|
clearTimeout(timer)
|
|
1500
1510
|
try { cp.kill() } catch {}
|
|
1501
|
-
resolve({ tools: tools || [], error:
|
|
1511
|
+
resolve({ tools: tools || [], error: error || null })
|
|
1502
1512
|
}
|
|
1503
1513
|
|
|
1504
|
-
|
|
1514
|
+
const armTimeout = (ms, phase) => {
|
|
1515
|
+
if (settled) return
|
|
1516
|
+
clearTimeout(timer)
|
|
1517
|
+
timer = setTimeout(() => {
|
|
1518
|
+
const detail = stderr.trim().split('\n').filter(Boolean).slice(-2).join(' ')
|
|
1519
|
+
finish([], `MCP ${phase}超时(${ms / 1000} 秒)${detail ? `:${detail}` : ''}`)
|
|
1520
|
+
}, ms)
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
cp.stderr.on('data', (d) => {
|
|
1524
|
+
stderr += d.toString()
|
|
1525
|
+
if (stderr.length > STDERR_TAIL_BYTES) stderr = stderr.slice(-STDERR_TAIL_BYTES)
|
|
1526
|
+
})
|
|
1505
1527
|
|
|
1506
1528
|
cp.stdout.on('data', (d) => {
|
|
1507
1529
|
output += d.toString()
|
|
@@ -1516,19 +1538,25 @@ export function queryStdioToolsList(cmd, args, extraEnv = {}) {
|
|
|
1516
1538
|
finish(json.result.tools, null)
|
|
1517
1539
|
return
|
|
1518
1540
|
}
|
|
1519
|
-
if (json.id === 0 && json.result) {
|
|
1541
|
+
if (json.id === 0 && json.result && !answered) {
|
|
1542
|
+
answered = true
|
|
1543
|
+
armTimeout(MCP_TOOLS_TIMEOUT_MS, '工具解析')
|
|
1520
1544
|
cp.stdin.write(JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' }) + '\n')
|
|
1521
1545
|
cp.stdin.write(toolsReq)
|
|
1522
1546
|
}
|
|
1523
|
-
if (json.id === 0
|
|
1547
|
+
if ((json.id === 0 || json.id === 1) && json.error) {
|
|
1548
|
+
finish([], json.error.message || 'MCP 工具解析失败')
|
|
1549
|
+
return
|
|
1550
|
+
}
|
|
1524
1551
|
} catch {}
|
|
1525
1552
|
}
|
|
1526
1553
|
})
|
|
1527
1554
|
|
|
1528
1555
|
cp.on('error', (err) => finish([], `无法启动 ${cmd}: ${err.message}`))
|
|
1556
|
+
cp.stdin.on?.('error', (err) => finish([], `MCP 输入连接失败: ${err.message}`))
|
|
1529
1557
|
|
|
1530
1558
|
cp.on('close', (code) => {
|
|
1531
|
-
if (!
|
|
1559
|
+
if (!settled) {
|
|
1532
1560
|
const detail = stderr.trim().split('\n').filter(Boolean).slice(-2).join(' ')
|
|
1533
1561
|
finish([], detail || `MCP 服务提前退出(exit ${code})`)
|
|
1534
1562
|
}
|
|
@@ -1548,29 +1576,45 @@ export function queryStdioToolsList(cmd, args, extraEnv = {}) {
|
|
|
1548
1576
|
params: {}
|
|
1549
1577
|
}) + '\n'
|
|
1550
1578
|
|
|
1579
|
+
armTimeout(MCP_STARTUP_TIMEOUT_MS, '启动')
|
|
1551
1580
|
try {
|
|
1552
1581
|
cp.stdin.write(initReq)
|
|
1553
|
-
} catch {}
|
|
1554
|
-
|
|
1555
|
-
timer = setTimeout(() => {
|
|
1556
|
-
if (!settled) {
|
|
1557
|
-
const detail = stderr.trim().split('\n').filter(Boolean).slice(-2).join(' ')
|
|
1558
|
-
finish([], detail || 'MCP 服务在 25 秒内没有返回工具列表')
|
|
1559
|
-
}
|
|
1560
|
-
}, 25000)
|
|
1582
|
+
} catch (err) { finish([], err.message) }
|
|
1561
1583
|
})
|
|
1562
1584
|
}
|
|
1563
1585
|
|
|
1564
1586
|
const MEMORY_TOOLS_CACHE = new Map()
|
|
1587
|
+
const MCP_TOOLS_INFLIGHT = new Map()
|
|
1565
1588
|
|
|
1566
1589
|
export async function fetchConnectorTools(pluginName, connectorName, forceFresh = false) {
|
|
1590
|
+
const key = `${pluginName}::${connectorName}`
|
|
1591
|
+
const inflight = MCP_TOOLS_INFLIGHT.get(key)
|
|
1592
|
+
// A caller asking for a fresh probe must never be served a background
|
|
1593
|
+
// probe's stale answer (e.g. right after the user fixed a bad URL).
|
|
1594
|
+
if (inflight && !(forceFresh && !inflight.forceFresh)) return inflight.promise
|
|
1595
|
+
const entry = { forceFresh, promise: null }
|
|
1596
|
+
entry.promise = discoverConnectorTools(pluginName, connectorName, forceFresh)
|
|
1597
|
+
MCP_TOOLS_INFLIGHT.set(key, entry)
|
|
1598
|
+
try {
|
|
1599
|
+
const result = await entry.promise
|
|
1600
|
+
// A failure is transient; remembering it with no expiry pinned the UI to
|
|
1601
|
+
// "解析失败" until the process restarted.
|
|
1602
|
+
if (result.ok === false) MEMORY_TOOLS_CACHE.delete(key)
|
|
1603
|
+
else MEMORY_TOOLS_CACHE.set(key, { tools: result.tools || [], ok: result.ok, message: result.message })
|
|
1604
|
+
return result
|
|
1605
|
+
} finally {
|
|
1606
|
+
if (MCP_TOOLS_INFLIGHT.get(key) === entry) MCP_TOOLS_INFLIGHT.delete(key)
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
async function discoverConnectorTools(pluginName, connectorName, forceFresh = false) {
|
|
1567
1611
|
const key = `${pluginName}::${connectorName}`
|
|
1568
1612
|
const state = readMcpToolsState()
|
|
1569
1613
|
const disabledTools = Array.isArray(state[key]?.disabledTools) ? state[key].disabledTools : []
|
|
1570
1614
|
|
|
1571
1615
|
if (!forceFresh && MEMORY_TOOLS_CACHE.has(key)) {
|
|
1572
1616
|
const mem = MEMORY_TOOLS_CACHE.get(key)
|
|
1573
|
-
return { ok:
|
|
1617
|
+
return { ok: mem.ok !== false, tools: mem.tools || [], disabledTools, ...(mem.message ? { message: mem.message } : {}) }
|
|
1574
1618
|
}
|
|
1575
1619
|
|
|
1576
1620
|
const target = installedDir(pluginName)
|
|
@@ -1601,9 +1645,9 @@ export async function fetchConnectorTools(pluginName, connectorName, forceFresh
|
|
|
1601
1645
|
|
|
1602
1646
|
// 1. HTTP / SSE fetch
|
|
1603
1647
|
if (transport !== 'stdio' && url) {
|
|
1648
|
+
const controller = new AbortController()
|
|
1649
|
+
const timer = setTimeout(() => controller.abort(), MCP_TOOLS_TIMEOUT_MS)
|
|
1604
1650
|
try {
|
|
1605
|
-
const controller = new AbortController()
|
|
1606
|
-
const timer = setTimeout(() => controller.abort(), 6000)
|
|
1607
1651
|
const res = await fetch(url, {
|
|
1608
1652
|
method: 'POST',
|
|
1609
1653
|
headers: {
|
|
@@ -1612,14 +1656,15 @@ export async function fetchConnectorTools(pluginName, connectorName, forceFresh
|
|
|
1612
1656
|
},
|
|
1613
1657
|
signal: controller.signal,
|
|
1614
1658
|
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/list', params: {} }),
|
|
1615
|
-
})
|
|
1659
|
+
})
|
|
1616
1660
|
|
|
1617
1661
|
if (res.status === 200) {
|
|
1618
1662
|
const text = await res.text()
|
|
1619
|
-
let tools =
|
|
1663
|
+
let tools = null
|
|
1620
1664
|
try {
|
|
1621
1665
|
const data = JSON.parse(text)
|
|
1622
1666
|
if (Array.isArray(data.result?.tools)) tools = data.result.tools
|
|
1667
|
+
else if (data.error) probeError = data.error.message || 'MCP 工具解析失败'
|
|
1623
1668
|
} catch {
|
|
1624
1669
|
const lines = text.split('\n')
|
|
1625
1670
|
for (const line of lines) {
|
|
@@ -1635,18 +1680,17 @@ export async function fetchConnectorTools(pluginName, connectorName, forceFresh
|
|
|
1635
1680
|
}
|
|
1636
1681
|
}
|
|
1637
1682
|
|
|
1638
|
-
if (tools
|
|
1639
|
-
|
|
1640
|
-
state[key].cachedTools = tools
|
|
1641
|
-
writeMcpToolsState(state)
|
|
1683
|
+
if (tools) {
|
|
1684
|
+
cacheConnectorTools(key, tools)
|
|
1642
1685
|
return { ok: true, tools, disabledTools }
|
|
1643
1686
|
}
|
|
1687
|
+
probeError ||= 'MCP 响应中未包含有效的工具列表'
|
|
1644
1688
|
} else {
|
|
1645
1689
|
probeError = `MCP 服务返回 HTTP ${res.status}`
|
|
1646
1690
|
}
|
|
1647
1691
|
} catch (err) {
|
|
1648
|
-
probeError = `连接 MCP 服务失败: ${err.message}`
|
|
1649
|
-
}
|
|
1692
|
+
probeError = controller.signal.aborted ? `MCP 工具解析超时(${MCP_TOOLS_TIMEOUT_MS / 1000} 秒)` : `连接 MCP 服务失败: ${err.message}`
|
|
1693
|
+
} finally { clearTimeout(timer) }
|
|
1650
1694
|
}
|
|
1651
1695
|
|
|
1652
1696
|
// 2. Stdio fetch
|
|
@@ -1657,9 +1701,7 @@ export async function fetchConnectorTools(pluginName, connectorName, forceFresh
|
|
|
1657
1701
|
try {
|
|
1658
1702
|
const probe = await queryStdioToolsList(cmd, args, entryCfg.env || found?.env || {})
|
|
1659
1703
|
if (probe.tools.length > 0 || !probe.error) {
|
|
1660
|
-
|
|
1661
|
-
state[key].cachedTools = probe.tools
|
|
1662
|
-
writeMcpToolsState(state)
|
|
1704
|
+
cacheConnectorTools(key, probe.tools)
|
|
1663
1705
|
return { ok: true, tools: probe.tools, disabledTools }
|
|
1664
1706
|
}
|
|
1665
1707
|
probeError = probe.error
|
|
@@ -1671,20 +1713,38 @@ export async function fetchConnectorTools(pluginName, connectorName, forceFresh
|
|
|
1671
1713
|
}
|
|
1672
1714
|
}
|
|
1673
1715
|
|
|
1674
|
-
// 3. Return cached fallback
|
|
1675
|
-
if (cached.length > 0) {
|
|
1676
|
-
return { ok: true, tools: cached, disabledTools }
|
|
1677
|
-
}
|
|
1678
|
-
|
|
1679
1716
|
// A probe that never reached the server is an error, not an empty tool list;
|
|
1680
|
-
// reporting ok:true
|
|
1717
|
+
// reporting ok:true with an empty list made the UI claim the server exposes
|
|
1718
|
+
// no tools. A cached list is different: it is still usable, and surfacing it
|
|
1719
|
+
// as an error replaced the whole row (and its toggles) with a failure notice.
|
|
1681
1720
|
if (probeError) {
|
|
1721
|
+
if (cached.length > 0) return { ok: true, tools: cached, disabledTools, message: probeError }
|
|
1682
1722
|
return { ok: false, tools: [], disabledTools, message: probeError }
|
|
1683
1723
|
}
|
|
1684
1724
|
|
|
1685
1725
|
return { ok: true, tools: [], disabledTools }
|
|
1686
1726
|
}
|
|
1687
1727
|
|
|
1728
|
+
function cacheConnectorTools(key, tools) {
|
|
1729
|
+
// A probe started before an uninstall can finish afterwards; writing then
|
|
1730
|
+
// resurrects the removed plugin's tool table for the next install of the
|
|
1731
|
+
// same name.
|
|
1732
|
+
const owner = key.slice(0, key.indexOf('::'))
|
|
1733
|
+
if (owner !== 'user-mcp' && !readState().plugins.some((p) => p.name === owner)) return
|
|
1734
|
+
const state = readMcpToolsState()
|
|
1735
|
+
state[key] = { ...state[key], cachedTools: tools }
|
|
1736
|
+
writeMcpToolsState(state)
|
|
1737
|
+
MEMORY_TOOLS_CACHE.set(key, { tools })
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
function warmInstalledConnectorTools(pluginName, connectors) {
|
|
1741
|
+
for (const connector of connectors) {
|
|
1742
|
+
if (getConnectorEntry(pluginName, connector.name)) {
|
|
1743
|
+
void fetchConnectorTools(pluginName, connector.name, true).catch(() => {})
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1688
1748
|
export function isScanDirRegistered(path) {
|
|
1689
1749
|
const state = readState()
|
|
1690
1750
|
const target = (path || '').replace(/\\/g, '/').toLowerCase().replace(/\/+$/, '')
|
|
@@ -2040,14 +2100,7 @@ export async function installPlugin({ sourceId, pluginName, refresh = false }) {
|
|
|
2040
2100
|
writeState(state)
|
|
2041
2101
|
invalidateParserCaches()
|
|
2042
2102
|
|
|
2043
|
-
|
|
2044
|
-
for (const c of pluginConnectors) {
|
|
2045
|
-
if (c.command === 'npx' || (c.args && c.args.some((a) => typeof a === 'string' && a.includes('@')))) {
|
|
2046
|
-
setTimeout(() => {
|
|
2047
|
-
fetchConnectorTools(pluginName, c.name, true).catch(() => {});
|
|
2048
|
-
}, 500);
|
|
2049
|
-
}
|
|
2050
|
-
}
|
|
2103
|
+
warmInstalledConnectorTools(pluginName, pluginConnectors)
|
|
2051
2104
|
|
|
2052
2105
|
return {
|
|
2053
2106
|
ok: true,
|
|
@@ -2112,6 +2165,7 @@ export function uninstallPlugin(pluginName) {
|
|
|
2112
2165
|
delete mcpToolsState[k]
|
|
2113
2166
|
mcpToolsStateChanged = true
|
|
2114
2167
|
MEMORY_TOOLS_CACHE.delete(k)
|
|
2168
|
+
MCP_TOOLS_INFLIGHT.delete(k)
|
|
2115
2169
|
}
|
|
2116
2170
|
}
|
|
2117
2171
|
if (mcpToolsStateChanged) {
|
|
@@ -2350,6 +2404,7 @@ export function installedDetails() {
|
|
|
2350
2404
|
return {
|
|
2351
2405
|
...rec,
|
|
2352
2406
|
...detail,
|
|
2407
|
+
description: rec.description || targetManifest?.description || marketRow?.description || '',
|
|
2353
2408
|
author: author || rec.author,
|
|
2354
2409
|
// Identity fields the icon chain reads. The detail page already merges
|
|
2355
2410
|
// these from the marketplace row before rendering, which is why the same
|
package/src/parser.js
CHANGED
|
@@ -66,6 +66,23 @@ function extractMdDescription(text) {
|
|
|
66
66
|
return ''
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
// Presentation only: read Codex's card copy without changing which manifest
|
|
70
|
+
// owns the plugin's description, components, or installation behavior.
|
|
71
|
+
function readPluginShortDescription(dir) {
|
|
72
|
+
if (!dir) return ''
|
|
73
|
+
const text = value => typeof value === 'string' ? value.trim() : ''
|
|
74
|
+
try {
|
|
75
|
+
const root = JSON.parse(readFileSync(join(dir, 'plugin.json'), 'utf8'))
|
|
76
|
+
const openai = root?.extensions?.['com.openai']
|
|
77
|
+
// An inline OpenAI extension replaces the compatibility overlay entirely.
|
|
78
|
+
if (openai && typeof openai === 'object' && !Array.isArray(openai)) return text(openai.interface?.shortDescription)
|
|
79
|
+
} catch {}
|
|
80
|
+
try {
|
|
81
|
+
const codex = JSON.parse(readFileSync(join(dir, '.codex-plugin', 'plugin.json'), 'utf8'))
|
|
82
|
+
return text(codex?.interface?.shortDescription)
|
|
83
|
+
} catch { return '' }
|
|
84
|
+
}
|
|
85
|
+
|
|
69
86
|
function normalizeRow(row, sourceId, dir) {
|
|
70
87
|
if (!row) return null
|
|
71
88
|
const name = typeof row.name === 'string' ? row.name : (typeof row.identifier === 'string' ? row.identifier : '')
|
|
@@ -81,6 +98,8 @@ function normalizeRow(row, sourceId, dir) {
|
|
|
81
98
|
const description = typeof row.description === 'string'
|
|
82
99
|
? row.description
|
|
83
100
|
: (row.interface?.shortDescription || meta.description || '')
|
|
101
|
+
const shortDescription = readPluginShortDescription(dir)
|
|
102
|
+
|| (typeof row.interface?.shortDescription === 'string' ? row.interface.shortDescription.trim() : '')
|
|
84
103
|
|
|
85
104
|
const source = row.source?.source === 'local' ? row.source.path : (row.source || './')
|
|
86
105
|
if (row.source?.source === 'local' && (typeof source !== 'string' || !source.startsWith('./'))) return null
|
|
@@ -91,6 +110,7 @@ function normalizeRow(row, sourceId, dir) {
|
|
|
91
110
|
name: cleanName,
|
|
92
111
|
displayName,
|
|
93
112
|
description,
|
|
113
|
+
...(shortDescription ? { shortDescription } : {}),
|
|
94
114
|
author: typeof author === 'string' ? author : (meta.author || undefined),
|
|
95
115
|
version: typeof row.version === 'string' ? row.version : (meta.version || undefined),
|
|
96
116
|
category: typeof row.category === 'string' ? row.category : (meta.category || undefined),
|
package/src/routes.js
CHANGED
|
@@ -501,7 +501,7 @@ async function handle(req, res, prefix = API_PREFIX, skills = null, applyProfile
|
|
|
501
501
|
// ── user MCP tool list / per-tool toggle (same shape as plugin connectors) ──
|
|
502
502
|
if (method === 'GET' && path.startsWith('/mcps/') && path.endsWith('/tools')) {
|
|
503
503
|
const name = safeSegment(normalizeMcpName(path.slice('/mcps/'.length, -'/tools'.length)), 'MCP 名称')
|
|
504
|
-
const result = await fetchConnectorTools('user-mcp', name)
|
|
504
|
+
const result = await fetchConnectorTools('user-mcp', name, url.searchParams.get('fresh') === '1')
|
|
505
505
|
return sendJson(res, 200, result)
|
|
506
506
|
}
|
|
507
507
|
|