Sequential Thinking Tool API

by bta4935
Integrations
  • Provides examples for interacting with the Sequential Thinking Tool API, demonstrating how to create sessions and post thoughts using curl commands.

  • Built as a Node.js backend service, providing the runtime environment for the Sequential Thinking Tool API.

  • Utilizes npm for package management and running predefined scripts for development and server execution.

Sequential Thinking Tool API

A Node.js/TypeScript backend for managing sequential thinking sessions and thoughts, supporting three robust interfaces for agent and human use:

  • STDIO (MCP Tool): For local tool/agent/CLI integration using the Model Context Protocol (MCP) over stdin/stdout.
  • SSE (Server-Sent Events): For streaming tool use in LLMs, agents, or web clients—enabling real-time, stepwise output.
  • REST API: For standard HTTP request/response workflows.

Input validation is handled with Zod, and the app is ready for containerized deployment (e.g., Render).

Table of Contents


Installation

  1. Clone the repository:
    git clone <your-repo-url> cd SQ
  2. Install dependencies:
    npm install

Running the Server

Using ts-node (development)

npx ts-node src/api/httpServer.ts

Using npm script (if available)

npm run dev

Using compiled JavaScript

npx tsc node dist/main.js

Using Docker

docker build -t sq-mcp . docker run -p 3000:3000 sq-mcp

The server will start on port 3000 by default, or the port specified in your PORT environment variable. For Render or cloud deployment, ensure the PORT env is set or inherited.


Interfaces & Usage

STDIO (MCP Tool)

For local agent/LLM/CLI integration using Model Context Protocol over stdin/stdout. Start the server in MCP mode:

node dist/main.js # or your MCP entry point
  • The process will accept MCP-compliant JSON messages on stdin and emit responses on stdout.
  • Example (JSON-RPC):
    { "jsonrpc": "2.0", "id": 1, "method": "call_tool", "params": { "name": "sequential_thinking", "arguments": { ... }}}
  • Streamed or batched responses will be sent back as JSON.

SSE (Streaming Tool/LLM)

For LLMs, agents, or web clients that require real-time, incremental output.

  • POST a thought to /api/sessions/:sessionId/thoughts.
  • GET /api/sessions/:sessionId/thoughts/stream to receive a live stream of steps/thoughts as they are generated.
  • Each SSE event is a JSON object:
    data: {"step":1,"content":"First step..."} data: {"step":2,"content":"Second step..."} data: {"done":true}
  • Example (JavaScript):
    const es = new EventSource('https://sq-mcp.onrender.com/api/sessions/12345/thoughts/stream'); es.onmessage = e => console.log(JSON.parse(e.data));
  • Useful for LLM tool wrappers, browser clients, or any agent needing streaming output.

REST API

Standard HTTP request/response endpoints for synchronous workflows.

