#
tokens: 7917/50000 6/6 files
lines: on (toggle) GitHub
raw markdown copy reset
# Directory Structure

```
├── .gitignore
├── package-lock.json
├── package.json
├── README.md
├── src
│   ├── index.js
│   └── index.ts
└── tsconfig.json
```

# Files

--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------

```
 1 | # dependencies
 2 | /node_modules
 3 | /.pnp
 4 | .pnp.js
 5 | 
 6 | # testing
 7 | /coverage
 8 | 
 9 | # production
10 | /build
11 | /dist
12 | 
13 | # misc
14 | .DS_Store
15 | .env.local
16 | .env.development.local
17 | .env.test.local
18 | .env.production.local
19 | 
20 | # logs
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 | 
25 | # editor directories and files
26 | .idea
27 | .vscode
28 | *.suo
29 | *.ntvs*
30 | *.njsproj
31 | *.sln
32 | *.sw? 
```

--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------

```markdown
 1 | 
 2 | # Sequential Thinking MCP Server
 3 | 
 4 | An MCP server implementation that provides a tool for dynamic and reflective problem-solving through a structured thinking process.
 5 | 
 6 | ## Features
 7 | 
 8 | - Break down complex problems into manageable steps
 9 | - Revise and refine thoughts as understanding deepens
10 | - Branch into alternative paths of reasoning
11 | - Adjust the total number of thoughts dynamically
12 | - Generate and verify solution hypotheses
13 | 
14 | ## Tool
15 | 
16 | ### sequential_thinking
17 | 
18 | Facilitates a detailed, step-by-step thinking process for problem-solving and analysis.
19 | 
20 | **Inputs:**
21 | - `thought` (string): The current thinking step
22 | - `nextThoughtNeeded` (boolean): Whether another thought step is needed
23 | - `thoughtNumber` (integer): Current thought number
24 | - `totalThoughts` (integer): Estimated total thoughts needed
25 | - `isRevision` (boolean, optional): Whether this revises previous thinking
26 | - `revisesThought` (integer, optional): Which thought is being reconsidered
27 | - `branchFromThought` (integer, optional): Branching point thought number
28 | - `branchId` (string, optional): Branch identifier
29 | - `needsMoreThoughts` (boolean, optional): If more thoughts are needed
30 | 
31 | ## Usage
32 | 
33 | The Sequential Thinking tool is designed for:
34 | - Breaking down complex problems into steps
35 | - Planning and design with room for revision
36 | - Analysis that might need course correction
37 | - Problems where the full scope might not be clear initially
38 | - Tasks that need to maintain context over multiple steps
39 | - Situations where irrelevant information needs to be filtered out
40 | 
41 | ## Configuration
42 | 
43 | ### Usage with Claude Desktop
44 | 
45 | Add this to your `claude_desktop_config.json`:
46 | 
47 | #### npx
48 | 
49 | ```json
50 | {
51 |   "mcpServers": {
52 |     "sequential-thinking": {
53 |       "command": "npx",
54 |       "args": [
55 |         "-y",
56 |         "@modelcontextprotocol/server-sequential-thinking"
57 |       ]
58 |     }
59 |   }
60 | }
61 | ```
62 | 
63 | #### docker
64 | 
65 | ```json
66 | {
67 |   "mcpServers": {
68 |     "sequentialthinking": {
69 |       "command": "docker",
70 |       "args": [
71 |         "run",
72 |         "--rm",
73 |         "-i",
74 |         "mcp/sequentialthinking"
75 |       ]
76 |     }
77 |   }
78 | }
79 | ```
80 | 
81 | ## Building
82 | 
83 | Docker:
84 | 
85 | ```bash
86 | docker build -t mcp/sequentialthinking -f src/sequentialthinking/Dockerfile .
87 | ```
88 | 
89 | ## License
90 | 
91 | This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.
92 | 
```

--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------

```json
 1 | {
 2 |   "compilerOptions": {
 3 |     "outDir": "./dist",
 4 |     "rootDir": "./src",
 5 |     "moduleResolution": "NodeNext",
 6 |     "module": "NodeNext",
 7 |     "target": "ES2022",
 8 |     "esModuleInterop": true,
 9 |     "strict": true
10 |   },
11 |   "include": ["./**/*.ts"]
12 | }
13 | 
```

