feat: add MAX_TOTAL_THOUGHTS environment variable to sequential-thinking server

Adds support for constraining the totalThoughts parameter via the MAX_TOTAL_THOUGHTS environment variable:
- When set to a positive integer, caps totalThoughts at the specified limit
- Displays warning when capping occurs
- Maintains backward compatibility (unlimited by default)
- Updated README with configuration documentation

Fixes #2226

Co-authored-by: Ola Hungerford <olaservo@users.noreply.github.com>
This commit is contained in:
claude[bot]
2025-08-27 12:39:17 +00:00
parent e3284edb47
commit 026f029ce3
2 changed files with 13 additions and 2 deletions

View File

@@ -77,8 +77,10 @@ Add this to your `claude_desktop_config.json`:
}
```
To disable logging of thought information set env var: `DISABLE_THOUGHT_LOGGING` to `true`.
Comment
### Environment Variables
- `DISABLE_THOUGHT_LOGGING`: Set to `true` to disable logging of thought information
- `MAX_TOTAL_THOUGHTS`: Set to a positive integer to limit the maximum number of thoughts allowed (e.g., `MAX_TOTAL_THOUGHTS=50`). When the AI model requests more thoughts than this limit, the value will be capped at the maximum with a warning message. Leave unset or set to 0 for unlimited thoughts (default behavior).
### Usage with VS Code

View File

@@ -26,9 +26,12 @@ class SequentialThinkingServer {
private thoughtHistory: ThoughtData[] = [];
private branches: Record<string, ThoughtData[]> = {};
private disableThoughtLogging: boolean;
private maxTotalThoughts?: number;
constructor() {
this.disableThoughtLogging = (process.env.DISABLE_THOUGHT_LOGGING || "").toLowerCase() === "true";
const maxThoughts = parseInt(process.env.MAX_TOTAL_THOUGHTS || "0") || 0;
this.maxTotalThoughts = maxThoughts > 0 ? maxThoughts : undefined;
}
private validateThoughtData(input: unknown): ThoughtData {
@@ -92,6 +95,12 @@ class SequentialThinkingServer {
try {
const validatedInput = this.validateThoughtData(input);
// Apply maximum total thoughts limit if configured
if (this.maxTotalThoughts && validatedInput.totalThoughts > this.maxTotalThoughts) {
console.error(`Warning: totalThoughts capped at ${this.maxTotalThoughts} (requested: ${validatedInput.totalThoughts})`);
validatedInput.totalThoughts = this.maxTotalThoughts;
}
if (validatedInput.thoughtNumber > validatedInput.totalThoughts) {
validatedInput.totalThoughts = validatedInput.thoughtNumber;
}