WaveMaker React Native MCP Server
by wm-raajvamsy
README.md
# WaveMaker React Native MCP Server
An MCP (Model Context Protocol) server providing intelligent development assistance for WaveMaker React Native projects. This tool integrates with Cursor IDE to help developers solve bugs, optimize performance, analyze code, and generate tests.
## ๐ Features
### ๐ฏ **NEW: Direct Codebase Access**
- **Runtime Source Code**: Direct access to all `wavemaker-rn-runtime` components and systems
- **Codegen Source Code**: Direct access to transpilers, themes, and templates
- **Smart Code Search**: Find implementations, patterns, and examples across both codebases
- **Component Lookup**: Instantly locate any component's source, props, styles, and tests
- **Real Code Examples**: AI provides actual code from the codebase, not hypothetical examples
### ๐ Bug Diagnosis & Debugging
- **Intelligent Issue Detection**: Pattern-based symptom matching with 5+ common issue types
- **Lifecycle Validation**: Comprehensive cleanup and memory management verification
- **Memory Leak Detection**: Automatic detection of orphaned resources (timeouts, subscriptions, watchers)
- **Data Binding Validation**: Verify reactive data binding and watch expressions
### โก Performance Analysis
- **Render Performance Profiling**: Analyze component complexity and re-render triggers
- **Watcher Profiling**: Detect expensive watch expressions and optimization opportunities
- **Optimization Suggestions**: Prioritized, actionable recommendations for performance improvements
### ๐ Code Analysis
- **Component Analysis**: Deep inspection of structure, props, lifecycle, and dependencies
- **Project Navigation**: Map project structure (pages, partials, prefabs, variables, services)
- **Dependency Resolution**: Track direct and transitive dependencies
- **Codebase Exploration**: Explore runtime and codegen structure with file listings
### ๐งช Testing
- **Test Skeleton Generation**: Automated test structure for unit, integration, and snapshot tests
- **Test Case Suggestions**: Smart test case recommendations based on component analysis
### ๐ Knowledge Base
- **18+ Curated Patterns**: Best practices and anti-patterns for WaveMaker RN development
- **5 Common Issues**: Documented causes, solutions, and code examples
- **6 Best Practice Categories**: Lifecycle, performance, data-binding, memory management, and more
## ๐ฆ Installation
```bash
cd /Users/raajr_500278/wavemaker-rn-mcp
npm install
npm run build
```
### Verify Installation
```bash
ls -la dist/ # Should show compiled JavaScript files
```
## โ๏ธ Configuration
### Required Environment Variable
The MCP server requires **WM_CODEBASE_PATH** to be set in your Cursor settings. This tells the server where to find the WaveMaker runtime and codegen source code.
### For Cursor IDE
Add to your Cursor settings (Cursor > Settings > MCP):
**For Generated Projects (node_modules):**
```json
{
"mcpServers": {
"wavemaker-rn": {
"command": "node",
"args": ["/Users/you/wavemaker-rn-mcp/dist/index.js"],
"env": {
"WM_CODEBASE_PATH": "/path/to/your-project/node_modules/@wavemaker",
"WORKSPACE_PATH": "/path/to/your/wavemaker/project"
}
}
}
}
```
**For Local Development (source code):**
```json
{
"mcpServers": {
"wavemaker-rn": {
"command": "node",
"args": ["/Users/you/wavemaker-rn-mcp/dist/index.js"],
"env": {
"WM_CODEBASE_PATH": "/Users/you/wavemaker-studio-frontend",
"WORKSPACE_PATH": "/path/to/your/wavemaker/project"
}
}
}
}
```
**Environment Variables:**
- **`WM_CODEBASE_PATH`** (required): Path to WaveMaker runtime/codegen source
- **Node modules setup:** Looks for `app-rn-runtime` and `rn-codegen` folders
- **Local codebase setup:** Looks for `wavemaker-rn-runtime` and `wavemaker-rn-codegen` folders
- **`WORKSPACE_PATH`** (required): Path to your WaveMaker project directory
- This is where the MCP tools will search for your project code
- Example: `/path/to/your-project/target/generated-expo-app`
The server validates paths on startup and provides clear error messages if misconfigured.
### Project-Specific Rules
To ensure the AI follows the debugging protocol in your project:
1. **Cursor Rules**: Create `.cursor/rules/wm.mdc` in your project root
- Copy from the MCP repo's `.cursorrules` file
- Cursor will automatically load these rules for your project
2. **Agent Configuration** (Optional): Create `.cursor/agent.md` in your project
- Use the template from `.cursor/agent-template.md`
- Customize with your specific paths
- Provides additional context for agent-like workflows
## ๐ Debugging Workflow
This MCP server enforces a **systematic debugging protocol** to ensure reliable, evidence-based bug fixes.
### Overview
The debugging workflow consists of **4 mandatory phases**:
```
Phase 0: GATHER RUNTIME DATA (REQUIRED FIRST)
โ
Phase 1: READ SOURCE CODE
โ
Phase 2: ANALYZE
โ
Phase 2.5: VERIFICATION CHECKPOINT
โ
Phase 3: PROPOSE FIX
```
### Phase 0: Gather Runtime Data (REQUIRED FIRST)
**The AI will ALWAYS ask for runtime information before analyzing code:**
1. **Request Current Information**
- Error messages or console output
- Reproduction steps
- Platform (iOS/Android/Web)
- Expected vs. actual behavior
2. **Add Diagnostic Logging**
```javascript
console.log('=== Debug Info ===');
console.log('State:', this.state);
console.log('Props:', this.props);
```
3. **Wait for User Response**
- AI will not proceed without data
- You must provide logs or confirm behavior
4. **Document Runtime Data**
- AI will summarize all collected information
- This becomes the foundation for analysis
### Phase 1: Read Source Code
After collecting runtime data, the AI will:
- Use `wm_rn_smart_search` to locate relevant files
- Use `wm_rn_read_file` to read component source
- Read third-party library source if needed
- Understand the actual implementation
### Phase 2: Analyze
The AI will:
- Calculate and verify with actual runtime values
- Trace logic step-by-step
- Identify root cause with code evidence
### Phase 2.5: Verification Checkpoint
**Before proposing ANY fix, the AI must answer:**
1. What is the EXACT root cause? (with evidence)
2. Where is the problematic code located?
- Runtime/Codegen (WM_CODEBASE_PATH) - READ ONLY
- Generated Project (WORKSPACE_PATH) - MODIFIABLE
- Third-party (node_modules) - READ ONLY
3. Can I modify the source? (If NO โ Need workaround)
4. Is this a regression from an upgrade?
5. What is my fix strategy?
### Phase 3: Propose Fix
Only after verification, the AI will:
- Propose ONE targeted fix in your project (WORKSPACE_PATH)
- Explain WHY it works (with evidence)
- Add verification logging
- Ask you to test and confirm
### Two Codebases
The debugging workflow operates with clear boundaries:
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ WaveMaker Runtime/Codegen โ
โ (WM_CODEBASE_PATH) โ
โ โ
โ Purpose: ANALYSIS ONLY โ
โ Rule: NEVER modify โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ (read to understand)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Your Generated Project โ
โ (WORKSPACE_PATH) โ
โ โ
โ Purpose: APPLY FIXES HERE โ
โ Rule: All changes in this project โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
### Example: Progress Circle Clipping Issue
**Phase 0: Gather Data**
```
AI: "Can you share:
- Screenshot of the issue?
- Console errors/warnings?
- Platform (iOS/Android)?
- Did this work in a previous version?"
You: "iOS, no errors, worked in Expo 52, broke in 54"
AI: "Let's add logging:
console.log('Container:', this.state.radius);
Please reload and share output."
You: "Container: 120"
AI: "RUNTIME DATA:
- Issue: 1px clipping
- Platform: iOS
- Version: Expo 54 (regression)
- Container: 120x120px"
```
**Phase 1-2: Read & Analyze**
```
wm_rn_smart_search "WmProgressCircle"
wm_rn_read_file progress-circle.component.tsx
wm_rn_read_file node_modules/react-native-circular-progress
Calculate: radius=52, stroke=8, edge=60, container=120
โ 0px buffer! SVG clipping at boundary.
```
**Phase 2.5: Checkpoint**
```
Q: Root cause?
A: SVG needs padding prop, runtime doesn't pass it
Q: Can I modify?
A: NO - runtime is in node_modules
Q: Fix strategy?
A: Workaround in generated page component
```
**Phase 3: Fix**
```
File: src/pages/MyPage/MyPage.component.js
<View style={{overflow: 'visible', margin: -2}}>
<WmProgressCircle ... />
</View>
Why: Creates 2px buffer without changing circle size
Verification: console.log('Wrapper margin:', -2)
```
### Benefits
โ
**No Random Fixes**: AI calculates once, fixes once
โ
**Evidence-Based**: Every fix backed by code analysis
โ
**Respects Boundaries**: Never modifies runtime/node_modules
โ
**Regression-Aware**: Handles upgrade issues correctly
โ
**Verification Built-In**: Confirms fix before and after
### Configuration Files
The debugging workflow is defined in:
- **`.cursorrules`**: Base protocol definition (this repo)
- **`.cursor/rules/wm.mdc`**: Project-specific rules (copy to your project)
- **`.cursor/agent.md`**: Optional agent configuration (customize paths)
See [`.cursorrules`](./.cursorrules) for the complete protocol definition.
## Available Tools
### ๐ฏ Codebase Exploration (NEW)
- `wm_rn_search_codebase` - Search across runtime/codegen source code
- `wm_rn_find_component_source` - Locate component implementations
- `wm_rn_get_implementation` - Get actual feature implementations
- `wm_rn_list_all_components` - List all available components
- `wm_rn_get_widget_transpiler` - Get widget transpiler source
- `wm_rn_explore_runtime_structure` - Explore runtime codebase
- `wm_rn_explore_codegen_structure` - Explore codegen codebase
### Bug Diagnosis & Debugging
- `wm_rn_diagnose_issue` - Diagnose issues from symptoms
- `wm_rn_check_component_lifecycle` - Validate lifecycle implementation
- `wm_rn_validate_data_binding` - Check data binding setup
- `wm_rn_check_memory_leaks` - Detect potential memory leaks
### Performance Analysis
- `wm_rn_analyze_render_performance` - Profile component renders
- `wm_rn_profile_watchers` - Analyze watch expressions
- `wm_rn_suggest_optimizations` - Get optimization suggestions
### Code Analysis
- `wm_rn_analyze_component` - Comprehensive component analysis
- `wm_rn_find_pattern` - Find code patterns
- `wm_rn_get_project_structure` - Map project structure
- `wm_rn_find_dependencies` - Resolve dependencies
### Testing
- `wm_rn_generate_test_skeleton` - Generate test structure
- `wm_rn_suggest_test_cases` - Get test case suggestions
### Utilities
- `wm_rn_grep_code` - Advanced code search
- `wm_rn_exec_command` - Execute shell commands
- `wm_rn_read_file` - Read file contents
- `wm_rn_write_file` - Write file contents
## Usage Examples
### Diagnose a Bug
```
User: "My component isn't re-rendering when data changes"
Assistant uses: wm_rn_diagnose_issue
```
### Analyze Performance
```
User: "Why is my Dashboard page slow?"
Assistant uses: wm_rn_analyze_render_performance + wm_rn_profile_watchers
```
### Check for Memory Leaks
```
User: "Check my LoginPage for memory leaks"
Assistant uses: wm_rn_check_memory_leaks
```
## ๐ฏ Quick Start Examples
### Diagnose a Bug
```typescript
// User: "My component isn't re-rendering when data changes"
// AI uses: wm_rn_diagnose_issue
{
"symptom": "component not re-rendering",
"componentPath": "src/pages/HomePage/HomePage.tsx"
}
// Returns: causes, solutions, code examples, documentation links
```
### Check for Memory Leaks
```typescript
// User: "Check my HomePage for memory leaks"
// AI uses: wm_rn_check_memory_leaks
{
"targetPath": "src/pages/HomePage",
"checkTypes": ["all"]
}
// Returns: orphaned timeouts, unsubscribed listeners, recommendations
```
### Analyze Performance
```typescript
// User: "Why is my Dashboard slow?"
// AI uses: wm_rn_analyze_render_performance
{
"componentPath": "src/pages/Dashboard/Dashboard.tsx"
}
// Returns: complexity analysis, performance issues, optimization suggestions
```
## ๐ Statistics
- **35 Tools** across 7 categories
- **10 Handler Implementations**
- **Direct Access** to 1000+ source files
- **18+ Knowledge Base Entries**
- **10,000+ Lines of Code**
- **< 5 Second Build Time**
## ๐๏ธ Architecture
```
wavemaker-rn-mcp/
โโโ src/
โ โโโ server.ts # Core MCP server
โ โโโ index.ts # Entry point
โ โโโ types.ts # Shared TypeScript types
โ โโโ tools/ # Tool definitions (28 tools)
โ โ โโโ analysis.tools.ts
โ โ โโโ debugging.tools.ts
โ โ โโโ performance.tools.ts
โ โ โโโ navigation.tools.ts
โ โ โโโ build.tools.ts
โ โ โโโ testing.tools.ts
โ โ โโโ utility.tools.ts
โ โโโ handlers/ # Tool implementations (9 handlers)
โ โ โโโ ComponentAnalyzer.ts
โ โ โโโ IssueDiagnoser.ts
โ โ โโโ LifecycleChecker.ts
โ โ โโโ MemoryLeakDetector.ts
โ โ โโโ RenderAnalyzer.ts
โ โ โโโ WatcherProfiler.ts
โ โ โโโ ProjectNavigator.ts
โ โ โโโ DataBindingValidator.ts
โ โ โโโ TestGenerator.ts
โ โโโ utils/ # Shared utilities
โ โ โโโ file-utils.ts
โ โ โโโ grep-utils.ts
โ โ โโโ command-executor.ts
โ โ โโโ logger.ts
โ โโโ knowledge/ # Knowledge base
โ โโโ patterns.json
โ โโโ issues.json
โ โโโ best-practices.json
โโโ scripts/
โ โโโ extract-knowledge.ts # Doc extraction script
โโโ dist/ # Compiled output
```
## ๐ ๏ธ Development
```bash
# Build
npm run build
# Watch mode
npm run watch
# Run locally
npm start
# Extract knowledge from docs (optional)
npm run extract-knowledge
```
## ๐ Documentation
- **[Codebase Integration](./CODEBASE_INTEGRATION.md)**: ๐ How to use direct source code access
- **[Usage Guide](./USAGE_GUIDE.md)**: Comprehensive usage examples and scenarios
- **[Configuration Guide](./CONFIG.md)**: Centralized path and environment configuration
- **[Path Handling Guide](./PATH_HANDLING.md)**: Understanding absolute vs relative paths in MCP tools
- **[Cursor Configuration](./CURSOR_CONFIG.md)**: Step-by-step setup for Cursor IDE
- **[Changelog](./CHANGELOG.md)**: Version history and release notes
- **[.cursorrules](./.cursorrules)**: In-editor best practices and patterns
## ๐ค Contributing
This is an internal tool for WaveMaker RN development. For issues or improvements, please contact the WaveMaker team.
## ๐ License
MIT
## ๐ Acknowledgments
Built with:
- [@modelcontextprotocol/sdk](https://github.com/modelcontextprotocol/sdk)
- TypeScript
- WaveMaker RN documentation and best practices