{ "mcpServers": { "microi": { "command": "node", "args": [ "-e", "/*\n * Codex CLI 0.136 仍不会把 plugin .mcp.json 的相对路径定位到插件根,\n * 也不会展开 ${PLUGIN_ROOT}。本脚本作为 `node -e` 内容运行,只在 Codex\n * 官方 plugin cache 中查找经过 manifest/package 双重校验的 Microi 包。\n */\nconst fs = require('node:fs');\nconst os = require('node:os');\nconst path = require('node:path');\n\nfunction readJson(filePath) {\n try { return JSON.parse(fs.readFileSync(filePath, 'utf8')); }\n catch { return undefined; }\n}\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' || pkg?.name !== '@microi.net/codex-plugin') 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 modifiedAt: Math.max(fs.statSync(adapter).mtimeMs, fs.statSync(router).mtimeMs),\n };\n}\n\nfunction findPluginRoot() {\n const explicit = String(process.env.MICROI_CODEX_PLUGIN_ROOT || '').trim();\n if (explicit) {\n const validated = validPluginRoot(path.resolve(explicit));\n if (!validated) throw new Error(`MICROI_CODEX_PLUGIN_ROOT 不是有效的 Microi Codex 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.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\n" ] } } }