UNPKG

@aashari/mcp-server-atlassian-confluence

Version:

Node.js/TypeScript MCP server for Atlassian Confluence. Provides tools enabling AI systems (LLMs) to list/get spaces & pages (content formatted as Markdown) and search via CQL. Connects AI seamlessly to Confluence knowledge bases using the standard MCP in

113 lines (112 loc) 5.84 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const logger_util_js_1 = require("../utils/logger.util.js"); const error_util_js_1 = require("../utils/error.util.js"); const atlassian_spaces_controller_js_1 = __importDefault(require("../controllers/atlassian.spaces.controller.js")); /** * CLI module for managing Confluence spaces. * Provides commands for listing spaces and retrieving space details. * All commands require valid Atlassian credentials. */ /** * Register Confluence Spaces CLI commands with the Commander program * @param program - The Commander program instance to register commands with * @throws Error if command registration fails */ function register(program) { const cliLogger = logger_util_js_1.Logger.forContext('cli/atlassian.spaces.cli.ts', 'register'); cliLogger.debug('Registering Confluence Spaces CLI commands...'); registerListSpacesCommand(program); registerGetSpaceCommand(program); cliLogger.debug('CLI commands registered successfully'); } /** * Register the command for listing Confluence spaces * @param program - The Commander program instance */ function registerListSpacesCommand(program) { program .command('ls-spaces') .description('List Confluence spaces accessible to the user, with filtering and pagination.') .option('-l, --limit <number>', 'Maximum number of items to return (1-100). Use this to control the response size. Useful for pagination or when you only need a few results. The Confluence API caps results at 100 items per request.', '25') .option('-c, --cursor <string>', 'Pagination cursor for retrieving the next set of results. Use this to navigate through large result sets. The cursor value can be obtained from the pagination information in a previous response.') .option('-t, --type <type>', 'Filter spaces by type. Options include: "global" (team spaces), "personal" (user spaces), or "archived" (archived spaces). If omitted, returns all types.', 'global') .option('-s, --status <status>', 'Filter spaces by status. Options include: "current" (active spaces) or "archived" (archived spaces). If omitted, returns spaces with all statuses.', 'current') .action(async (options) => { const actionLogger = logger_util_js_1.Logger.forContext('cli/atlassian.spaces.cli.ts', 'ls-spaces'); try { actionLogger.debug('Processing command options:', options); // Validate type if provided if (options.type && !['global', 'personal', 'archived'].includes(options.type)) { throw new Error('Type must be one of: "global", "personal", or "archived"'); } // Validate status if provided if (options.status && !['current', 'archived'].includes(options.status)) { throw new Error('Status must be either "current" or "archived"'); } // Validate limit if provided if (options.limit) { const limit = parseInt(options.limit, 10); if (isNaN(limit) || limit <= 0) { throw new Error('Invalid --limit value: Must be a positive integer.'); } } const filterOptions = { ...(options.type && { type: options.type, }), ...(options.status && { status: options.status, }), ...(options.limit && { limit: parseInt(options.limit, 10), }), ...(options.cursor && { cursor: options.cursor }), }; actionLogger.debug('Fetching spaces with filters:', filterOptions); const result = await atlassian_spaces_controller_js_1.default.list(filterOptions); actionLogger.debug('Successfully retrieved spaces'); // Print the main content (which now includes pagination information) console.log(result.content); } catch (error) { actionLogger.error('Operation failed:', error); (0, error_util_js_1.handleCliError)(error); } }); } /** * Register the command for retrieving a specific Confluence space * @param program - The Commander program instance */ function registerGetSpaceCommand(program) { program .command('get-space') .description('Get detailed information about a specific Confluence space using its key.') .requiredOption('-k, --space-key <key>', 'The key of the Confluence space to retrieve (e.g., "DEV" or "MARKETING"). The space key is a unique identifier for a space, typically a short uppercase code.') .action(async (options) => { const actionLogger = logger_util_js_1.Logger.forContext('cli/atlassian.spaces.cli.ts', 'get-space'); try { actionLogger.debug('Processing command options:', options); // Validate space key format (typically uppercase alphanumeric) if (!options.spaceKey.match(/^[A-Za-z0-9_]+$/)) { throw new Error('Space key must contain only letters, numbers, and underscores.'); } actionLogger.debug(`Fetching space: ${options.spaceKey}`); const result = await atlassian_spaces_controller_js_1.default.get({ spaceKey: options.spaceKey, }); // Print the main content (already includes all information) console.log(result.content); } catch (error) { (0, error_util_js_1.handleCliError)(error); } }); } exports.default = { register };