MCP ADR Analysis Server Architecture
Overviewโ
The MCP ADR Analysis Server is an intelligent architectural analysis platform that provides LLM clients with comprehensive ADR (Architectural Decision Record) analysis capabilities. The server has evolved from a prompt-only system to a hybrid architecture that combines actual file system operations with intelligent AI processing.
High-Level Communication Flowโ
Detailed Tool Communication Patternโ
Before vs After Architecture Comparisonโ
Core Componentsโ
1. MCP Server Core (src/index.ts)โ
- Entry Point: Main server initialization and protocol handling
- Tool Registry: 31 MCP tools for comprehensive ADR analysis and project management
- Resource Registry: 3 MCP resources for structured data access
- Prompt Registry: AI-ready templates for analysis tasks
- Knowledge Graph: Advanced intent tracking and TODO synchronization
2. File System Layer (New)โ
Three new fundamental tools that enable universal LLM compatibility:
read_file Toolโ
{
name: 'read_file',
description: 'Read contents of a file',
inputSchema: {
type: 'object',
properties: {
path: { type: 'string', description: 'Path to file' }
},
required: ['path']
}
}
write_file Toolโ
{
name: 'write_file',
description: 'Write content to a file',
inputSchema: {
type: 'object',
properties: {
path: { type: 'string', description: 'Path to file' },
content: { type: 'string', description: 'Content to write' }
},
required: ['path', 'content']
}
}
list_directory Toolโ
{
name: 'list_directory',
description: 'List contents of a directory',
inputSchema: {
type: 'object',
properties: {
path: { type: 'string', description: 'Path to directory' }
},
required: ['path']
}
}
3. Utility Layerโ
Provides actual file operations and intelligent processing:
ADR Discovery (src/utils/adr-discovery.js)โ
- Function:
discoverAdrsInDirectory() - Purpose: Actually read and parse ADR files + initialize
.mcp-adr-cacheinfrastructure - Output: Structured ADR data with content
- Note: Always initializes cache infrastructure, regardless of ADR presence
File Operations (src/utils/actual-file-operations.js)โ
- Function:
scanProjectStructure() - Purpose: Comprehensive project analysis
- Features: Shell script detection, content masking, pattern matching
Content Masking (src/utils/content-masking.js)โ
- Function:
analyzeSensitiveContent() - Purpose: Security analysis and data protection
- Features: Pattern detection, confidence scoring, masking strategies
Research Integration (src/utils/research-integration.js)โ
- Function:
monitorResearchDirectory() - Purpose: Research file processing and ADR impact analysis
- Features: Topic extraction, impact evaluation, update suggestions
4. AI Processing Layerโ
Internal AI Engine (src/utils/prompt-execution.js)โ
// Enhanced analysis with actual file content
const result = await discoverAdrsInDirectory(adrDirectory, true, projectPath);
const analysisPrompt = generatePrompt(result.actualContent);
const aiResult = await executePromptWithFallback(analysisPrompt);
AI-Powered Tool Orchestrationโ
- OpenRouter.ai Integration: Advanced AI planning through external LLM services
- Dynamic Tool Sequencing: AI generates optimal tool execution sequences
- Hallucination Detection: Reality checks prevent AI confusion and loops
- Human Override Patterns: Predefined workflows bypass AI confusion
Generated Knowledge Prompting (GKP)โ
- Enhanced Analysis: Leverages architectural knowledge for better insights
- Context-Aware: Understands project-specific patterns and technologies
- Confidence Scoring: Provides reliability metrics for recommendations
Intelligent Workflow Managementโ
// AI-powered tool orchestration
const plan = await generateToolPlan(userIntent, availableTools);
const sequence = await validateToolSequence(plan.tools);
const execution = await executeWithFallback(sequence);
Fallback Strategyโ
if (executionResult.isAIGenerated) {
// Return smart analysis
return formatMCPResponse({...});
} else {
// Return raw data for external processing
return { content: [...] };
}
Key Architectural Improvementsโ
1. Universal LLM Compatibilityโ
- Before: Worked only with Claude (had file access)
- After: Works with all LLM providers through internal file operations
2. Intelligent Fallback Strategyโ
The server provides both AI-enhanced analysis and raw data depending on capabilities:
- AI Available: Smart insights with confidence scores
- AI Unavailable: Structured prompts with actual file content
3. Security-First File Accessโ
- Path Validation: Absolute paths required, security sandboxing
- Content Masking: Automatic sensitive data detection and protection
- Access Control: Configurable project boundaries
4. Performance Optimizationโ
- Caching System: Results cached in
.mcp-adr-cache/with TTL - Lazy Loading: Utilities loaded on-demand
- Intelligent Filtering: Content-aware file processing
5. Enhanced AI Capabilitiesโ
- Generated Knowledge Prompting: Domain expertise enhancement
- Context Awareness: Project-specific analysis
- Risk Assessment: Confidence scoring and impact evaluation
6. Advanced Project Management Toolsโ
- Smart Scoring System: Dynamic project health assessment across all dimensions
- TODO Lifecycle Management: Complete task tracking with status transitions
- AI-Powered Troubleshooting: Systematic failure analysis with test plan generation
- Intelligent Tool Orchestration: Dynamic workflow automation based on user intent
- Human Override System: Force planning when LLMs get confused or stuck
- Smart Git Operations: Release readiness analysis with sensitive content filtering
7. Knowledge Graph Integrationโ
- Intent Tracking: Comprehensive tracking of human requests and AI responses
- Tool Execution History: Complete audit trail of all tool executions
- TODO Synchronization: Bidirectional sync between TODO.md and knowledge graph
- Analytics Generation: Real-time project insights and completion metrics
Communication Protocolsโ
MCP Protocol Integrationโ
The server communicates with LLM clients via the Model Context Protocol:
- Transport: stdin/stdout JSON-RPC
- Format: Structured tool calls and responses
- Validation: Zod schema validation for all inputs/outputs
Tool Execution Flowโ
- Client Request: LLM client calls MCP tool
- Security Validation: Path and content validation
- File Operations: Read actual project files
- AI Processing: Internal analysis or prompt generation
- Response: Structured insights or prompts for external processing
File System Securityโ
Path Securityโ
// Absolute path requirement
if (!path.isAbsolute(filePath)) {
throw new McpAdrError('File path must be absolute', 'INVALID_PATH');
}
// Project boundary validation
const projectPath = process.env.PROJECT_PATH || process.cwd();
if (!filePath.startsWith(projectPath)) {
throw new McpAdrError('Access denied: file outside project', 'ACCESS_DENIED');
}