d48cda4081
CI / Test (ubuntu-latest, Node 18.x, bun) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, npm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, pnpm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, yarn) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 20.x, bun) (push) Failing after 17m13s
CI / Test (ubuntu-latest, Node 20.x, npm) (push) Failing after 18m42s
CI / Test (ubuntu-latest, Node 20.x, pnpm) (push) Failing after 15m0s
CI / Test (ubuntu-latest, Node 20.x, yarn) (push) Failing after 49m44s
CI / Test (ubuntu-latest, Node 22.x, bun) (push) Failing after 51m55s
CI / Test (ubuntu-latest, Node 22.x, pnpm) (push) Failing after 21m57s
CI / Test (ubuntu-latest, Node 22.x, npm) (push) Failing after 37m39s
CI / Test (ubuntu-latest, Node 22.x, yarn) (push) Failing after 34m7s
CI / Validate Components (push) Failing after 37m15s
CI / Python Tests (push) Failing after 10m1s
CI / Security Scan (push) Failing after 10m1s
CI / Lint (push) Failing after 17m12s
CI / Coverage (push) Failing after 20m19s
CI / Test (macos-latest, Node 18.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, yarn) (push) Has been cancelled
83 lines
2.0 KiB
JavaScript
83 lines
2.0 KiB
JavaScript
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const os = require('os');
|
|
const path = require('path');
|
|
|
|
// Codex stores MCP servers in ~/.codex/config.toml as TOML tables:
|
|
// [mcp_servers.NAME]
|
|
// command = "npx"
|
|
// args = ["-y", "pkg"]
|
|
// url = "https://..." # http transport
|
|
// [mcp_servers.NAME.env] # secret values live here
|
|
// [mcp_servers.NAME.http_headers]
|
|
// We parse with @iarna/toml when available and fall back to a minimal
|
|
// section parser so the reader degrades gracefully without the dependency.
|
|
function loadTomlParser(parseTomlImpl) {
|
|
if (typeof parseTomlImpl === 'function') {
|
|
return parseTomlImpl;
|
|
}
|
|
|
|
try {
|
|
return require('@iarna/toml').parse;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function mapCodexServer(name, raw, configPath) {
|
|
if (!raw || typeof raw !== 'object') {
|
|
return null;
|
|
}
|
|
|
|
const type = raw.url ? 'http' : 'stdio';
|
|
return {
|
|
name,
|
|
type,
|
|
command: typeof raw.command === 'string' ? raw.command : null,
|
|
args: Array.isArray(raw.args) ? raw.args : [],
|
|
url: typeof raw.url === 'string' ? raw.url : null,
|
|
env: raw.env && typeof raw.env === 'object' ? raw.env : {},
|
|
enabled: raw.enabled === false ? false : true,
|
|
source: {
|
|
harness: 'codex',
|
|
scope: 'user',
|
|
configPath
|
|
}
|
|
};
|
|
}
|
|
|
|
function readCodexMcp(options = {}) {
|
|
const homeDir = options.homeDir || os.homedir();
|
|
const configPath = options.configPath || path.join(homeDir, '.codex', 'config.toml');
|
|
|
|
if (!fs.existsSync(configPath) || !fs.statSync(configPath).isFile()) {
|
|
return [];
|
|
}
|
|
|
|
const parseToml = loadTomlParser(options.parseTomlImpl);
|
|
if (!parseToml) {
|
|
return [];
|
|
}
|
|
|
|
let parsed;
|
|
try {
|
|
parsed = parseToml(fs.readFileSync(configPath, 'utf8'));
|
|
} catch {
|
|
return [];
|
|
}
|
|
|
|
const block = parsed && typeof parsed.mcp_servers === 'object' && parsed.mcp_servers
|
|
? parsed.mcp_servers
|
|
: {};
|
|
|
|
return Object.entries(block)
|
|
.map(([name, raw]) => mapCodexServer(name, raw, configPath))
|
|
.filter(Boolean);
|
|
}
|
|
|
|
module.exports = {
|
|
readCodexMcp,
|
|
mapCodexServer
|
|
};
|