universal-plugin-hub 1.0.6 → 1.0.12

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/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、Hooks 与 LSP。",
6
- "version": "1.0.6",
6
+ "version": "1.0.12",
7
7
  "type": "module",
8
8
  "main": "src/index.js",
9
9
  "license": "MIT",
@@ -30,6 +30,7 @@
30
30
  "mcp"
31
31
  ],
32
32
  "dependencies": {
33
+ "@modelcontextprotocol/sdk": "1.32.1",
33
34
  "js-yaml": "^5.3.0"
34
35
  },
35
36
  "peerDependencies": {
@@ -67,5 +68,10 @@
67
68
  "scripts/postinstall.js",
68
69
  "cordis.patch.yml",
69
70
  "assets/hero.png"
70
- ]
71
+ ],
72
+ "devDependencies": {
73
+ "react": "^19.2.0",
74
+ "react-test-renderer": "^19.2.0",
75
+ "acorn": "^8.18.0"
76
+ }
71
77
  }
package/src/index.js CHANGED
@@ -7,6 +7,7 @@
7
7
  * scripts behind an approval prompt, so startup is the reliable path.
8
8
  */
9
9
  import { mountRoutes } from './routes.js'
10
+ import { cancelAllOAuthVerifications } from './oauth.js'
10
11
  import { syncAllInstalledSkillsToDsh, installProfilePackages, LSP_HOST_PACKAGES, HOOK_HOST_PACKAGES } from './install.js'
11
12
 
12
13
  export const name = 'universal-plugin-hub'
@@ -27,6 +28,9 @@ export function apply(ctx) {
27
28
  })
28
29
 
29
30
  ctx.inject(['webServer'], (hostCtx) => {
30
- hostCtx.effect(() => mountRoutes(hostCtx.webServer), 'universal-plugin-hub: http routes')
31
+ hostCtx.effect(() => {
32
+ const unmount = mountRoutes(hostCtx.webServer)
33
+ return () => { unmount(); cancelAllOAuthVerifications() }
34
+ }, 'universal-plugin-hub: http routes')
31
35
  })
32
36
  }
package/src/install.js CHANGED
@@ -8,16 +8,23 @@
8
8
  * agents.
9
9
  */
10
10
  import { existsSync, mkdirSync, rmSync, readFileSync, writeFileSync, renameSync, readdirSync, copyFileSync, statSync, accessSync, constants as fsConstants } from 'node:fs'
11
+ import { fileURLToPath } from 'node:url'
11
12
  import { dirname, join, basename, isAbsolute, resolve, extname, delimiter } from 'node:path'
12
13
  import { spawn, execFile, execFileSync } from 'node:child_process'
13
14
  import { gunzipSync } from 'node:zlib'
15
+ import { createHash } from 'node:crypto'
14
16
  import { homedir } from 'node:os'
15
17
  import * as yaml from 'js-yaml'
16
- import { installedDir, readState, writeState, slugify, dshHome, dshSkillsDir, safeRmDir } from './store.js'
18
+ import { installedDir, readState, writeState, slugify, dshHome, dshSkillsDir, safeRmDir, sourceCacheDir } from './store.js'
17
19
  import { materializePlugin, pullSource, pluginPath } from './market.js'
18
- import { copyDir, listSkills, listAgents, listPrompts, listConnectors, listHooks, listLspServers, readPluginManifest, resolveHookConfigPath, invalidateParserCaches, invalidateMarketplaceCache } from './parser.js'
20
+ import { copyDir, listSkills, listAgents, listPrompts, listConnectors, listHooks, listLspServers, readPluginManifest, resolveHookConfigPath, invalidateParserCaches, invalidateMarketplaceCache, readMarketplace, connectorTransport, isRemoteTransportName } from './parser.js'
19
21
  import { parseAgentDefinition, compileSubagentsHubSkill, cleanupLegacyPresets } from './agents-map.js'
20
22
  import { buildPluginIcons } from './icons.js'
