safe-commander-mcp
Version:
A secure MCP server for executing whitelisted development commands with comprehensive security controls and resource limits
70 lines (69 loc) • 2.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.COMMAND_CATEGORIES = void 0;
exports.getAllowedCommands = getAllowedCommands;
exports.getCommandsByCategory = getCommandsByCategory;
exports.getCommandCategory = getCommandCategory;
exports.isCommandAllowed = isCommandAllowed;
exports.getCommandDescription = getCommandDescription;
const config_loader_1 = require("../config/config-loader");
/**
* Command categories for better organization and discovery
*/
exports.COMMAND_CATEGORIES = {
PACKAGE_MANAGERS: ['npm', 'yarn', 'pnpm'],
VERSION_CONTROL: ['git'],
FILE_OPERATIONS: ['ls', 'cat', 'pwd'],
RUNTIME: ['node', 'python', 'python3'],
BUILD_TOOLS: ['make', 'cmake', 'tsc'],
DEVELOPMENT: ['curl', 'wget', 'grep', 'find']
};
/**
* Get all allowed commands from configuration
*
* @returns Array of allowed command names
*/
function getAllowedCommands() {
return [...config_loader_1.CONFIG.ALLOWED_COMMANDS];
}
/**
* Get commands by category
*
* @param category - The category to filter by
* @returns Array of commands in the specified category that are also allowed
*/
function getCommandsByCategory(category) {
const categoryCommands = exports.COMMAND_CATEGORIES[category];
return categoryCommands.filter((cmd) => config_loader_1.CONFIG.ALLOWED_COMMANDS.includes(cmd));
}
/**
* Get the category of a command
*
* @param command - The command to categorize
* @returns The category name or 'OTHER' if not found
*/
function getCommandCategory(command) {
for (const [category, commands] of Object.entries(exports.COMMAND_CATEGORIES)) {
if (commands.includes(command)) {
return category;
}
}
return 'OTHER';
}
/**
* Check if a command is allowed
*
* @param command - The command to check
* @returns True if the command is in the allowed list
*/
function isCommandAllowed(command) {
return config_loader_1.CONFIG.ALLOWED_COMMANDS.includes(command);
}
/**
* Get command description for the MCP tool listing
*
* @returns Description string for the run_command tool
*/
function getCommandDescription() {
return `Execute allowed development commands safely with security controls and resource limits. Allowed commands: ${config_loader_1.CONFIG.ALLOWED_COMMANDS.join(', ')}`;
}