@aashari/mcp-server-atlassian-bitbucket
Version:
Node.js/TypeScript MCP server for Atlassian Bitbucket. Enables AI systems (LLMs) to interact with workspaces, repositories, and pull requests via tools (list, get, comment, search). Connects AI directly to version control workflows through the standard MC
49 lines (48 loc) • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.executeShellCommand = executeShellCommand;
const util_1 = require("util");
const child_process_1 = require("child_process");
const logger_util_js_1 = require("./logger.util.js");
const execFile = (0, util_1.promisify)(child_process_1.execFile);
const utilLogger = logger_util_js_1.Logger.forContext('utils/shell.util.ts');
/**
* Executes a command directly without shell interpretation.
* Uses execFile instead of exec to prevent command injection (CWE-78).
*
* @param file The executable to run.
* @param args Arguments to pass to the executable.
* @param operationDesc A brief description of the operation for logging purposes.
* @returns A promise that resolves with the stdout of the command.
* @throws An error if the command execution fails, including stderr.
*/
async function executeShellCommand(file, args, operationDesc) {
const methodLogger = utilLogger.forMethod('executeShellCommand');
methodLogger.debug(`Attempting to ${operationDesc}: ${file} ${args.join(' ')}`);
try {
const { stdout, stderr } = await execFile(file, args, {
timeout: 5 * 60 * 1000,
});
if (stderr) {
methodLogger.warn(`Stderr from ${operationDesc}: ${stderr}`);
}
methodLogger.info(`Successfully executed ${operationDesc}. Stdout: ${stdout}`);
return stdout || `Successfully ${operationDesc}.`;
}
catch (error) {
methodLogger.error(`Failed to ${operationDesc}: ${file} ${args.join(' ')}`, error);
let errorMessage = 'Unknown error during shell command execution.';
if (error instanceof Error) {
const execError = error;
errorMessage =
execError.stderr || execError.stdout || execError.message;
}
else if (typeof error === 'string') {
errorMessage = error;
}
if (!errorMessage && error) {
errorMessage = String(error);
}
throw new Error(`Failed to ${operationDesc}: ${errorMessage}`);
}
}