23
+ import { beginOAuthVerification, completeOAuthVerification, saveCustomOAuthClient, readSavedOAuthClient } from './oauth.js'
24
+ import { encodeOAuthConfig, isOAuthMode, oauthCredentialKey, oauthRuntimeConfig, remoteConfigFromEntry } from './oauth-config.js'
25
+ import { oauthStoreDir } from './oauth-store.js'
26
+
27
+ const OAUTH_BRIDGE_PATH = fileURLToPath(new URL('./oauth-bridge.js', import.meta.url))
21
28
 
22
29
  /** Active profile name: env DSH_PROFILE -> desktop (if present) -> web. */
23
30
  export function resolveActiveProfileName() {
@@ -75,7 +82,7 @@ export function getConnectorEntry(pluginName, connectorName) {
75
82
 
76
83
  export function connectorRequiresAuth(cfg) {
77
84
  if (!cfg) return true
78
- const isHttp = (cfg.type === 'http' || cfg.type === 'sse' || (!cfg.command && (!!cfg.url || !cfg.args?.length)))
85
+ const isHttp = (connectorTransport(cfg.type, cfg.url, cfg.command) === 'http')
79
86
 
80
87
  // 1. If HTTP / SSE connector has NO valid URL or empty placeholder URL, it ALWAYS requires configuration/auth!
81
88
  if (isHttp) {
@@ -134,7 +141,7 @@ export function isConnectorAuthenticated(pluginName, connectorName) {
134
141
  const entry = getConnectorEntry(pluginName, connectorName)
135
142
  const cfg = entry?.config || found || {}
136
143
 
137
- const isHttp = (entry?.config?.transport === 'streamable-http' || found?.type === 'http' || found?.type === 'sse' || (!found?.command && (found?.url || cfg.url)) || (!found?.command && !found?.args?.length))
144
+ const isHttp = (isRemoteTransportName(entry?.config?.transport) || isRemoteTransportName(found?.type) || (!found?.command && (found?.url || cfg.url)) || (!found?.command && !found?.args?.length))
138
145
  if (isHttp) {
139
146
  const url = cfg.url || found?.url || ''
140
147
  if (!url || typeof url !== 'string' || !/^https?:\/\//i.test(url.trim())) {
@@ -173,10 +180,47 @@ export function isConnectorAuthenticated(pluginName, connectorName) {
173
180
  return false
174
181
  }
175
182
 
183
+ function isRemoteConnector(config = {}) {
184
+ return isRemoteTransportName(config.transport) || isRemoteTransportName(config.type) || (!config.command && (!!config.url || !config.args?.length))
185
+ }
186
+
187
+ function remoteConfigFingerprint(config = {}) {
188
+ const normalized = {
189
+ transport: 'http',
190
+ url: String(config.url || '').trim(),
191
+ headers: Object.fromEntries(Object.entries(config.headers || {}).filter(([key]) => {
192
+ const name = key.toLowerCase()
193
+ return name !== 'content-type' && (!isOAuthMode(config.oauth) || name !== 'authorization')
194
+ }).sort(([a], [b]) => a.localeCompare(b))),
195
+ oauth: config.oauth || 'none',
196
+ oauthClientId: config.oauthClientId || '',
197
+ oauthScope: config.oauthScope || '',
198
+ oauthCallbackPort: Number(config.oauthCallbackPort) || null,
199
+ }
200
+ return createHash('sha256').update(JSON.stringify(normalized)).digest('hex')
201
+ }
202
+
203
+ function setRemoteVerification(pluginName, connectorName, payload, verified) {
204
+ const key = `${pluginName}::${connectorName}`
205
+ const state = readMcpToolsState()
206
+ state[key] = {
207
+ ...(state[key] || {}),
208
+ verifiedRemoteConfig: verified ? remoteConfigFingerprint(payload) : null,
209
+ }
210
+ writeMcpToolsState(state)
211
+ }
212
+
176
213
  export function isConnectorActive(pluginName, connectorName) {
177
214
  const entry = getConnectorEntry(pluginName, connectorName)
178
215
  if (!entry) return false
179
- return isConnectorAuthenticated(pluginName, connectorName)
216
+ const remote = remoteConfigFromEntry(entry.config)
217
+ if (remote) {
218
+ const key = `${pluginName}::${connectorName}`
219
+ return readMcpToolsState()[key]?.verifiedRemoteConfig === remoteConfigFingerprint(remote)
220
+ }
221
+ if (!isRemoteConnector(entry.config)) return isConnectorAuthenticated(pluginName, connectorName)
222
+ const key = `${pluginName}::${connectorName}`
223
+ return readMcpToolsState()[key]?.verifiedRemoteConfig === remoteConfigFingerprint(entry.config)
180
224
  }
181
225
 
182
226
  export const getPluginConnectors = listConnectors
@@ -204,6 +248,7 @@ export function substitutePluginRoot(val, pluginRoot) {
204
248
  export function registerConnector(pluginName, connectorName, connectorConfig) {
205
249
  const patch = readCordisPatch()
206
250
  const id = getConnectorId(pluginName, connectorName)
251
+ const existingEntry = patch.flatMap((item) => item?.insert || []).find((item) => item?.id === id)
207
252
  const pluginRoot = installedDir(pluginName)
208
253
  const resolvedConfig = substitutePluginRoot(connectorConfig, pluginRoot)
209
254
 
@@ -215,7 +260,7 @@ export function registerConnector(pluginName, connectorName, connectorConfig) {
215
260
 
216
261
  insertBlock.insert = insertBlock.insert.filter((item) => item && item.id !== id)
217
262
 
218
- const isHttp = resolvedConfig.type === 'http' || resolvedConfig.type === 'sse' || (!resolvedConfig.command && (!!resolvedConfig.url || !resolvedConfig.args?.length))
263
+ const isHttp = connectorTransport(resolvedConfig.type || resolvedConfig.transport, resolvedConfig.url, resolvedConfig.command) === 'http'
219
264
  if (isHttp && (!resolvedConfig.url || !resolvedConfig.url.trim() || !/^https?:\/\//i.test(resolvedConfig.url.trim()))) {
220
265
  return { ok: false, connected: false, error: '缺少有效的服务 URL' }
221
266
  }
@@ -246,6 +291,13 @@ export function registerConnector(pluginName, connectorName, connectorConfig) {
246
291
  export function unregisterConnector(pluginName, connectorName) {
247
292
  const patch = readCordisPatch()
248
293
  const id = getConnectorId(pluginName, connectorName)
294
+ const remote = remoteConfigFromEntry(getConnectorEntry(pluginName, connectorName)?.config)
295
+ if (remote) {
296
+ const key = `${pluginName}::${connectorName}`
297
+ const state = readMcpToolsState()
298
+ state[key] = { ...(state[key] || {}), savedOAuthRemoteConfig: remote }
299
+ writeMcpToolsState(state)
300
+ }
249
301
 
250
302
  for (const item of patch) {
251
303
  if (item && Array.isArray(item.insert)) {
@@ -907,6 +959,18 @@ export function toggleConnector(pluginName, connectorName, enabled) {
907
959
  const found = connectors.find((c) => c.name === connectorName) || { name: connectorName }
908
960
 
909
961
  if (enabled) {
962
+ const entry = getConnectorEntry(pluginName, connectorName)
963
+ const remote = remoteConfigFromEntry(entry?.config) || readMcpToolsState()[`${pluginName}::${connectorName}`]?.savedOAuthRemoteConfig
964
+ if (remote && isOAuthMode(remote.oauth)) {
965
+ const saved = remoteConfigFromEntry(entry?.config) ? entry.config : {
966
+ command: process.execPath, args: [OAUTH_BRIDGE_PATH],
967
+ env: { UPH_OAUTH_STORE_DIR: oauthStoreDir(), UPH_MCP_REMOTE_CONFIG: encodeOAuthConfig(oauthRuntimeConfig({
968
+ ...remote, credentialKey: oauthCredentialKey(pluginName, connectorName, remote.url, remote.oauth),
969
+ oauth: { mode: remote.oauth, clientId: remote.oauthClientId, callbackPort: remote.oauthCallbackPort, scope: remote.oauthScope },
970
+ })) },
971
+ }
972
+ return registerConnector(pluginName, connectorName, { ...remote, type: 'stdio', command: saved.command, args: saved.args, env: saved.env })
973
+ }
910
974
  if (connectorRequiresAuth(found) && !isConnectorAuthenticated(pluginName, connectorName)) {
911
975
  throw new Error(`请先验证并配置 ${connectorName} 的授权访问 Token`)
912
976
  }
@@ -927,7 +991,26 @@ export async function verifyConnectorAuth(pluginName, connectorName, payload) {
927
991
  const url = (typeof payload === 'object' && payload?.url) || found?.url || (connectorName === 'notion' ? 'https://mcp.notion.com/mcp' : null)
928
992
  const command = (typeof payload === 'object' && payload?.command) || found?.command || null
929
993
 
994
+ if (transport !== 'stdio' && url && isOAuthMode(payload?.oauth)) {
995
+ setRemoteVerification(pluginName, connectorName, payload, false)
996
+ try {
997
+ saveCustomOAuthClient(pluginName, connectorName, payload)
998
+ const session = beginOAuthVerification(pluginName, connectorName, { ...payload, url }, {
999
+ onFinished: (result) => setRemoteVerification(pluginName, connectorName, payload, result.ok === true),
1000
+ })
1001
+ const result = await Promise.race([
1002
+ completeOAuthVerification(session),
1003
+ new Promise((resolve) => setTimeout(() => resolve({ pending: true, sessionId: session.id, status: session.status, message: session.message || '正在准备 OAuth 授权…' }), 250)),
1004
+ ])
1005
+ setRemoteVerification(pluginName, connectorName, payload, result.ok === true)
1006
+ return { ...result, server: connectorName, transport: 'http', endpoint: url, statusCode: result.statusCode ?? result.status }
1007
+ } catch (error) {
1008
+ return { ok: false, message: error.message, server: connectorName, transport: 'http', endpoint: url }
1009
+ }
1010
+ }
1011
+
930
1012
  if (transport === 'stdio') {
1013
+ setRemoteVerification(pluginName, connectorName, payload, false)
931
1014
  if (found && found.url && !command) {
932
1015
  return {
933
1016
  ok: false,
@@ -963,6 +1046,7 @@ export async function verifyConnectorAuth(pluginName, connectorName, payload) {
963
1046
  }
964
1047
  }
965
1048
  if (!url) {
1049
+ setRemoteVerification(pluginName, connectorName, payload, false)
966
1050
  return {
967
1051
  ok: false,
968
1052
  message: '请输入有效的服务 URL',
@@ -983,6 +1067,7 @@ export async function verifyConnectorAuth(pluginName, connectorName, payload) {
983
1067
  }
984
1068
 
985
1069
  const startTime = Date.now()
1070
+ let result
986
1071
  try {
987
1072
  const controller = new AbortController()
988
1073
  const timer = setTimeout(() => controller.abort(), 8000)
@@ -995,7 +1080,7 @@ export async function verifyConnectorAuth(pluginName, connectorName, payload) {
995
1080
 
996
1081
  const duration = Date.now() - startTime
997
1082
  if (res.status === 200) {
998
- return {
1083
+ result = {
999
1084
  ok: true,
1000
1085
  message: '验证成功!已连接到 MCP 远程服务并激活权限。',
1001
1086
  server: connectorName,
@@ -1014,7 +1099,7 @@ export async function verifyConnectorAuth(pluginName, connectorName, payload) {
1014
1099
  userFriendly = `认证未通过:缺少访问令牌 (Access Token) 或需要 OAuth 授权`
1015
1100
  }
1016
1101
  }
1017
- return {
1102
+ result = {
1018
1103
  ok: false,
1019
1104
  message: userFriendly,
1020
1105
  server: connectorName,
@@ -1028,7 +1113,7 @@ export async function verifyConnectorAuth(pluginName, connectorName, payload) {
1028
1113
  } catch (e) {
1029
1114
  const duration = Date.now() - startTime
1030
1115
  if (e.name === 'AbortError') {
1031
- return {
1116
+ result = {
1032
1117
  ok: false,
1033
1118
  message: '连接超时(8 秒未响应),请检查服务 URL 与网络',
1034
1119
  server: connectorName,
@@ -1038,7 +1123,7 @@ export async function verifyConnectorAuth(pluginName, connectorName, payload) {
1038
1123
  duration,
1039
1124
  }
1040
1125
  }
1041
- return {
1126
+ result = {
1042
1127
  ok: false,
1043
1128
  message: `连接异常:${e.message}`,
1044
1129
  server: connectorName,
@@ -1048,6 +1133,8 @@ export async function verifyConnectorAuth(pluginName, connectorName, payload) {
1048
1133
  duration,
1049
1134
  }
1050
1135
  }
1136
+ setRemoteVerification(pluginName, connectorName, { transport, url, headers: reqHeaders, oauth: payload?.oauth }, result.ok === true)
1137
+ return result
1051
1138
  }
1052
1139
 
1053
1140
  export function saveConnectorAuth(pluginName, connectorName, payload) {
@@ -1062,6 +1149,7 @@ export function saveConnectorAuth(pluginName, connectorName, payload) {
1062
1149
  let customEnv = typeof payload === 'object' && payload?.env ? { ...payload.env } : { ...(found.env || {}) }
1063
1150
  let customArgs = typeof payload === 'object' && Array.isArray(payload?.args) ? payload.args : (found.args || [])
1064
1151
  let oauth = typeof payload === 'object' && payload?.oauth ? payload.oauth : 'none'
1152
+ if (isOAuthMode(oauth)) token = ''
1065
1153
 
1066
1154
  if (token && token.trim()) {
1067
1155
  const authVal = token.trim().startsWith('Bearer ') ? token.trim() : `Bearer ${token.trim()}`
@@ -1079,7 +1167,7 @@ export function saveConnectorAuth(pluginName, connectorName, payload) {
1079
1167
  }
1080
1168
 
1081
1169
  const isStdio = (transport === 'stdio')
1082
- const result = registerConnector(pluginName, connectorName, {
1170
+ let registration = {
1083
1171
  ...found,
1084
1172
  type: isStdio ? 'stdio' : (transport === 'sse' ? 'sse' : 'http'),
1085
1173
  url: isStdio ? null : (url || found.url || null),
@@ -1088,11 +1176,41 @@ export function saveConnectorAuth(pluginName, connectorName, payload) {
1088
1176
  env: { ...baseEnv, ...customEnv },
1089
1177
  headers: { ...baseHeaders, ...customHeaders },
1090
1178
  oauth: isStdio ? 'none' : oauth,
1091
- })
1092
- // Re-auth (or transport switch) changes which remote the connector talks to.
1093
- // The cached tool list was captured against the old connection, so drop it
1094
- // here — fetchConnectorTools will repopulate on the next list call.
1179
+ }
1180
+ if (!isStdio && isOAuthMode(oauth)) {
1181
+ saveCustomOAuthClient(pluginName, connectorName, payload)
1182
+ const credentialKey = oauthCredentialKey(pluginName, connectorName, url, oauth)
1183
+ const remote = oauthRuntimeConfig({
1184
+ url, headers: customHeaders, credentialKey,
1185
+ oauth: {
1186
+ mode: oauth, clientId: payload.oauthClientId || '', callbackPort: Number(payload.oauthCallbackPort) || null,
1187
+ scope: payload.oauthScope || '',
1188
+ },
1189
+ })
1190
+ registration = {
1191
+ type: 'stdio', command: process.execPath, args: [OAUTH_BRIDGE_PATH],
1192
+ env: { UPH_MCP_REMOTE_CONFIG: encodeOAuthConfig(remote), UPH_OAUTH_STORE_DIR: oauthStoreDir() },
1193
+ }
1194
+ }
1195
+ const result = registerConnector(pluginName, connectorName, registration)
1095
1196
  const toolsKey = `${pluginName}::${connectorName}`
1197
+ if (result.ok && !isStdio) {
1198
+ const verifiedConfig = { transport, url, headers: customHeaders, oauth, oauthClientId: payload.oauthClientId || '', oauthScope: payload.oauthScope || '', oauthCallbackPort: payload.oauthCallbackPort }
1199
+ const savedState = readMcpToolsState()
1200
+ savedState[toolsKey] = { ...(savedState[toolsKey] || {}), savedOAuthRemoteConfig: isOAuthMode(oauth) ? remoteConfigFromEntry(registration.env ? { env: registration.env } : {}) : undefined }
1201
+ if (!isOAuthMode(oauth)) delete savedState[toolsKey].savedOAuthRemoteConfig
1202
+ writeMcpToolsState(savedState)
1203
+ if (savedState[toolsKey]?.verifiedRemoteConfig !== remoteConfigFingerprint(verifiedConfig)) {
1204
+ setRemoteVerification(pluginName, connectorName, verifiedConfig, false)
1205
+ }
1206
+ }
1207
+ if (result.ok) {
1208
+ const savedState = readMcpToolsState()
1209
+ if (savedState[toolsKey]) {
1210
+ delete savedState[toolsKey].cachedTools
1211
+ writeMcpToolsState(savedState)
1212
+ }
1213
+ }
1096
1214
  if (MEMORY_TOOLS_CACHE.has(toolsKey)) {
1097
1215
  const mem = MEMORY_TOOLS_CACHE.get(toolsKey)
1098
1216
  MEMORY_TOOLS_CACHE.set(toolsKey, { ...mem, tools: [], disabledTools: mem.disabledTools || [] })
@@ -1170,7 +1288,7 @@ function quoteArgForShell(value) {
1170
1288
  * an (possibly empty) tool list, so callers can tell "no tools" from "the
1171
1289
  * probe never reached the server".
1172
1290
  */
1173
- function queryStdioToolsList(cmd, args, extraEnv = {}) {
1291
+ export function queryStdioToolsList(cmd, args, extraEnv = {}) {
1174
1292
  return new Promise((resolve) => {
1175
1293
  const argv = Array.isArray(args) ? args : []
1176
1294
  const useShell = SHELL_COMMANDS.test(String(cmd).trim())
@@ -1195,10 +1313,12 @@ function queryStdioToolsList(cmd, args, extraEnv = {}) {
1195
1313
  let stderr = ''
1196
1314
  let answered = false
1197
1315
  let settled = false
1316
+ let timer
1198
1317
 
1199
1318
  const finish = (tools, error) => {
1200
1319
  if (settled) return
1201
1320
  settled = true
1321
+ clearTimeout(timer)
1202
1322
  try { cp.kill() } catch {}
1203
1323
  resolve({ tools: tools || [], error: tools ? null : error })
1204
1324
  }
@@ -1207,7 +1327,9 @@ function queryStdioToolsList(cmd, args, extraEnv = {}) {
1207
1327
 
1208
1328
  cp.stdout.on('data', (d) => {
1209
1329
  output += d.toString()
1210
- for (const line of output.split('\n')) {
1330
+ const lines = output.split('\n')
1331
+ output = lines.pop() || ''
1332
+ for (const line of lines) {
1211
1333
  if (!line.trim()) continue
1212
1334
  try {
1213
1335
  const json = JSON.parse(line.trim())
@@ -1216,6 +1338,11 @@ function queryStdioToolsList(cmd, args, extraEnv = {}) {
1216
1338
  finish(json.result.tools, null)
1217
1339
  return
1218
1340
  }
1341
+ if (json.id === 0 && json.result) {
1342
+ cp.stdin.write(JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' }) + '\n')
1343
+ cp.stdin.write(toolsReq)
1344
+ }
1345
+ if (json.id === 0 && json.error) finish([], json.error.message || 'MCP initialize failed')
1219
1346
  } catch {}
1220
1347
  }
1221
1348
  })
@@ -1245,16 +1372,9 @@ function queryStdioToolsList(cmd, args, extraEnv = {}) {
1245
1372
 
1246
1373
  try {
1247
1374
  cp.stdin.write(initReq)
1248
- setTimeout(() => {
1249
- if (!settled) {
1250
- try {
1251
- cp.stdin.write(toolsReq)
1252
- } catch {}
1253
- }
1254
- }, 300)
1255
1375
  } catch {}
1256
1376
 
1257
- setTimeout(() => {
1377
+ timer = setTimeout(() => {
1258
1378
  if (!settled) {
1259
1379
  const detail = stderr.trim().split('\n').filter(Boolean).slice(-2).join(' ')
1260
1380
  finish([], detail || 'MCP 服务在 25 秒内没有返回工具列表')
@@ -1289,8 +1409,9 @@ export async function fetchConnectorTools(pluginName, connectorName, forceFresh
1289
1409
  return { ok: true, tools: cached, disabledTools }
1290
1410
  }
1291
1411
 
1292
- const transport = entryCfg.transport === 'stdio' ? 'stdio' : (found?.type === 'stdio' ? 'stdio' : 'http')
1293
- const url = entryCfg.url || found?.url
1412
+ const transport = entryCfg.transport || (found?.type === 'stdio' ? 'stdio' : 'http')
1413
+ const remote = remoteConfigFromEntry(entryCfg)
1414
+ const url = remote?.url || entryCfg.url || found?.url
1294
1415
  const headers = entryCfg.headers || found?.headers || {}
1295
1416
 
1296
1417
  // Nothing to connect to (unknown server, or a config with neither URL nor
@@ -1357,7 +1478,7 @@ export async function fetchConnectorTools(pluginName, connectorName, forceFresh
1357
1478
  if (cmd) {
1358
1479
  try {
1359
1480
  const probe = await queryStdioToolsList(cmd, args, entryCfg.env || found?.env || {})
1360
- if (probe.tools.length > 0) {
1481
+ if (probe.tools.length > 0 || !probe.error) {
1361
1482
  if (!state[key]) state[key] = { disabledTools, cachedTools: [] }
1362
1483
  state[key].cachedTools = probe.tools
1363
1484
  writeMcpToolsState(state)
@@ -1685,7 +1806,7 @@ export async function installPlugin({ sourceId, pluginName, refresh = false }) {
1685
1806
  }
1686
1807
  for (const c of pluginConnectors) {
1687
1808
  if (!connectorRequiresAuth(c)) {
1688
- const isHttp = (c.type === 'http' || c.type === 'sse' || (!c.command && (!!c.url || !c.args?.length)))
1809
+ const isHttp = (connectorTransport(c.type, c.url, c.command) === 'http')
1689
1810
  if (isHttp && (!c.url || !c.url.trim() || !/^https?:\/\//i.test(c.url.trim()))) {
1690
1811
  continue
1691
1812
  }
@@ -1866,7 +1987,7 @@ export async function updatePlugin(pluginName) {
1866
1987
  if (!rec) throw new Error(`plugin not installed: ${pluginName}`)
1867
1988
  const source = state.sources.find((s) => s.id === rec.sourceId)
1868
1989
  if (source && typeof source.url === 'string') {
1869
- const cacheDir = join(marketRoot(), 'market', rec.sourceId)
1990
+ const cacheDir = sourceCacheDir(rec.sourceId)
1870
1991
  if (existsSync(join(cacheDir, '.git'))) {
1871
1992
  await pullSource(rec.sourceId)
1872
1993
  }
@@ -1894,6 +2015,19 @@ export async function findMarketRow(sourceId, pluginName) {
1894
2015
  return rows.find((r) => r.name === pluginName) ?? null
1895
2016
  }
1896
2017
 
2018
+ /**
2019
+ * Author from the source's live marketplace row. Used as the last fallback for
2020
+ * installed records written before the reader merged each plugin's own
2021
+ * manifest (`author: null`). Returns null when the row or its author is absent.
2022
+ */
2023
+ function findMarketRowAuthor(sourceId, pluginName) {
2024
+ try {
2025
+ return readMarketplace(sourceId).find((r) => r.name === pluginName)?.author ?? null
2026
+ } catch {
2027
+ return null
2028
+ }
2029
+ }
2030
+
1897
2031
  /** Re-exported for routes: list installed plugins with details. */
1898
2032
  export function installedDetails() {
1899
2033
  const state = readState()
@@ -1931,11 +2065,13 @@ export function installedDetails() {
1931
2065
  const connected = isConnectorActive(rec.name, c.name)
1932
2066
  const savedEntry = getConnectorEntry(rec.name, c.name)
1933
2067
  const savedConfig = savedEntry?.config || {}
1934
- const savedHeaders = (savedConfig.headers && Object.keys(savedConfig.headers).length > 0) ? savedConfig.headers : c.headers
1935
- const savedEnv = (savedConfig.env && Object.keys(savedConfig.env).length > 0) ? savedConfig.env : c.env
1936
- const savedUrl = savedConfig.url || c.url
1937
- const savedArgs = (savedConfig.args && savedConfig.args.length > 0) ? savedConfig.args : c.args
1938
- const savedTransport = savedConfig.transport ? (savedConfig.transport === 'streamable-http' ? 'http' : (savedConfig.transport === 'stdio' ? 'stdio' : c.type)) : c.type
2068
+ const remote = remoteConfigFromEntry(savedConfig) || (!savedEntry ? readMcpToolsState()[`${rec.name}::${c.name}`]?.savedOAuthRemoteConfig : null)
2069
+ const savedHeaders = remote ? remote.headers : ((savedConfig.headers && Object.keys(savedConfig.headers).length > 0) ? savedConfig.headers : c.headers)
2070
+ const savedEnv = remote ? {} : ((savedConfig.env && Object.keys(savedConfig.env).length > 0) ? savedConfig.env : c.env)
2071
+ const savedUrl = remote ? remote.url : (savedConfig.url || c.url)
2072
+ const savedArgs = remote ? [] : ((savedConfig.args && savedConfig.args.length > 0) ? savedConfig.args : c.args)
2073
+ const savedTransport = remote ? 'http' : connectorTransport(savedConfig.transport || savedConfig.type, savedUrl, savedConfig.command || c.command)
2074
+ const savedClient = remote?.oauth === 'custom' ? readSavedOAuthClient(rec.name, c.name, savedUrl, remote.oauth) : null
1939
2075
 
1940
2076
  return {
1941
2077
  ...c,
@@ -1944,9 +2080,14 @@ export function installedDetails() {
1944
2080
  headers: savedHeaders,
1945
2081
  env: savedEnv,
1946
2082
  args: savedArgs,
1947
- oauth: savedConfig.oauth || c.oauth || 'none',
2083
+ oauth: remote?.oauth || savedConfig.oauth || c.oauth || 'none',
2084
+ oauthClientId: savedClient?.clientId || '',
2085
+ oauthHasClientSecret: savedClient?.hasClientSecret || false,
2086
+ oauthCallbackPort: remote?.oauthCallbackPort || '',
2087
+ oauthScope: remote?.oauthScope || '',
1948
2088
  needsAuth,
1949
2089
  authenticated,
2090
+ enabled: !!savedEntry,
1950
2091
  connected,
1951
2092
  }
1952
2093
  }) : []
@@ -1992,8 +2133,17 @@ export function installedDetails() {
1992
2133
  const missingCommand = !active && !!s.command && !resolveCommandPath(s.command)
1993
2134
  return { ...s, active, missingCommand }
1994
2135
  })
2136
+ const targetManifest = existsSync(target) ? readPluginManifest(target) : null
2137
+ // Author: the state record is written at install time, so installs made
2138
+ // before the marketplace reader learned to merge a plugin's own manifest
2139
+ // carry `author: null` forever. Fall back to the installed copy's manifest,
2140
+ // then to the live marketplace row, so those records self-heal on read.
2141
+ const manifestAuthor = targetManifest?.author
2142
+ ? (typeof targetManifest.author === 'string' ? targetManifest.author : targetManifest.author.name)
2143
+ : null
2144
+ const author = rec.author || manifestAuthor || findMarketRowAuthor(rec.sourceId, rec.name)
1995
2145
  const detail = existsSync(target) ? {
1996
- icons: buildPluginIcons(readPluginManifest(target), { sourceId: rec.sourceId, name: rec.name, dir: target }),
2146
+ icons: buildPluginIcons(targetManifest, { sourceId: rec.sourceId, name: rec.name, dir: target }),
1997
2147
  skills: listSkills(target),
1998
2148
  agents: listAgents(target),
1999
2149
  prompts: listPrompts(target),
@@ -2005,6 +2155,7 @@ export function installedDetails() {
2005
2155
  return {
2006
2156
  ...rec,
2007
2157
  ...detail,
2158
+ author: author || rec.author,
2008
2159
  skillCount: detail.skills.length,
2009
2160
  agentCount: detail.agents.length,
2010
2161
  promptCount: detail.prompts.length,