UNPKG

rulesync

Version:

Unified AI rules management CLI tool that generates configuration files for various AI development tools

146 lines (143 loc) 5.96 kB
import { generateMcpConfig, generateMcpConfigurationFiles } from "./chunk-PPAQWVXX.js"; // src/generators/mcp/codexcli.ts function generateCodexMcp(config) { return generateMcpConfig(config, { target: "codexcli", configPaths: [".codex/mcp-config.json"], serverTransform: (server) => { const codexServer = {}; if (server.command) { codexServer.command = server.command; if (server.args) codexServer.args = server.args; codexServer.transport = server.transport || "stdio"; } else if (server.url || server.httpUrl) { const url = server.httpUrl || server.url; if (url) { codexServer.url = url; } if (server.httpUrl) { codexServer.transport = "http"; } else if (server.transport === "sse") { codexServer.transport = "sse"; } else if (server.transport === "http") { codexServer.transport = "http"; } else { codexServer.transport = "stdio"; } } else { codexServer.transport = "stdio"; } if (server.env) { codexServer.env = { ...server.env }; if (!codexServer.env.CODEX_DEFAULT_MODEL) { codexServer.env.CODEX_DEFAULT_MODEL = "gpt-4o-mini"; } } if (server.cwd) { codexServer.cwd = server.cwd; codexServer.workingDirectory = server.cwd; } if (server.timeout) { codexServer.timeout = server.timeout; } if (server.headers) { codexServer.headers = server.headers; } return codexServer; }, configWrapper: (servers) => ({ // Configuration format for MCP wrapper servers that expose Codex CLI functionality servers, _comment: "Configuration for MCP wrapper servers like openai-codex-mcp that integrate with Codex CLI", _usage: "This file is intended for use with third-party MCP servers that wrap Codex CLI functionality", _examples: { python_server: "python -m mcp_server or uvicorn codex_server:app", nodejs_server: "node dist/server.js or npm start", docker_server: "docker run -i --rm custom/codex-mcp:latest" }, _security_note: "Store API keys in environment variables, not in this configuration file" }) }); } function generateCodexMcpConfiguration(mcpServers, baseDir = "") { return generateMcpConfigurationFiles( mcpServers, { target: "codexcli", configPaths: [".codex/mcp-config.json"], serverTransform: (server) => { const { targets: _, transport, ...serverConfig } = server; const codexServer = {}; if (serverConfig.command !== void 0) codexServer.command = serverConfig.command; if (serverConfig.args !== void 0) codexServer.args = serverConfig.args; if (serverConfig.url !== void 0) codexServer.url = serverConfig.url; if (serverConfig.httpUrl !== void 0) codexServer.httpUrl = serverConfig.httpUrl; if (serverConfig.env !== void 0) codexServer.env = serverConfig.env; if (serverConfig.disabled !== void 0) codexServer.disabled = serverConfig.disabled; if (serverConfig.networkTimeout !== void 0) codexServer.networkTimeout = serverConfig.networkTimeout; if (serverConfig.timeout !== void 0) codexServer.timeout = serverConfig.timeout; if (serverConfig.trust !== void 0) codexServer.trust = serverConfig.trust; if (serverConfig.cwd !== void 0) codexServer.cwd = serverConfig.cwd; if (serverConfig.type !== void 0) codexServer.type = serverConfig.type; if (serverConfig.alwaysAllow !== void 0) codexServer.alwaysAllow = serverConfig.alwaysAllow; if (serverConfig.tools !== void 0) codexServer.tools = serverConfig.tools; if (serverConfig.kiroAutoApprove !== void 0) codexServer.autoApprove = serverConfig.kiroAutoApprove; if (serverConfig.kiroAutoBlock !== void 0) codexServer.autoBlock = serverConfig.kiroAutoBlock; if (serverConfig.headers !== void 0) codexServer.headers = serverConfig.headers; if (serverConfig.httpUrl !== void 0) { codexServer.url = serverConfig.httpUrl; delete codexServer.httpUrl; } if (transport) { codexServer.transport = transport; } else if (serverConfig.url && !serverConfig.httpUrl) { codexServer.transport = "sse"; } else { codexServer.transport = "stdio"; } if (serverConfig.env) { codexServer.env = { ...serverConfig.env }; if (!codexServer.env.CODEX_DEFAULT_MODEL) { codexServer.env.CODEX_DEFAULT_MODEL = "gpt-4o-mini"; } } if (serverConfig.cwd) { codexServer.cwd = serverConfig.cwd; codexServer.workingDirectory = serverConfig.cwd; } if (serverConfig.timeout) { codexServer.timeout = serverConfig.timeout; } if (serverConfig.headers) { codexServer.headers = serverConfig.headers; } return codexServer; }, configWrapper: (servers) => ({ // Configuration format for MCP wrapper servers that integrate with Codex CLI servers, _comment: "Configuration for MCP wrapper servers like openai-codex-mcp that integrate with Codex CLI", _usage: "Use with third-party MCP servers that expose Codex CLI functionality to other MCP clients", _examples: { python_server: "python -m mcp_server or uvicorn codex_server:app", nodejs_server: "node dist/server.js or npm start", docker_server: "docker run -i --rm custom/codex-mcp:latest" }, _security_note: "Store API keys in environment variables, not in this configuration file", _supported_transports: ["stdio", "sse", "http"] }) }, baseDir ); } export { generateCodexMcp, generateCodexMcpConfiguration };