@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
90 lines (89 loc) • 3.38 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDefaultWorkspace = getDefaultWorkspace;
exports.getWorkspaces = getWorkspaces;
const logger_util_js_1 = require("./logger.util.js");
const config_util_js_1 = require("./config.util.js");
const vendor_atlassian_workspaces_service_js_1 = __importDefault(require("../services/vendor.atlassian.workspaces.service.js"));
const workspaceLogger = logger_util_js_1.Logger.forContext('utils/workspace.util.ts');
/**
* Cache for workspace data to avoid repeated API calls
*/
let cachedDefaultWorkspace = null;
let cachedWorkspaces = null;
/**
* Get the default workspace slug
*
* This function follows this priority:
* 1. Use cached value if available
* 2. Check BITBUCKET_DEFAULT_WORKSPACE environment variable
* 3. Fetch from API and use the first workspace in the list
*
* @returns {Promise<string|null>} The default workspace slug or null if not available
*/
async function getDefaultWorkspace() {
const methodLogger = workspaceLogger.forMethod('getDefaultWorkspace');
// Step 1: Return cached value if available
if (cachedDefaultWorkspace) {
methodLogger.debug(`Using cached default workspace: ${cachedDefaultWorkspace}`);
return cachedDefaultWorkspace;
}
// Step 2: Check environment variable
const envWorkspace = config_util_js_1.config.get('BITBUCKET_DEFAULT_WORKSPACE');
if (envWorkspace) {
methodLogger.debug(`Using default workspace from environment: ${envWorkspace}`);
cachedDefaultWorkspace = envWorkspace;
return envWorkspace;
}
// Step 3: Fetch from API
methodLogger.debug('No default workspace configured, fetching from API...');
try {
const workspaces = await getWorkspaces();
if (workspaces.length > 0) {
const defaultWorkspace = workspaces[0].workspace.slug;
methodLogger.debug(`Using first workspace from API as default: ${defaultWorkspace}`);
cachedDefaultWorkspace = defaultWorkspace;
return defaultWorkspace;
}
else {
methodLogger.warn('No workspaces found in the account');
return null;
}
}
catch (error) {
methodLogger.error('Failed to fetch default workspace', error);
return null;
}
}
/**
* Get list of workspaces from API or cache
*
* @returns {Promise<WorkspaceMembership[]>} Array of workspace membership objects
*/
async function getWorkspaces() {
const methodLogger = workspaceLogger.forMethod('getWorkspaces');
if (cachedWorkspaces) {
methodLogger.debug(`Using ${cachedWorkspaces.length} cached workspaces`);
return cachedWorkspaces;
}
try {
const result = await vendor_atlassian_workspaces_service_js_1.default.list({
pagelen: 10, // Limit to first 10 workspaces
});
if (result.values) {
cachedWorkspaces = result.values;
methodLogger.debug(`Cached ${result.values.length} workspaces`);
return result.values;
}
else {
return [];
}
}
catch (error) {
methodLogger.error('Failed to fetch workspaces list', error);
return [];
}
}