--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------

```json
 1 | {
 2 |   "name": "@modelcontextprotocol/server-sequential-thinking",
 3 |   "version": "0.6.2",
 4 |   "description": "MCP server for sequential thinking and problem solving",
 5 |   "license": "MIT",
 6 |   "author": "Anthropic, PBC (https://anthropic.com)",
 7 |   "homepage": "https://modelcontextprotocol.io",
 8 |   "bugs": "https://github.com/modelcontextprotocol/servers/issues",
 9 |   "type": "module",
10 |   "bin": {
11 |     "mcp-server-sequential-thinking": "dist/index.js"
12 |   },
13 |   "files": [
14 |     "dist"
15 |   ],
16 |   "scripts": {
17 |     "build": "tsc && shx chmod +x dist/*.js",
18 |     "prepare": "npm run build",
19 |     "watch": "tsc --watch"
20 |   },
21 |   "dependencies": {
22 |     "@modelcontextprotocol/sdk": "0.5.0",
23 |     "chalk": "^5.3.0",
24 |     "yargs": "^17.7.2"
25 |   },
26 |   "devDependencies": {
27 |     "@types/node": "^22.13.10",
28 |     "@types/yargs": "^17.0.32",
29 |     "shx": "^0.3.4",
30 |     "typescript": "^5.3.3"
31 |   }
32 | }
33 | 
```

--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------

