@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
97 lines (96 loc) • 5.06 kB
JavaScript
;
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_types_js_1 = require("./atlassian.spaces.types.js");
const atlassian_spaces_controller_js_1 = __importDefault(require("../controllers/atlassian.spaces.controller.js"));
/**
* MCP Tool: List Confluence Spaces
*
* Lists Confluence spaces with optional filtering by type and name.
* Returns a formatted markdown response with space details and pagination info.
*
* @param {ListSpacesToolArgsType} args - Tool arguments for filtering spaces
* @returns {Promise<{ content: Array<{ type: 'text', text: string }> }>} MCP response with formatted spaces list
* @throws Will return error message if space listing fails
*/
async function listSpaces(args) {
const toolLogger = logger_util_js_1.Logger.forContext('tools/atlassian.spaces.tool.ts', 'listSpaces');
toolLogger.debug('Listing Confluence spaces with filters:', args);
try {
// Pass the args directly to the controller without any transformation
const result = await atlassian_spaces_controller_js_1.default.list(args);
toolLogger.debug('Successfully retrieved spaces from controller');
return {
content: [
{
type: 'text',
text: result.content, // Content now includes pagination information
},
],
};
}
catch (error) {
toolLogger.error('Failed to list spaces', error);
return (0, error_util_js_1.formatErrorForMcpTool)(error);
}
}
/**
* MCP Tool: Get Confluence Space Details
*
* Retrieves detailed information about a specific Confluence space.
* Returns a formatted markdown response with space metadata.
*
* @param {GetSpaceToolArgsType} args - Tool arguments containing the space key or ID
* @returns {Promise<{ content: Array<{ type: 'text', text: string }> }>} MCP response with formatted space details
* @throws Will return error message if space retrieval fails
*/
async function getSpace(args) {
const methodLogger = logger_util_js_1.Logger.forContext('tools/atlassian.spaces.tool.ts', 'getSpace');
methodLogger.debug('Tool called with args:', args);
try {
// Call the controller to get space details with args directly
const result = await atlassian_spaces_controller_js_1.default.get(args);
methodLogger.debug('Successfully retrieved space details');
// Convert the string content to an MCP text resource
return {
content: [
{
type: 'text',
text: result.content,
},
],
};
}
catch (error) {
methodLogger.error('Error retrieving space details:', error);
// Format the error for MCP tools
return (0, error_util_js_1.formatErrorForMcpTool)(error);
}
}
/**
* Register Atlassian Spaces MCP Tools
*
* Registers the list-spaces and get-space tools with the MCP server.
* Each tool is registered with its schema, description, and handler function.
*
* @param {McpServer} server - The MCP server instance to register tools with
*/
function registerTools(server) {
const toolLogger = logger_util_js_1.Logger.forContext('tools/atlassian.spaces.tool.ts', 'registerTools');
toolLogger.debug('Registering Atlassian Spaces tools...');
// Register the list spaces tool
server.tool('conf_ls_spaces', `Lists Confluence spaces accessible to the user, with optional filtering by \`type\` (global, personal), or \`status\` (current, archived).
- Use this to discover spaces and find their keys needed for other tools.
- Supports pagination via \`limit\` and \`cursor\` parameters. Pagination information, including next cursor value, is included directly in the returned text content.
- **Note:** Filtering by \`type\` alone does not filter by status; the \`status\` parameter defaults to returning spaces with *all* statuses (current and archived) unless explicitly set to \`current\` or \`archived\`.
- Returns a formatted list of spaces including ID, key, name, type, status, and URL.
- Default sort is by name descending.`, atlassian_spaces_types_js_1.ListSpacesToolArgs.shape, listSpaces);
// Register the get space details tool
server.tool('conf_get_space', `Retrieves comprehensive details for a specific Confluence space identified by \`spaceKey\`. Returns the space's description, homepage ID, type, status, theme, permissions, and other metadata as formatted Markdown. Use this after finding a space key via \`conf_ls_spaces\` to get the full space context.`, atlassian_spaces_types_js_1.GetSpaceToolArgs.shape, getSpace);
toolLogger.debug('Successfully registered Atlassian Spaces tools');
}
exports.default = { registerTools };