Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor version update + major edits #6

Merged
merged 9 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Jacck, frgmt0
Copyright (c) 2025 Jacck, frgmt0

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
119 changes: 70 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,62 @@
# MCP Reasoner
A systematic reasoning MCP server implementation for Claude Desktop featuring both Beam Search and Monte Carlo Tree Search (MCTS) capabilities.
A reasoning implementation for Claude Desktop that lets you use both Beam Search and Monte Carlo Tree Search (MCTS). tbh this started as a way to see if we could make Claude even better at complex problem-solving... turns out we definitely can.

### Current Version:
**v2.0.0**

#### What's New:

> Added 2 Experimental Reasoning Algorithms:
>
> - `mcts-002-alpha`
>
> - Uses the A* Search Method along with an early *alpha* implementation of a Policy Simulation Layer
>
> - Also includes an early *alpha* implementation of Adaptive Exploration Simulator & Outcome Based Reasoning Simulator
>
> *NOTE* the implementation of these alpha simulators is not complete and is subject to change
>
> - `mcts-002alt-alpha`
>
> - Uses the Bidirectional Search Method along with an early *alpha* implementation of a Policy Simulation Layer
>
> - Also includes an early *alpha* implementation of Adaptive Exploration Simulator & Outcome Based Reasoning Simulator
>
> *NOTE* the implementation of these alpha simulators is not complete and is subject to change


What happened to `mcts-001-alpha` and `mcts-001alt-alpha`?
> Quite simply: It was useless and near similar to the base `mcts` method. After initial testing the results yielded in basic thought processes was near similar showing that simply adding policy simulation may not have an effect.

So why add Polciy Simulation Layer now?
> Well i think its important to incorporate Policy AND Search in tandem as that is how most of the algorithms implement them.

#### Previous Versions:
**v1.1.0**

> Added model control over search parameters:
>
> beamWidth - lets Claude adjust how many paths to track (1-10)
>
> numSimulations - fine-tune MCTS simulation count (1-150)

## Features
* Dual search strategies:
* Beam search with configurable width
* MCTS for complex decision spaces
* Thought scoring and evaluation
* Tree-based reasoning paths
* Statistical analysis of reasoning process
* MCP protocol compliance
- Two search strategies that you can switch between:
- Beam search (good for straightforward stuff)
- MCTS (when stuff gets complex) with alpha variations (see above)
- Tracks how good different reasoning paths are
- Maps out all the different ways Claude thinks through problems
- Analyzes how the reasoning process went
- Follows the MCP protocol (obviously)

## Installation
```
git clone https://github.com/frgmt0/mcp-reasoner.git

OR clone the original:

git clone https://github.com/Jacck/mcp-reasoner.git

cd mcp-reasoner
npm install
npm run build
Expand All @@ -31,46 +75,23 @@ Add to Claude Desktop config:
}
```

## Search Strategies

### Beam Search
* Maintains fixed-width set of most promising paths
* Optimal for step-by-step reasoning
* Best for: Mathematical problems, logical puzzles

### Monte Carlo Tree Search
* Simulation-based exploration of decision space
* Balances exploration and exploitation
* Best for: Complex problems with uncertain outcomes

**Note:** Monte Carlo Tree Search allowed Claude to perform really well on the Arc AGI benchmark (scored 6/10 on the public test), whereas beam search yielded a (3/10) on the same puzzles. For super complex tasks, you'd want to direct Claude to utilize the MCTS strategy over the beam search.

## Algorithm Details
1. Search Strategy Selection
* Beam Search: Evaluates and ranks multiple solution paths
* MCTS: Uses UCT for node selection and random rollouts
2. Thought Scoring Based On:
* Detail level
* Mathematical expressions
* Logical connectors
* Parent-child relationship strength
3. Process Management
* Tree-based state tracking
* Statistical analysis of reasoning
* Progress monitoring

