React Patterns MCP Server
by 1beyza
README.md
# React Patterns MCP Server v2
A comprehensive MCP (Model Context Protocol) server that teaches and applies React architecture, design patterns, and best practices ā covering everything from [patterns.dev/react](https://www.patterns.dev/react/).
Built in **TypeScript / Node.js** for use with **Claude Code**.
---
## Features
| Category | Tools |
|----------|-------|
| **Pattern Reference** | All patterns.dev/react patterns with full details, comparisons, recommendations |
| **Code Analyzer** | Detect anti-patterns and suggest refactors in existing React code |
| **Template Engine** | Ready-to-use TypeScript code templates per pattern |
| **Scaffold** | Generate project skeleton based on architecture + patterns |
| **Architecture Doc** | ADR generator that recommends patterns for your project |
| **Live Docs** | Fetch docs.react.dev + React version-aware API guidance |
| **Mobile** | Tailwind responsive patterns + React Native layouts |
| **Memory** | Persist project state between sessions |
| **Task Planner** | Break goals into parallelisable subtasks for Claude subagents |
| **Token Optimizer** | Compress outputs, manage response cache |
---
## Covered Patterns
### šØ Design Patterns
| ID | Pattern |
|----|---------|
| `hoc-pattern` | Higher-Order Component (HOC) |
| `hooks-pattern` | Hooks Pattern |
| `compound-pattern` | Compound Pattern |
| `container-presentational-pattern` | Container / Presentational |
| `render-props-pattern` | Render Props |
| `observer-pattern` | Observer / Pub-Sub (Zustand) |
| `provider-pattern` | Provider (React Context) |
| `prototype-pattern` | Prototype / Object Pool |
| `module-pattern` | Module / Feature Slice |
| `singleton-pattern` | Singleton (API clients, stores) |
### āļø Rendering Patterns
| ID | Pattern |
|----|---------|
| `client-side-rendering` | CSR (Vite SPA, dashboards) |
| `server-side-rendering` | SSR (Next.js per-request) |
| `static-rendering` | SSG (Next.js build-time) |
| `incremental-static-rendering` | ISR (stale-while-revalidate) |
| `progressive-hydration` | Progressive Hydration |
| `streaming-ssr` | Streaming SSR |
| `react-server-components` | RSC (Next.js App Router) |
| `selective-hydration` | Selective Hydration (React 18) |
### ā” Performance Patterns
| ID | Pattern |
|----|---------|
| `dynamic-import` | Dynamic Import / Code Splitting |
| `import-on-visibility` | Import on Visibility (IntersectionObserver) |
| `import-on-interaction` | Import on Interaction (defer until click/hover) |
| `route-based-splitting` | Route-Based Code Splitting |
| `bundle-splitting` | Bundle Splitting / Vendor Chunking |
| `tree-shaking` | Tree Shaking (dead-code elimination) |
| `preload` | Preload Critical Resources |
| `prefetch` | Prefetch Next-Page Resources |
| `prpl-pattern` | PRPL Pattern (PWA loading strategy) |
---
## Tool Reference
| Tool | Description |
|------|-------------|
| `list_all_patterns` | All patterns grouped by category |
| `list_performance_patterns` | Performance patterns only |
| `get_pattern` | Full detail + code example for a pattern |
| `compare_patterns` | Side-by-side comparison of 2ā5 patterns |
| `find_pattern_for_use_case` | Describe a problem, get pattern recommendations |
| `ask_architecture_preference` | **Call this first** ā shows architecture options |
| `scaffold_project` | Generate project skeleton |
| `analyze_code` | Detect anti-patterns in React code |
| `get_code_template` | Ready-to-use TypeScript code template |
| `generate_architecture_doc` | ADR ā which patterns and why for your project |
| `fetch_react_docs` | Live fetch from docs.react.dev with version guidance |
| `save_memory` / `get_memory` | Persist and recall project context across sessions |
| `create_task_plan` | Break a goal into parallelisable subtasks |
| `compress_output` | Compress verbose responses to save tokens |
---
## Installation
### Prerequisites
- Node.js 20+
- npm or pnpm
### Setup
```bash
git clone https://github.com/1beyza/react-patterns-mcp.git
cd react-patterns-mcp
npm install
npm run build
```
### Add to Claude Code
In your project's `.claude/mcp.json` (or global `~/.claude/mcp.json`):
```json
{
"mcpServers": {
"react-patterns": {
"command": "node",
"args": ["/absolute/path/to/react-patterns-mcp/dist/index.js"]
}
}
}
```
Or run directly for testing:
```bash
npm run dev # tsx (no build needed)
```
---
## Usage Workflows
### New Project
```
1. create_task_plan ā break the goal into subtasks
2. generate_architecture_doc ā get pattern recommendations + ADR
3. scaffold_project ā generate directory structure + setup commands
4. get_code_template ā get starter code for each essential pattern
5. save_memory ā persist architecture choices
```
### Existing Project Improvement
```
1. analyze_code ā detect issues and pattern opportunities
2. compare_patterns ā compare alternatives
3. suggest_refactor ā get a refactor plan toward a target pattern
4. get_code_template ā get the target pattern's starter code
```
### Quick Pattern Lookup
```
list_all_patterns ā browse everything
get_pattern <id> ā full details + code example
find_pattern_for_use_case ā describe your problem, get recommendations
```
---
## Architecture
```
react-patterns-mcp/
āāā src/
ā āāā index.ts # MCP server entry ā registers all tools
ā āāā tools/ # Tool layer ā MCP tool handlers
ā ā āāā index.ts # Barrel export
ā ā āāā pattern-tools.ts # Pattern query / compare / recommend
ā ā āāā scaffold-tools.ts # Project scaffolding
ā ā āāā analyzer-tools.ts # Code analysis + refactor suggestions
ā ā āāā template-tools.ts # Code template retrieval
ā ā āāā architecture-tools.ts # ADR generation
ā ā āāā docs-tools.ts # Live React docs + version guidance
ā ā āāā mobile-tools.ts # Mobile / responsive patterns
ā ā āāā memory-tools.ts # Project state persistence
ā ā āāā task-planner-tools.ts # Subtask decomposition
ā ā āāā token-optimizer-tools.ts # Output compression + cache
ā āāā data/ # Data layer ā pure data, no MCP logic
ā ā āāā patterns.ts # All design & rendering pattern definitions
ā ā āāā templates.ts # Code templates per pattern
ā ā āāā mobile-patterns.ts # Mobile responsiveness patterns
ā āāā utils/ # Utility layer ā shared functions
ā āāā validator.ts # Zod schemas for all tool inputs
ā āāā formatter.ts # Markdown output formatting
ā āāā cache.ts # TTL response cache
ā āāā file-io.ts # Memory persistence (JSON files)
āāā memory/ # Runtime project memory (gitignored)
āāā dist/ # Compiled JavaScript output
āāā package.json
āāā tsconfig.json
āāā README.md
```
**Layer rules:**
- `data/` ā pure data objects, no side effects
- `utils/` ā pure functions and shared helpers, no MCP awareness
- `tools/` ā MCP tool handlers; validate with Zod, call data/utils, return strings
- `index.ts` ā MCP protocol binding only; no business logic
---
## All MCP Tools
| Tool | Description |
|------|-------------|
| `list_all_patterns` | List all patterns with summaries |
| `list_design_patterns` | List design patterns only |
| `list_rendering_patterns` | List rendering patterns only |
| `get_pattern` | Full details + code example for a pattern |
| `compare_patterns` | Side-by-side comparison of 2ā5 patterns |
| `find_pattern_for_use_case` | Describe your problem ā get recommendations |
| `get_related_patterns` | Patterns related to a given pattern |
| `get_pattern_tradeoffs` | Quick pros/cons for a pattern |
| `scaffold_project` | Generate full project scaffold |
| `analyze_code` | Detect anti-patterns in React code |
| `suggest_refactor` | Refactor plan toward a target pattern |
| `get_code_template` | Get ready TypeScript code for a pattern |
| `list_templates` | List all available code templates |
| `generate_architecture_doc` | ADR with pattern recommendations |
| `fetch_react_docs` | Live docs.react.dev content |
| `get_react_version_guidance` | Version-specific API guidance |
| `get_mobile_pattern` | Mobile/responsive pattern details |
| `get_tailwind_responsive_cheatsheet` | Tailwind responsive design guide |
| `save_memory` | Persist project state to disk |
| `get_memory` | Retrieve saved project state |
| `clear_memory` | Delete project memory |
| `list_project_memory` | List all projects with saved state |
| `create_task_plan` | Break a goal into parallelisable subtasks |
| `compress_output` | Reduce token cost of verbose output |
| `get_cache_stats` | View response cache statistics |
| `clear_caches` | Clear all response caches |
This server cannot be deployed
Maintenance
ActivitySlowing
ResponsivenessSyncing