loading…
Search for a command to run...
loading…
Enables AI agents to achieve production-ready solutions through iterative refinement and recursive thinking processes. It features token optimization via contex
Enables AI agents to achieve production-ready solutions through iterative refinement and recursive thinking processes. It features token optimization via context compression and session-based tracking to improve problem-solving depth while minimizing cost.
v2.0.0 - Now with chain-of-thought reasoning, self-evaluation, and continuous refinement!
Token-efficient MCP server that makes AI agents think deeper through structured reasoning chains, self-critique, and automatic rethinking loops.
| Feature | Description | Benefit |
|---|---|---|
| Chain of Thought | AI explains WHY it chose each solution | Transparent reasoning, better decisions |
| Self-Evaluation | AI rates its own solutions (1-10 scale) | Honest assessment of solution quality |
| Rethink Loop | Automatic rethinking if rating <7 or issues found | Continuous improvement without token waste |
| Phase-Based Prompts | 5 structured phases (explore → justify → evaluate → rethink → finalize) | Focused thinking, reduced token usage |
| Smart Compression | Preserves reasoning while compressing history | ~70% token reduction maintained |
┌─────────────┐
│ 1. EXPLORE │ ──→ Propose solution with reasoning & alternatives
└──────┬──────┘
▼
┌─────────────┐
│ 2. JUSTIFY │ ──→ Critically examine reasoning & assumptions
└──────┬──────┘
▼
┌─────────────┐
│ 3. EVALUATE│ ──→ Rate solution (1-10), identify weaknesses
└──────┬──────┘
▼
┌───┴───┐
│ Score │
│ ≥7? │ ──NO─→ ┌─────────────┐
└───┬───┘ │ 4. RETHINK │ ──→ Improve based on weaknesses
│YES └──────┬──────┘
▼ │
┌─────────────┐ │
│ 5. FINALIZE│ ←──────────┘
└─────────────┘
Goal: Generate initial solution with reasoning
AI must provide:
Goal: Critically examine the reasoning
AI must provide:
Goal: Self-assessment with honest rating
AI must provide:
{
"score": 7, // 1-10 scale (be harsh!)
"isGood": false, // Would you bet your reputation on this?
"rationale": "...", // Why this rating?
"improvements": "..." // What MUST be improved?
}
Goal: Improve based on identified weaknesses
Triggered when: score <7 OR isGood=false OR enableRethinking=true
AI must provide:
Goal: Compile production-ready solution
AI must provide:
npx -y recursive-thinking-mcp
npm install -g recursive-thinking-mcp
# Clone or download the project
cd recursive-thinking-mcp
# Install dependencies
npm install
# Build
npm run build
# Link globally (for development)
npm link
Add to your MCP configuration file:
Windows: C:\Users\YourUsername\.claude\plugins\marketplaces\thedotmack\.mcp.json
macOS/Linux: ~/.claude/plugins/marketplaces/thedotmack/.mcp.json
{
"mcpServers": {
"recursive-thinking": {
"command": "npx",
"args": [
"-y",
"recursive-thinking-mcp"
]
}
}
}
Add to your user or workspace .vscode/mcp.json:
{
"servers": {
"recursive-thinking": {
"command": "npx",
"args": [
"-y",
"recursive-thinking-mcp"
]
}
}
}
// Start with a task
await mcp.callTool('recursive_thinking', {
action: 'start',
task: 'Implement a secure authentication system with JWT and rate limiting',
config: {
maxDepth: 5,
minConfidence: 0.9,
minRating: 8, // Require 8/10 minimum rating
enableRethinking: true // Enable continuous refinement
}
});
// Phase 1 response (EXPLORE)
const result1 = await mcp.callTool('recursive_thinking', {
action: 'iterate',
sessionId: 'session_1234567890_abc123',
response: `
**Solution**: Use Express + TypeScript with JWT authentication.
**Reasoning**: I chose this because Express is mature, has excellent
middleware support, and JWT provides stateless authentication suitable
for distributed systems.
**Alternatives Considered**:
- Session-based auth: Rejected because it requires server-side storage
- OAuth2: Overkill for this use case, adds complexity
`
});
// Phase 2 response (JUSTIFY)
const result2 = await mcp.callTool('recursive_thinking', {
action: 'iterate',
sessionId: result1.sessionId,
response: `
**Why This Works**: JWT is industry standard, well-tested.
**Hidden Assumptions**:
- Assuming tokens won't be intercepted (need HTTPS)
- Assuming clients store tokens securely
**Edge Cases**:
- Token expiration handling
- Refresh token rotation
- Concurrent session limits
**Confidence**: 0.75
`
});
// Phase 3 response (EVALUATE)
const result3 = await mcp.callTool('recursive_thinking', {
action: 'iterate',
sessionId: result2.sessionId,
response: `
{
"score": 6,
"isGood": false,
"rationale": "Missing rate limiting, no mention of token storage security,
no refresh token strategy",
"improvements": "Add rate limiting, specify secure token storage (httpOnly
cookies), implement refresh token rotation"
}
`
});
// Phase 4 (RETHINK) - automatically triggered due to low score
// Continue until Phase 5 (FINALIZE)
Phase Response:
{
"sessionId": "session_1234567890_abc123",
"phase": "evaluate",
"prompt": "## PHASE 3: SELF-EVALUATION\n\nRate your solution CRITICALLY...",
"depth": 2,
"confidence": 0.75,
"currentRating": {
"score": 6,
"isGood": false,
"rationale": "Missing rate limiting..."
},
"isComplete": false,
"instruction": "Rate your solution (1-10). Be honest about weaknesses."
}
Final Response:
{
"sessionId": "session_1234567890_abc123",
"isComplete": true,
"phase": "finalize",
"depth": 4,
"confidence": 0.92,
"iterations": [
{
"iteration": 1,
"phase": "completed",
"solution": "...",
"reasoning": "I chose this because...",
"selfRating": { "score": 6, "isGood": false, "rationale": "..." },
"improvements": "Add rate limiting..."
},
{
"iteration": 2,
"phase": "completed",
"solution": "...",
"reasoning": "Improved approach because...",
"selfRating": { "score": 8, "isGood": true, "rationale": "..." },
"improvements": "Minor optimizations possible"
}
],
"finalSolution": "Complete production-ready implementation...",
"summary": {
"totalIterations": 4,
"finalConfidence": 0.92,
"finalRating": { "score": 9, "isGood": true, "rationale": "..." },
"rethinkingEnabled": true
},
"instruction": "Production-ready solution achieved."
}
| Parameter | Type | Default | Range | Description |
|---|---|---|---|---|
maxDepth |
number | 5 | 1-10 | Maximum recursion depth |
minConfidence |
number | 0.85 | 0-1 | Stop when confidence meets threshold |
minRating |
number | 7 | 1-10 | Minimum acceptable score (1-10) |
enableRethinking |
boolean | true | - | Enable continuous refinement loop |
maxIterations |
number | 8 | 1-20 | Maximum total iterations |
// 1. Start thinking
const result1 = await recursive_thinking({
action: 'start',
task: 'Build a REST API for user management with proper validation'
});
// Returns: Phase 1 (EXPLORE) prompt
// 2. AI provides solution with reasoning
const result2 = await recursive_thinking({
action: 'iterate',
sessionId: result1.sessionId,
response: `
**Solution**: Express + TypeScript + Zod validation
**Reasoning**: Zod provides runtime type checking with excellent
TypeScript integration. Chose Express for its middleware ecosystem.
**Alternatives**: Considered NestJS but adds unnecessary complexity.
`
});
// Returns: Phase 2 (JUSTIFY) prompt
// 3. AI justifies reasoning
const result3 = await recursive_thinking({
action: 'iterate',
sessionId: result2.sessionId,
response: `
**Why This Works**: Zod schemas validate at runtime, catching invalid data.
**Hidden Assumptions**: Assuming all endpoints need same validation depth.
**Edge Cases**: Malformed JSON, missing required fields, SQL injection attempts.
**Confidence**: 0.70
`
});
// Returns: Phase 3 (EVALUATE) prompt
// 4. AI self-evaluates (honest assessment)
const result4 = await recursive_thinking({
action: 'iterate',
sessionId: result3.sessionId,
response: `
{
"score": 5,
"isGood": false,
"rationale": "No error handling strategy, no rate limiting, no input
sanitization mentioned",
"improvements": "Add centralized error handling, rate limiting, input
sanitization, request logging"
}
`
});
// Returns: Phase 4 (RETHINK) prompt - triggered due to low score
// 5. AI rethinks and improves
const result5 = await recursive_thinking({
action: 'iterate',
sessionId: result4.sessionId,
response: `
**What Was Wrong**: Previous solution lacked production considerations.
**New Approach**: Added express-rate-limit, express-validator, winston logging,
centralized error handler middleware.
**Why Better**: Now handles rate limiting, input validation, structured logging,
and consistent error responses.
**New Confidence**: 0.85
`
});
// Loops back to Phase 1 (EXPLORE) with improved approach
// ... continues until production-ready ...
// 6. Final result
console.log(resultFinal);
// {
// isComplete: true,
// depth: 4,
// confidence: 0.92,
// finalRating: { score: 9, isGood: true },
// finalSolution: "..."
// }
| Metric | v1.0 | v2.0 |
|---|---|---|
| Average iterations | 2-3 | 3-5 |
| Solution quality | Good | Excellent |
| Reasoning transparency | Low | High |
| Token usage per session | ~1000-1500 | ~1500-2000 |
| Production readiness | 85% | 95%+ |
Trade-off: Slightly more tokens for significantly better solutions with full reasoning chains.
| Metric | Value |
|---|---|
| Average iterations to solution | 3-5 |
| Token usage per session | ~1500-2000 |
| Bundle size | 0.52 MB |
| Success rate | 100% |
| Production readiness | 95%+ |
# Install dependencies
npm install
# Build
npm run build
# Run locally
npm start
# Watch mode for development
npm run dev
# Link globally (for testing)
npm link
minRating = better solutions but more iterationsenableRethinking: true for production work# Verify global installation
npm list -g recursive-thinking-mcp
# Reinstall globally
npm install -g recursive-thinking-mcp
# Or use npx directly in config
# Clean and rebuild
rm -rf dist node_modules
npm install
npm run build
Sessions are in-memory and expire when the server restarts. If you lose a session:
action=start with the same taskMIT
AI agent, MCP server, Model Context Protocol, chain of thought, recursive thinking, iterative refinement, self-evaluation, continuous improvement, token optimization, Claude AI, AI problem solving, production-ready solutions, context compression, thinking engine, automation tool, LLM enhancement, Claude Desktop, Claude Code, VS Code MCP, reasoning chain, AI self-critique, solution quality, rethinking loop.
Добавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"recursive-thinking-mcp-server": {
"command": "npx",
"args": []
}
}
}