mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-06 17:23:28 +08:00
feat: support disabling bundled mcp servers
This commit is contained in:
@@ -4,6 +4,7 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const { writeInstallState } = require('../install-state');
|
||||
const { filterMcpConfig, parseDisabledMcpServers } = require('../mcp-config');
|
||||
|
||||
function readJsonObject(filePath, label) {
|
||||
let parsed;
|
||||
@@ -124,6 +125,49 @@ function findHooksSourcePath(plan, hooksDestinationPath) {
|
||||
return operation ? operation.sourcePath : null;
|
||||
}
|
||||
|
||||
function isMcpConfigPath(filePath) {
|
||||
const basename = path.basename(String(filePath || ''));
|
||||
return basename === '.mcp.json' || basename === 'mcp.json';
|
||||
}
|
||||
|
||||
function buildFilteredMcpWrites(plan) {
|
||||
const disabledServers = parseDisabledMcpServers(process.env.ECC_DISABLED_MCPS);
|
||||
if (disabledServers.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const writes = [];
|
||||
|
||||
for (const operation of plan.operations) {
|
||||
if (!isMcpConfigPath(operation.destinationPath) || !operation.sourcePath || !fs.existsSync(operation.sourcePath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let sourceConfig;
|
||||
try {
|
||||
sourceConfig = readJsonObject(operation.sourcePath, 'MCP config');
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!sourceConfig.mcpServers || typeof sourceConfig.mcpServers !== 'object' || Array.isArray(sourceConfig.mcpServers)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const filtered = filterMcpConfig(sourceConfig, disabledServers);
|
||||
if (filtered.removed.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
writes.push({
|
||||
destinationPath: operation.destinationPath,
|
||||
filteredConfig: filtered.config,
|
||||
});
|
||||
}
|
||||
|
||||
return writes;
|
||||
}
|
||||
|
||||
function buildMergedSettings(plan) {
|
||||
if (!plan.adapter || plan.adapter.target !== 'claude') {
|
||||
return null;
|
||||
@@ -177,6 +221,7 @@ function buildMergedSettings(plan) {
|
||||
|
||||
function applyInstallPlan(plan) {
|
||||
const mergedSettingsPlan = buildMergedSettings(plan);
|
||||
const filteredMcpWrites = buildFilteredMcpWrites(plan);
|
||||
|
||||
for (const operation of plan.operations) {
|
||||
fs.mkdirSync(path.dirname(operation.destinationPath), { recursive: true });
|
||||
@@ -198,6 +243,15 @@ function applyInstallPlan(plan) {
|
||||
);
|
||||
}
|
||||
|
||||
for (const writePlan of filteredMcpWrites) {
|
||||
fs.mkdirSync(path.dirname(writePlan.destinationPath), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
writePlan.destinationPath,
|
||||
JSON.stringify(writePlan.filteredConfig, null, 2) + '\n',
|
||||
'utf8'
|
||||
);
|
||||
}
|
||||
|
||||
writeInstallState(plan.installStatePath, plan.statePreview);
|
||||
|
||||
return {
|
||||
|
||||
56
scripts/lib/mcp-config.js
Normal file
56
scripts/lib/mcp-config.js
Normal 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,
|
||||
};
|
||||
Reference in New Issue
Block a user