mcp-adr-analysis-server
Version:
MCP server for analyzing Architectural Decision Records and project architecture
107 lines (93 loc) ⢠3.79 kB
JavaScript
/**
* Expand Analysis Tool
*
* Retrieves full analysis content from tiered responses stored in memory.
* Supports expanding entire analysis or specific sections.
*/
import { TieredResponseManager } from '../utils/tiered-response-manager.js';
import { MemoryEntityManager } from '../utils/memory-entity-manager.js';
import { McpAdrError } from '../types/index.js';
export async function expandAnalysisSection(params) {
const { expandableId, section, format = 'markdown' } = params;
try {
const memoryManager = new MemoryEntityManager();
const tieredManager = new TieredResponseManager(memoryManager);
await tieredManager.initialize();
// Retrieve expandable content
const expandableContent = await tieredManager.getExpandableContent(expandableId);
if (!expandableContent) {
throw new McpAdrError(`No expandable content found for ID: ${expandableId}. It may have been deleted or expired.`, 'NOT_FOUND');
}
// Determine what to return
let outputContent;
let title;
if (section) {
// Expand specific section
if (!expandableContent.sections[section]) {
const availableSections = Object.keys(expandableContent.sections).join(', ');
throw new McpAdrError(`Section "${section}" not found. Available sections: ${availableSections}`, 'INVALID_INPUT');
}
outputContent = expandableContent.sections[section];
title = `${expandableContent.metadata.toolName} - ${section}`;
}
else {
// Expand full analysis
outputContent = expandableContent.content;
title = `${expandableContent.metadata.toolName} - Full Analysis`;
}
// Format output
if (format === 'json') {
return {
content: [
{
type: 'text',
text: JSON.stringify({
expandableId,
section: section || 'full',
metadata: expandableContent.metadata,
content: outputContent,
}, null, 2),
},
],
};
}
// Markdown format (default)
const formattedOutput = `# ${title}
## š Analysis Details
**Tool:** ${expandableContent.metadata.toolName}
**Generated:** ${new Date(expandableContent.metadata.timestamp).toLocaleString()}
**Token Count:** ~${expandableContent.metadata.tokenCount} tokens
**Expandable ID:** \`${expandableId}\`
${section ? `**Section:** ${section}` : '**Scope:** Complete Analysis'}
---
## š Content
${outputContent}
---
## š Related Actions
${!section && Object.keys(expandableContent.sections).length > 0
? `
### Available Sections
You can expand specific sections for focused analysis:
${Object.keys(expandableContent.sections)
.map(s => `- **${s}**: \`expand_analysis_section\` with \`expandableId: "${expandableId}", section: "${s}"\``)
.join('\n')}
`
: ''}
### Tool Arguments Used
\`\`\`json
${JSON.stringify(expandableContent.metadata.toolArgs || {}, null, 2)}
\`\`\`
š” **Tip:** You can reference this analysis using expandable ID \`${expandableId}\` in future conversations.
`;
return {
content: [{ type: 'text', text: formattedOutput }],
};
}
catch (error) {
if (error instanceof McpAdrError) {
throw error;
}
throw new McpAdrError(`Failed to expand analysis: ${error instanceof Error ? error.message : String(error)}`, 'EXPANSION_ERROR');
}
}
//# sourceMappingURL=expand-analysis-tool.js.map