```typescript
  1 | #!/usr/bin/env node
  2 | 
  3 | import { Server } from "@modelcontextprotocol/sdk/server/index.js";
  4 | import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
  5 | import {
  6 |   CallToolRequestSchema,
  7 |   ListToolsRequestSchema,
  8 |   Tool,
  9 | } from "@modelcontextprotocol/sdk/types.js";
 10 | // Fixed chalk import for ESM
 11 | import chalk from 'chalk';
 12 | 
 13 | interface ThoughtData {
 14 |   thought: string;
 15 |   thoughtNumber: number;
 16 |   totalThoughts: number;
 17 |   isRevision?: boolean;
 18 |   revisesThought?: number;
 19 |   branchFromThought?: number;
 20 |   branchId?: string;
 21 |   needsMoreThoughts?: boolean;
 22 |   nextThoughtNeeded: boolean;
 23 | }
 24 | 
 25 | class SequentialThinkingServer {
 26 |   private thoughtHistory: ThoughtData[] = [];
 27 |   private branches: Record<string, ThoughtData[]> = {};
 28 | 
 29 |   private validateThoughtData(input: unknown): ThoughtData {
 30 |     const data = input as Record<string, unknown>;
 31 | 
 32 |     if (!data.thought || typeof data.thought !== 'string') {
 33 |       throw new Error('Invalid thought: must be a string');
 34 |     }
 35 |     if (!data.thoughtNumber || typeof data.thoughtNumber !== 'number') {
 36 |       throw new Error('Invalid thoughtNumber: must be a number');
 37 |     }
 38 |     if (!data.totalThoughts || typeof data.totalThoughts !== 'number') {
 39 |       throw new Error('Invalid totalThoughts: must be a number');
 40 |     }
 41 |     if (typeof data.nextThoughtNeeded !== 'boolean') {
 42 |       throw new Error('Invalid nextThoughtNeeded: must be a boolean');
 43 |     }
 44 | 
 45 |     return {
 46 |       thought: data.thought,
 47 |       thoughtNumber: data.thoughtNumber,
 48 |       totalThoughts: data.totalThoughts,
 49 |       nextThoughtNeeded: data.nextThoughtNeeded,
 50 |       isRevision: data.isRevision as boolean | undefined,
 51 |       revisesThought: data.revisesThought as number | undefined,
 52 |       branchFromThought: data.branchFromThought as number | undefined,
 53 |       branchId: data.branchId as string | undefined,
 54 |       needsMoreThoughts: data.needsMoreThoughts as boolean | undefined,
 55 |     };
 56 |   }
 57 | 
 58 |   private formatThought(thoughtData: ThoughtData): string {
 59 |     const { thoughtNumber, totalThoughts, thought, isRevision, revisesThought, branchFromThought, branchId } = thoughtData;
 60 | 
 61 |     let prefix = '';
 62 |     let context = '';
 63 | 
 64 |     if (isRevision) {
 65 |       prefix = chalk.yellow('🔄 Revision');
 66 |       context = ` (revising thought ${revisesThought})`;
 67 |     } else if (branchFromThought) {
 68 |       prefix = chalk.green('🌿 Branch');
 69 |       context = ` (from thought ${branchFromThought}, ID: ${branchId})`;
 70 |     } else {
 71 |       prefix = chalk.blue('💭 Thought');
 72 |       context = '';
 73 |     }
 74 | 
 75 |     const header = `${prefix} ${thoughtNumber}/${totalThoughts}${context}`;
 76 |     const border = '─'.repeat(Math.max(header.length, thought.length) + 4);
 77 | 
 78 |     return `
 79 | ┌${border}┐
 80 | │ ${header} │
 81 | ├${border}┤
 82 | │ ${thought.padEnd(border.length - 2)} │
 83 | └${border}┘`;
 84 |   }
 85 | 
 86 |   public processThought(input: unknown): { content: Array<{ type: string; text: string }>; isError?: boolean } {
 87 |     try {
 88 |       const validatedInput = this.validateThoughtData(input);
 89 | 
 90 |       if (validatedInput.thoughtNumber > validatedInput.totalThoughts) {
 91 |         validatedInput.totalThoughts = validatedInput.thoughtNumber;
 92 |       }
 93 | 
 94 |       this.thoughtHistory.push(validatedInput);
 95 | 
 96 |       if (validatedInput.branchFromThought && validatedInput.branchId) {
 97 |         if (!this.branches[validatedInput.branchId]) {
 98 |           this.branches[validatedInput.branchId] = [];
 99 |         }
100 |         this.branches[validatedInput.branchId].push(validatedInput);
101 |       }
102 | 
103 |       const formattedThought = this.formatThought(validatedInput);
104 |       console.error(formattedThought);
105 | 
106 |       return {
107 |         content: [{
108 |           type: "text",
109 |           text: JSON.stringify({
110 |             thoughtNumber: validatedInput.thoughtNumber,
111 |             totalThoughts: validatedInput.totalThoughts,
112 |             nextThoughtNeeded: validatedInput.nextThoughtNeeded,
113 |             branches: Object.keys(this.branches),
114 |             thoughtHistoryLength: this.thoughtHistory.length
115 |           }, null, 2)
116 |         }]
117 |       };
118 |     } catch (error) {
119 |       return {
120 |         content: [{
121 |           type: "text",
122 |           text: JSON.stringify({
123 |             error: error instanceof Error ? error.message : String(error),
124 |             status: 'failed'
125 |           }, null, 2)
126 |         }],
127 |         isError: true
128 |       };
129 |     }
130 |   }
131 | }
132 | 
133 | const SEQUENTIAL_THINKING_TOOL: Tool = {
134 |   name: "sequentialthinking",
135 |   description: `A detailed tool for dynamic and reflective problem-solving through thoughts.
136 | This tool helps analyze problems through a flexible thinking process that can adapt and evolve.
137 | Each thought can build on, question, or revise previous insights as understanding deepens.
138 | 
139 | When to use this tool:
140 | - Breaking down complex problems into steps
141 | - Planning and design with room for revision
142 | - Analysis that might need course correction
143 | - Problems where the full scope might not be clear initially
144 | - Problems that require a multi-step solution
145 | - Tasks that need to maintain context over multiple steps
146 | - Situations where irrelevant information needs to be filtered out
147 | 
148 | Key features:
149 | - You can adjust total_thoughts up or down as you progress
150 | - You can question or revise previous thoughts
151 | - You can add more thoughts even after reaching what seemed like the end
152 | - You can express uncertainty and explore alternative approaches
153 | - Not every thought needs to build linearly - you can branch or backtrack
154 | - Generates a solution hypothesis
155 | - Verifies the hypothesis based on the Chain of Thought steps
156 | - Repeats the process until satisfied
157 | - Provides a correct answer
158 | 
159 | Parameters explained:
160 | - thought: Your current thinking step, which can include:
161 | * Regular analytical steps
162 | * Revisions of previous thoughts
163 | * Questions about previous decisions
164 | * Realizations about needing more analysis
165 | * Changes in approach
166 | * Hypothesis generation
167 | * Hypothesis verification
168 | - next_thought_needed: True if you need more thinking, even if at what seemed like the end
169 | - thought_number: Current number in sequence (can go beyond initial total if needed)
170 | - total_thoughts: Current estimate of thoughts needed (can be adjusted up/down)
171 | - is_revision: A boolean indicating if this thought revises previous thinking
172 | - revises_thought: If is_revision is true, which thought number is being reconsidered
173 | - branch_from_thought: If branching, which thought number is the branching point
174 | - branch_id: Identifier for the current branch (if any)
175 | - needs_more_thoughts: If reaching end but realizing more thoughts needed
176 | 
177 | You should:
178 | 1. Start with an initial estimate of needed thoughts, but be ready to adjust
179 | 2. Feel free to question or revise previous thoughts
180 | 3. Don't hesitate to add more thoughts if needed, even at the "end"
181 | 4. Express uncertainty when present
182 | 5. Mark thoughts that revise previous thinking or branch into new paths
183 | 6. Ignore information that is irrelevant to the current step
184 | 7. Generate a solution hypothesis when appropriate
185 | 8. Verify the hypothesis based on the Chain of Thought steps
186 | 9. Repeat the process until satisfied with the solution
187 | 10. Provide a single, ideally correct answer as the final output
188 | 11. Only set next_thought_needed to false when truly done and a satisfactory answer is reached`,
189 |   inputSchema: {
190 |     type: "object",
191 |     properties: {
192 |       thought: {
193 |         type: "string",
194 |         description: "Your current thinking step"
195 |       },
196 |       nextThoughtNeeded: {
197 |         type: "boolean",
198 |         description: "Whether another thought step is needed"
199 |       },
200 |       thoughtNumber: {
201 |         type: "integer",
202 |         description: "Current thought number",
203 |         minimum: 1
204 |       },
205 |       totalThoughts: {
206 |         type: "integer",
207 |         description: "Estimated total thoughts needed",
208 |         minimum: 1
209 |       },
210 |       isRevision: {
211 |         type: "boolean",
212 |         description: "Whether this revises previous thinking"
213 |       },
214 |       revisesThought: {
215 |         type: "integer",
216 |         description: "Which thought is being reconsidered",
217 |         minimum: 1
218 |       },
219 |       branchFromThought: {
220 |         type: "integer",
221 |         description: "Branching point thought number",
222 |         minimum: 1
223 |       },
224 |       branchId: {
225 |         type: "string",
226 |         description: "Branch identifier"
227 |       },
228 |       needsMoreThoughts: {
229 |         type: "boolean",
230 |         description: "If more thoughts are needed"
231 |       }
232 |     },
233 |     required: ["thought", "nextThoughtNeeded", "thoughtNumber", "totalThoughts"]
234 |   }
235 | };
236 | 
237 | const server = new Server(
238 |   {
239 |     name: "sequential-thinking-server",
240 |     version: "0.2.0",
241 |   },
242 |   {
243 |     capabilities: {
244 |       tools: {},
245 |     },
246 |   }
247 | );
248 | 
249 | const thinkingServer = new SequentialThinkingServer();
250 | 
251 | server.setRequestHandler(ListToolsRequestSchema, async () => ({
252 |   tools: [SEQUENTIAL_THINKING_TOOL],
253 | }));
254 | 
255 | server.setRequestHandler(CallToolRequestSchema, async (request) => {
256 |   if (request.params.name === "sequentialthinking") {
257 |     return thinkingServer.processThought(request.params.arguments);
258 |   }
259 | 
260 |   return {
261 |     content: [{
262 |       type: "text",
263 |       text: `Unknown tool: ${request.params.name}`
264 |     }],
265 |     isError: true
266 |   };
267 | });
268 | 
269 | async function runServer() {
270 |   const transport = new StdioServerTransport();
271 |   await server.connect(transport);
272 |   console.error("Sequential Thinking MCP Server running on stdio");
273 | }
274 | 
275 | runServer().catch((error) => {
276 |   console.error("Fatal error running server:", error);
277 |   process.exit(1);
278 | });
279 | 
```

