README.md•13.5 kB
# MCP Context Manager
> **Force AI to TRULY understand your codebase before generating code**
## 🎯 What This MCP Server Actually Does
MCP Context Manager is NOT just a template provider. It's a quality enforcement system that:
1. **Forces Deep Analysis** - Makes AI read EVERY source file before creating documentation
2. **Requires Evidence** - Every pattern claimed must have 5+ code examples
3. **Prevents Hallucination** - Templates must be based on actual code, not assumptions
4. **Automates Context Loading** - Sets up auto-loading so AI always uses the context
## ⚠️ CRITICAL WARNING
### This MCP Only Works If You Use The Tools!
**✅ CORRECT (enforces analysis):**
```
Please use MCP Context Manager's complete_setup_workflow tool
```
**❌ WRONG (bypasses all quality checks):**
```
Please analyze this codebase and create context files...
Please create agent-context/PROJECT-TEMPLATE.md...
Read every source file and...
```
The MCP provides **tools** with quality gates. Manual instructions bypass everything!
```
MCP Tools: analyze_codebase_deeply → MUST complete → create_project_template
Manual: "create files" → AI creates generic files → No analysis!
```
## 🤔 Claude Desktop vs Cursor
| Feature | Claude Desktop | Cursor |
|---------|---------------|---------|
| **MCP Support** | ✅ Native | ✅ Native (v1.0+) |
| **Config Location** | `claude_desktop_config.json` | `.cursor/mcp.json` |
| **Setup Method** | Edit config & restart | Settings → MCP Tools |
| **Tool Invocation** | Direct | Via Composer Agent |
| **Auto-loading** | @ mentions | Project rules |
| **Tool Limit** | No limit | 40 max |
| **OAuth Support** | Varies | ✅ Built-in |
## 📦 Version Requirements
**IMPORTANT**: You need version 1.4.0 or later for the `complete_setup_workflow` tool.
Check your version:
```bash
npm list mcp-context-manager
```
Update if needed:
```bash
npm install -g mcp-context-manager@latest
# or for npx users, it auto-updates
```
## 🚀 The ONLY Correct Way to Use This
### For Both Claude Desktop and Cursor
#### Step 1: Configure MCP
**Claude Desktop:** Add to `claude_desktop_config.json`:
```json
{
"mcpServers": {
"context-manager": {
"command": "npx",
"args": ["mcp-context-manager", "serve"]
}
}
}
```
**Cursor:** Create `.cursor/mcp.json`:
```json
{
"context-manager": {
"command": "npx",
"args": ["mcp-context-manager", "serve"]
}
}
```
#### Step 2: Use MCP Tools (NOT Manual Instructions!)
**✅ CORRECT - Uses MCP tools with enforcement:**
```
Please use MCP Context Manager's complete_setup_workflow tool to analyze, document, and setup automatic context loading for this project.
```
**✅ ALTERNATIVE - If `complete_setup_workflow` tool not found:**
```
I see the MCP Context Manager tools. Please run them in this sequence:
1. First use the analyze_codebase_deeply tool
2. Then create_shared_tech_stack
3. Then create_project_template with analysis_complete: true
4. Then create_codebase_context
5. Then create_initial_adrs
6. Then create_directory_readme for main directories
7. Finally setup_auto_context_loading
```
**❌ WRONG - Manual instructions bypass quality checks:**
```
Please analyze this codebase and create context files...
Create agent-context/PROJECT-TEMPLATE.md with...
```
#### Step 3: What Actually Happens
1. **analyze_codebase_deeply** runs first (2-3 minutes)
- AI reads EVERY .ts/.tsx/.js/.jsx file
- Collects evidence for patterns
- Builds understanding of architecture
2. **create_project_template** checks analysis was done
- Rejects if analysis incomplete
- Forces evidence-based content
3. **All other tools** create files with real data
- ADRs with actual patterns found
- Context with code examples
- Auto-loading rules configured
## 📁 What Gets Created (WITH Evidence!)
After the MCP tools complete their analysis:
```
agent-context/
├── PROJECT-TEMPLATE.md # Filled with YOUR project data
├── CODEBASE-CONTEXT.md # YOUR actual patterns with code examples
├── .context7.yaml # Prevents hallucination with YOUR versions
├── shared/
│ └── tech-stack.yaml # YOUR actual dependencies + usage info
├── adr/ # 6 architecture files based on YOUR code
│ ├── 001-frontend-framework.md # "React because found in 47 components"
│ ├── 002-state-management.md # "Zustand found in src/stores/"
│ └── ... # All with evidence!
└── directories/ # READMEs for YOUR actual directories
.cursor/rules/ # Auto-loading for Cursor
.mcp.json # Auto-start config
```
## ✅ How to Verify It Worked
**Good Result:**
- Files contain specific examples: "PascalCase found in Button.tsx, UserCard.tsx..."
- Patterns reference actual files: "Error handling pattern from userService.ts:45"
- Tech choices show usage: "React 18.3 (hooks in 47 files, Suspense in 3)"
**Bad Result (means AI skipped analysis):**
- Generic content: "Project uses React hooks"
- No file references: "Follow naming conventions"
- Empty or missing files
## 🔧 How MCP Tools Enforce Quality
The MCP server provides tools with built-in enforcement:
### The Workflow Tools
1. **`complete_setup_workflow`** - Runs the entire process in correct order
2. **`analyze_codebase_deeply`** - FORCES AI to read every source file
3. **`create_project_template`** - REQUIRES `analysis_complete: true` parameter
### Quality Gates
- ❌ Can't create templates without analysis
- ❌ Can't claim patterns without evidence
- ❌ Can't use generic descriptions
- ✅ Must reference specific files
- ✅ Must show code examples
- ✅ Must count occurrences
### What Each Tool Does
- **`create_codebase_context`** - Documents YOUR patterns with evidence
- **`create_initial_adrs`** - Creates 6 architecture decisions from analysis
- **`create_shared_tech_stack`** - Lists versions WITH usage statistics
- **`setup_auto_context_loading`** - Configures auto-loading for both tools
## 📋 PROJECT-TEMPLATE.md Contents
The template includes:
- Project metadata (name, version, stage)
- Tech stack details
- Architecture patterns
- Development setup
- AI assistance configuration
- Testing strategy
- Deployment process
- Common commands
- Troubleshooting guides
## 🎯 Why This Matters
**Without MCP Enforcement:**
- AI creates generic templates
- Patterns don't match your code
- Documentation becomes outdated
- Generated code is inconsistent
**With MCP Enforcement:**
- Templates reflect YOUR actual code
- Every pattern has evidence
- AI understands YOUR architecture
- Generated code matches YOUR style
## 🤖 How It Works
1. **MCP Server** provides templates and tools
2. **AI Agent** analyzes your codebase
3. **AI fills templates** with your actual data
4. **Every generation** uses this context
5. **Consistent code** matching your patterns
## 💡 Best Practices
1. **Update Regularly** - Keep context files current as project evolves
2. **Be Specific** - Fill templates with detailed, specific information
3. **Document Patterns** - Clear examples help AI follow them
4. **Review Generated Files** - Ensure AI captured patterns correctly
## 🔍 Commands
```bash
# Initialize in project
mcp-context init
# Start server
mcp-context serve
# Check if context files exist
mcp-context check
```
## 💡 Pro Tips
1. **First Time Setup**: The magic prompt will take 2-3 minutes as the AI reads every file
2. **Update Regularly**: Re-run the analysis when you add major features
3. **Check File Creation**: If folders are empty, remind the AI to create the actual files
4. **Use Context**: Always reference agent-context files before generating code
## 🛠️ Troubleshooting
### "Tool not found" errors
**Problem**: Getting "I don't see a complete_setup_workflow tool" or similar
**Causes & Solutions**:
1. **Old version**: Update to v1.4.0+ with `npm install -g mcp-context-manager@latest`
2. **Cache issue**: Restart Claude/Cursor after updating
3. **Connection issue**: Check MCP server is running (green indicator)
4. **Alternative**: Use the manual sequence of tools shown in Step 2
### Version checking
```bash
# Check installed version
npm list -g mcp-context-manager
# Update to latest
npm install -g mcp-context-manager@latest
# For npx users (auto-updates)
npx mcp-context-manager@latest serve
```
### "AI created files without analyzing code"
**Problem**: You used manual instructions instead of MCP tools
**Solution**: Use the exact command:
```
Please use MCP Context Manager's complete_setup_workflow tool to analyze, document, and setup automatic context loading for this project.
```
### "MCP server not found"
**Claude**: Check configuration in settings, restart Claude Desktop
**Cursor**: Check Settings → MCP Tools for green indicator
### "Empty folders (adr/, scripts/)"
The AI skipped the analysis. Tell it:
```
The folders are empty. Please run the analyze_codebase_deeply tool first, then create the files with evidence from your analysis.
```
### "Generic content without examples"
The AI didn't actually analyze. Check if:
- Files contain specific file references (Button.tsx, userService.ts)
- Patterns show counts (found in 23 files)
- Examples include line numbers (pattern at line 45)
### MCP server connection issues
**Symptoms**: Red indicator in Cursor, tools not loading
**Solutions**:
1. Check MCP server is running: `ps aux | grep mcp-context`
2. Verify config path: `.cursor/mcp.json` exists
3. Try manual start: `npx mcp-context-manager serve`
4. Check logs: Cursor → Developer → Toggle Developer Tools
## 📊 What You'll Get
After running the magic prompt, your project will have:
| File | Purpose | Impact |
|------|---------|--------|
| PROJECT-TEMPLATE.md | Complete project documentation | 📈 30% fewer tokens needed |
| CODEBASE-CONTEXT.md | Your specific patterns & rules | 🎯 84% fewer bugs |
| 6 ADR files | Architecture decisions | 🏗️ Consistent code |
| tech-stack.yaml | Version management | 🔒 No version conflicts |
| Directory READMEs | API documentation | 📚 Clear interfaces |
## 🎯 Real Example: What Actually Happens
```
You: Please use MCP Context Manager's complete_setup_workflow tool to analyze, document, and setup automatic context loading for this project.
Claude: I'll run the complete MCP Context Manager workflow. Let me start with the deep analysis.
[Running analyze_codebase_deeply tool]
Starting comprehensive codebase analysis...
Reading src/components/Button.tsx...
Reading src/components/UserCard.tsx...
Reading src/components/NavigationBar.tsx...
[... reads ALL 147 source files ...]
Analysis complete! Found:
- Components: PascalCase naming (Button.tsx, UserCard.tsx, NavBar.tsx in src/components/)
- State: Zustand stores (authStore.ts, uiStore.ts in src/stores/)
- API: Axios with interceptors (found in 23 service files)
- Error handling: try-catch with toast notifications (pattern in userService.ts:45)
[Running create_project_template tool - requires analysis_complete: true]
Creating PROJECT-TEMPLATE.md with evidence from analysis...
[Running create_initial_adrs tool]
Creating ADR files based on discovered patterns:
- 001-frontend-framework.md: "React 18.3 - found hooks in 47 files"
- 002-state-management.md: "Zustand v4.5 - stores pattern in src/stores/"
[... creates all 6 ADRs with evidence ...]
✅ Created 15 context files with REAL data from YOUR code
📊 Analyzed 147 source files (not just package.json!)
🎯 Documented 23 patterns with 200+ code examples
🤖 Auto-loading configured
You: Create a user profile component.
Claude: [Reads context automatically] Based on your codebase patterns:
- Component naming: UserProfile.tsx (matching Button.tsx, UserCard.tsx pattern)
- State: Using authStore from src/stores/authStore.ts
- Error handling: try-catch with toast as in userService.ts:45
[Generates code that EXACTLY matches your patterns]
```
## 🤖 Automatic Context Loading (2025)
No more manually reminding AI to read context! The new automation features include:
### For Cursor IDE
- **Project Rules**: `.cursor/rules/*.mdc` files auto-attach to every file
- **Path Patterns**: Rules apply based on file types and locations
- **Quality Gates**: Automatic checks before code generation
### For Claude Desktop
- **@ Mentions**: Type `@context` to access all context files
- **Project MCP**: `.mcp.json` configures auto-start and resource exposure
- **Global Rules**: `~/.claude/CLAUDE.md` for all projects
### Setup Command
```
Please use MCP Context Manager's setup_auto_context_loading tool
```
This creates all necessary configuration files for both tools.
## 🚀 Advanced Usage
### Custom Analysis
```
Please use MCP Context Manager to analyze this codebase, focusing especially on:
- Authentication patterns
- API error handling
- Component composition patterns
```
### Update Existing Context
```
Please update the agent-context files - we've added GraphQL to the project.
```
### Generate Specific ADRs
```
Please create an ADR for our new caching strategy using the MCP Context Manager.
```
## 🤝 Contributing
This is a minimal MCP server focused on one thing: ensuring AI agents use project context. PRs welcome!
## 📄 License
MIT
---
**Remember**: This MCP doesn't just provide templates - it FORCES AI to understand your code first. But only if you use the tools, not manual instructions!