feat: support disabling bundled mcp servers

This commit is contained in:
Affaan Mustafa
2026-04-05 14:37:28 -07:00
parent 1346f83b08
commit 786f46dad5
7 changed files with 283 additions and 4 deletions

56
scripts/lib/mcp-config.js Normal file
View File

@@ -0,0 +1,56 @@
'use strict';
function parseDisabledMcpServers(value) {
return [...new Set(
String(value || '')
.split(',')
.map((entry) => entry.trim())
.filter(Boolean)
)];
}
function filterMcpConfig(config, disabledServerNames = []) {
if (!config || typeof config !== 'object' || Array.isArray(config)) {
throw new Error('MCP config must be a JSON object');
}
const servers = config.mcpServers;
if (!servers || typeof servers !== 'object' || Array.isArray(servers)) {
throw new Error('MCP config must include an mcpServers object');
}
const disabled = new Set(parseDisabledMcpServers(disabledServerNames));
if (disabled.size === 0) {
return {
config: {
...config,
mcpServers: { ...servers },
},
removed: [],
};
}
const nextServers = {};
const removed = [];
for (const [name, serverConfig] of Object.entries(servers)) {
if (disabled.has(name)) {
removed.push(name);
continue;
}
nextServers[name] = serverConfig;
}
return {
config: {
...config,
mcpServers: nextServers,
},
removed,
};
}
module.exports = {
filterMcpConfig,
parseDisabledMcpServers,
};