b

bta4935

@bta4935/SQ-MCP
0 Stars 317 次浏览 bta4935 更新于 2026-08-23
该服务暂未提供标准配置,请参考 README 手动接入

服务介绍

顺序思维工具 API

一个用于管理顺序思维会话和想法的 Node.js/TypeScript 后端,支持三种强大的接口供代理和人类使用:

  • STDIO (MCP 工具): 通过 stdin/stdout 使用模型上下文协议(MCP)进行本地工具/代理/CLI 集成。
  • SSE (服务器发送事件): 用于在 LLMs、代理或 Web 客户端中流式传输工具使用——实现实时、逐步输出。
  • REST API: 用于标准 HTTP 请求/响应工作流程。

输入验证使用 Zod 处理,应用程序已准备好进行容器化部署(例如,Render)。

目录


安装

  1. 克隆仓库:
    bash
    git clone
    cd SQ

  2. 安装依赖项:
    bash
    npm install


运行服务器

使用 ts-node (开发)

bash
npx ts-node src/api/httpServer.ts

使用 npm 脚本 (如果可用)

bash
npm run dev

使用编译后的 JavaScript

bash
npx tsc
node dist/main.js

使用 Docker

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

服务器默认将在端口 3000 上启动,或者在您的 PORT 环境变量中指定的端口。对于 Render 或云部署,请确保设置了 PORT 环境变量或继承了它。


接口与使用

STDIO (MCP 工具)

用于通过 stdin/stdout 使用模型上下文协议(MCP)进行本地代理/LLM/CLI 集成。以 MCP 模式启动服务器:

bash
node dist/main.js # 或您的 MCP 入口点

  • 进程将接受符合 MCP 的 JSON 消息并通过 stdout 发出响应。

  • 示例 (JSON-RPC):
    json
    { "jsonrpc": "2.0", "id": 1, "method": "call_tool", "params": { "name": "sequential_thinking", "arguments": { ... }}}

  • 流式或批量响应将以 JSON 格式返回。

SSE (流式工具/LLM)

适用于需要实时、增量输出的 LLMs、代理或 Web 客户端。

  • POST 一个想法到 /api/sessions/:sessionId/thoughts

  • GET /api/sessions/:sessionId/thoughts/stream 以接收生成的想法/步骤的实时流。

  • 每个 SSE 事件都是一个 JSON 对象:
    plaintext
    data: {"step":1,"content":"第一步..."}
    data: {"step":2,"content":"第二步..."}
    data: {"done":true}

  • 示例 (JavaScript):
    js
    const es = new EventSource( https://sq-mcp.onrender.com/api/sessions/12345/thoughts/stream );
    es.onmessage = e => console.log(JSON.parse(e.data));

  • 适用于 LLM 工具包装器、浏览器客户端或任何需要流式输出的代理。

REST API

用于同步工作流程的标准 HTTP 请求/响应端点。

1. 创建带有第一个想法的会话

  • 端点: POST /api/sessions

  • 描述: 创建一个新的会话,并将提供的想法作为该会话的第一个想法存储。返回新的会话 ID 和处理后想法的信息。

  • 请求体:
    json
    {
    "thought": "string (required)",
    "thoughtNumber": 1,
    "totalThoughts": 3,
    "nextThoughtNeeded": true,
    "isRevision": false, // 可选
    "revisesThought": 2, // 可选
    "branchFromThought": 1, // 可选
    "branchId": "string", // 可选
    "needsMoreThoughts": false // 可选
    }

  • 响应:
    json
    {
    "sessionId": "",
    "thoughtNumber": 1,
    "totalThoughts": 3,
    "nextThoughtNeeded": true,
    "branches": [],
    "thoughtHistoryLength": 1,
    "processedThought": "这是我的第一个想法。"
    }

2. 发布额外的想法

  • 端点: POST /api/sessions/:sessionId/thoughts- 描述: 向指定会话添加一个想法。输入使用 Zod 进行验证。

  • 请求体:
    json
    {
    "thought": "string (必填)",
    "thoughtNumber": 2,
    "totalThoughts": 3,
    "nextThoughtNeeded": true,
    "isRevision": false, // 可选
    "revisesThought": 1, // 可选
    "branchFromThought": 1, // 可选
    "branchId": "string", // 可选
    "needsMoreThoughts": false // 可选
    }

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


验证

所有发送到 /thoughts 的 POST 请求都使用 Zod 进行验证。无效的请求将返回 400 状态码和验证错误列表。


用户流程:在第一个想法时创建会话

  1. 用户向 /api/sessions 发送他们的第一个想法

    • 服务器创建一个新的会话并将第一个想法存储起来。
    • 返回新的 sessionId 和处理后的想法信息。

    示例 curl 命令:
    bash
    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
    }

    示例响应:
    json
    {
    "sessionId": "abc123",
    "thoughtNumber": 1,
    "totalThoughts": 3,
    "nextThoughtNeeded": true,
    "branches": [],
    "thoughtHistoryLength": 1,
    "processedThought": "This is my first thought."
    }

  2. 用户向 /api/sessions/:sessionId/thoughts 发送额外的想法

    • 服务器将想法添加到现有的会话中。

    示例 curl 命令:
    bash
    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
    }

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


示例错误响应(无效输入)

json
{
"errors": [
{
"path": ["thought"],
"message": "想法不能为空"
}
]
}


开发

  • TypeScript 配置文件位于 tsconfig.json
  • Zod 模式定义位于 src/types.ts
  • 验证中间件位于 src/api/validationMiddleware.ts
  • 主服务器逻辑位于 src/api/httpServer.ts
  • MCP/STDIO 逻辑位于 src/mcp/mcpServer.ts
  • 提供了 Dockerfile 用于容器化部署。

许可证

MIT

相关 MCP 服务