UNPKG

mcp-codesentry

Version:

CodeSentry MCP - AI-powered code review assistant with 5 specialized review tools for security, best practices, and comprehensive code analysis

265 lines (218 loc) 8.21 kB
# Product Requirements Document: Software Architect MCP Server ## 1. Executive Summary The Software Architect MCP Server is a Model Context Protocol server that provides intelligent code review capabilities for LLM-driven development workflows. It acts as a quality gate, offering pre-task planning reviews and post-task implementation reviews by leveraging codebase analysis through Repomix and Google Gemini's large context capabilities. ### Key Value Propositions - **Proactive Quality Assurance**: Reviews development plans before implementation - **Automated Code Review**: Provides post-implementation feedback - **Context-Aware Analysis**: Uses full codebase context for comprehensive reviews - **LLM-Agnostic**: Works with any LLM that supports MCP ## 2. Problem Statement ### Current Challenges 1. **Lack of Planning Validation**: LLMs often proceed with implementation without validating their approach against the entire codebase 2. **Post-Implementation Surprises**: Issues are discovered after code is written, leading to rework 3. **Limited Context**: Most LLMs work with partial codebase context, missing important architectural considerations 4. **Quality Consistency**: Code quality varies without systematic review processes ### Target Users - **Primary**: Developers using AI assistants for coding - **Secondary**: Development teams implementing AI-driven development workflows - **Tertiary**: Organizations looking to maintain code quality standards with AI assistance ## 3. Product Goals & Objectives ### Primary Goals 1. Improve code quality in AI-assisted development by 40% 2. Reduce implementation rework by 50% 3. Increase developer confidence in AI-generated solutions by 60% ### Success Metrics - Average review score from Gemini (target: >8/10) - Reduction in post-implementation fixes - Developer satisfaction ratings - Time saved through early issue detection - Adoption rate among AI-assisted development workflows ## 4. Core Features ### 4.1 Pre-Task Review **Description**: Before executing a development task, the LLM submits its plan for review **Functionality**: - Accept task description and implementation plan - Execute repomix to capture current codebase state - Submit context + plan to Gemini for review - Return structured feedback on: - Architectural alignment - Potential issues - Suggested improvements - Risk assessment ### 4.2 Post-Task Review **Description**: After task completion, review the implementation against the plan and codebase **Functionality**: - Accept task completion summary and changes made - Execute repomix to capture updated codebase - Compare before/after states - Submit to Gemini for implementation review - Return feedback on: - Plan adherence - Code quality - Best practices compliance - Potential bugs or issues ### 4.3 Persistent Context Management **Description**: Maintain task context between pre and post reviews **Functionality**: - Store task IDs with associated plans - Link pre-task plans with post-task reviews - Maintain codebase snapshots in .tmp directory - Enable contextual comparison ## 5. Technical Requirements ### 5.1 MCP Server Implementation - Built using Model Context Protocol TypeScript SDK - Expose two main tools: - `review_plan`: Pre-task review - `review_implementation`: Post-task review - Support standard MCP communication protocols ### 5.2 Integration Requirements - **Repomix Integration**: - Execute via `npx repomix` - Configure output format for optimal LLM consumption - Handle large codebases efficiently - **Gemini API Integration**: - Support for Gemini 1.5 Pro or Flash (large context models) - Structured prompt engineering for consistent reviews - Error handling and fallback strategies ### 5.3 Storage & Performance - Store flattened codebases in user's `.tmp` directory - Implement cleanup policies for old snapshots - Optimize for sub-5 second response times - Handle codebases up to 2M tokens ## 6. API Design ### 6.1 MCP Tools Specification ```typescript interface ReviewPlanParams { taskId: string; taskDescription: string; implementationPlan: string; codebaseRoot?: string; includePatterns?: string[]; excludePatterns?: string[]; } interface ReviewImplementationParams { taskId: string; completionSummary: string; changedFiles?: string[]; codebaseRoot?: string; } interface ReviewResponse { taskId: string; reviewType: 'plan' | 'implementation'; overallScore: number; feedback: { summary: string; strengths: string[]; concerns: string[]; suggestions: string[]; risks?: string[]; }; metadata: { codebaseSize: number; reviewTimestamp: string; modelUsed: string; }; } ``` ## 7. User Workflows ### Workflow 1: Pre-Task Review 1. LLM receives a development task 2. LLM formulates implementation plan 3. LLM calls `review_plan` with task details 4. Server flattens codebase using repomix 5. Server sends context to Gemini 6. Server returns structured feedback 7. LLM adjusts plan based on feedback 8. LLM proceeds with implementation ### Workflow 2: Post-Task Review 1. LLM completes implementation 2. LLM calls `review_implementation` with summary 3. Server captures new codebase state 4. Server compares with pre-task snapshot 5. Server requests Gemini review 6. Server returns implementation feedback 7. LLM makes corrections if needed ## 8. Configuration & Setup ### Required Configuration - Gemini API key - Repomix configuration - Storage limits and cleanup policies - Review prompt templates ### Optional Configuration - Custom review criteria - Model selection (Gemini Pro vs Flash) - Codebase size limits - Response format preferences ## 9. Security & Privacy ### Security Considerations - API keys stored securely - Temporary files encrypted at rest - No persistent storage of code content - Audit logging for all operations ### Privacy Requirements - User opt-in for code submission to Gemini - Clear data retention policies - Option to use self-hosted models - Compliance with data protection regulations ## 10. Future Enhancements ### Phase 2 Features - Support for multiple LLM reviewers - Historical review analytics - Team-based review templates - Integration with CI/CD pipelines ### Phase 3 Features - Custom review criteria definition - Machine learning on review outcomes - Automated fix suggestions - Multi-language support ## 11. Technical Architecture ### Component Overview - **MCP Server Core**: Handles protocol communication - **Repomix Manager**: Executes and manages repomix operations - **Storage Manager**: Handles temporary file management - **Gemini Client**: Manages API communication - **Review Engine**: Orchestrates the review process ### Data Flow 1. LLM → MCP Server (request) 2. MCP Server → Repomix (codebase capture) 3. Repomix → Storage (.tmp files) 4. Storage → Gemini Client (context preparation) 5. Gemini Client → Gemini API (review request) 6. Gemini API → Review Engine (response processing) 7. Review Engine → LLM (structured feedback) ## 12. Development Roadmap ### MVP (Month 1-2) - Basic MCP server setup - Repomix integration - Simple Gemini review implementation - Core review workflows ### Beta (Month 3-4) - Enhanced review prompts - Performance optimization - Basic configuration options - Documentation and examples ### GA (Month 5-6) - Full feature set - Production-ready performance - Comprehensive testing - User documentation ## 13. Risks & Mitigation ### Technical Risks - **Large codebase handling**: Implement streaming and chunking - **API rate limits**: Add queueing and caching - **Context window limits**: Smart content selection ### Operational Risks - **Gemini API costs**: Implement usage monitoring and limits - **Storage growth**: Automated cleanup policies - **Response latency**: Async processing options ## 14. Success Criteria ### Launch Criteria - 95% uptime for MCP server - <5 second average response time - 90% positive feedback score - Zero critical security issues ### Long-term Success - 1000+ active users within 6 months - 50% reduction in AI-generated bugs - Integration with top 3 AI coding assistants - Community-contributed review templates