## Use Cases
* Mathematical problems
* Logical puzzles
* Step-by-step analysis
* Complex problem decomposition
* Decision tree exploration
* Strategy optimization

## Future Implementations
* Implement New Algorithms
* Iterative Deepening Depth-First Search (IDDFS)
* Alpha-Beta Pruning
## Testing

[More Testing Coming Soon]

## Benchmarks

[Benchmarking will be added soon]

Key Benchmarks to test against:

- MATH500

- GPQA-Diamond

- GMSK8

- Maybe Polyglot &/or SWE-Bench

## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
24 changes: 0 additions & 24 deletions dist/engine.d.ts

This file was deleted.

78 changes: 0 additions & 78 deletions dist/engine.js

This file was deleted.

26 changes: 24 additions & 2 deletions dist/index.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ function processInput(input) {
thoughtNumber: Number(input.thoughtNumber || 0),
totalThoughts: Number(input.totalThoughts || 0),
nextThoughtNeeded: Boolean(input.nextThoughtNeeded),
strategyType: input.strategyType
strategyType: input.strategyType,
beamWidth: Number(input.beamWidth || 3),
numSimulations: Number(input.numSimulations || 50)
};
// Validate
if (!result.thought) {
Expand All @@ -34,6 +36,12 @@ function processInput(input) {
if (result.totalThoughts < 1) {
throw new Error("totalThoughts must be >= 1");
}
if (result.beamWidth < 1 || result.beamWidth > 10) {
throw new Error("beamWidth must be between 1 and 10");
}
if (result.numSimulations < 1 || result.numSimulations > 150) {
throw new Error("numSimulations must be between 1 and 150");
}
return result;
}
// Register the tool
Expand Down Expand Up @@ -66,6 +74,18 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
type: "string",
enum: Object.values(ReasoningStrategy),
description: "Reasoning strategy to use (beam_search or mcts)"
},
beamWidth: {
type: "integer",
description: "Number of top paths to maintain (n-sampling). Defaults to 3 if not specified",
minimum: 1,
maximum: 10
},
numSimulations: {
type: "integer",
description: "Number of MCTS simulations to run. Defaults to 50 if not specified",
minimum: 1,
maximum: 150
}
},
required: ["thought", "thoughtNumber", "totalThoughts", "nextThoughtNeeded"]
Expand All @@ -92,7 +112,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
thoughtNumber: step.thoughtNumber,
totalThoughts: step.totalThoughts,
nextThoughtNeeded: step.nextThoughtNeeded,
strategyType: step.strategyType
strategyType: step.strategyType,
beamWidth: step.beamWidth,
numSimulations: step.numSimulations
});
// Get reasoning stats
const stats = await reasoner.getStats();
Expand Down
2 changes: 1 addition & 1 deletion dist/reasoner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export declare class Reasoner {
getCurrentStrategyName(): ReasoningStrategy;
getBestPath(): Promise<ThoughtNode[]>;
clear(): Promise<void>;
setStrategy(strategyType: ReasoningStrategy): void;
setStrategy(strategyType: ReasoningStrategy, beamWidth?: number, numSimulations?: number): void;
getAvailableStrategies(): ReasoningStrategy[];
}
33 changes: 28 additions & 5 deletions dist/reasoner.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ export class Reasoner {
this.stateManager = new StateManager(CONFIG.cacheSize);
// Initialize available strategies
this.strategies = new Map();
this.strategies.set(ReasoningStrategy.BEAM_SEARCH, StrategyFactory.createStrategy(ReasoningStrategy.BEAM_SEARCH, this.stateManager));
this.strategies.set(ReasoningStrategy.MCTS, StrategyFactory.createStrategy(ReasoningStrategy.MCTS, this.stateManager));
// Initialize base strategies
this.strategies.set(ReasoningStrategy.BEAM_SEARCH, StrategyFactory.createStrategy(ReasoningStrategy.BEAM_SEARCH, this.stateManager, CONFIG.beamWidth));
this.strategies.set(ReasoningStrategy.MCTS, StrategyFactory.createStrategy(ReasoningStrategy.MCTS, this.stateManager, undefined, CONFIG.numSimulations));
// Initialize experimental MCTS strategies
this.strategies.set(ReasoningStrategy.MCTS_002_ALPHA, StrategyFactory.createStrategy(ReasoningStrategy.MCTS_002_ALPHA, this.stateManager, undefined, CONFIG.numSimulations));
this.strategies.set(ReasoningStrategy.MCTS_002_ALT_ALPHA, StrategyFactory.createStrategy(ReasoningStrategy.MCTS_002_ALT_ALPHA, this.stateManager, undefined, CONFIG.numSimulations));
// Set default strategy
const defaultStrategy = CONFIG.defaultStrategy;
this.currentStrategy = this.strategies.get(defaultStrategy) ||
Expand All @@ -16,7 +20,17 @@ export class Reasoner {
async processThought(request) {
// Switch strategy if requested
if (request.strategyType && this.strategies.has(request.strategyType)) {
this.currentStrategy = this.strategies.get(request.strategyType);
const strategyType = request.strategyType;
// Create new strategy instance with appropriate parameters
if (strategyType === ReasoningStrategy.BEAM_SEARCH) {
this.currentStrategy = StrategyFactory.createStrategy(strategyType, this.stateManager, request.beamWidth);
}
else {
// All MCTS variants (base and experimental) use numSimulations
this.currentStrategy = StrategyFactory.createStrategy(strategyType, this.stateManager, undefined, request.numSimulations);
}
// Update strategy in map
this.strategies.set(strategyType, this.currentStrategy);
}
// Process thought using current strategy
const response = await this.currentStrategy.processThought(request);
Expand Down Expand Up @@ -80,11 +94,20 @@ export class Reasoner {
await strategy.clear();
}
}
setStrategy(strategyType) {
setStrategy(strategyType, beamWidth, numSimulations) {
if (!this.strategies.has(strategyType)) {
throw new Error(`Unknown strategy type: ${strategyType}`);
}
this.currentStrategy = this.strategies.get(strategyType);
// Create new strategy instance with appropriate parameters
if (strategyType === ReasoningStrategy.BEAM_SEARCH) {
this.currentStrategy = StrategyFactory.createStrategy(strategyType, this.stateManager, beamWidth);
}
else {
// All MCTS variants (base and experimental) use numSimulations
this.currentStrategy = StrategyFactory.createStrategy(strategyType, this.stateManager, undefined, numSimulations);
}
// Update strategy in map
this.strategies.set(strategyType, this.currentStrategy);
}
getAvailableStrategies() {
return Array.from(this.strategies.keys());
Expand Down
2 changes: 1 addition & 1 deletion dist/strategies/beam-search.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BaseStrategy } from './base.js';
export declare class BeamSearchStrategy extends BaseStrategy {
private beamWidth;
private beams;
constructor(stateManager: any, beamWidth?: 3);
constructor(stateManager: any, beamWidth?: number);
processThought(request: ReasoningRequest): Promise<ReasoningResponse>;
private calculatePossiblePaths;
getBestPath(): Promise<ThoughtNode[]>;
Expand Down
6 changes: 4 additions & 2 deletions dist/strategies/factory.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { StateManager } from '../state.js';
import { BaseStrategy } from './base.js';
export declare enum ReasoningStrategy {
BEAM_SEARCH = "beam_search",
MCTS = "mcts"
MCTS = "mcts",
MCTS_002_ALPHA = "mcts_002_alpha",
MCTS_002_ALT_ALPHA = "mcts_002_alt_alpha"
}
export declare class StrategyFactory {
static createStrategy(type: ReasoningStrategy, stateManager: StateManager): BaseStrategy;
static createStrategy(type: ReasoningStrategy, stateManager: StateManager, beamWidth?: number, numSimulations?: number): BaseStrategy;
}
Loading