--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------

```javascript
  1 | #!/usr/bin/env node
  2 | "use strict";
  3 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  4 |     function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  5 |     return new (P || (P = Promise))(function (resolve, reject) {
  6 |         function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  7 |         function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  8 |         function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  9 |         step((generator = generator.apply(thisArg, _arguments || [])).next());
 10 |     });
 11 | };
 12 | var __generator = (this && this.__generator) || function (thisArg, body) {
 13 |     var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
 14 |     return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
 15 |     function verb(n) { return function (v) { return step([n, v]); }; }
 16 |     function step(op) {
 17 |         if (f) throw new TypeError("Generator is already executing.");
 18 |         while (g && (g = 0, op[0] && (_ = 0)), _) try {
 19 |             if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
 20 |             if (y = 0, t) op = [op[0] & 2, t.value];
 21 |             switch (op[0]) {
 22 |                 case 0: case 1: t = op; break;
 23 |                 case 4: _.label++; return { value: op[1], done: false };
 24 |                 case 5: _.label++; y = op[1]; op = [0]; continue;
 25 |                 case 7: op = _.ops.pop(); _.trys.pop(); continue;
 26 |                 default:
 27 |                     if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
 28 |                     if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
 29 |                     if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
 30 |                     if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
 31 |                     if (t[2]) _.ops.pop();
 32 |                     _.trys.pop(); continue;
 33 |             }
 34 |             op = body.call(thisArg, _);
 35 |         } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
 36 |         if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
 37 |     }
 38 | };
 39 | Object.defineProperty(exports, "__esModule", { value: true });
 40 | var index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
 41 | var stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
 42 | var types_js_1 = require("@modelcontextprotocol/sdk/types.js");
 43 | // Fixed chalk import for ESM
 44 | var chalk_1 = require("chalk");
 45 | var SequentialThinkingServer = /** @class */ (function () {
 46 |     function SequentialThinkingServer() {
 47 |         this.thoughtHistory = [];
 48 |         this.branches = {};
 49 |     }
 50 |     SequentialThinkingServer.prototype.validateThoughtData = function (input) {
 51 |         var data = input;
 52 |         if (!data.thought || typeof data.thought !== 'string') {
 53 |             throw new Error('Invalid thought: must be a string');
 54 |         }
 55 |         if (!data.thoughtNumber || typeof data.thoughtNumber !== 'number') {
 56 |             throw new Error('Invalid thoughtNumber: must be a number');
 57 |         }
 58 |         if (!data.totalThoughts || typeof data.totalThoughts !== 'number') {
 59 |             throw new Error('Invalid totalThoughts: must be a number');
 60 |         }
 61 |         if (typeof data.nextThoughtNeeded !== 'boolean') {
 62 |             throw new Error('Invalid nextThoughtNeeded: must be a boolean');
 63 |         }
 64 |         return {
 65 |             thought: data.thought,
 66 |             thoughtNumber: data.thoughtNumber,
 67 |             totalThoughts: data.totalThoughts,
 68 |             nextThoughtNeeded: data.nextThoughtNeeded,
 69 |             isRevision: data.isRevision,
 70 |             revisesThought: data.revisesThought,
 71 |             branchFromThought: data.branchFromThought,
 72 |             branchId: data.branchId,
 73 |             needsMoreThoughts: data.needsMoreThoughts,
 74 |         };
 75 |     };
 76 |     SequentialThinkingServer.prototype.formatThought = function (thoughtData) {
 77 |         var thoughtNumber = thoughtData.thoughtNumber, totalThoughts = thoughtData.totalThoughts, thought = thoughtData.thought, isRevision = thoughtData.isRevision, revisesThought = thoughtData.revisesThought, branchFromThought = thoughtData.branchFromThought, branchId = thoughtData.branchId;
 78 |         var prefix = '';
 79 |         var context = '';
 80 |         if (isRevision) {
 81 |             prefix = chalk_1.default.yellow('🔄 Revision');
 82 |             context = " (revising thought ".concat(revisesThought, ")");
 83 |         }
 84 |         else if (branchFromThought) {
 85 |             prefix = chalk_1.default.green('🌿 Branch');
 86 |             context = " (from thought ".concat(branchFromThought, ", ID: ").concat(branchId, ")");
 87 |         }
 88 |         else {
 89 |             prefix = chalk_1.default.blue('💭 Thought');
 90 |             context = '';
 91 |         }
 92 |         var header = "".concat(prefix, " ").concat(thoughtNumber, "/").concat(totalThoughts).concat(context);
 93 |         var border = '─'.repeat(Math.max(header.length, thought.length) + 4);
 94 |         return "\n\u250C".concat(border, "\u2510\n\u2502 ").concat(header, " \u2502\n\u251C").concat(border, "\u2524\n\u2502 ").concat(thought.padEnd(border.length - 2), " \u2502\n\u2514").concat(border, "\u2518");
 95 |     };
 96 |     SequentialThinkingServer.prototype.processThought = function (input) {
 97 |         try {
 98 |             var validatedInput = this.validateThoughtData(input);
 99 |             if (validatedInput.thoughtNumber > validatedInput.totalThoughts) {
100 |                 validatedInput.totalThoughts = validatedInput.thoughtNumber;
101 |             }
102 |             this.thoughtHistory.push(validatedInput);
103 |             if (validatedInput.branchFromThought && validatedInput.branchId) {
104 |                 if (!this.branches[validatedInput.branchId]) {
105 |                     this.branches[validatedInput.branchId] = [];
106 |                 }
107 |                 this.branches[validatedInput.branchId].push(validatedInput);
108 |             }
109 |             var formattedThought = this.formatThought(validatedInput);
110 |             console.error(formattedThought);
111 |             return {
112 |                 content: [{
113 |                         type: "text",
114 |                         text: JSON.stringify({
115 |                             thoughtNumber: validatedInput.thoughtNumber,
116 |                             totalThoughts: validatedInput.totalThoughts,
117 |                             nextThoughtNeeded: validatedInput.nextThoughtNeeded,
118 |                             branches: Object.keys(this.branches),
119 |                             thoughtHistoryLength: this.thoughtHistory.length
120 |                         }, null, 2)
121 |                     }]
122 |             };
123 |         }
124 |         catch (error) {
125 |             return {
126 |                 content: [{
127 |                         type: "text",
128 |                         text: JSON.stringify({
129 |                             error: error instanceof Error ? error.message : String(error),
130 |                             status: 'failed'
131 |                         }, null, 2)
132 |                     }],
133 |                 isError: true
134 |             };
135 |         }
136 |     };
137 |     return SequentialThinkingServer;
138 | }());
139 | var SEQUENTIAL_THINKING_TOOL = {
140 |     name: "sequentialthinking",
141 |     description: "A detailed tool for dynamic and reflective problem-solving through thoughts.\nThis tool helps analyze problems through a flexible thinking process that can adapt and evolve.\nEach thought can build on, question, or revise previous insights as understanding deepens.\n\nWhen to use this tool:\n- Breaking down complex problems into steps\n- Planning and design with room for revision\n- Analysis that might need course correction\n- Problems where the full scope might not be clear initially\n- Problems that require a multi-step solution\n- Tasks that need to maintain context over multiple steps\n- Situations where irrelevant information needs to be filtered out\n\nKey features:\n- You can adjust total_thoughts up or down as you progress\n- You can question or revise previous thoughts\n- You can add more thoughts even after reaching what seemed like the end\n- You can express uncertainty and explore alternative approaches\n- Not every thought needs to build linearly - you can branch or backtrack\n- Generates a solution hypothesis\n- Verifies the hypothesis based on the Chain of Thought steps\n- Repeats the process until satisfied\n- Provides a correct answer\n\nParameters explained:\n- thought: Your current thinking step, which can include:\n* Regular analytical steps\n* Revisions of previous thoughts\n* Questions about previous decisions\n* Realizations about needing more analysis\n* Changes in approach\n* Hypothesis generation\n* Hypothesis verification\n- next_thought_needed: True if you need more thinking, even if at what seemed like the end\n- thought_number: Current number in sequence (can go beyond initial total if needed)\n- total_thoughts: Current estimate of thoughts needed (can be adjusted up/down)\n- is_revision: A boolean indicating if this thought revises previous thinking\n- revises_thought: If is_revision is true, which thought number is being reconsidered\n- branch_from_thought: If branching, which thought number is the branching point\n- branch_id: Identifier for the current branch (if any)\n- needs_more_thoughts: If reaching end but realizing more thoughts needed\n\nYou should:\n1. Start with an initial estimate of needed thoughts, but be ready to adjust\n2. Feel free to question or revise previous thoughts\n3. Don't hesitate to add more thoughts if needed, even at the \"end\"\n4. Express uncertainty when present\n5. Mark thoughts that revise previous thinking or branch into new paths\n6. Ignore information that is irrelevant to the current step\n7. Generate a solution hypothesis when appropriate\n8. Verify the hypothesis based on the Chain of Thought steps\n9. Repeat the process until satisfied with the solution\n10. Provide a single, ideally correct answer as the final output\n11. Only set next_thought_needed to false when truly done and a satisfactory answer is reached",
142 |     inputSchema: {
143 |         type: "object",
144 |         properties: {
145 |             thought: {
146 |                 type: "string",
147 |                 description: "Your current thinking step"
148 |             },
149 |             nextThoughtNeeded: {
150 |                 type: "boolean",
151 |                 description: "Whether another thought step is needed"
152 |             },
153 |             thoughtNumber: {
154 |                 type: "integer",
155 |                 description: "Current thought number",
156 |                 minimum: 1
157 |             },
158 |             totalThoughts: {
159 |                 type: "integer",
160 |                 description: "Estimated total thoughts needed",
161 |                 minimum: 1
162 |             },
163 |             isRevision: {
164 |                 type: "boolean",
165 |                 description: "Whether this revises previous thinking"
166 |             },
167 |             revisesThought: {
168 |                 type: "integer",
169 |                 description: "Which thought is being reconsidered",
170 |                 minimum: 1
171 |             },
172 |             branchFromThought: {
173 |                 type: "integer",
174 |                 description: "Branching point thought number",
175 |                 minimum: 1
176 |             },
177 |             branchId: {
178 |                 type: "string",
179 |                 description: "Branch identifier"
180 |             },
181 |             needsMoreThoughts: {
182 |                 type: "boolean",
183 |                 description: "If more thoughts are needed"
184 |             }
185 |         },
186 |         required: ["thought", "nextThoughtNeeded", "thoughtNumber", "totalThoughts"]
187 |     }
188 | };
189 | var server = new index_js_1.Server({
190 |     name: "sequential-thinking-server",
191 |     version: "0.2.0",
192 | }, {
193 |     capabilities: {
194 |         tools: {},
195 |     },
196 | });
197 | var thinkingServer = new SequentialThinkingServer();
198 | server.setRequestHandler(types_js_1.ListToolsRequestSchema, function () { return __awaiter(void 0, void 0, void 0, function () {
199 |     return __generator(this, function (_a) {
200 |         return [2 /*return*/, ({
201 |                 tools: [SEQUENTIAL_THINKING_TOOL],
202 |             })];
203 |     });
204 | }); });
205 | server.setRequestHandler(types_js_1.CallToolRequestSchema, function (request) { return __awaiter(void 0, void 0, void 0, function () {
206 |     return __generator(this, function (_a) {
207 |         if (request.params.name === "sequentialthinking") {
208 |             return [2 /*return*/, thinkingServer.processThought(request.params.arguments)];
209 |         }
210 |         return [2 /*return*/, {
211 |                 content: [{
212 |                         type: "text",
213 |                         text: "Unknown tool: ".concat(request.params.name)
214 |                     }],
215 |                 isError: true
216 |             }];
217 |     });
218 | }); });
219 | function runServer() {
220 |     return __awaiter(this, void 0, void 0, function () {
221 |         var transport;
222 |         return __generator(this, function (_a) {
223 |             switch (_a.label) {
224 |                 case 0:
225 |                     transport = new stdio_js_1.StdioServerTransport();
226 |                     return [4 /*yield*/, server.connect(transport)];
227 |                 case 1:
228 |                     _a.sent();
229 |                     console.error("Sequential Thinking MCP Server running on stdio");
230 |                     return [2 /*return*/];
231 |             }
232 |         });
233 |     });
234 | }
235 | runServer().catch(function (error) {
236 |     console.error("Fatal error running server:", error);
237 |     process.exit(1);
238 | });
239 | 
```