@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
132 lines (131 loc) • 6.52 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CLI_NAME = exports.PACKAGE_NAME = exports.VERSION = exports.config = exports.Logger = void 0;
exports.startServer = startServer;
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
const logger_util_js_1 = require("./utils/logger.util.js");
const config_util_js_1 = require("./utils/config.util.js");
Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_util_js_1.config; } });
const error_util_js_1 = require("./utils/error.util.js");
const constants_util_js_1 = require("./utils/constants.util.js");
const index_js_1 = require("./cli/index.js");
// Import Confluence-specific tools
const atlassian_spaces_tool_js_1 = __importDefault(require("./tools/atlassian.spaces.tool.js"));
const atlassian_pages_tool_js_1 = __importDefault(require("./tools/atlassian.pages.tool.js"));
const atlassian_search_tool_js_1 = __importDefault(require("./tools/atlassian.search.tool.js"));
// Create a contextualized logger for this file
const indexLogger = logger_util_js_1.Logger.forContext('index.ts');
// Log initialization at debug level
indexLogger.debug('Confluence MCP server module loaded');
let serverInstance = null;
let transportInstance = null;
/**
* Start the MCP server with the specified transport mode
*
* @param mode The transport mode to use (stdio or sse)
* @returns Promise that resolves to the server instance when started successfully
*/
async function startServer(mode = 'stdio') {
// Create method-level logger with more specific context
const serverLogger = logger_util_js_1.Logger.forContext('index.ts', 'startServer');
// Load configuration
serverLogger.info('Starting MCP server initialization...');
config_util_js_1.config.load();
serverLogger.info('Configuration loaded successfully');
// Enable debug logging if DEBUG is set to true
if (config_util_js_1.config.getBoolean('DEBUG')) {
serverLogger.debug('Debug mode enabled');
}
// Log debug configuration settings at debug level
serverLogger.debug(`DEBUG environment variable: ${process.env.DEBUG}`);
serverLogger.debug(`ATLASSIAN_API_TOKEN exists: ${Boolean(process.env.ATLASSIAN_API_TOKEN)}`);
serverLogger.debug(`Config DEBUG value: ${config_util_js_1.config.get('DEBUG')}`);
serverLogger.info(`Initializing Confluence MCP server v${constants_util_js_1.VERSION}`);
serverInstance = new mcp_js_1.McpServer({
name: constants_util_js_1.PACKAGE_NAME,
version: constants_util_js_1.VERSION,
});
if (mode === 'stdio') {
serverLogger.info('Using STDIO transport for MCP communication');
transportInstance = new stdio_js_1.StdioServerTransport();
}
else {
throw (0, error_util_js_1.createUnexpectedError)('SSE mode is not supported yet');
}
// Register tools
serverLogger.info('Registering MCP tools...');
atlassian_spaces_tool_js_1.default.registerTools(serverInstance);
serverLogger.debug('Registered Spaces tools');
atlassian_pages_tool_js_1.default.registerTools(serverInstance);
serverLogger.debug('Registered Pages tools');
atlassian_search_tool_js_1.default.registerTools(serverInstance);
serverLogger.debug('Registered Search tools');
serverLogger.info('All tools registered successfully');
try {
serverLogger.info(`Connecting to ${mode.toUpperCase()} transport...`);
await serverInstance.connect(transportInstance);
serverLogger.info('MCP server started successfully and ready to process requests');
return serverInstance;
}
catch (err) {
serverLogger.error(`Failed to start server`, err);
process.exit(1);
}
}
/**
* Main entry point - this will run when executed directly
* Determines whether to run in CLI or server mode based on command-line arguments
*/
async function main() {
// Create method-level logger with more specific context
const mainLogger = logger_util_js_1.Logger.forContext('index.ts', 'main');
// Load configuration
config_util_js_1.config.load();
// Check if arguments are provided (CLI mode)
if (process.argv.length > 2) {
// CLI mode: Pass arguments to CLI runner
mainLogger.info('Starting in CLI mode');
await (0, index_js_1.runCli)(process.argv.slice(2));
mainLogger.info('CLI execution completed');
}
else {
// MCP Server mode: Start server with default STDIO
mainLogger.info('Starting in server mode');
await startServer();
mainLogger.info('Server is now running');
}
}
// If this file is being executed directly (not imported), run the main function
if (require.main === module) {
main().catch((err) => {
indexLogger.error('Unhandled error in main process', err);
process.exit(1);
});
}
// Export key utilities for library users
var logger_util_js_2 = require("./utils/logger.util.js");
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_util_js_2.Logger; } });
__exportStar(require("./utils/error.util.js"), exports);
var constants_util_js_2 = require("./utils/constants.util.js");
Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return constants_util_js_2.VERSION; } });
Object.defineProperty(exports, "PACKAGE_NAME", { enumerable: true, get: function () { return constants_util_js_2.PACKAGE_NAME; } });
Object.defineProperty(exports, "CLI_NAME", { enumerable: true, get: function () { return constants_util_js_2.CLI_NAME; } });