add checks for other rules and other profile folder items before removing
This commit is contained in:
@@ -72,6 +72,7 @@ export function setupMCPConfiguration(projectDir, mcpConfigPath) {
|
||||
const hasMCPString = Object.values(mcpConfig.mcpServers).some(
|
||||
(server) =>
|
||||
server.args &&
|
||||
Array.isArray(server.args) &&
|
||||
server.args.some(
|
||||
(arg) => typeof arg === 'string' && arg.includes('task-master-ai')
|
||||
)
|
||||
@@ -126,3 +127,118 @@ export function setupMCPConfiguration(projectDir, mcpConfigPath) {
|
||||
// Add note to console about MCP integration
|
||||
log('info', 'MCP server will use the installed task-master-ai package');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Task Master MCP server configuration from an existing mcp.json file
|
||||
* Only removes Task Master entries, preserving other MCP servers
|
||||
* @param {string} projectDir - Target project directory
|
||||
* @param {string} mcpConfigPath - Relative path to MCP config file (e.g., '.cursor/mcp.json')
|
||||
* @returns {Object} Result object with success status and details
|
||||
*/
|
||||
export function removeTaskMasterMCPConfiguration(projectDir, mcpConfigPath) {
|
||||
const mcpPath = path.join(projectDir, mcpConfigPath);
|
||||
|
||||
let result = {
|
||||
success: false,
|
||||
removed: false,
|
||||
deleted: false,
|
||||
error: null,
|
||||
hasOtherServers: false
|
||||
};
|
||||
|
||||
if (!fs.existsSync(mcpPath)) {
|
||||
result.success = true;
|
||||
result.removed = false;
|
||||
log('debug', `[MCP Config] MCP config file does not exist: ${mcpPath}`);
|
||||
return result;
|
||||
}
|
||||
|
||||
try {
|
||||
// Read existing config
|
||||
const mcpConfig = JSON.parse(fs.readFileSync(mcpPath, 'utf8'));
|
||||
|
||||
if (!mcpConfig.mcpServers) {
|
||||
result.success = true;
|
||||
result.removed = false;
|
||||
log('debug', `[MCP Config] No mcpServers section found in: ${mcpPath}`);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Check if Task Master is configured
|
||||
const hasTaskMaster =
|
||||
mcpConfig.mcpServers['task-master-ai'] ||
|
||||
Object.values(mcpConfig.mcpServers).some(
|
||||
(server) =>
|
||||
server.args &&
|
||||
Array.isArray(server.args) &&
|
||||
server.args.some(
|
||||
(arg) => typeof arg === 'string' && arg.includes('task-master-ai')
|
||||
)
|
||||
);
|
||||
|
||||
if (!hasTaskMaster) {
|
||||
result.success = true;
|
||||
result.removed = false;
|
||||
log(
|
||||
'debug',
|
||||
`[MCP Config] Task Master not found in MCP config: ${mcpPath}`
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Remove task-master-ai server
|
||||
delete mcpConfig.mcpServers['task-master-ai'];
|
||||
|
||||
// Also remove any servers that have task-master-ai in their args
|
||||
Object.keys(mcpConfig.mcpServers).forEach((serverName) => {
|
||||
const server = mcpConfig.mcpServers[serverName];
|
||||
if (
|
||||
server.args &&
|
||||
Array.isArray(server.args) &&
|
||||
server.args.some(
|
||||
(arg) => typeof arg === 'string' && arg.includes('task-master-ai')
|
||||
)
|
||||
) {
|
||||
delete mcpConfig.mcpServers[serverName];
|
||||
log(
|
||||
'debug',
|
||||
`[MCP Config] Removed server '${serverName}' containing task-master-ai`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Check if there are other MCP servers remaining
|
||||
const remainingServers = Object.keys(mcpConfig.mcpServers);
|
||||
result.hasOtherServers = remainingServers.length > 0;
|
||||
|
||||
if (result.hasOtherServers) {
|
||||
// Write back the modified config with remaining servers
|
||||
fs.writeFileSync(mcpPath, formatJSONWithTabs(mcpConfig) + '\n');
|
||||
result.success = true;
|
||||
result.removed = true;
|
||||
result.deleted = false;
|
||||
log(
|
||||
'info',
|
||||
`[MCP Config] Removed Task Master from MCP config, preserving other servers: ${remainingServers.join(', ')}`
|
||||
);
|
||||
} else {
|
||||
// No other servers, delete the entire file
|
||||
fs.rmSync(mcpPath, { force: true });
|
||||
result.success = true;
|
||||
result.removed = true;
|
||||
result.deleted = true;
|
||||
log(
|
||||
'info',
|
||||
`[MCP Config] Removed MCP config file (no other servers remaining): ${mcpPath}`
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
result.error = error.message;
|
||||
log(
|
||||
'error',
|
||||
`[MCP Config] Failed to remove Task Master from MCP config: ${error.message}`
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user