{ "mcpServers": { "microi": { "command": "node", "args": [ "-e", "/*\n * Codex CLI 仍不会把 plugin .mcp.json 的相对路径定位到插件根。\n * 本脚本作为 `node -e` 内容运行:CodeBuddy/WorkBuddy 优先使用宿主注入的\n * plugin root;Codex 则回退到官方 plugin cache,并统一执行双清单校验。\n */\nconst fs = require('node:fs');\nconst os = require('node:os');\nconst path = require('node:path');\nconst primaryPackageName = '@microi.net/cli';\nconst legacyPackageName = '@microi.net/codex-plugin';\n\nfunction readJson(filePath) {\n try { return JSON.parse(fs.readFileSync(filePath, 'utf8')); }\n catch { return undefined; }\n}\nfunction validPluginRoot(root) {\n const manifest = readJson(path.join(root, '.codex-plugin', 'plugin.json'));\n const pkg = readJson(path.join(root, 'package.json'));\n const adapter = path.join(root, 'scripts', 'mcp-codex-stdio-adapter.js');\n const router = path.join(root, 'scripts', 'microi-codex-router.js');\n if (manifest?.name !== 'microi' || ![primaryPackageName, legacyPackageName].includes(pkg?.name)) return undefined;\n if (!manifest.version || manifest.version !== pkg.version) return undefined;\n if (!fs.existsSync(adapter) || !fs.existsSync(router)) return undefined;\n return {\n root,\n adapter,\n router,\n packagePriority: pkg.name === primaryPackageName ? 1 : 0,\n modifiedAt: Math.max(fs.statSync(adapter).mtimeMs, fs.statSync(router).mtimeMs),\n };\n}\n\nfunction findPluginRoot() {\n const explicitRoots = [\n ['MICROI_CODEX_PLUGIN_ROOT', process.env.MICROI_CODEX_PLUGIN_ROOT],\n ['CODEBUDDY_PLUGIN_ROOT', process.env.CODEBUDDY_PLUGIN_ROOT],\n ['WORKBUDDY_PLUGIN_ROOT', process.env.WORKBUDDY_PLUGIN_ROOT],\n ['CLAUDE_PLUGIN_ROOT', process.env.CLAUDE_PLUGIN_ROOT],\n ];\n for (const [source, value] of explicitRoots) {\n const explicit = String(value || '').trim();\n if (!explicit) continue;\n const validated = validPluginRoot(path.resolve(explicit));\n if (!validated) throw new Error(`${source} 不是有效的 Microi Plugin:${explicit}`);\n return validated;\n }\n\n const codexHome = path.resolve(process.env.CODEX_HOME || path.join(os.homedir(), '.codex'));\n const cacheRoot = path.join(codexHome, 'plugins', 'cache');\n const candidates = [];\n if (fs.existsSync(cacheRoot)) {\n for (const marketplace of fs.readdirSync(cacheRoot, { withFileTypes: true }).filter(entry => entry.isDirectory())) {\n const pluginDir = path.join(cacheRoot, marketplace.name, 'microi');\n if (!fs.existsSync(pluginDir)) continue;\n for (const version of fs.readdirSync(pluginDir, { withFileTypes: true }).filter(entry => entry.isDirectory())) {\n const candidateRoot = path.resolve(pluginDir, version.name);\n const relative = path.relative(cacheRoot, candidateRoot);\n if (relative.startsWith('..') || path.isAbsolute(relative)) continue;\n const validated = validPluginRoot(candidateRoot);\n if (validated) candidates.push(validated);\n }\n }\n }\n candidates.sort((left, right) => right.packagePriority - left.packagePriority || right.modifiedAt - left.modifiedAt);\n if (!candidates[0]) {\n throw new Error(`未在 Codex plugin cache 找到有效的 Microi Codex Plugin:${cacheRoot}`);\n }\n return candidates[0];\n}\n\ntry {\n const plugin = findPluginRoot();\n process.env.MICROI_CODEX_PLUGIN_ROOT = plugin.root;\n process.argv[2] = plugin.router;\n require(plugin.adapter);\n} catch (error) {\n console.error(`[microi-codex-bootstrap] ${error instanceof Error ? error.message : String(error)}`);\n process.exit(1);\n}\n" ] } } }