universal-plugin-hub 1.0.50 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/client.js +311 -10
- package/package.json +1 -1
- package/src/index.js +2 -2
- package/src/install.js +315 -89
- package/src/oauth-bridge.js +8 -3
- package/src/oauth-store.js +60 -10
- package/src/oauth.js +28 -2
- package/src/parser.js +37 -26
- package/src/routes.js +20 -5
- package/src/store.js +23 -4
package/src/oauth-bridge.js
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
PromptListChangedNotificationSchema,
|
|
16
16
|
} from '@modelcontextprotocol/sdk/types.js'
|
|
17
17
|
import { decodeOAuthConfig } from './oauth-config.js'
|
|
18
|
-
import {
|
|
18
|
+
import { openOAuthRecordWriter, readOAuthRecord } from './oauth-store.js'
|
|
19
19
|
|
|
20
20
|
const interactive = process.env.UPH_MCP_INTERACTIVE === '1'
|
|
21
21
|
const verifying = process.env.UPH_MCP_VERIFY === '1'
|
|
@@ -102,8 +102,13 @@ function waitForCallback() {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
function provider() {
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
const writer = openOAuthRecordWriter(config.credentialKey)
|
|
106
|
+
if (!writer) throw new Error('OAuth 授权已移除,请重新登录。')
|
|
107
|
+
process.once('exit', () => { try { writer.close() } catch {} })
|
|
108
|
+
const record = readOAuthRecord(config.credentialKey)
|
|
109
|
+
const persist = () => {
|
|
110
|
+
if (!writer.write(record)) throw new Error('OAuth 授权已移除,请重新登录。')
|
|
111
|
+
}
|
|
107
112
|
const callback = callbackUrl || record.clientInformation?.redirect_uris?.[0] || `http://localhost:${config.oauth.callbackPort || 0}/callback`
|
|
108
113
|
const custom = config.oauth.mode === 'custom' ? record.customClient : undefined
|
|
109
114
|
return {
|
package/src/oauth-store.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'
|
|
1
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'
|
|
2
2
|
import { dirname, join } from 'node:path'
|
|
3
3
|
import { execFileSync } from 'node:child_process'
|
|
4
4
|
import { randomBytes } from 'node:crypto'
|
|
@@ -52,22 +52,62 @@ export function readOAuthRecord(key) {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
const file = oauthCredentialPath(key)
|
|
57
|
-
mkdirSync(dirname(file), { recursive: true, mode: 0o700 })
|
|
55
|
+
function writeRecord(file, record, stagingDir) {
|
|
58
56
|
const plainText = JSON.stringify(record)
|
|
59
57
|
const stored = process.platform === 'win32'
|
|
60
58
|
? { version: 1, dpapi: true, data: protectDpapi(plainText) }
|
|
61
59
|
: JSON.parse(plainText)
|
|
62
|
-
const tmp = join(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
const tmp = join(stagingDir, `.${process.pid}.${randomBytes(8).toString('hex')}.tmp`)
|
|
61
|
+
try {
|
|
62
|
+
writeFileSync(tmp, JSON.stringify(stored), { mode: 0o600 })
|
|
63
|
+
renameSync(tmp, file)
|
|
64
|
+
} finally {
|
|
65
|
+
rmSync(tmp, { force: true })
|
|
66
|
+
}
|
|
66
67
|
// Seed the read cache with what was just written: no pwsh round trip, and a
|
|
67
68
|
// concurrent reader can never see the previous version.
|
|
68
69
|
RECORD_CACHE.set(file, { raw: JSON.stringify(stored), record })
|
|
69
70
|
}
|
|
70
71
|
|
|
72
|
+
export function allowOAuthRecordWrites(key) {
|
|
73
|
+
rmSync(`${oauthCredentialPath(key)}.revoked`, { force: true })
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function writeOAuthRecord(key, record) {
|
|
77
|
+
const file = oauthCredentialPath(key)
|
|
78
|
+
mkdirSync(dirname(file), { recursive: true, mode: 0o700 })
|
|
79
|
+
allowOAuthRecordWrites(key)
|
|
80
|
+
writeRecord(file, record, dirname(file))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** A running bridge can publish only while its private staging directory exists. */
|
|
84
|
+
export function openOAuthRecordWriter(key) {
|
|
85
|
+
const file = oauthCredentialPath(key)
|
|
86
|
+
const revoked = `${file}.revoked`
|
|
87
|
+
if (existsSync(revoked)) return null
|
|
88
|
+
const root = `${file}.writers`
|
|
89
|
+
mkdirSync(root, { recursive: true, mode: 0o700 })
|
|
90
|
+
const directory = mkdtempSync(join(root, 'bridge-'))
|
|
91
|
+
const close = () => rmSync(directory, { recursive: true, force: true })
|
|
92
|
+
if (existsSync(revoked)) {
|
|
93
|
+
close()
|
|
94
|
+
return null
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
write(record) {
|
|
98
|
+
if (!existsSync(directory) || existsSync(revoked)) return false
|
|
99
|
+
try {
|
|
100
|
+
writeRecord(file, record, directory)
|
|
101
|
+
return true
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (error.code === 'ENOENT' && !existsSync(directory)) return false
|
|
104
|
+
throw error
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
close,
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
71
111
|
export function saveOAuthClientCredentials(key, client) {
|
|
72
112
|
const record = readOAuthRecord(key)
|
|
73
113
|
const sameClient = record.customClient?.client_id === String(client.clientId || '').trim()
|
|
@@ -90,8 +130,18 @@ export function saveOAuthClientCredentials(key, client) {
|
|
|
90
130
|
* removed: leaving the file behind would resurrect a stale sign-in if a server
|
|
91
131
|
* of the same name were added again with the same URL and OAuth mode.
|
|
92
132
|
*/
|
|
93
|
-
export function deleteOAuthRecord(key) {
|
|
133
|
+
export function deleteOAuthRecord(key, { required = false, ifPresent = false } = {}) {
|
|
94
134
|
const file = oauthCredentialPath(key)
|
|
95
135
|
RECORD_CACHE.delete(file)
|
|
96
|
-
try {
|
|
136
|
+
try {
|
|
137
|
+
if (ifPresent && !existsSync(file) && !existsSync(`${file}.writers`)) return
|
|
138
|
+
// Block new bridges first. Removing the old bridges' staging directories
|
|
139
|
+
// prevents even a refresh already in progress from publishing after cleanup.
|
|
140
|
+
mkdirSync(dirname(file), { recursive: true, mode: 0o700 })
|
|
141
|
+
writeFileSync(`${file}.revoked`, '', { mode: 0o600 })
|
|
142
|
+
rmSync(`${file}.writers`, { recursive: true, force: true, maxRetries: 3, retryDelay: 50 })
|
|
143
|
+
rmSync(file, { force: true })
|
|
144
|
+
} catch (error) {
|
|
145
|
+
if (required) throw error
|
|
146
|
+
}
|
|
97
147
|
}
|
package/src/oauth.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process'
|
|
2
2
|
import { fileURLToPath } from 'node:url'
|
|
3
3
|
import { encodeOAuthConfig, oauthCredentialKey, oauthRuntimeConfig, remoteConfigFromEntry } from './oauth-config.js'
|
|
4
|
-
import { readOAuthRecord, oauthStoreDir, saveOAuthClientCredentials } from './oauth-store.js'
|
|
4
|
+
import { allowOAuthRecordWrites, readOAuthRecord, oauthStoreDir, saveOAuthClientCredentials } from './oauth-store.js'
|
|
5
5
|
|
|
6
6
|
const sessions = new Map()
|
|
7
7
|
const bridgePath = fileURLToPath(new URL('./oauth-bridge.js', import.meta.url))
|
|
@@ -107,6 +107,7 @@ function startProcess(session) {
|
|
|
107
107
|
|
|
108
108
|
export function beginOAuthVerification(pluginName, connectorName, payload, options = {}) {
|
|
109
109
|
const credentialKey = oauthCredentialKey(pluginName, connectorName, payload.url, payload.oauth)
|
|
110
|
+
allowOAuthRecordWrites(credentialKey)
|
|
110
111
|
const config = oauthRuntimeConfig({
|
|
111
112
|
url: payload.url, headers: payload.headers,
|
|
112
113
|
oauth: connectorOauthSettings(pluginName, connectorName, payload), credentialKey,
|
|
@@ -117,7 +118,8 @@ export function beginOAuthVerification(pluginName, connectorName, payload, optio
|
|
|
117
118
|
let resolve
|
|
118
119
|
const completion = new Promise((r) => { resolve = r })
|
|
119
120
|
const session = {
|
|
120
|
-
id, pluginName, connectorName, credentialKey, config,
|
|
121
|
+
id, pluginName, connectorName, credentialKey, config, pluginOwned: options.pluginOwned,
|
|
122
|
+
status: 'starting', startedAt: Date.now(), resolve, completion,
|
|
121
123
|
noBrowser: options.noBrowser || process.env.UPH_MCP_NO_BROWSER === '1', callbackTimeout: options.callbackTimeout, onFinished: options.onFinished,
|
|
122
124
|
timeout: setTimeout(() => cancelOAuthVerification(id, '授权等待超时,请重新测试'), options.callbackTimeout || CALLBACK_TIMEOUT),
|
|
123
125
|
}
|
|
@@ -151,6 +153,30 @@ export function cancelAllOAuthVerifications() {
|
|
|
151
153
|
for (const session of sessions.values()) if (!session.done) cancelOAuthVerification(session.id)
|
|
152
154
|
}
|
|
153
155
|
|
|
156
|
+
/** Stop pending verification for a plugin before removing its credentials. */
|
|
157
|
+
export function cancelPluginOAuthVerifications(pluginName, ownsConnector = () => true) {
|
|
158
|
+
const pending = []
|
|
159
|
+
for (const session of sessions.values()) {
|
|
160
|
+
if (session.pluginName !== pluginName) continue
|
|
161
|
+
if (pluginName === 'user-mcp' && (!session.pluginOwned || !ownsConnector(session.connectorName))) continue
|
|
162
|
+
session.cancelled = true
|
|
163
|
+
const child = session.child
|
|
164
|
+
if (child?.pid && child.exitCode === null && child.signalCode === null) {
|
|
165
|
+
pending.push(new Promise(resolve => child.once('close', resolve)))
|
|
166
|
+
// Do not leave the callback or a token exchange running during cleanup.
|
|
167
|
+
child.kill('SIGKILL')
|
|
168
|
+
}
|
|
169
|
+
finish(session, { ok: false, message: '插件已卸载,授权已取消' })
|
|
170
|
+
}
|
|
171
|
+
return pending.length ? Promise.all(pending) : null
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function standaloneOAuthConnectorNames() {
|
|
175
|
+
return [...sessions.values()]
|
|
176
|
+
.filter(session => session.pluginName === 'user-mcp' && !session.pluginOwned)
|
|
177
|
+
.map(session => session.connectorName)
|
|
178
|
+
}
|
|
179
|
+
|
|
154
180
|
export function oauthSessionStatusUrl(pluginName, connectorName, sessionId, userMcp = false) {
|
|
155
181
|
return userMcp
|
|
156
182
|
? `/mcps/oauth-status?sessionId=${encodeURIComponent(sessionId)}`
|
package/src/parser.js
CHANGED
|
@@ -123,13 +123,16 @@ function normalizeRow(row, sourceId, dir) {
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
const MARKETPLACE_CACHE = new Map()
|
|
126
|
+
const MARKETPLACE_SELECTION_CACHE = new Map()
|
|
126
127
|
const MARKETPLACE_CACHE_TTL = 30000 // 30 seconds
|
|
127
128
|
|
|
128
129
|
export function invalidateMarketplaceCache(sourceId) {
|
|
129
130
|
if (sourceId) {
|
|
130
131
|
MARKETPLACE_CACHE.delete(sourceId)
|
|
132
|
+
MARKETPLACE_SELECTION_CACHE.delete(sourceId)
|
|
131
133
|
} else {
|
|
132
134
|
MARKETPLACE_CACHE.clear()
|
|
135
|
+
MARKETPLACE_SELECTION_CACHE.clear()
|
|
133
136
|
}
|
|
134
137
|
}
|
|
135
138
|
|
|
@@ -137,7 +140,7 @@ export function invalidateMarketplaceCache(sourceId) {
|
|
|
137
140
|
* Universal Marketplace Reader.
|
|
138
141
|
* Inspects a source repository cache and extracts all discoverable plugins.
|
|
139
142
|
*/
|
|
140
|
-
export function readMarketplace(sourceId) {
|
|
143
|
+
export function readMarketplace(sourceId, names) {
|
|
141
144
|
safeSegment(sourceId, 'source id')
|
|
142
145
|
const cache = sourceCacheDir(sourceId)
|
|
143
146
|
if (!existsSync(cache)) return []
|
|
@@ -145,9 +148,17 @@ export function readMarketplace(sourceId) {
|
|
|
145
148
|
const now = Date.now()
|
|
146
149
|
const cached = MARKETPLACE_CACHE.get(sourceId)
|
|
147
150
|
if (cached && (now - cached.time < MARKETPLACE_CACHE_TTL)) {
|
|
148
|
-
return cached.data
|
|
151
|
+
return names ? cached.data.filter(row => names.has(row.name)) : cached.data
|
|
149
152
|
}
|
|
150
153
|
|
|
154
|
+
if (names) {
|
|
155
|
+
const key = JSON.stringify([...names].sort())
|
|
156
|
+
const selection = MARKETPLACE_SELECTION_CACHE.get(sourceId)
|
|
157
|
+
if (selection?.key === key && now - selection.time < MARKETPLACE_CACHE_TTL) return selection.data
|
|
158
|
+
const data = parseMarketplaceFromDisk(sourceId, cache, names).filter(row => names.has(row.name))
|
|
159
|
+
MARKETPLACE_SELECTION_CACHE.set(sourceId, { key, time: now, data })
|
|
160
|
+
return data
|
|
161
|
+
}
|
|
151
162
|
const rows = parseMarketplaceFromDisk(sourceId, cache)
|
|
152
163
|
MARKETPLACE_CACHE.set(sourceId, { time: now, data: rows })
|
|
153
164
|
return rows
|
|
@@ -198,7 +209,7 @@ export function parsePluginRowFromDir(entryDir, fallbackName, sourceId) {
|
|
|
198
209
|
}, sourceId, entryDir)
|
|
199
210
|
}
|
|
200
211
|
|
|
201
|
-
export function parseMarketplaceFromDisk(sourceId, cache) {
|
|
212
|
+
export function parseMarketplaceFromDisk(sourceId, cache, names) {
|
|
202
213
|
// 1. Check Multi-Plugin Manifest Candidates
|
|
203
214
|
const manifestCandidates = [
|
|
204
215
|
join(cache, '.claude-plugin', 'marketplace.json'),
|
|
@@ -221,22 +232,26 @@ export function parseMarketplaceFromDisk(sourceId, cache) {
|
|
|
221
232
|
const content = JSON.parse(readFileSync(manifestPath, 'utf8'))
|
|
222
233
|
// Case A: Claude / standard manifest with plugins array
|
|
223
234
|
if (Array.isArray(content.plugins)) {
|
|
235
|
+
let skipped = false
|
|
224
236
|
const rows = content.plugins.map((r) => {
|
|
225
237
|
const source = r.source?.source === 'local' ? r.source.path : r.source
|
|
226
|
-
let
|
|
227
|
-
|
|
228
|
-
if (typeof source === 'string' && source.startsWith('./')) {
|
|
229
|
-
dir = pluginPath(cache, source)
|
|
230
|
-
} else if (source && typeof source === 'object' && r.name) {
|
|
238
|
+
let dir = typeof source === 'string' && source.startsWith('./') ? pluginPath(cache, source) : null
|
|
239
|
+
if (source && typeof source === 'object' && r.name) {
|
|
231
240
|
dir = sourceRepositoryDir(cache, source) || pluginContentDir(sourceId, r.name, source, false)
|
|
232
241
|
}
|
|
233
|
-
if (
|
|
242
|
+
if (names && typeof r.name === 'string' && !names.has(r.name.toLowerCase())) {
|
|
243
|
+
skipped = true
|
|
244
|
+
return null
|
|
245
|
+
}
|
|
246
|
+
const manifest = dir ? readPluginManifest(dir, false) : null
|
|
234
247
|
return normalizeRow({ ...manifest, ...r,
|
|
235
248
|
displayName: r.displayName || r.interface?.displayName || manifest?.displayName,
|
|
236
249
|
description: r.description || r.interface?.shortDescription || manifest?.description,
|
|
237
250
|
}, sourceId, dir)
|
|
238
251
|
}).filter(Boolean)
|
|
239
252
|
if (rows.length > 0) return rows
|
|
253
|
+
// Preserve manifest precedence and discovery fallbacks on a miss.
|
|
254
|
+
if (skipped) return parseMarketplaceFromDisk(sourceId, cache)
|
|
240
255
|
}
|
|
241
256
|
// Case B: Direct array of plugin descriptors
|
|
242
257
|
if (Array.isArray(content)) {
|
|
@@ -425,10 +440,12 @@ export function pluginContentDir(sourceId, pluginName, source, preferInstalled =
|
|
|
425
440
|
export function readPluginManifest(dir, includeParent = true) {
|
|
426
441
|
const rootManifest = join(dir, 'plugin.json')
|
|
427
442
|
let portable = false
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
443
|
+
if (existsSync(rootManifest)) {
|
|
444
|
+
try {
|
|
445
|
+
const root = JSON.parse(readFileSync(rootManifest, 'utf8'))
|
|
446
|
+
portable = /^https:\/\/agent-plugins\.org\//.test(root.$schema || '') || Boolean(root.extensions?.['com.openai'])
|
|
447
|
+
} catch {}
|
|
448
|
+
}
|
|
432
449
|
const candidates = [
|
|
433
450
|
join(dir, '.claude-plugin', 'plugin.json'),
|
|
434
451
|
...(portable ? [rootManifest] : []),
|
|
@@ -494,7 +511,7 @@ export function readPluginManifest(dir, includeParent = true) {
|
|
|
494
511
|
}
|
|
495
512
|
|
|
496
513
|
/** List skill & command directories/files (skills/*, commands/*, root SKILL.md, .cursor/rules). */
|
|
497
|
-
export function listSkills(dir) {
|
|
514
|
+
export function listSkills(dir, manifest = readPluginManifest(dir)) {
|
|
498
515
|
const out = []
|
|
499
516
|
const seen = new Set()
|
|
500
517
|
|
|
@@ -511,7 +528,6 @@ export function listSkills(dir) {
|
|
|
511
528
|
}
|
|
512
529
|
|
|
513
530
|
// 1. Check skills/ subdirectory
|
|
514
|
-
const manifest = readPluginManifest(dir)
|
|
515
531
|
const declaredSkills = typeof manifest?.skills === 'string' ? [manifest.skills] : (Array.isArray(manifest?.skills) ? manifest.skills.filter((s) => typeof s === 'string' && s.startsWith('./')) : [])
|
|
516
532
|
const candidateSkillRoots = [...declaredSkills.map((p) => pluginPath(dir, p)), join(dir, 'skills'), join(dir, '..', 'skills')]
|
|
517
533
|
for (const sRoot of candidateSkillRoots) {
|
|
@@ -624,7 +640,7 @@ export function listSkills(dir) {
|
|
|
624
640
|
}
|
|
625
641
|
|
|
626
642
|
/** List agent definition files (agents/*.yaml|yml|md|json, .well-known/agent-card.json, agent.json). */
|
|
627
|
-
export function listAgents(dir) {
|
|
643
|
+
export function listAgents(dir, manifest = readPluginManifest(dir)) {
|
|
628
644
|
const out = []
|
|
629
645
|
const seen = new Set()
|
|
630
646
|
|
|
@@ -722,7 +738,6 @@ export function listAgents(dir) {
|
|
|
722
738
|
}
|
|
723
739
|
|
|
724
740
|
// Check manifest "agents" array
|
|
725
|
-
const manifest = readPluginManifest(dir)
|
|
726
741
|
if (manifest && Array.isArray(manifest.agents)) {
|
|
727
742
|
for (const item of manifest.agents) {
|
|
728
743
|
const rawName = typeof item === 'string' ? item : item?.name
|
|
@@ -748,7 +763,7 @@ export function listAgents(dir) {
|
|
|
748
763
|
}
|
|
749
764
|
|
|
750
765
|
/** Prompt-ish entries: prompts/*.md|txt|yaml or plugin.json "prompts". */
|
|
751
|
-
export function listPrompts(dir) {
|
|
766
|
+
export function listPrompts(dir, manifest = readPluginManifest(dir)) {
|
|
752
767
|
const prompts = []
|
|
753
768
|
const pRoots = [join(dir, 'prompts'), join(dir, '..', 'prompts')]
|
|
754
769
|
for (const pRoot of pRoots) {
|
|
@@ -762,7 +777,6 @@ export function listPrompts(dir) {
|
|
|
762
777
|
} catch {}
|
|
763
778
|
}
|
|
764
779
|
}
|
|
765
|
-
const manifest = readPluginManifest(dir)
|
|
766
780
|
if (manifest && Array.isArray(manifest.prompts)) {
|
|
767
781
|
prompts.push(...manifest.prompts.map((p) => (typeof p === 'string' ? p : p.name)).filter(Boolean))
|
|
768
782
|
}
|
|
@@ -824,8 +838,7 @@ export function parseHookConfig(raw, isJson) {
|
|
|
824
838
|
* path first, then `hooks/hooks.json|yaml|yml`, then `*-hooks.{json,yaml}` files.
|
|
825
839
|
* Returns null when the plugin declares no hook config (e.g. only scripts).
|
|
826
840
|
*/
|
|
827
|
-
export function resolveHookConfigPath(dir) {
|
|
828
|
-
const manifest = readPluginManifest(dir)
|
|
841
|
+
export function resolveHookConfigPath(dir, manifest = readPluginManifest(dir)) {
|
|
829
842
|
if (manifest && typeof manifest.hooks === 'string') {
|
|
830
843
|
const p = isAbsolute(manifest.hooks) ? manifest.hooks : join(dir, manifest.hooks)
|
|
831
844
|
if (existsSync(p) && statSync(p).isFile()) return p
|
|
@@ -848,12 +861,12 @@ export function resolveHookConfigPath(dir) {
|
|
|
848
861
|
}
|
|
849
862
|
|
|
850
863
|
/** Hook entries: follow the plugin manifest's `hooks` config, then hooks/ config files. */
|
|
851
|
-
export function listHooks(dir) {
|
|
864
|
+
export function listHooks(dir, manifest = readPluginManifest(dir)) {
|
|
852
865
|
const hooks = []
|
|
853
866
|
const seen = new Set()
|
|
854
867
|
const add = (h) => { if (h && !seen.has(h)) { seen.add(h); hooks.push(h) } }
|
|
855
868
|
|
|
856
|
-
const cfg = resolveHookConfigPath(dir)
|
|
869
|
+
const cfg = resolveHookConfigPath(dir, manifest)
|
|
857
870
|
if (cfg) {
|
|
858
871
|
try {
|
|
859
872
|
const raw = readFileSync(cfg, 'utf8')
|
|
@@ -863,7 +876,6 @@ export function listHooks(dir) {
|
|
|
863
876
|
|
|
864
877
|
// Manifest `hooks` as inline object/array (no file path to follow).
|
|
865
878
|
if (hooks.length === 0) {
|
|
866
|
-
const manifest = readPluginManifest(dir)
|
|
867
879
|
if (manifest && manifest.hooks) {
|
|
868
880
|
if (Array.isArray(manifest.hooks)) {
|
|
869
881
|
for (const h of manifest.hooks) add(typeof h === 'string' ? h : (h && h.name))
|
|
@@ -899,7 +911,7 @@ export function isRemoteTransportName(type) {
|
|
|
899
911
|
}
|
|
900
912
|
|
|
901
913
|
/** Connector-ish entries: .mcp.json, mcp.json, server.json, or plugin.json "mcp" / "connectors". */
|
|
902
|
-
export function listConnectors(dir) {
|
|
914
|
+
export function listConnectors(dir, manifest = readPluginManifest(dir)) {
|
|
903
915
|
const connectors = []
|
|
904
916
|
const seen = new Set()
|
|
905
917
|
|
|
@@ -948,7 +960,6 @@ export function listConnectors(dir) {
|
|
|
948
960
|
}
|
|
949
961
|
}
|
|
950
962
|
|
|
951
|
-
const manifest = readPluginManifest(dir)
|
|
952
963
|
if (manifest) {
|
|
953
964
|
let dict = null
|
|
954
965
|
if (manifest.mcpServers && typeof manifest.mcpServers === 'object') {
|
package/src/routes.js
CHANGED
|
@@ -7,13 +7,13 @@ import { existsSync } from 'node:fs'
|
|
|
7
7
|
import { join } from 'node:path'
|
|
8
8
|
import { sendJson, readJsonBody, sameOrigin } from './http.js'
|
|
9
9
|
import {
|
|
10
|
-
readState, writeState, slugify, suggestSourceName, parseGitUrl, normalizeGitRepoUrl, findDuplicateSource, installedDir,
|
|
10
|
+
readState, writeState, slugify, suggestSourceName, parseGitUrl, normalizeGitRepoUrl, findDuplicateSource, installedDir, removeManagedDir, sourceCacheDir,
|
|
11
11
|
} from './store.js'
|
|
12
12
|
import { ensureSourceCloned, pullSource, safeSegment, materializePlugin } from './market.js'
|
|
13
13
|
import { readMarketplace, pluginDetail, pluginContentDir, invalidateMarketplaceCache } from './parser.js'
|
|
14
14
|
import { getOrFetchIcon, readLocalIcon } from './icons.js'
|
|
15
15
|
import {
|
|
16
|
-
installPlugin, uninstallPlugin, togglePlugin, updatePlugin, installedDetails, isScanDirRegistered,
|
|
16
|
+
installPlugin, uninstallPlugin, togglePlugin, updatePlugin, installedDetails, isScanDirRegistered, toolCallIconGroups,
|
|
17
17
|
toggleConnector, isConnectorActive, verifyConnectorAuth, saveConnectorAuth,
|
|
18
18
|
fetchConnectorTools, setToolDisabled, isLspActive, readCordisPatch, unregisterConnector, removeUserMcp, renameUserMcp, getConnectorEntry, getConnectorId, readMcpToolsState, userMcpConfig,
|
|
19
19
|
} from './install.js'
|
|
@@ -82,6 +82,10 @@ async function handle(req, res, prefix = API_PREFIX, skills = null, applyProfile
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
// ── state ────────────────────────────────────────────────────────────
|
|
85
|
+
if (method === 'GET' && path === '/tool-call-icons') {
|
|
86
|
+
return sendJson(res, 200, { groups: toolCallIconGroups() })
|
|
87
|
+
}
|
|
88
|
+
|
|
85
89
|
if (method === 'GET' && path === '/state') {
|
|
86
90
|
const state = readState()
|
|
87
91
|
const details = installedDetails()
|
|
@@ -332,6 +336,9 @@ async function handle(req, res, prefix = API_PREFIX, skills = null, applyProfile
|
|
|
332
336
|
if (source.builtin) throw new Error('内置源不可删除')
|
|
333
337
|
const used = state.plugins.some((p) => p.sourceId === sourceId)
|
|
334
338
|
if (used) throw new Error('该源下仍有已安装插件,请先卸载')
|
|
339
|
+
// The remote checkout pool is shared by marketplaces. Only remove this
|
|
340
|
+
// source's own clone or uploaded marketplace copy.
|
|
341
|
+
if (sourceId !== 'remote') removeManagedDir(sourceCacheDir(sourceId))
|
|
335
342
|
state.sources = state.sources.filter((s) => s.id !== sourceId)
|
|
336
343
|
writeState(state)
|
|
337
344
|
invalidateMarketplaceCache(sourceId)
|
|
@@ -352,11 +359,13 @@ async function handle(req, res, prefix = API_PREFIX, skills = null, applyProfile
|
|
|
352
359
|
}
|
|
353
360
|
// Migrate legacy patch-only entries (saved before userMcps state existed)
|
|
354
361
|
let changed = false
|
|
362
|
+
const pluginTools = state.plugins.some(plugin => plugin.name === 'user-mcp') ? readMcpToolsState() : null
|
|
355
363
|
for (const block of patch) {
|
|
356
364
|
if (!block || !Array.isArray(block.insert)) continue
|
|
357
365
|
for (const item of block.insert) {
|
|
358
366
|
if (!item || typeof item.id !== 'string' || !item.id.startsWith(getConnectorId('user-mcp', ''))) continue
|
|
359
367
|
const cfg = item.config || {}
|
|
368
|
+
if (pluginTools?.[`user-mcp::${cfg.serverName}`]?.pluginOAuthOwned && remoteConfigFromEntry(cfg)) continue
|
|
360
369
|
if (cfg.serverName && !state.userMcps.some((x) => x && x.name === cfg.serverName)) {
|
|
361
370
|
state.userMcps.push(userMcpConfig(cfg.serverName, {
|
|
362
371
|
transport: cfg.transport, url: cfg.url, command: cfg.command,
|
|
@@ -565,7 +574,10 @@ async function handle(req, res, prefix = API_PREFIX, skills = null, applyProfile
|
|
|
565
574
|
const pluginName = safeSegment(parts[0], 'plugin name')
|
|
566
575
|
const connectorName = safeSegment(parts[2], 'connector name')
|
|
567
576
|
const body = await readJsonBody(req)
|
|
568
|
-
|
|
577
|
+
if (!readState().plugins.some(plugin => plugin.name === pluginName)) {
|
|
578
|
+
return sendJson(res, 404, { ok: false, error: '插件未安装或已卸载' })
|
|
579
|
+
}
|
|
580
|
+
const result = await verifyConnectorAuth(pluginName, connectorName, body, { pluginOwned: true })
|
|
569
581
|
return sendJson(res, 200, result)
|
|
570
582
|
}
|
|
571
583
|
|
|
@@ -575,7 +587,10 @@ async function handle(req, res, prefix = API_PREFIX, skills = null, applyProfile
|
|
|
575
587
|
const pluginName = safeSegment(parts[0], 'plugin name')
|
|
576
588
|
const connectorName = safeSegment(parts[2], 'connector name')
|
|
577
589
|
const body = await readJsonBody(req)
|
|
578
|
-
|
|
590
|
+
if (!readState().plugins.some(plugin => plugin.name === pluginName)) {
|
|
591
|
+
return sendJson(res, 404, { ok: false, error: '插件未安装或已卸载' })
|
|
592
|
+
}
|
|
593
|
+
const result = saveConnectorAuth(pluginName, connectorName, body, { pluginOwned: true })
|
|
579
594
|
return sendJson(res, 200, scheduledResult(result, applyProfile, [getConnectorId(pluginName, connectorName)]))
|
|
580
595
|
}
|
|
581
596
|
|
|
@@ -708,7 +723,7 @@ async function handle(req, res, prefix = API_PREFIX, skills = null, applyProfile
|
|
|
708
723
|
if (method === 'DELETE' && path.startsWith('/plugins/')) {
|
|
709
724
|
requireSameOrigin(req)
|
|
710
725
|
const pluginName = safeSegment(path.slice('/plugins/'.length), 'plugin name')
|
|
711
|
-
const result = uninstallPlugin(pluginName)
|
|
726
|
+
const result = await uninstallPlugin(pluginName)
|
|
712
727
|
invalidateMarketplaceCache()
|
|
713
728
|
return sendJson(res, 200, scheduledResult(result, applyProfile))
|
|
714
729
|
}
|
package/src/store.js
CHANGED
|
@@ -8,12 +8,21 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { homedir } from 'node:os'
|
|
10
10
|
import { dirname, join } from 'node:path'
|
|
11
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync, statSync, rmSync } from 'node:fs'
|
|
11
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync, statSync, lstatSync, rmSync, unlinkSync } from 'node:fs'
|
|
12
12
|
import { execFileSync } from 'node:child_process'
|
|
13
13
|
|
|
14
14
|
/** Robust directory deletion handling Windows readonly/locked files. */
|
|
15
|
-
export function safeRmDir(dir) {
|
|
16
|
-
if (!dir
|
|
15
|
+
export function safeRmDir(dir, { allowTrash = true } = {}) {
|
|
16
|
+
if (!dir) return
|
|
17
|
+
// A dangling junction is invisible to existsSync. Unlink junctions directly
|
|
18
|
+
// so the Windows directory fallbacks never operate on their targets.
|
|
19
|
+
let entry
|
|
20
|
+
try { entry = lstatSync(dir, { throwIfNoEntry: false }) } catch {}
|
|
21
|
+
if (entry?.isSymbolicLink()) {
|
|
22
|
+
unlinkSync(dir)
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
if (!entry && !existsSync(dir)) return
|
|
17
26
|
try {
|
|
18
27
|
rmSync(dir, { recursive: true, force: true, maxRetries: 3, retryDelay: 50 })
|
|
19
28
|
return
|
|
@@ -28,6 +37,7 @@ export function safeRmDir(dir) {
|
|
|
28
37
|
execFileSync('cmd.exe', ['/c', `rd /s /q "${dir}"`], { stdio: 'ignore', windowsHide: true })
|
|
29
38
|
if (!existsSync(dir)) return
|
|
30
39
|
} catch {}
|
|
40
|
+
if (!allowTrash) return
|
|
31
41
|
try {
|
|
32
42
|
const trash = `${dir}.trash-${Date.now()}`
|
|
33
43
|
renameSync(dir, trash)
|
|
@@ -40,6 +50,14 @@ export function safeRmDir(dir) {
|
|
|
40
50
|
}
|
|
41
51
|
}
|
|
42
52
|
|
|
53
|
+
/** Remove managed files before forgetting the record needed to retry cleanup. */
|
|
54
|
+
export function removeManagedDir(dir) {
|
|
55
|
+
safeRmDir(dir, { allowTrash: false })
|
|
56
|
+
if (lstatSync(dir, { throwIfNoEntry: false })) {
|
|
57
|
+
throw Object.assign(new Error(`无法清理目录:${dir}`), { code: 'EBUSY', path: dir })
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
43
61
|
let STATE_CACHE = null
|
|
44
62
|
let STATE_CACHE_MTIME = 0
|
|
45
63
|
|
|
@@ -206,7 +224,8 @@ export function suggestSourceName(url) {
|
|
|
206
224
|
const ownerLower = (owner || '').toLowerCase()
|
|
207
225
|
const repoLower = (repo || '').toLowerCase()
|
|
208
226
|
|
|
209
|
-
if (
|
|
227
|
+
if (ownerLower === 'anthropics' && repoLower === 'knowledge-work-plugins') return 'Knowledge Work'
|
|
228
|
+
if (repoLower === 'claude-plugins-official') return 'Anthropic'
|
|
210
229
|
if (repoLower === 'claude-plugins-community') return 'Community'
|
|
211
230
|
|
|
212
231
|
const genericRepoNames = new Set([
|