MCP Architecture
Understand the Model Context Protocol (MCP) and how Aichaku’s MCP server integrates with Claude Code to provide automated code review capabilities.
What is MCP?
Section titled “What is MCP?”The Model Context Protocol (MCP) is a standard that enables AI assistants like Claude to interact with external tools and services. Think of it as a bridge between Claude’s AI capabilities and specialized tools on your computer.
Key concepts
Section titled “Key concepts”- MCP Server - A program that provides tools to AI assistants
- MCP Client - The AI assistant (Claude Code) that uses these tools
- Tools - Specific functions the server exposes (like
review_file) - Transport - How client and server communicate (stdio, not network)
Why MCP matters
Section titled “Why MCP matters”Without MCP:
- Claude can only work with information you provide
- No access to specialized tools or local resources
- Limited ability to verify or validate code
With MCP:
- Claude can use security scanners
- Access project-specific configurations
- Provide real-time code analysis
- Maintain privacy (everything stays local)
Aichaku MCP Server Architecture
Section titled “Aichaku MCP Server Architecture”System Overview
Section titled “System Overview”graph TB subgraph "Claude Code Environment" CC[Claude Code<br/>MCP Client] UI[Chat Interface] end
subgraph "MCP Server Process" MS[MCP Server<br/>stdio interface] RE[Review Engine] SM[Standards Manager] MM[Methodology Manager] SC[Scanner Controller] FB[Feedback Builder] end
subgraph "Local File System" PF[Project Files] CF[Configuration<br/>.claude/] STD[Standards Library<br/>~/.claude/docs/standards/] end
subgraph "External Tools (Optional)" CQ[CodeQL] DS[DevSkim] SG[Semgrep] end
UI -->|User Request| CC CC <-->|JSON-RPC<br/>over stdio| MS MS --> RE RE --> SM RE --> MM RE --> SC RE --> FB SM --> CF SM --> STD MM --> CF SC --> PF SC -.->|If available| CQ SC -.->|If available| DS SC -.->|If available| SG FB -->|Educational<br/>Response| MSComponent Details
Section titled “Component Details”MCP Server (mcp-code-reviewer)
Section titled “MCP Server (mcp-code-reviewer)”The main server process that:
- Implements the MCP protocol
- Handles tool requests from Claude
- Manages the lifecycle of reviews
- Returns structured responses
Key characteristics:
- Stateless - No persistent state between requests
- Ephemeral - Spawned on demand, exits when done
- Isolated - Each request is independent
- Fast startup - < 100ms to initialize
Review Engine
Section titled “Review Engine”Orchestrates the review process:
- Parses the review request
- Loads project configuration
- Runs security patterns
- Checks standards compliance
- Aggregates results
- Generates educational feedback
Standards Manager
Section titled “Standards Manager”Handles standards-related operations:
- Loads selected standards from
.claude/.aichaku-standards.json - Reads standard definitions from
~/.claude/docs/standards/ - Applies standard-specific rules
- Tracks violations and suggestions
Methodology Manager
Section titled “Methodology Manager”Detects and validates methodologies:
- Scans project structure for methodology artifacts
- Loads methodology rules from
~/.claude/methodologies/ - Checks compliance with methodology practices
- Provides improvement suggestions
Scanner Controller
Section titled “Scanner Controller”Manages external security scanners:
- Detects available scanners in PATH
- Runs scanners with appropriate parameters
- Parses scanner output (SARIF format)
- Merges results with built-in patterns
Feedback Builder
Section titled “Feedback Builder”Creates educational responses:
- Formats issues with context
- Provides good/bad examples
- Includes step-by-step fixes
- Adds learning resources
- Maintains encouraging tone
Communication Protocol
Section titled “Communication Protocol”JSON-RPC over stdio
Section titled “JSON-RPC over stdio”MCP uses JSON-RPC 2.0 for communication:
- Request from Claude:
{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "review_file", "arguments": { "file": "/path/to/file.ts", "includeExternal": true } }}- Response from MCP Server:
{ "jsonrpc": "2.0", "id": 1, "result": { "content": [ { "type": "text", "text": "Security review complete..." } ] }}Why stdio instead of network?
Section titled “Why stdio instead of network?”- Security - No network exposure, no ports to secure
- Simplicity - No authentication, no TLS certificates
- Performance - Direct process communication
- Privacy - Impossible to accidentally expose to internet
- Compatibility - Works the same on all platforms
Security Architecture
Section titled “Security Architecture”Threat Model
Section titled “Threat Model”The MCP server is designed to be secure by default:
| Threat | Mitigation |
|---|---|
| Code injection | Read-only operations, no code execution |
| Path traversal | Strict path validation, project boundaries |
| Information disclosure | No network access, local only |
| Privilege escalation | Runs as user, no elevated permissions |
| Supply chain attacks | Minimal dependencies, signed releases |
Security Boundaries
Section titled “Security Boundaries”graph LR subgraph "Trust Boundary" CC[Claude Code] MCP[MCP Server] PF[Project Files] end
subgraph "Untrusted" NET[Network] OTHER[Other Users] end
CC <--> MCP MCP --> PF MCP -.X.- NET MCP -.X.- OTHERPrivacy Guarantees
Section titled “Privacy Guarantees”- No telemetry - Zero usage tracking
- No network calls - Everything stays local
- No persistent storage - No databases or logs by default
- No credentials - No API keys or authentication
- Project isolation - Reviews don’t cross project boundaries
Performance Architecture
Section titled “Performance Architecture”Startup Performance
Section titled “Startup Performance”The MCP server optimizes startup time:
Process spawn: ~10msDeno runtime init: ~30msCode loading: ~20msFirst review ready: ~60ms-----------------------Total: ~120msMemory Usage
Section titled “Memory Usage”- Base footprint: ~50MB (Deno runtime + code)
- Per review: +5-10MB (file content + analysis)
- Garbage collected: Memory released after each review
Caching Strategy
Section titled “Caching Strategy”graph LR subgraph "Memory Cache" FC[File Content<br/>5 min TTL] SC[Standards Config<br/>Until changed] PC[Pattern Cache<br/>Process lifetime] end
subgraph "Disk Cache" ER[External Results<br/>1 hour TTL] end
Review --> FC Review --> SC Review --> PC Scanner --> ERIntegration Patterns
Section titled “Integration Patterns”Project Detection
Section titled “Project Detection”How the MCP server finds project configuration:
Given: /Users/alice/projects/app/src/auth/login.ts
1. Check: /Users/alice/projects/app/src/auth/.claude/ ❌2. Check: /Users/alice/projects/app/src/.claude/ ❌3. Check: /Users/alice/projects/app/.claude/ ✅ Found: Project root with configurationStandards Resolution
Section titled “Standards Resolution”How standards are loaded:
1. Read .claude/.aichaku-standards.json → ["nist-csf", "tdd", "solid"]
2. Load each standard: ~/.claude/docs/standards/security/nist-csf.md ~/.claude/docs/standards/testing/tdd.md ~/.claude/docs/standards/development/solid.md
3. Parse rules and patterns from each standard
4. Apply during reviewExternal Scanner Integration
Section titled “External Scanner Integration”How external scanners are invoked:
sequenceDiagram participant MCP as MCP Server participant SC as Scanner Controller participant CQ as CodeQL participant Cache as Result Cache
MCP->>SC: Review file.ts SC->>Cache: Check cache alt Cache hit Cache-->>SC: Return cached else Cache miss SC->>CQ: Run analysis CQ-->>SC: SARIF results SC->>Cache: Store results end SC-->>MCP: Merged resultsExtensibility
Section titled “Extensibility”Adding New Security Patterns
Section titled “Adding New Security Patterns”Security patterns in patterns/security-patterns.ts:
export const securityPatterns = [ { id: "sql-injection", severity: "critical", owasp: "A03", pattern: /query.*\+.*user|user.*\+.*query/i, message: "Potential SQL injection", fix: "Use parameterized queries", }, // Add new patterns here];Adding New Standards Support
Section titled “Adding New Standards Support”- Create standard definition in
~/.claude/docs/standards/ - Add parsing logic in
standards-manager.ts - Include standard-specific patterns
- Update documentation
Adding New Scanners
Section titled “Adding New Scanners”Scanner integration in scanner-controller.ts:
const scanners = { newscanner: { command: "newscanner", args: ["--format", "sarif"], parse: (output) => JSON.parse(output), },};Benefits of MCP Architecture
Section titled “Benefits of MCP Architecture”For developers
Section titled “For developers”- Automated review - Consistent code quality checks
- Educational feedback - Learn while you code
- Privacy-first - Your code never leaves your machine
- Zero configuration - Works out of the box
- Fast feedback - Results in seconds, not minutes
For teams
Section titled “For teams”- Standardization - Consistent standards across projects
- Knowledge sharing - Best practices embedded in tools
- Security by default - Catch issues before commit
- Flexible adoption - Use what works for your team
- No infrastructure - No servers to maintain
For Claude
Section titled “For Claude”- Enhanced capabilities - Access to security tools
- Project awareness - Understand project context
- Accurate feedback - Based on real analysis
- Educational responses - Teach, don’t just report
- Trust building - Reliable, consistent results
Limitations and Considerations
Section titled “Limitations and Considerations”Current limitations
Section titled “Current limitations”- File size - Large files may timeout (default 5MB)
- Binary files - Cannot analyze compiled code
- Language support - Best for JS/TS, Python, Go
- External scanners - Optional, not required
- Async operations - Sequential file processing
Design trade-offs
Section titled “Design trade-offs”| Choice | Benefit | Trade-off |
|---|---|---|
| Stdio transport | Security, simplicity | No remote access |
| Stateless design | Scalability, isolation | No cross-file analysis |
| Local only | Privacy, performance | No cloud features |
| Read-only | Security | Cannot auto-fix issues |
Future Architecture Considerations
Section titled “Future Architecture Considerations”Potential enhancements
Section titled “Potential enhancements”- Incremental analysis - Analyze only changed code
- Project-wide analysis - Cross-file relationships
- Custom rules - User-defined patterns
- IDE integration - Beyond Claude Code
- Metrics dashboard - Track improvement over time
Maintaining simplicity
Section titled “Maintaining simplicity”The architecture prioritizes:
- Simplicity over features
- Security over convenience
- Privacy over analytics
- Education over enforcement
- Local over cloud
Summary
Section titled “Summary”The Aichaku MCP server architecture provides:
✅ Secure - Multiple layers of protection
✅ Private - Everything stays on your machine
✅ Fast - Sub-second response times
✅ Educational - Teaches while reviewing
✅ Extensible - Add patterns and scanners
The architecture makes Claude Code a more capable development partner while maintaining the security and privacy developers expect.
Related Documentation
Section titled “Related Documentation”- Setup MCP Server - Get started
- MCP API Reference - Technical details
- Using MCP with Multiple Projects - Practical usage