From 026f029ce38e0c299e0eb02179c2d7942bfd0da2 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <209825114+claude[bot]@users.noreply.github.com> Date: Wed, 27 Aug 2025 12:39:17 +0000 Subject: [PATCH] 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 --- src/sequentialthinking/README.md | 6 ++++-- src/sequentialthinking/index.ts | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/sequentialthinking/README.md b/src/sequentialthinking/README.md index c3886a9b..8b2f94a2 100644 --- a/src/sequentialthinking/README.md +++ b/src/sequentialthinking/README.md @@ -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 diff --git a/src/sequentialthinking/index.ts b/src/sequentialthinking/index.ts index 34986971..76d932e1 100644 --- a/src/sequentialthinking/index.ts +++ b/src/sequentialthinking/index.ts @@ -26,9 +26,12 @@ class SequentialThinkingServer { private thoughtHistory: ThoughtData[] = []; private branches: Record = {}; 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; }