UNPKG

rulesync

Version:

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

79 lines (76 loc) 2.37 kB
import { shouldIncludeServer } from "./chunk-VI6SBYFB.js"; // src/generators/mcp/copilot.ts function generateCopilotMcp(config, target) { const servers = {}; const inputs = []; const inputMap = /* @__PURE__ */ new Map(); for (const [serverName, server] of Object.entries(config.mcpServers)) { if (!shouldIncludeServer(server, "copilot")) continue; const copilotServer = {}; if (server.command) { copilotServer.command = server.command; if (server.args) copilotServer.args = server.args; } else if (server.url || server.httpUrl) { const url = server.httpUrl || server.url; if (url) { copilotServer.url = url; } } if (server.env) { copilotServer.env = {}; for (const [key, value] of Object.entries(server.env)) { if (target === "editor" && value.includes("SECRET")) { const inputId = `${serverName}_${key}`; inputMap.set(inputId, value); copilotServer.env[key] = `\${input:${inputId}}`; inputs.push({ id: inputId, type: "password", description: `${key} for ${serverName}` }); } else { copilotServer.env[key] = value; } } } if (server.tools) { copilotServer.tools = server.tools; } else if (server.alwaysAllow) { copilotServer.tools = server.alwaysAllow; } servers[serverName] = copilotServer; } if (target === "codingAgent") { const config2 = { mcpServers: servers }; return JSON.stringify(config2, null, 2); } else { const config2 = { servers }; if (inputs.length > 0) { config2.inputs = inputs; } return JSON.stringify(config2, null, 2); } } function generateCopilotMcpConfiguration(mcpServers, baseDir = "") { const configs = []; const rulesyncConfig = { mcpServers }; const editorContent = generateCopilotMcp(rulesyncConfig, "editor"); configs.push({ filepath: baseDir ? `${baseDir}/.vscode/mcp.json` : ".vscode/mcp.json", content: `${editorContent} ` }); const codingAgentContent = generateCopilotMcp(rulesyncConfig, "codingAgent"); configs.push({ filepath: baseDir ? `${baseDir}/.copilot/mcp.json` : ".copilot/mcp.json", content: `${codingAgentContent} ` }); return configs; } export { generateCopilotMcp, generateCopilotMcpConfiguration };