// /Users/Luther/RiderProjects/claude/mcp-servers/conversation-continuity/src/index.ts
/**
* Conversation Continuity MCP Server - Main Entry Point
* The world's first MCP orchestrator for seamless AI development sessions
*
* CLEANED: Removed all emojis and optimized console logging for JSON-RPC compatibility
*/
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import {
CallToolRequestSchema,
ListToolsRequestSchema,
} from '@modelcontextprotocol/sdk/types.js';
import { MCPClientFactory } from '@/utils/mcp-client-factory.js';
import { ConversationContinuityOrchestrator } from '@/conductor/mcp-orchestrator.js';
import { SessionRulesEngine } from '@/components/session-rules.js';
import type { SessionRule } from '@/types/rule-types.js';
import type { MCPClientConfig } from '@/types/orchestration-types.js';
import type { ProposedAction } from '@/types/rule-types.js';
import type { MCPType } from '@/types/shared-types.js';
import type { ProjectIntelligence, ProjectChange } from '@/types/project-intelligence-types.js';
// Global types are automatically included via global.d.ts
// ===== NULL RULES ENGINE FOR MISSING MEMORY MCP =====
class NullSessionRulesEngine {
async createRule(ruleData: any): Promise<SessionRule> {
return {
id: `disabled_rule_${Date.now()}`,
rule: ruleData.rule || 'Rule creation disabled',
type: ruleData.type || 'workflow',
priority: ruleData.priority || 1,
active: false,
scope: ruleData.scope || 'session',
enforcement: ruleData.enforcement || 'log_only',
createdAt: new Date(),
updatedAt: new Date(),
usageCount: 0,
violationCount: 0
};
}
async getRules(scope?: string): Promise<SessionRule[]> {
return [];
}
async enforceRules(action: ProposedAction): Promise<any[]> {
return [];
}
async initializeLutherRules(): Promise<void> {
// Rules initialization disabled - Memory MCP not available
}
async optimizeRules(): Promise<any[]> {
return [];
}
}
class ConversationContinuityServer {
private server: Server;
private orchestrator!: ConversationContinuityOrchestrator;
private rulesEngine!: SessionRulesEngine | NullSessionRulesEngine;
private clientFactory!: MCPClientFactory;
private currentSession = { id: `session_${Date.now()}` };
constructor() {
this.server = new Server(
{
name: 'conversation-continuity',
version: '1.0.0',
},
{
capabilities: {
tools: {},
},
}
);
this.setupHandlers();
}
private setupHandlers() {
// List available tools
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
// === CHECKPOINT SYSTEM ===
{
name: 'create_checkpoint',
description: 'Create a new real checkpoint of RiderProjects directory',
inputSchema: {
type: 'object',
properties: {
description: { type: 'string', description: 'Description of the checkpoint' },
name: { type: 'string', description: 'Optional name for the checkpoint' }
},
required: ['description'],
},
},
{
name: 'list_checkpoints',
description: 'List all available real checkpoints',
inputSchema: {
type: 'object',
properties: {},
},
},
{
name: 'restore_checkpoint',
description: 'Restore a checkpoint (with emergency backup)',
inputSchema: {
type: 'object',
properties: {
checkpoint: { type: 'string', description: 'Checkpoint ID or partial name to restore' },
dry_run: { type: 'boolean', description: 'Preview restore without applying changes' }
},
required: ['checkpoint'],
},
},
{
name: 'setup_claudepoint',
description: 'Initialize the real checkpoint system',
inputSchema: {
type: 'object',
properties: {},
},
},
{
name: 'get_changelog',
description: 'Get development history and changelog',
inputSchema: {
type: 'object',
properties: {},
},
},
{
name: 'set_changelog',
description: 'Add entry to development changelog',
inputSchema: {
type: 'object',
properties: {
action_type: { type: 'string', description: 'Type of action (CREATE_CHECKPOINT, FEATURE, BUG_FIX, etc.)' },
description: { type: 'string', description: 'Description of the change' },
details: { type: 'string', description: 'Additional details about the change' }
},
required: ['action_type', 'description'],
},
},
// === ECOSYSTEM MONITORING ===
{
name: 'monitor_ecosystem_state',
description: 'Monitor the state of all 5 integrated MCPs (Memory, Claudepoint, Filesystem, Git, Database)',
inputSchema: {
type: 'object',
properties: {},
},
},
// === SESSION RULES ===
{
name: 'create_session_rule',
description: 'Create a new persistent session rule (stored in Memory MCP)',
inputSchema: {
type: 'object',
properties: {
rule: { type: 'string', description: 'The rule text' },
type: {
type: 'string',
enum: ['approval', 'display', 'architecture', 'workflow', 'quality', 'documentation', 'conditional'],
description: 'Type of rule'
},
priority: { type: 'number', description: 'Rule priority (lower = higher priority)' },
enforcement: {
type: 'string',
enum: ['hard_block', 'soft_block', 'reminder', 'suggestion', 'log_only'],
description: 'How strictly to enforce the rule'
},
triggers: {
type: 'array',
items: { type: 'string' },
description: 'Action types that trigger this rule'
},
scope: {
type: 'string',
enum: ['user', 'project', 'session'],
description: 'Scope of rule application'
}
},
required: ['rule'],
},
},
{
name: 'get_session_rules',
description: 'Retrieve all active session rules',
inputSchema: {
type: 'object',
properties: {
scope: {
type: 'string',
enum: ['user', 'project', 'session'],
description: 'Optional: filter by rule scope'
}
},
},
},
{
name: 'enforce_session_rules',
description: 'Check if a proposed action complies with session rules',
inputSchema: {
type: 'object',
properties: {
action: {
type: 'object',
properties: {
type: { type: 'string', description: 'Type of action being attempted' },
description: { type: 'string', description: 'Description of the action' },
context: { type: 'object', description: 'Additional context for the action' },
riskLevel: {
type: 'string',
enum: ['low', 'medium', 'high'],
description: 'Risk level of the action'
},
reversible: { type: 'boolean', description: 'Whether the action can be undone' }
},
required: ['type', 'description']
}
},
required: ['action'],
},
},
{
name: 'initialize_luther_rules',
description: 'Initialize Luther\'s predefined session rules',
inputSchema: {
type: 'object',
properties: {},
},
},
// === UNIFIED HANDOFF MANAGEMENT ===
{
name: 'create_unified_handoff',
description: 'Create a coordinated handoff package using all 5 MCPs',
inputSchema: {
type: 'object',
properties: {
reason: { type: 'string', description: 'Reason for creating handoff (e.g., "token limit reached")' },
currentTask: { type: 'string', description: 'Current task being worked on' }
},
},
},
{
name: 'reconstruct_context',
description: 'Reconstruct conversation context from a unified handoff package',
inputSchema: {
type: 'object',
properties: {
handoffId: { type: 'string', description: 'ID of the handoff package to reconstruct from' }
},
required: ['handoffId'],
},
},
// === MCP COORDINATION ===
{
name: 'sync_all_mcps',
description: 'Synchronize state across all integrated MCPs',
inputSchema: {
type: 'object',
properties: {
force: { type: 'boolean', description: 'Force sync even if recent sync exists' }
},
},
},
{
name: 'coordinate_checkpoint',
description: 'Create a coordinated checkpoint across multiple MCPs',
inputSchema: {
type: 'object',
properties: {
description: { type: 'string', description: 'Description of the checkpoint' }
},
},
},
// === CONVERSATION MONITORING ===
{
name: 'monitor_conversation_length',
description: 'Monitor current conversation token usage and capacity',
inputSchema: {
type: 'object',
properties: {},
},
},
{
name: 'compress_context',
description: 'Compress conversation context using intelligent algorithms',
inputSchema: {
type: 'object',
properties: {
threshold: { type: 'number', description: 'Compression threshold (0-1)' },
preserveRecent: { type: 'number', description: 'Number of recent messages to preserve verbatim' }
},
},
},
// === LEARNING & OPTIMIZATION ===
{
name: 'suggest_new_rules',
description: 'Analyze patterns and suggest new session rules',
inputSchema: {
type: 'object',
properties: {
analyzeLastDays: { type: 'number', description: 'Number of days to analyze for patterns' }
},
},
},
{
name: 'optimize_rules',
description: 'Analyze current rules and suggest optimizations',
inputSchema: {
type: 'object',
properties: {},
},
},
// === PROJECT INTELLIGENCE CACHE ===
{
name: 'create_project_intelligence_cache',
description: 'Create comprehensive project intelligence cache to eliminate session startup overhead',
inputSchema: {
type: 'object',
properties: {
projectName: { type: 'string', description: 'Name of the project (defaults to MCPConductor)' },
options: {
type: 'object',
properties: {
includeFileContents: { type: 'boolean', description: 'Include file contents in analysis' },
maxDepth: { type: 'number', description: 'Maximum directory depth to analyze' },
excludePatterns: { type: 'array', items: { type: 'string' }, description: 'Patterns to exclude from analysis' },
compressionLevel: { type: 'string', enum: ['minimal', 'standard', 'comprehensive'], description: 'Level of analysis detail' }
}
}
}
},
},
{
name: 'load_project_intelligence_cache',
description: 'Load existing project intelligence cache for instant context (eliminates exploration phase)',
inputSchema: {
type: 'object',
properties: {
projectName: { type: 'string', description: 'Name of the project to load intelligence for' }
},
required: ['projectName']
},
},
{
name: 'validate_project_intelligence_cache',
description: 'Validate freshness and accuracy of cached project intelligence',
inputSchema: {
type: 'object',
properties: {
projectName: { type: 'string', description: 'Name of the project to validate' }
},
required: ['projectName']
},
},
{
name: 'refresh_project_intelligence',
description: 'Update project intelligence cache with latest changes',
inputSchema: {
type: 'object',
properties: {
projectName: { type: 'string', description: 'Name of the project to refresh' },
changes: {
type: 'array',
items: {
type: 'object',
properties: {
type: { type: 'string', enum: ['file_added', 'file_modified', 'file_deleted', 'config_changed'] },
path: { type: 'string' },
magnitude: { type: 'string', enum: ['minor', 'moderate', 'major', 'breaking'] }
}
},
description: 'Optional: specific changes to process'
}
},
required: ['projectName']
},
},
{
name: 'invalidate_project_cache',
description: 'Invalidate project intelligence cache when major changes occur',
inputSchema: {
type: 'object',
properties: {
projectName: { type: 'string', description: 'Name of the project' },
reason: { type: 'string', description: 'Reason for invalidation' }
},
required: ['projectName', 'reason']
},
},
// === HEALTH & DIAGNOSTICS ===
{
name: 'check_mcp_health',
description: 'Check the health status of all integrated MCPs',
inputSchema: {
type: 'object',
properties: {
mcpType: {
type: 'string',
enum: ['memory', 'claudepoint', 'filesystem', 'git', 'database-platform', 'database-analytics'],
description: 'Optional: check specific MCP only'
}
},
},
},
],
};
});
// Handle tool calls
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params;
try {
switch (name) {
// === CHECKPOINT SYSTEM HANDLERS ===
case 'create_checkpoint':
return await this.handleCreateCheckpoint(args);
case 'list_checkpoints':
return await this.handleListCheckpoints();
case 'restore_checkpoint':
return await this.handleRestoreCheckpoint(args);
case 'setup_claudepoint':
return await this.handleSetupClaudepoint();
case 'get_changelog':
return await this.handleGetChangelog();
case 'set_changelog':
return await this.handleSetChangelog(args);
// === ECOSYSTEM MONITORING ===
case 'monitor_ecosystem_state':
return await this.handleMonitorEcosystem();
case 'create_session_rule':
return await this.handleCreateRule(args);
case 'get_session_rules':
return await this.handleGetRules(args);
case 'enforce_session_rules':
return await this.handleEnforceRules(args);
case 'initialize_luther_rules':
return await this.handleInitializeLutherRules();
case 'create_unified_handoff':
return await this.handleCreateHandoff(args);
case 'reconstruct_context':
return await this.handleReconstructContext(args);
case 'sync_all_mcps':
return await this.handleSyncMCPs(args);
case 'coordinate_checkpoint':
return await this.handleCoordinateCheckpoint(args);
case 'monitor_conversation_length':
return await this.handleMonitorConversation();
case 'compress_context':
return await this.handleCompressContext(args);
case 'suggest_new_rules':
return await this.handleSuggestRules(args);
case 'optimize_rules':
return await this.handleOptimizeRules();
case 'check_mcp_health':
return await this.handleCheckHealth(args);
// Project Intelligence Cache handlers
case 'create_project_intelligence_cache':
return await this.handleCreateProjectIntelligenceCache(args);
case 'load_project_intelligence_cache':
return await this.handleLoadProjectIntelligenceCache(args);
case 'validate_project_intelligence_cache':
return await this.handleValidateProjectIntelligenceCache(args);
case 'refresh_project_intelligence':
return await this.handleRefreshProjectIntelligence(args);
case 'invalidate_project_cache':
return await this.handleInvalidateProjectCache(args);
default:
throw new Error(`Unknown tool: ${name}`);
}
} catch (error) {
return {
content: [
{
type: 'text',
text: `Error: ${error instanceof Error ? error.message : String(error)}`,
},
],
};
}
});
}
// ===== CHECKPOINT SYSTEM HANDLERS =====
private async handleCreateCheckpoint(args: any) {
try {
const clients = await this.clientFactory.getAllAvailableClients();
if (!clients.claudepoint) {
return {
content: [{
type: 'text',
text: 'Error: Real checkpoint system not available - ClaudePoint client not initialized.'
}]
};
}
const checkpoint = await clients.claudepoint.createCheckpoint({
description: args.description,
name: args.name
});
return {
content: [{
type: 'text',
text: `Real checkpoint created successfully!
**Checkpoint ID**: ${checkpoint.id}
**Name**: ${checkpoint.name}
**Description**: ${checkpoint.description}
**Created**: ${checkpoint.createdAt.toLocaleString()}
**File Count**: ${checkpoint.fileCount}
**Location**: /Users/Luther/RiderProjects/.checkpoints/snapshots/${checkpoint.id}
**Size**: Expected ~5-50MB (much smaller than old system!)
Your RiderProjects directory has been safely backed up with smart exclusions.`
}]
};
} catch (error) {
return {
content: [{
type: 'text',
text: `Failed to create checkpoint: ${error instanceof Error ? error.message : String(error)}`
}]
};
}
}
private async handleListCheckpoints() {
try {
const clients = await this.clientFactory.getAllAvailableClients();
if (!clients.claudepoint) {
return {
content: [{
type: 'text',
text: 'Error: Real checkpoint system not available - ClaudePoint client not initialized.'
}]
};
}
const checkpoints = await clients.claudepoint.listCheckpoints();
if (checkpoints.length === 0) {
return {
content: [{
type: 'text',
text: 'No real checkpoints found.\n\nCreate your first checkpoint with `create_checkpoint`!'
}]
};
}
const checkpointList = checkpoints.map((cp, index) =>
`${index + 1}. **${cp.name}**\n Description: ${cp.description}\n Created: ${cp.createdAt.toLocaleString()} | ${cp.fileCount} files\n ID: \`${cp.id}\``
).join('\n\n');
return {
content: [{
type: 'text',
text: `Real Checkpoints (${checkpoints.length} total):\n\n${checkpointList}\n\n**Location**: /Users/Luther/RiderProjects/.checkpoints/snapshots/`
}]
};
} catch (error) {
return {
content: [{
type: 'text',
text: `Failed to list checkpoints: ${error instanceof Error ? error.message : String(error)}`
}]
};
}
}
private async handleRestoreCheckpoint(args: any) {
try {
const clients = await this.clientFactory.getAllAvailableClients();
if (!clients.claudepoint) {
return {
content: [{
type: 'text',
text: 'Error: Real checkpoint system not available - ClaudePoint client not initialized.'
}]
};
}
const result = await clients.claudepoint.restoreCheckpoint(args.checkpoint, args.dry_run);
const statusIcon = result.success ? 'SUCCESS' : 'FAILED';
const actionText = args.dry_run ? 'DRY RUN' : (result.success ? 'RESTORED' : 'FAILED');
return {
content: [{
type: 'text',
text: `${statusIcon} Checkpoint ${actionText}\n\n**Checkpoint**: ${args.checkpoint}\n**Result**: ${result.message}\n\n${result.filesRestored && result.filesRestored > 0 ? `**Files Restored**: ${result.filesRestored}` : ''}`
}]
};
} catch (error) {
return {
content: [{
type: 'text',
text: `Failed to restore checkpoint: ${error instanceof Error ? error.message : String(error)}`
}]
};
}
}
private async handleSetupClaudepoint() {
try {
const clients = await this.clientFactory.getAllAvailableClients();
if (!clients.claudepoint) {
return {
content: [{
type: 'text',
text: 'Error: Real checkpoint system not available - ClaudePoint client not initialized.'
}]
};
}
await clients.claudepoint.setupClaudepoint();
return {
content: [{
type: 'text',
text: `Real ClaudePoint system setup complete!\n\n**Directory**: /Users/Luther/RiderProjects/.checkpoints/\n**Configuration**: Smart exclusions enabled\n**Ready**: Create checkpoints with \`create_checkpoint\`\n\n**Revolution**: Your checkpoint system now creates ~50MB backups instead of 25-50GB monsters!`
}]
};
} catch (error) {
return {
content: [{
type: 'text',
text: `Failed to setup ClaudePoint: ${error instanceof Error ? error.message : String(error)}`
}]
};
}
}
private async handleGetChangelog() {
try {
const clients = await this.clientFactory.getAllAvailableClients();
if (!clients.claudepoint) {
return {
content: [{
type: 'text',
text: 'Error: Real checkpoint system not available - ClaudePoint client not initialized.'
}]
};
}
const changelog = await clients.claudepoint.getChangelog();
if (changelog.length === 0) {
return {
content: [{
type: 'text',
text: 'No changelog entries found.\n\nChangelog will be populated as you use the system!'
}]
};
}
const changelogText = changelog.slice(0, 10).map((entry, index) =>
`${index + 1}. **${entry.action_type}** - ${entry.description}\n ${entry.details || ''}`
).join('\n\n');
return {
content: [{
type: 'text',
text: `Development History (${changelog.length} entries):\n\n${changelogText}${changelog.length > 10 ? '\n\n...and ' + (changelog.length - 10) + ' more entries' : ''}`
}]
};
} catch (error) {
return {
content: [{
type: 'text',
text: `Failed to get changelog: ${error instanceof Error ? error.message : String(error)}`
}]
};
}
}
private async handleSetChangelog(args: any) {
try {
const clients = await this.clientFactory.getAllAvailableClients();
if (!clients.claudepoint) {
return {
content: [{
type: 'text',
text: 'Error: Real checkpoint system not available - ClaudePoint client not initialized.'
}]
};
}
await clients.claudepoint.setChangelog({
action_type: args.action_type,
description: args.description,
details: args.details
});
return {
content: [{
type: 'text',
text: `Changelog entry added successfully!\n\n**Action**: ${args.action_type}\n**Description**: ${args.description}\n${args.details ? `**Details**: ${args.details}` : ''}\n\nEntry saved to development history.`
}]
};
} catch (error) {
return {
content: [{
type: 'text',
text: `Failed to set changelog: ${error instanceof Error ? error.message : String(error)}`
}]
};
}
}
// ===== TOOL HANDLERS =====
private async handleMonitorEcosystem() {
const state = await this.orchestrator.monitorEcosystemState();
return {
content: [
{
type: 'text',
text: `MCP Ecosystem State:
**Conversation**: ${state.conversationTokens} tokens used
**Memory MCP**: ${state.memoryEntities} entities stored
**Claudepoint MCP**: ${state.claudepointCheckpoints.length} checkpoints available
**Filesystem MCP**: ${state.filesystemActivity.length} recent file activities
**Git MCP**: On ${state.gitStatus.branch}, ${state.gitStatus.modified} modified files
**Database MCPs**: ${state.databaseSessions.length} active sessions
**Coordination Health**: ${state.coordinationHealth.status} (${state.coordinationHealth.errorCount} errors)
**Last Sync**: ${new Date(state.coordinationHealth.lastFullSync).toLocaleString()}
**Avg Response**: ${state.coordinationHealth.averageResponseTime}ms`,
},
],
};
}
private async handleCreateRule(args: any) {
const rule = await this.rulesEngine.createRule(args);
return {
content: [
{
type: 'text',
text: `Session rule created successfully!
**Rule ID**: ${rule.id}
**Rule**: "${rule.rule}"
**Type**: ${rule.type}
**Enforcement**: ${rule.enforcement}
**Priority**: ${rule.priority}
**Scope**: ${rule.scope}
**Triggers**: ${rule.triggers?.join(', ') || 'none'}
The rule has been stored in Memory MCP and will persist across all future sessions.`,
},
],
};
}
private async handleGetRules(args: any) {
const rules = await this.rulesEngine.getRules(args?.scope);
const rulesList = rules.map(rule =>
`• **${rule.id}** (${rule.type}, priority ${rule.priority}): "${rule.rule}" [${rule.enforcement}]`
).join('\n');
return {
content: [
{
type: 'text',
text: `Active Session Rules (${rules.length} total):
${rulesList}
**Legend**:
- hard_block: Prevents action completely
- soft_block: Warns and waits for confirmation
- reminder: Shows reminder but allows action
- suggestion: Passive suggestion only`,
},
],
};
}
private async handleEnforceRules(args: any) {
const action: ProposedAction = args.action;
const enforcement = await this.rulesEngine.enforceRules(action);
if (enforcement.length === 0) {
return {
content: [
{
type: 'text',
text: `Action "${action.type}" cleared - no applicable rules found.`,
},
],
};
}
const blocked = enforcement.filter(e => e.result === 'blocked');
const warned = enforcement.filter(e => e.result === 'warned');
const reminders = enforcement.filter(e => e.result === 'allowed' && e.message);
let response = `Rule Enforcement Results for "${action.type}":\n\n`;
if (blocked.length > 0) {
response += `**BLOCKED** by ${blocked.length} rule(s):\n`;
blocked.forEach(b => response += ` • ${b.message}\n`);
response += '\n';
}
if (warned.length > 0) {
response += `**WARNINGS** from ${warned.length} rule(s):\n`;
warned.forEach(w => response += ` • ${w.message}\n ${w.userPrompt}\n`);
response += '\n';
}
if (reminders.length > 0) {
response += `**REMINDERS** from ${reminders.length} rule(s):\n`;
reminders.forEach(r => response += ` • ${r.message}\n`);
response += '\n';
}
response += blocked.length > 0
? '**Action not permitted** - please modify your approach'
: '**Action permitted** - you may proceed';
return {
content: [
{
type: 'text',
text: response,
},
],
};
}
private async handleInitializeLutherRules() {
await this.rulesEngine.initializeLutherRules();
return {
content: [
{
type: 'text',
text: `Luther's session rules initialized successfully!
The following rules are now active:
1. **Approval Required**: Always check before thundering off wielding the powers of creation all willy nilly
2. **Artifact Display**: Always use right panel for completed work
3. **Architecture Check**: Check existing patterns before new implementations
4. **File Paths**: Include complete paths in all artifacts
5. **Documentation First**: Update design docs before major changes
All rules are stored in Memory MCP and will persist across sessions.`,
},
],
};
}
private async handleCreateHandoff(args: any) {
const handoffPackage = await this.orchestrator.createUnifiedHandoffPackage();
return {
content: [
{
type: 'text',
text: `Unified handoff package created successfully!
**Handoff ID**: ${handoffPackage.handoffId}
**Created**: ${handoffPackage.createdAt.toLocaleString()}
**Package Contents**:
Memory MCP: ${handoffPackage.memoryPackage.compressedContextEntities.length} context entities
Claudepoint: Checkpoint ${handoffPackage.claudepointPackage.checkpointId}
Filesystem: ${handoffPackage.filesystemPackage.activeFiles.length} active files
Git: Branch ${handoffPackage.gitPackage.currentBranch} (${handoffPackage.gitPackage.uncommittedChanges} uncommitted changes)
Database: Session analytics stored
**Cross-References**: ${handoffPackage.crossReferences.length} MCP linkages created
**Reconstruction Steps**: ${handoffPackage.reconstructionInstructions.length} instructions prepared
The handoff package is ready for seamless context reconstruction in a new session.`,
},
],
};
}
private async handleReconstructContext(args: any) {
const context = await this.orchestrator.reconstructUnifiedContext(args.handoffId);
return {
content: [
{
type: 'text',
text: `Context reconstruction completed!
**Context ID**: ${context.contextId}
**Source Handoff**: ${context.sourceHandoffId}
**Reconstruction Time**: ${context.reconstructionTime}ms
**Reconstruction Quality**:
**Completeness**: ${(context.completeness * 100).toFixed(1)}%
**Accuracy**: ${(context.accuracy * 100).toFixed(1)}%
**Restored Elements**:
${context.memoryContext ? 'Memory MCP context' : 'Memory context missing'}
${context.claudepointState ? 'Claudepoint state' : 'Claudepoint state missing'}
${context.filesystemState ? 'Filesystem state' : 'Filesystem state missing'}
${context.gitState ? 'Git state' : 'Git state missing'}
${context.databaseState ? 'Database state' : 'Database state missing'}
${context.missingElements.length > 0
? `**Missing Elements**: ${context.missingElements.join(', ')}`
: '**Perfect reconstruction** - all elements restored successfully!'
}
Your session context has been seamlessly restored from the handoff package.`,
},
],
};
}
private async handleSyncMCPs(args: any) {
const result = await this.orchestrator.syncStateAcrossMCPs();
return {
content: [
{
type: 'text',
text: `Cross-MCP synchronization ${result.success ? 'completed' : 'failed'}!
**Duration**: ${result.duration}ms
${result.conflicts.length > 0 ? `**Conflicts**: ${result.conflicts.length} detected` : '**No conflicts** detected'}
**MCP Results**:
${Object.entries(result.mcpResults).map(([mcp, result]: [string, any]) =>
`**${mcp}**: ${result.success ? 'SUCCESS' : 'FAILED'} (${result.responseTime || 0}ms)`
).join('\n')}
${result.nextSyncRecommended
? `**Next sync recommended**: ${result.nextSyncRecommended.toLocaleString()}`
: ''
}`,
},
],
};
}
private async handleCoordinateCheckpoint(args: any) {
const checkpoint = await this.orchestrator.coordinateConversationCheckpoint();
return {
content: [
{
type: 'text',
text: `Coordinated checkpoint created successfully!
**Checkpoint ID**: ${checkpoint.checkpointId}
**Created**: ${checkpoint.coordinatedAt.toLocaleString()}
**Description**: ${checkpoint.description}
**MCP Checkpoints**:
${Object.entries(checkpoint.mcpCheckpoints).map(([mcp, id]) =>
`**${mcp}**: ${id}`
).join('\n')}
This checkpoint coordinates state across multiple MCPs and can be used for unified rollback or reference.`,
},
],
};
}
private async handleMonitorConversation() {
return {
content: [
{
type: 'text',
text: `Conversation Monitoring:
**Current Status**: Monitoring active
**Token Usage**: Not yet implemented (requires Claude integration)
**Threshold**: 85% for compression, 95% for handoff
**Next Action**: Continue monitoring
Note: Full token monitoring requires integration with Claude's conversation state.`,
},
],
};
}
private async handleCompressContext(args: any) {
return {
content: [
{
type: 'text',
text: `Context compression initiated...
**Parameters**:
- Threshold: ${args?.threshold || 0.85}
- Preserve recent: ${args?.preserveRecent || 15} messages
**Compression Strategy**:
Recent messages preserved verbatim
Key decisions extracted and summarized
Code changes documented
Context stored in Memory MCP
Note: Full implementation pending conversation access integration.`,
},
],
};
}
private async handleSuggestRules(args: any) {
return {
content: [
{
type: 'text',
text: `Rule suggestions analysis...
**Pattern Analysis**: Analyzing last ${args?.analyzeLastDays || 7} days
**Detection**: Looking for repeated user corrections
**Suggestions**: Ready to propose new rules
Note: Full pattern analysis requires conversation history integration.`,
},
],
};
}
private async handleOptimizeRules() {
const optimizations = await this.rulesEngine.optimizeRules();
if (optimizations.length === 0) {
return {
content: [
{
type: 'text',
text: `Rule optimization analysis complete - no optimizations needed!
Your current rules are well-configured and effective.`,
},
],
};
}
const optimizationsList = optimizations.map(opt =>
`• **${opt.optimizationType}**: ${opt.description}`
).join('\n');
return {
content: [
{
type: 'text',
text: `Rule optimization suggestions:
${optimizationsList}
These optimizations can improve rule effectiveness and reduce conflicts.`,
},
],
};
}
private async handleCheckHealth(args: any) {
const healthStatus = this.clientFactory.getHealthStatus(args?.mcpType);
if (args?.mcpType) {
const status = healthStatus as any;
return {
content: [
{
type: 'text',
text: `Health check for ${args.mcpType}:
**Status**: ${status.status}
**Last Checked**: ${status.lastChecked.toLocaleString()}
${status.responseTime ? `**Response Time**: ${status.responseTime}ms` : ''}
${status.errorMessage ? `**Error**: ${status.errorMessage}` : ''}`,
},
],
};
} else {
const allStatuses = healthStatus as Map<MCPType, any>;
const statusList = Array.from(allStatuses.entries()).map(([mcp, status]) =>
`**${mcp}**: ${status.status} (${status.responseTime || 0}ms)`
).join('\n');
return {
content: [
{
type: 'text',
text: `MCP Ecosystem Health:
${statusList}
${Array.from(allStatuses.values()).every(s => s.status === 'online')
? 'All MCPs are healthy!'
: 'Some MCPs need attention'
}`,
},
],
};
}
}
// ===== PROJECT INTELLIGENCE CACHE HANDLERS =====
private async handleCreateProjectIntelligenceCache(args: any) {
try {
const projectName = args.projectName || 'MCPConductor';
const options = args.options || {
includeFileContents: false,
maxDepth: 5,
excludePatterns: ['node_modules', '.git', 'dist', '.DS_Store'],
includeGitInfo: true,
includeDependencies: true,
compressionLevel: 'standard'
};
const intelligence = await this.orchestrator.createProjectIntelligenceCache(projectName, options);
await this.logIntelligenceEvent({
eventId: `cache_created_${Date.now()}`,
timestamp: new Date(),
projectName,
eventType: 'cache_created',
intelligence_version: intelligence.cacheVersion,
affected_sections: ['structure', 'architecture', 'development', 'context'],
mcps_involved: ['memory', 'filesystem', 'claudepoint']
});
return {
content: [
{
type: 'text',
text: `**Project Intelligence Cache Created Successfully!**
**Project**: ${intelligence.projectName}
**Cache Version**: ${intelligence.cacheVersion}
**Created**: ${intelligence.createdAt.toLocaleString()}
**Intelligence Summary**:
**Structure**: ${intelligence.structure.summary}
**Architecture**: ${intelligence.architecture.currentPhase}
**Development**: ${intelligence.development.recentFocus}
**Momentum**: ${intelligence.development.momentum.velocity}
**Analysis Results**:
• **Total Files**: ${intelligence.structure.totalFiles}
• **Critical Files**: ${intelligence.structure.criticalFiles.length}
• **Key Directories**: ${intelligence.structure.keyDirectories.length}
• **Dependencies**: ${intelligence.structure.dependencyGraph.length}
• **Components**: ${intelligence.structure.componentMap.length}
**Next Steps**: ${intelligence.development.nextLogicalSteps.slice(0, 3).map(step => step.step).join(', ')}
**EFFICIENCY REVOLUTION**: This cache eliminates session startup overhead! Use \`load_project_intelligence_cache\` to instantly restore complete project context.
**Cache Status**: Stored in Memory MCP with ${intelligence.invalidationTriggers.length} smart invalidation triggers.`,
},
],
};
} catch (error) {
return {
content: [
{
type: 'text',
text: `**Failed to create Project Intelligence Cache**
**Error**: ${error instanceof Error ? error.message : String(error)}
**Troubleshooting**:
• Ensure Memory MCP is connected
• Check filesystem access permissions
• Verify project directory exists
• Try with simplified options (lower maxDepth, more excludePatterns)`,
},
],
};
}
}
private async handleLoadProjectIntelligenceCache(args: any) {
try {
const intelligence = await this.orchestrator.loadProjectIntelligenceCache(args.projectName);
if (!intelligence) {
return {
content: [
{
type: 'text',
text: `**Project Intelligence Cache Not Found**
**Project**: ${args.projectName}
**No cached intelligence found for this project.**
**Next Steps**:
1. Create cache first: \`create_project_intelligence_cache\`
2. Or check available caches: \`monitor_ecosystem_state\`
3. Verify project name spelling`,
},
],
};
}
const validation = await this.orchestrator.validateProjectIntelligenceCache(args.projectName);
await this.logIntelligenceEvent({
eventId: `cache_loaded_${Date.now()}`,
timestamp: new Date(),
projectName: args.projectName,
eventType: 'cache_loaded',
intelligence_version: intelligence.cacheVersion,
affected_sections: ['structure', 'architecture', 'development', 'context'],
mcps_involved: ['memory']
});
const recommendationText = validation.valid
? '**Ready to use!**'
: `**Recommendation**: ${validation.recommended_action} (confidence: ${(validation.confidence * 100).toFixed(1)}%)`;
return {
content: [
{
type: 'text',
text: `**Project Intelligence Loaded Successfully!**
**Project**: ${intelligence.projectName}
**Cache Version**: ${intelligence.cacheVersion}
**Last Updated**: ${intelligence.lastUpdated.toLocaleString()}
**Freshness**: ${intelligence.freshness.status} (${(intelligence.freshness.confidence * 100).toFixed(1)}% confidence)
**INSTANT CONTEXT RESTORATION**:
**Structure**: ${intelligence.structure.summary}
**Architecture**: ${intelligence.architecture.currentPhase}
**Development**: ${intelligence.development.recentFocus}
**Momentum**: ${intelligence.development.momentum.velocity}
**Project Overview**:
• **Files**: ${intelligence.structure.totalFiles} total, ${intelligence.structure.criticalFiles.length} critical
• **Technologies**: ${intelligence.metadata.technologies.join(', ')}
• **Maturity**: ${intelligence.metadata.maturity_level}
• **Complexity**: ${(intelligence.metadata.complexity_score * 100).toFixed(0)}%
**Immediate Next Steps**:
${intelligence.development.nextLogicalSteps.slice(0, 5).map((step, i) =>
`${i + 1}. **${step.step}** (${step.priority} priority, ${step.effort} effort)`
).join('\n')}
${validation.staleness_reasons.length > 0
? `**Staleness Indicators**: ${validation.staleness_reasons.join(', ')}`
: ''
}
**EFFICIENCY WIN**: Session startup overhead eliminated! You now have complete project context instantly.
${recommendationText}`,
},
],
};
} catch (error) {
return {
content: [
{
type: 'text',
text: `**Failed to load Project Intelligence Cache**
**Project**: ${args.projectName}
**Error**: ${error instanceof Error ? error.message : String(error)}
**Troubleshooting**:
• Check Memory MCP connection
• Verify cache exists: \`monitor_ecosystem_state\`
• Try recreating cache if corrupted`,
},
],
};
}
}
private async handleValidateProjectIntelligenceCache(args: any) {
try {
const validation = await this.orchestrator.validateProjectIntelligenceCache(args.projectName);
await this.logIntelligenceEvent({
eventId: `cache_validated_${Date.now()}`,
timestamp: new Date(),
projectName: args.projectName,
eventType: validation.valid ? 'cache_loaded' : 'validation_failed',
intelligence_version: 'current',
affected_sections: [],
mcps_involved: ['memory', 'filesystem']
});
let recommendationText = '';
switch (validation.recommended_action) {
case 'use':
recommendationText = '**Use cache** - Fresh and reliable';
break;
case 'refresh':
recommendationText = '**Refresh recommended** - Some changes detected';
break;
case 'recreate':
recommendationText = '**Recreate cache** - Significant changes detected';
break;
case 'invalidate':
recommendationText = '**Invalidate cache** - No longer reliable';
break;
}
return {
content: [
{
type: 'text',
text: `**Project Intelligence Cache Validation**
**Project**: ${args.projectName}
**Status**: ${validation.valid ? 'VALID' : 'INVALID'}
**Confidence**: ${(validation.confidence * 100).toFixed(1)}%
${recommendationText}
${validation.staleness_reasons.length > 0 ? `
**Staleness Reasons**:
${validation.staleness_reasons.map(reason => `• ${reason}`).join('\n')}
` : '**No staleness detected** - Cache is fresh!'}
${validation.partial_updates_available.length > 0 ? `
**Partial Updates Available**:
${validation.partial_updates_available.map(update => `• ${update}`).join('\n')}
` : ''}
**Next Actions**:
${validation.recommended_action === 'use'
? '• Continue using cache as-is\n• No action required'
: validation.recommended_action === 'refresh'
? '• Run \`refresh_project_intelligence\` to update\n• Apply incremental changes'
: validation.recommended_action === 'recreate'
? '• Run \`create_project_intelligence_cache\` to rebuild\n• Full analysis recommended'
: '• Run \`invalidate_project_cache\` first\n• Then recreate cache completely'
}`,
},
],
};
} catch (error) {
return {
content: [
{
type: 'text',
text: `**Cache Validation Failed**
**Project**: ${args.projectName}
**Error**: ${error instanceof Error ? error.message : String(error)}
**Recovery Options**:
• Check if cache exists: \`monitor_ecosystem_state\`
• Try loading cache: \`load_project_intelligence_cache\`
• Recreate if necessary: \`create_project_intelligence_cache\``,
},
],
};
}
}
private async handleRefreshProjectIntelligence(args: any) {
try {
const changes = args.changes || [];
const updateResult = await this.orchestrator.refreshProjectIntelligence(args.projectName, changes);
await this.logIntelligenceEvent({
eventId: `cache_refreshed_${Date.now()}`,
timestamp: new Date(),
projectName: args.projectName,
eventType: 'cache_refreshed',
intelligence_version: updateResult.new_cache_version,
affected_sections: updateResult.updated_sections,
mcps_involved: ['memory', 'filesystem']
});
const improvementText = updateResult.confidence_improvement > 0
? `**Confidence Improved**: +${(updateResult.confidence_improvement * 100).toFixed(1)}%`
: '';
return {
content: [
{
type: 'text',
text: `**Project Intelligence Refresh Complete**
**Project**: ${args.projectName}
**Status**: ${updateResult.success ? 'SUCCESS' : 'FAILED'}
**New Version**: ${updateResult.new_cache_version}
**Duration**: ${updateResult.update_duration}ms
**Update Summary**:
**Updated Sections**: ${updateResult.updated_sections.length > 0
? updateResult.updated_sections.join(', ')
: 'None required'}
${updateResult.invalidated_sections.length > 0 ? `
**Invalidated Sections**: ${updateResult.invalidated_sections.join(', ')}
` : ''}
${changes.length > 0 ? `
**Processed Changes**:
${changes.map((change: ProjectChange) => `• ${change.type}: ${change.path} (${change.magnitude})`).join('\n')}
` : '**Auto-detected changes** and applied updates'}
${improvementText}
**EFFICIENCY**: Incremental refresh completed! Cache maintains peak performance while staying current.
**Next Steps**:
• Cache is ready for immediate use
• Continue development with fresh intelligence
• Auto-invalidation triggers remain active`,
},
],
};
} catch (error) {
return {
content: [
{
type: 'text',
text: `**Project Intelligence Refresh Failed**
**Project**: ${args.projectName}
**Error**: ${error instanceof Error ? error.message : String(error)}
**Recovery Options**:
• Validate cache first: \`validate_project_intelligence_cache\`
• Try full recreation: \`create_project_intelligence_cache\`
• Check for filesystem issues`,
},
],
};
}
}
private async handleInvalidateProjectCache(args: any) {
try {
await this.orchestrator.invalidateProjectCache(args.projectName, args.reason);
await this.logIntelligenceEvent({
eventId: `cache_invalidated_${Date.now()}`,
timestamp: new Date(),
projectName: args.projectName,
eventType: 'cache_invalidated',
intelligence_version: 'invalidated',
affected_sections: ['structure', 'architecture', 'development', 'context'],
mcps_involved: ['memory']
});
return {
content: [
{
type: 'text',
text: `**Project Intelligence Cache Invalidated**
**Project**: ${args.projectName}
**Reason**: ${args.reason}
**Timestamp**: ${new Date().toLocaleString()}
**Cache Status**: Successfully invalidated and removed from Memory MCP
**Impact**:
• Project intelligence no longer available for instant loading
• Session startup will require full project analysis
• All cached insights have been cleared
**Next Steps**:
1. **Recreate cache**: \`create_project_intelligence_cache\`
2. **Full reanalysis**: Enable comprehensive project understanding
3. **Restore efficiency**: Return to instant context loading
**Tip**: Consider refreshing instead of invalidating when possible to maintain efficiency benefits.`,
},
],
};
} catch (error) {
return {
content: [
{
type: 'text',
text: `**Cache Invalidation Failed**
**Project**: ${args.projectName}
**Error**: ${error instanceof Error ? error.message : String(error)}
**Manual Recovery**:
• Check Memory MCP connection
• Verify cache exists before invalidation
• Cache may already be invalid/missing`,
},
],
};
}
}
// ===== PRIVATE HELPER METHODS FOR PROJECT INTELLIGENCE =====
private async logIntelligenceEvent(event: any): Promise<void> {
try {
const clients = await this.clientFactory.getAllClients();
await clients.memory.createEntities([{
name: `IntelligenceEvent_${event.eventId}`,
entityType: 'intelligence_event',
observations: [
`Event Type: ${event.eventType}`,
`Project: ${event.projectName}`,
`Version: ${event.intelligence_version}`,
`Sections: ${event.affected_sections.join(', ')}`,
`MCPs: ${event.mcps_involved.join(', ')}`,
`Timestamp: ${event.timestamp.toISOString()}`
]
}]);
await clients.databasePlatform.query(`
INSERT INTO project_intelligence_log (
event_id, session_id, project_name, event_type,
intelligence_version, affected_sections, timestamp
) VALUES (?, ?, ?, ?, ?, ?, ?)
`, [
event.eventId,
this.currentSession.id,
event.projectName,
event.eventType,
event.intelligence_version,
JSON.stringify(event.affected_sections),
event.timestamp
]);
} catch (error) {
// Logging failure is non-critical - continue operation
}
}
private getMCPEmoji(mcpType: string): string {
// Note: This method is kept for compatibility but returns empty string
// since we've removed emojis from responses to fix JSON-RPC corruption
return '';
}
// ===== DYNAMIC MCP DETECTION =====
private detectAvailableMCPs(): MCPClientConfig[] {
const configs: MCPClientConfig[] = [];
const potentialMCPs: MCPClientConfig[] = [
{ type: 'memory' },
{ type: 'claudepoint', workingDirectory: process.env.MCP_CONDUCTOR_PROJECT_DIR || '/Users/Luther/RiderProjects' },
{ type: 'filesystem' },
];
if (process.env.MCP_INCLUDE_GIT === 'true' || (globalThis as any).local__git__status) {
potentialMCPs.push({ type: 'git', workingDirectory: process.env.MCP_CONDUCTOR_PROJECT_DIR || '/Users/Luther/RiderProjects' });
}
if (process.env.MCP_INCLUDE_DATABASE === 'true' || (globalThis as any).local__postgres_platform__query) {
potentialMCPs.push({ type: 'database-platform', connectionString: process.env.MCP_DATABASE_PLATFORM_URL || 'postgresql://localhost/fantasygm_platform' });
}
if (process.env.MCP_INCLUDE_DATABASE === 'true' || (globalThis as any).local__postgres_analytics__query) {
potentialMCPs.push({ type: 'database-analytics', connectionString: process.env.MCP_DATABASE_ANALYTICS_URL || 'postgresql://localhost/nfl_analytics' });
}
const testMode = process.env.MCP_TEST_MODE === 'true';
if (testMode) {
return potentialMCPs;
}
for (const config of potentialMCPs) {
const isAvailable = this.isMCPAvailable(config.type);
if (isAvailable) {
configs.push(config);
}
}
return configs;
}
private isMCPAvailable(mcpType: MCPType): boolean {
switch (mcpType) {
case 'memory':
return !!(globalThis as any).local__memory__read_graph;
case 'claudepoint':
return true; // ClaudePoint is internal - always available
case 'filesystem':
return !!(globalThis as any).local__filesystem__read_file;
case 'git':
return !!(globalThis as any).local__git__status;
case 'database-platform':
return !!(globalThis as any).local__postgres_platform__query;
case 'database-analytics':
return !!(globalThis as any).local__postgres_analytics__query;
default:
return false;
}
}
// ===== INITIALIZATION =====
async initialize() {
const testMode = process.env.MCP_TEST_MODE === 'true';
if (testMode) {
console.warn('Test mode: Running with mock MCP implementations');
}
const mcpConfigs = this.detectAvailableMCPs();
if (mcpConfigs.length === 0) {
console.warn('WARNING: No MCPs detected! Running in standalone mode with mock implementations.');
process.env.MCP_TEST_MODE = 'true';
mcpConfigs.push(
{ type: 'memory' },
{ type: 'filesystem' }
);
}
this.clientFactory = new MCPClientFactory(mcpConfigs);
this.orchestrator = new ConversationContinuityOrchestrator(this.clientFactory);
let memoryClient = null;
try {
memoryClient = await this.clientFactory.createMemoryClientSafe();
if (memoryClient) {
this.rulesEngine = new SessionRulesEngine(memoryClient);
} else {
this.rulesEngine = new NullSessionRulesEngine();
}
} catch (error) {
console.warn('Failed to initialize Session Rules Engine - using null engine');
this.rulesEngine = new NullSessionRulesEngine();
}
}
async run() {
await this.initialize();
const transport = new StdioServerTransport();
await this.server.connect(transport);
}
}
// Start the server
const server = new ConversationContinuityServer();
server.run().catch(error => {
console.error('Server startup error:', error);
process.exit(1);
});