/**
* Manage Theme Tool
* Handles theme activation, listing, and info for the MCP server.
*/
import {
getAvailableThemes,
setActiveTheme,
getActiveTheme,
clearActiveTheme,
getThemesSummary,
getThemeInfo,
reloadCustomThemes,
} from '../themes/index.js';
export type ThemeAction = 'list' | 'set' | 'clear' | 'info';
export interface ManageThemeResult {
action: ThemeAction;
success: boolean;
message: string;
details?: string;
}
/**
* Manage theme standards.
*/
export function manageTheme(action: ThemeAction, themeId?: string): ManageThemeResult {
switch (action) {
case 'list': {
reloadCustomThemes();
return {
action: 'list',
success: true,
message: 'Available theme standards',
details: getThemesSummary(),
};
}
case 'set': {
if (!themeId) {
return {
action: 'set',
success: false,
message: 'themeId is required for "set" action. Use manage_theme({ action: "list" }) to see available themes.',
};
}
reloadCustomThemes();
const theme = setActiveTheme(themeId);
if (!theme) {
const available = Object.keys(getAvailableThemes()).join(', ');
return {
action: 'set',
success: false,
message: `Theme "${themeId}" not found. Available themes: ${available}`,
};
}
return {
action: 'set',
success: true,
message: `Theme "${theme.name}" activated. All validation and pattern suggestions will now include ${theme.name}-specific rules.`,
details: getThemeInfo(themeId),
};
}
case 'clear': {
const active = getActiveTheme();
clearActiveTheme();
return {
action: 'clear',
success: true,
message: active
? `Theme "${active.name}" deactivated. Using base Magento standards only.`
: 'No active theme to clear. Already using base Magento standards only.',
};
}
case 'info': {
return {
action: 'info',
success: true,
message: themeId ? `Theme info for "${themeId}"` : 'Active theme info',
details: getThemeInfo(themeId),
};
}
default:
return {
action: action,
success: false,
message: `Unknown action "${action}". Valid actions: list, set, clear, info`,
};
}
}