mcp-context-engineering
Version:
The intelligent context optimization system for AI coding assistants. Built with Cole's PRP methodology, Context Portal knowledge graphs, and production-ready MongoDB architecture.
360 lines (359 loc) • 12.8 kB
TypeScript
import { z } from 'zod';
import { ResearchEngine } from './research-engine.js';
import { UniversalContextPattern } from '../../mongodb/models/contextPattern.js';
export declare const PRPTemplateSchema: z.ZodObject<{
header: z.ZodObject<{
goal: z.ZodString;
business_value: z.ZodString;
success_criteria: z.ZodArray<z.ZodString, "many">;
estimated_complexity: z.ZodEnum<["low", "medium", "high"]>;
}, "strip", z.ZodTypeAny, {
goal?: string;
business_value?: string;
success_criteria?: string[];
estimated_complexity?: "low" | "medium" | "high";
}, {
goal?: string;
business_value?: string;
success_criteria?: string[];
estimated_complexity?: "low" | "medium" | "high";
}>;
research_section: z.ZodObject<{
codebase_analysis: z.ZodArray<z.ZodString, "many">;
external_research: z.ZodArray<z.ZodString, "many">;
existing_patterns: z.ZodArray<z.ZodString, "many">;
potential_challenges: z.ZodArray<z.ZodString, "many">;
best_practices: z.ZodArray<z.ZodString, "many">;
confidence_score: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
codebase_analysis?: string[];
external_research?: string[];
existing_patterns?: string[];
potential_challenges?: string[];
confidence_score?: number;
best_practices?: string[];
}, {
codebase_analysis?: string[];
external_research?: string[];
existing_patterns?: string[];
potential_challenges?: string[];
confidence_score?: number;
best_practices?: string[];
}>;
implementation_section: z.ZodObject<{
technical_requirements: z.ZodArray<z.ZodString, "many">;
pseudocode: z.ZodString;
task_breakdown: z.ZodArray<z.ZodObject<{
task: z.ZodString;
order: z.ZodNumber;
dependencies: z.ZodArray<z.ZodString, "many">;
validation: z.ZodString;
estimated_effort: z.ZodString;
}, "strip", z.ZodTypeAny, {
validation?: string;
task?: string;
order?: number;
dependencies?: string[];
estimated_effort?: string;
}, {
validation?: string;
task?: string;
order?: number;
dependencies?: string[];
estimated_effort?: string;
}>, "many">;
integration_points: z.ZodArray<z.ZodString, "many">;
error_handling_strategy: z.ZodString;
}, "strip", z.ZodTypeAny, {
technical_requirements?: string[];
pseudocode?: string;
task_breakdown?: {
validation?: string;
task?: string;
order?: number;
dependencies?: string[];
estimated_effort?: string;
}[];
error_handling_strategy?: string;
integration_points?: string[];
}, {
technical_requirements?: string[];
pseudocode?: string;
task_breakdown?: {
validation?: string;
task?: string;
order?: number;
dependencies?: string[];
estimated_effort?: string;
}[];
error_handling_strategy?: string;
integration_points?: string[];
}>;
validation_section: z.ZodObject<{
syntax_checks: z.ZodArray<z.ZodString, "many">;
unit_test_commands: z.ZodArray<z.ZodString, "many">;
integration_tests: z.ZodArray<z.ZodString, "many">;
quality_checklist: z.ZodArray<z.ZodString, "many">;
acceptance_criteria: z.ZodArray<z.ZodString, "many">;
}, "strip", z.ZodTypeAny, {
syntax_checks?: string[];
unit_test_commands?: string[];
integration_tests?: string[];
quality_checklist?: string[];
acceptance_criteria?: string[];
}, {
syntax_checks?: string[];
unit_test_commands?: string[];
integration_tests?: string[];
quality_checklist?: string[];
acceptance_criteria?: string[];
}>;
knowledge_connections: z.ZodObject<{
related_decisions: z.ZodArray<z.ZodString, "many">;
dependent_patterns: z.ZodArray<z.ZodString, "many">;
potential_conflicts: z.ZodArray<z.ZodString, "many">;
architecture_impact: z.ZodString;
}, "strip", z.ZodTypeAny, {
related_decisions?: string[];
dependent_patterns?: string[];
potential_conflicts?: string[];
architecture_impact?: string;
}, {
related_decisions?: string[];
dependent_patterns?: string[];
potential_conflicts?: string[];
architecture_impact?: string;
}>;
agent_guidance: z.ZodObject<{
cursor_specific: z.ZodString;
windsurf_specific: z.ZodString;
claude_code_specific: z.ZodString;
universal_notes: z.ZodString;
}, "strip", z.ZodTypeAny, {
cursor_specific?: string;
windsurf_specific?: string;
claude_code_specific?: string;
universal_notes?: string;
}, {
cursor_specific?: string;
windsurf_specific?: string;
claude_code_specific?: string;
universal_notes?: string;
}>;
}, "strip", z.ZodTypeAny, {
header?: {
goal?: string;
business_value?: string;
success_criteria?: string[];
estimated_complexity?: "low" | "medium" | "high";
};
research_section?: {
codebase_analysis?: string[];
external_research?: string[];
existing_patterns?: string[];
potential_challenges?: string[];
confidence_score?: number;
best_practices?: string[];
};
implementation_section?: {
technical_requirements?: string[];
pseudocode?: string;
task_breakdown?: {
validation?: string;
task?: string;
order?: number;
dependencies?: string[];
estimated_effort?: string;
}[];
error_handling_strategy?: string;
integration_points?: string[];
};
validation_section?: {
syntax_checks?: string[];
unit_test_commands?: string[];
integration_tests?: string[];
quality_checklist?: string[];
acceptance_criteria?: string[];
};
knowledge_connections?: {
related_decisions?: string[];
dependent_patterns?: string[];
potential_conflicts?: string[];
architecture_impact?: string;
};
agent_guidance?: {
cursor_specific?: string;
windsurf_specific?: string;
claude_code_specific?: string;
universal_notes?: string;
};
}, {
header?: {
goal?: string;
business_value?: string;
success_criteria?: string[];
estimated_complexity?: "low" | "medium" | "high";
};
research_section?: {
codebase_analysis?: string[];
external_research?: string[];
existing_patterns?: string[];
potential_challenges?: string[];
confidence_score?: number;
best_practices?: string[];
};
implementation_section?: {
technical_requirements?: string[];
pseudocode?: string;
task_breakdown?: {
validation?: string;
task?: string;
order?: number;
dependencies?: string[];
estimated_effort?: string;
}[];
error_handling_strategy?: string;
integration_points?: string[];
};
validation_section?: {
syntax_checks?: string[];
unit_test_commands?: string[];
integration_tests?: string[];
quality_checklist?: string[];
acceptance_criteria?: string[];
};
knowledge_connections?: {
related_decisions?: string[];
dependent_patterns?: string[];
potential_conflicts?: string[];
architecture_impact?: string;
};
agent_guidance?: {
cursor_specific?: string;
windsurf_specific?: string;
claude_code_specific?: string;
universal_notes?: string;
};
}>;
export declare const PRPGenerationRequestSchema: z.ZodObject<{
feature_description: z.ZodString;
project_context: z.ZodObject<{
project_id: z.ZodString;
current_patterns: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
tech_stack: z.ZodArray<z.ZodString, "many">;
complexity_preference: z.ZodDefault<z.ZodEnum<["low", "medium", "high"]>>;
}, "strip", z.ZodTypeAny, {
project_id?: string;
tech_stack?: string[];
complexity_preference?: "low" | "medium" | "high";
current_patterns?: string[];
}, {
project_id?: string;
tech_stack?: string[];
complexity_preference?: "low" | "medium" | "high";
current_patterns?: string[];
}>;
agent_type: z.ZodDefault<z.ZodEnum<["cursor", "windsurf", "claude_code", "generic"]>>;
research_depth: z.ZodDefault<z.ZodEnum<["basic", "comprehensive", "exhaustive"]>>;
include_learning: z.ZodDefault<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
agent_type?: "cursor" | "windsurf" | "claude_code" | "generic";
feature_description?: string;
project_context?: {
project_id?: string;
tech_stack?: string[];
complexity_preference?: "low" | "medium" | "high";
current_patterns?: string[];
};
research_depth?: "basic" | "comprehensive" | "exhaustive";
include_learning?: boolean;
}, {
agent_type?: "cursor" | "windsurf" | "claude_code" | "generic";
feature_description?: string;
project_context?: {
project_id?: string;
tech_stack?: string[];
complexity_preference?: "low" | "medium" | "high";
current_patterns?: string[];
};
research_depth?: "basic" | "comprehensive" | "exhaustive";
include_learning?: boolean;
}>;
export type PRPTemplate = z.infer<typeof PRPTemplateSchema>;
export type PRPGenerationRequest = z.infer<typeof PRPGenerationRequestSchema>;
/**
* PRP Generator - Core engine combining Cole's methodology with Context Portal knowledge graphs
*
* Perfect harmony: MongoDB (memory) → MCP (interface) → AI Agent (execution)
*
* This creates intelligent, memory-backed planning templates that:
* 1. Remember what worked before (MongoDB effectiveness tracking)
* 2. Adapt to different AI agents (Universal optimization)
* 3. Integrate knowledge graphs (Context Portal patterns)
* 4. Follow Cole's proven methodology (PRP structure)
*/
export declare class PRPGenerator {
private researchEngine;
private mongoOperations;
private embeddingService;
constructor(researchEngine: ResearchEngine, mongoOperations: any, // Will be MongoDB operations interface
embeddingService: any);
/**
* Generate complete PRP following Cole's template with Context Portal integration
*
* This is the core method that creates perfect planning templates by:
* 1. Using Cole's research methodology
* 2. Leveraging stored knowledge patterns
* 3. Optimizing for specific AI agents
* 4. Learning from past effectiveness
*/
generatePRP(request: PRPGenerationRequest): Promise<{
prp_template: PRPTemplate;
context_pattern: UniversalContextPattern;
confidence_score: number;
learning_applied: string[];
}>;
/**
* Find similar successful patterns from MongoDB
* Uses hybrid search: embeddings + metadata filtering
*/
private findSimilarPatterns;
/**
* Get agent-specific optimizations based on historical effectiveness
*/
private getAgentOptimizations;
/**
* Build Context Portal style knowledge graph connections
*/
private buildKnowledgeConnections;
/**
* Assemble the complete PRP template following Cole's verified structure
*/
private assemblePRPTemplate;
/**
* Create universal context pattern for MongoDB storage
*/
private createContextPattern;
private extractBusinessValue;
private generateSuccessCriteria;
private generateTechnicalRequirements;
private generatePseudocode;
private generateTaskBreakdown;
private identifyIntegrationPoints;
private generateErrorHandlingStrategy;
private generateSyntaxChecks;
private generateTestCommands;
private generateIntegrationTests;
private generateQualityChecklist;
private generateAcceptanceCriteria;
private generateCursorGuidance;
private generateWindsurfGuidance;
private generateClaudeCodeGuidance;
private generateUniversalNotes;
private analyzeArchitectureImpact;
private generateEmbedding;
private classifyPatternType;
private generateTags;
private calculateOverallConfidence;
private extractLearningApplied;
}