MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / scanCachedPlugin

Function scanCachedPlugin

packages/plugins/mcp/src/sdk/codex-plugins.ts:296–375  ·  view source on GitHub ↗
(
  codexHome: string,
  pluginDir: string,
  pluginName: string,
)

Source from the content-addressed store, hash-verified

294// ---------------------------------------------------------------------------
295
296const scanCachedPlugin = (
297 codexHome: string,
298 pluginDir: string,
299 pluginName: string,
300): readonly CodexPluginEntry[] => {
301 const versions = [...listDirs(pluginDir)].sort(compareVersionsDesc);
302 const version = versions[0];
303 if (version === undefined) return [];
304 const versionDir = path.join(pluginDir, version);
305
306 const manifest = Option.getOrUndefined(
307 decodeManifestJson(readText(path.join(versionDir, ".codex-plugin", "plugin.json"))),
308 );
309 if (manifest?.mcpServers === undefined) return [];
310
311 // `mcpServers` is a relative path to an `.mcp.json` in every known manifest;
312 // tolerate an inline object of the same shape.
313 const servers = Option.getOrUndefined(
314 typeof manifest.mcpServers === "string"
315 ? decodeServersFileJson(readText(path.resolve(versionDir, manifest.mcpServers)))
316 : decodeServersFile({ mcpServers: manifest.mcpServers }),
317 );
318 if (servers === undefined) return [];
319
320 const displayName = manifest.interface?.displayName ?? manifest.name;
321 const summary =
322 manifest.interface?.shortDescription ??
323 manifest.description?.split("\n")[0] ??
324 `Local MCP server from the Codex plugin "${manifest.name}".`;
325 const icon =
326 manifest.interface?.logo === undefined
327 ? undefined
328 : readIconDataUri(path.resolve(versionDir, manifest.interface.logo));
329 const display: CodexPluginDisplay = {
330 ...(icon === undefined ? {} : { icon }),
331 ...(manifest.interface?.displayName === undefined
332 ? {}
333 : { displayName: manifest.interface.displayName }),
334 ...(manifest.interface?.shortDescription === undefined
335 ? {}
336 : { tagline: manifest.interface.shortDescription }),
337 ...(manifest.interface?.longDescription === undefined
338 ? {}
339 : { description: manifest.interface.longDescription }),
340 };
341
342 const localServers = Object.entries(servers.mcpServers).flatMap(([serverKey, spec]) =>
343 spec.command !== undefined && spec.type !== "http" && spec.url === undefined
344 ? [{ serverKey, command: spec.command, args: spec.args, cwd: spec.cwd }]
345 : [],
346 );
347
348 return localServers.map(({ serverKey, ...spec }) => {
349 // Manifest paths are relative to the versioned plugin dir. The versioned
350 // dir moves on plugin updates — the connection health check surfaces that
351 // as "command missing" and the card re-adds against the new path.
352 const command = path.resolve(versionDir, spec.command);
353 const cwd = path.resolve(versionDir, spec.cwd ?? ".");

Callers 1

scanCodexPluginsFunction · 0.85

Calls 9

setupHintFunction · 0.90
listDirsFunction · 0.85
readTextFunction · 0.85
readIconDataUriFunction · 0.85
isExecutableFileFunction · 0.85
sanitizeIdFunction · 0.85
sanitizeSlugFunction · 0.85
resolveMethod · 0.80
replaceMethod · 0.65

Tested by

no test coverage detected