@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
118 lines (117 loc) • 4.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatPagesList = formatPagesList;
exports.formatPageDetails = formatPageDetails;
const markdown_util_js_1 = require("../utils/markdown.util.js");
const formatter_util_js_1 = require("../utils/formatter.util.js");
/**
* Format a list of pages for display
* @param pagesData - Raw pages data from the API
* @param baseUrl - Base URL for constructing page links
* @returns Formatted string with pages information in markdown format
*/
function formatPagesList(pagesData, baseUrl = '') {
if (!pagesData || pagesData.length === 0) {
return 'No Confluence pages found matching your criteria.';
}
const lines = [(0, formatter_util_js_1.formatHeading)('Confluence Pages', 1), ''];
// Format each page with its details
const formattedList = (0, formatter_util_js_1.formatNumberedList)(pagesData, (page, index) => {
const itemLines = [];
// Basic information
itemLines.push((0, formatter_util_js_1.formatHeading)(page.title, 2));
// Create an object with all the properties to display
const pageUrl = `${baseUrl}/pages/viewpage.action?pageId=${page.id}`;
const properties = {
ID: page.id,
Status: page.status,
'Space ID': page.spaceId || 'N/A',
Title: page.title,
Created: page.createdAt
? (0, formatter_util_js_1.formatDate)(new Date(page.createdAt))
: 'Not available',
Author: page.authorId || 'Unknown',
Version: page.version?.number || 'N/A',
URL: (0, formatter_util_js_1.formatUrl)(pageUrl, page.title),
};
// Format as a bullet list
itemLines.push((0, formatter_util_js_1.formatBulletList)(properties, (key) => key));
// Add separator between pages except for the last one
if (index < pagesData.length - 1) {
itemLines.push('');
itemLines.push((0, formatter_util_js_1.formatSeparator)());
}
return itemLines.join('\n');
});
lines.push(formattedList);
// Add timestamp for when this information was retrieved
lines.push('');
lines.push(`*Page information retrieved at ${(0, formatter_util_js_1.formatDate)(new Date())}*`);
return lines.join('\n');
}
/**
* Format detailed page information for display
* @param pageData - Raw page details from the API
* @returns Formatted string with page details in markdown format
*/
function formatPageDetails(pageData) {
// Create URL
const baseUrl = pageData._links.base || '';
const pageUrl = pageData._links.webui || '';
const fullUrl = pageUrl.startsWith('http')
? pageUrl
: `${baseUrl}${pageUrl}`;
const lines = [
(0, formatter_util_js_1.formatHeading)(`Confluence Page: ${pageData.title}`, 1),
'',
`> A ${pageData.status} page in space \`${pageData.spaceId}\` created on ${(0, formatter_util_js_1.formatDate)(pageData.createdAt)}.`,
'',
(0, formatter_util_js_1.formatHeading)('Basic Information', 2),
];
// Format basic information as a bullet list
const basicProperties = {
ID: pageData.id,
Title: pageData.title,
'Space ID': pageData.spaceId,
Status: pageData.status,
'Created At': pageData.createdAt,
'Author ID': pageData.authorId,
'Parent ID': pageData.parentId,
};
lines.push((0, formatter_util_js_1.formatBulletList)(basicProperties, (key) => key));
// Content section
lines.push('');
lines.push((0, formatter_util_js_1.formatHeading)('Content', 2));
if (pageData.body?.view?.value) {
// Convert HTML content to Markdown
const markdownContent = (0, markdown_util_js_1.htmlToMarkdown)(pageData.body.view.value.trim());
lines.push(markdownContent);
}
else {
lines.push('*No content available*');
}
// Labels section
lines.push('');
lines.push((0, formatter_util_js_1.formatHeading)('Labels', 2));
if (pageData.labels?.results && pageData.labels.results.length > 0) {
const labelLines = [];
pageData.labels.results.forEach((label) => {
labelLines.push(`- **${label.name}** (ID: ${label.id})`);
});
lines.push(labelLines.join('\n'));
}
else {
lines.push('*No labels assigned to this page*');
}
// Links section
lines.push('');
lines.push((0, formatter_util_js_1.formatHeading)('Links', 2));
lines.push(`- **Web UI**: ${fullUrl}`);
lines.push(`- ${(0, formatter_util_js_1.formatUrl)(fullUrl, 'Open in Confluence')}`);
// Footer
lines.push('');
lines.push((0, formatter_util_js_1.formatSeparator)());
lines.push(`*Page information retrieved at ${(0, formatter_util_js_1.formatDate)(new Date())}*`);
lines.push(`*To view this page in Confluence, visit: ${fullUrl}*`);
return lines.join('\n');
}