UNPKG

rulesync

Version:

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

95 lines (92 loc) 2.53 kB
import { shouldIncludeServer } from "./chunk-VI6SBYFB.js"; // src/generators/mcp/shared-factory.ts function generateMcpConfig(config, toolConfig) { const servers = {}; for (const [serverName, server] of Object.entries(config.mcpServers)) { if (!shouldIncludeServer(server, toolConfig.target)) continue; servers[serverName] = toolConfig.serverTransform(server, serverName); } const finalConfig = toolConfig.configWrapper(servers); return JSON.stringify(finalConfig, null, 2); } function generateMcpConfigurationFiles(mcpServers, toolConfig, baseDir = "") { const configs = []; const rulesyncConfig = { mcpServers }; for (const configPath of toolConfig.configPaths) { const filepath = baseDir ? `${baseDir}/${configPath}` : configPath; const content = generateMcpConfig(rulesyncConfig, toolConfig); configs.push({ filepath, content: `${content} ` }); } return configs; } var serverTransforms = { /** * Basic server transformation (command, args, env, url handling) */ basic: (server) => { const result = {}; if (server.command) { result.command = server.command; if (server.args) result.args = server.args; } else if (server.url || server.httpUrl) { const url = server.httpUrl || server.url; if (url) result.url = url; } if (server.env) { result.env = server.env; } return result; }, /** * Extended server transformation (includes disabled, alwaysAllow, etc.) */ extended: (server) => { const result = serverTransforms.basic(server); if (server.disabled !== void 0) { result.disabled = server.disabled; } if (server.alwaysAllow) { result.alwaysAllow = server.alwaysAllow; } if (server.networkTimeout !== void 0) { result.networkTimeout = server.networkTimeout; } if (server.tools) { result.tools = server.tools; } return result; }, /** * Remove rulesync-specific properties from server config */ cleanRulesyncProps: (server) => { const { targets: _, transport: _transport, ...cleanServer } = server; return { ...cleanServer }; } }; var configWrappers = { /** * Standard mcpServers wrapper */ mcpServers: (servers) => ({ mcpServers: servers }), /** * Servers-only wrapper (for tools that use "servers" instead of "mcpServers") */ servers: (servers) => ({ servers }) }; export { generateMcpConfig, generateMcpConfigurationFiles, serverTransforms, configWrappers };