1. Create Session with First Thought
  • Endpoint: POST /api/sessions
  • Description: Creates a new session and stores the provided thought as the first thought in that session. Returns the new session ID and processed thought info.
  • Request Body:
    { "thought": "string (required)", "thoughtNumber": 1, "totalThoughts": 3, "nextThoughtNeeded": true, "isRevision": false, // optional "revisesThought": 2, // optional "branchFromThought": 1, // optional "branchId": "string", // optional "needsMoreThoughts": false // optional }
  • Response:
    { "sessionId": "<uuid>", "thoughtNumber": 1, "totalThoughts": 3, "nextThoughtNeeded": true, "branches": [], "thoughtHistoryLength": 1, "processedThought": "This is my first thought." }

2. Post Additional Thought

  • Endpoint: POST /api/sessions/:sessionId/thoughts
  • Description: Adds a thought to the specified session. Input is validated using Zod.
  • Request Body:
    { "thought": "string (required)", "thoughtNumber": 2, "totalThoughts": 3, "nextThoughtNeeded": true, "isRevision": false, // optional "revisesThought": 1, // optional "branchFromThought": 1, // optional "branchId": "string", // optional "needsMoreThoughts": false // optional }
  • Response:
    { "thoughtNumber": 2, "totalThoughts": 3, "nextThoughtNeeded": true, "branches": [], "thoughtHistoryLength": 2, "processedThought": "This is my second thought." }

Validation

All POST requests to /thoughts are validated using Zod. Invalid requests will return a 400 status and a list of validation errors.


User Flow: Session Created on First Thought

  1. User sends their first thought to /api/sessions
    • The server creates a new session and stores the first thought.
    • Returns the new sessionId and processed thought info.

    Example curl:

    curl -X POST http://localhost:3000/api/sessions \ -H "Content-Type: application/json" \ -d '{ "thought": "This is my first thought.", "thoughtNumber": 1, "totalThoughts": 3, "nextThoughtNeeded": true }'

    Example response:

    { "sessionId": "abc123", "thoughtNumber": 1, "totalThoughts": 3, "nextThoughtNeeded": true, "branches": [], "thoughtHistoryLength": 1, "processedThought": "This is my first thought." }
  2. User sends additional thoughts to /api/sessions/:sessionId/thoughts
    • The server adds the thought to the existing session.

    Example curl:

    curl -X POST http://localhost:3000/api/sessions/abc123/thoughts \ -H "Content-Type: application/json" \ -d '{ "thought": "This is my second thought.", "thoughtNumber": 2, "totalThoughts": 3, "nextThoughtNeeded": true }'

    Example response:

    { "thoughtNumber": 2, "totalThoughts": 3, "nextThoughtNeeded": true, "branches": [], "thoughtHistoryLength": 2, "processedThought": "This is my second thought." }

Example Error Response (invalid input)

{ "errors": [ { "path": ["thought"], "message": "Thought cannot be empty" } ] }

Development

  • TypeScript configuration is in tsconfig.json.
  • Zod schemas are in src/types.ts.
  • Validation middleware is in src/api/validationMiddleware.ts.
  • Main server logic is in src/api/httpServer.ts.
  • MCP/STDIO logic is in src/mcp/mcpServer.ts.
  • Dockerfile is provided for containerized deployments.

License

MIT

-
security - not tested
F
license - not found
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

A Node.js/TypeScript backend for managing sequential thinking sessions, allowing users to create sessions and post thoughts in a structured sequence with support for real-time updates via Server-Sent Events.

  1. Table of Contents
    1. Installation
      1. Running the Server
        1. Using ts-node (development)
        2. Using npm script (if available)
        3. Using compiled JavaScript
        4. Using Docker
      2. Interfaces & Usage
        1. STDIO (MCP Tool)
        2. SSE (Streaming Tool/LLM)
        3. REST API
        4. Post Additional Thought
      3. Validation
        1. User Flow: Session Created on First Thought
          1. Example Error Response (invalid input)
        2. Development
          1. License

            Related MCP Servers

            • -
              security
              F
              license
              -
              quality
              This TypeScript-based server implements a simple notes system, allowing users to create and manage text notes and generate summaries, showcasing core MCP concepts.
              Last updated -
              2
              7
              TypeScript
              • Apple
            • A
              security
              F
              license
              A
              quality
              A TypeScript Model Context Protocol server that integrates with Google Tasks API, allowing users to create, list, update, delete, and toggle completion status of tasks.
              Last updated -
              4
              3
              JavaScript
            • A
              security
              A
              license
              A
              quality
              Node.js server implementing Model Context Protocol that enables interaction with TaskWarrior through natural language to view, filter, add, and complete tasks.
              Last updated -
              3
              13
              1
              JavaScript
              MIT License
            • -
              security
              F
              license
              -
              quality
              A Node.js and TypeScript server project that provides a simple starter example with Express.js web server, supporting hot-reload, testing, and modular structure.
              Last updated -
              TypeScript

            View all related MCP servers

            MCP directory API

            We provide all the information about MCP servers via our MCP API.

            curl -X GET 'https://glama.ai/api/mcp/v1/servers/bta4935/SQ-MCP'

            If you have feedback or need assistance with the MCP directory API, please join our Discord server