@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
50 lines (49 loc) • 2.31 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 exec = (0, util_1.promisify)(child_process_1.exec);
const utilLogger = logger_util_js_1.Logger.forContext('utils/shell.util.ts');
/**
* Executes a shell command.
*
* @param command The command string to execute.
* @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(command, operationDesc) {
const methodLogger = utilLogger.forMethod('executeShellCommand');
methodLogger.debug(`Attempting to ${operationDesc}: ${command}`);
try {
const { stdout, stderr } = await exec(command);
if (stderr) {
methodLogger.warn(`Stderr from ${operationDesc}: ${stderr}`);
// Depending on the command, stderr might not always indicate a failure,
// but for git clone, it usually does if stdout is empty.
// If stdout is also present, it might be a warning.
}
methodLogger.info(`Successfully executed ${operationDesc}. Stdout: ${stdout}`);
return stdout || `Successfully ${operationDesc}.`; // Return stdout or a generic success message
}
catch (error) {
methodLogger.error(`Failed to ${operationDesc}: ${command}`, error);
let errorMessage = 'Unknown error during shell command execution.';
if (error instanceof Error) {
// Node's child_process.ExecException often has stdout and stderr properties
const execError = error;
errorMessage =
execError.stderr || execError.stdout || execError.message;
}
else if (typeof error === 'string') {
errorMessage = error;
}
// Ensure a default message if somehow it's still undefined (though unlikely with above checks)
if (!errorMessage && error) {
errorMessage = String(error);
}
throw new Error(`Failed to ${operationDesc}: ${errorMessage}`);
}
}