routie dev init since i didn't adhere to any proper guidance up until now
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.mergeMcp = mergeMcp;
|
||||
/**
|
||||
* Merge native and incoming MCP server configurations according to strategy.
|
||||
* @param base Existing native MCP config object.
|
||||
* @param incoming Ruler MCP config object.
|
||||
* @param strategy Merge strategy: 'merge' to union servers, 'overwrite' to replace.
|
||||
* @param serverKey The key to use for servers in the output (e.g., 'servers' for Copilot, 'mcpServers' for others).
|
||||
* @returns Merged MCP config object.
|
||||
*/
|
||||
function mergeMcp(base, incoming, strategy, serverKey) {
|
||||
if (strategy === 'overwrite') {
|
||||
// Ensure the incoming object uses the correct server key.
|
||||
// Transform from the standard (Crush) MCP config format
|
||||
const incomingServers = incoming[serverKey] ||
|
||||
incoming.mcpServers ||
|
||||
incoming.mcp ||
|
||||
{};
|
||||
return {
|
||||
[serverKey]: incomingServers,
|
||||
};
|
||||
}
|
||||
const baseServers = base[serverKey] ||
|
||||
base.mcpServers ||
|
||||
base.mcp ||
|
||||
{};
|
||||
const incomingServers = incoming[serverKey] ||
|
||||
incoming.mcpServers ||
|
||||
incoming.mcp ||
|
||||
{};
|
||||
const mergedServers = { ...baseServers, ...incomingServers };
|
||||
const newBase = { ...base };
|
||||
delete newBase.mcpServers; // Remove old key if present
|
||||
return {
|
||||
...newBase,
|
||||
[serverKey]: mergedServers,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user