API对话接口转换工具

Swaggbot是一款将Swagger/OpenAPI文档转换为对话界面的工具,支持自然语言交互、工作流自动化和本地化部署,适用于开发者进行API探索和集成。

  • by TechBloom-ai
  • TypeScript
  • 本地部署
  • 3 星标
  • 更新于
在 GitHub 查看 TechBloom-ai/swaggbot

使用说明

Swaggbot

将Swagger/OpenAPI文档转换为会话界面。自主、本土、AI驱动的API勘探。


快速开始

# Docker (recommended)
git clone https://github.com/techbloom-ai/swaggbot.git
cd swaggbot && cp .env.example .env
# Generate SESSION_SECRET and add LLM API keys
docker-compose up -d

打开 http://localhost:3003


Swaggbot是什么?

Swaggbot将任何Swagger/OpenAPI文档API转换为会话接口。专为想要:

  • 自然地探索API --聊天而不是读取原始JSON
  • 自动化工作流程 --具有数据提取功能的多步操作
  • 保持控制 --自托管,数据保持本地
  • 随时随地集成 -Web UI、MCP服务器或直接API

特性

  • 🤖 自然语言API交互 --“列出所有用户”→ GET /users
  • 🔄 工作流程自动化 -使用依赖项解析链接多个API调用
  • 🔌 MCP服务器 --与克劳德桌面、光标、Windsurf一起使用
  • 🏠 自托管 --您的数据,您的基础设施
  • 🔐 会话管理 --加密的身份验证令牌,每个会话隔离
  • 🌐 多提供商LLM --Moonshot、OpenAI、Anthropic、Olama
  • 📊 数组筛选 — [name=John].id 数据提取语法
  • 🛡️ 安全 --CSP标头、速率限制、加密存储

建筑

┌─────────┐  ┌─────────┐  ┌─────────┐
│ Web UI  │  │  MCP    │  │  API    │
│ Next.js │  │ Server  │  │ Clients │
└────┬────┘  └────┬────┘  └────┬────┘
     └─────────────┼─────────────┘
                   ▼
          ┌─────────────────┐
          │  Chat Service   │  Intent Classification
          │  + LLM Provider │  → Curl Generation → Execution
          └─────────────────┘
                   │
     ┌─────────────┼─────────────┐
     ▼             ▼             ▼
┌────────┐   ┌─────────┐   ┌──────────┐
│SQLite  │   │Workflow │   │ Target   │
│(Local) │   │ Engine  │   │   API    │
└────────┘   └─────────┘   └──────────┘

安装

先决条件

  • Node.js 18+ 或 码头工人
  • LLM API密钥(Moonshot、OpenAI、Anthropic或Ollama)

Docker(推荐)

# 1. Clone and configure
git clone https://github.com/techbloom-ai/swaggbot.git
cd swaggbot
cp .env.example .env

# 2. Set SESSION_SECRET (required for auth)
# Linux/macOS:
export SESSION_SECRET=$(openssl rand -base64 32)
# Or add to .env: SESSION_SECRET=your_random_secret_here

# 3. Add your LLM API key to .env
# MOONSHOT_API_KEY=your_key_here

# 4. Start
docker-compose up -d

数据库迁移自动运行 第一次创业。

本地开发

git clone https://github.com/techbloom-ai/swaggbot.git
cd swaggbot
pnpm install
cp .env.example .env.local
# Edit .env.local with SESSION_SECRET and LLM API keys
pnpm db:migrate
pnpm dev

配置

变量 必填 默认 描述
SESSION_SECRET 是 -- 会话加密的随机密钥(最少32个字符)
MOONSHOT_API_KEY 是* - Moonshot AI API密钥
OPENAI_API_KEY 是* - OpenAI API密钥
ANTHROPIC_API_KEY 是* - 人类API密钥
OLLAMA_BASE_URL 是* -- Ollama服务器URL
LLM_PROVIDER 没有 moonshot moonshot
DATABASE_URL 没有 file:./data/swaggbot.db SQLite数据库路径
NEXT_PUBLIC_APP_URL 没有 http://localhost:3003 应用程序基本URL

*至少需要一个LLM提供者

生成会话_SECRET

# Linux/macOS
openssl rand -base64 32

# Or any random string (min 32 characters)

API 参考

REST API

所有端点都需要通过会话cookie进行身份验证。

端点 方法 描述
/api/auth/login POST 验证并创建会话
/api/session POST 从Swagger URL创建API会话
/api/session GET 列出所有会话(分页)
/api/chat POST 向API发送消息
/api/workflow POST 创建多步骤工作流
/api/workflow/:id/execute POST 执行工作流

MCP服务器

{
  "mcpServers": {
    "swaggbot": {
      "command": "docker",
      "args": ["compose", "run", "--rm", "swaggbot-mcp"],
      "env": {
        "SESSION_SECRET": "your_secret",
        "MOONSHOT_API_KEY": "your_key"
      }
    }
  }
}

使用示例

Web用户界面

  1. 导航到登录页面
  2. 使用您的Swagger URL创建会话
  3. 开始聊天:
    "Create a user named John"
    "List all pets with status available"
    "Execute the login workflow"
    

API

# Authenticate
curl -X POST http://localhost:3003/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"password": "your_password"}' \
  -c cookies.txt

# Chat with API
curl -X POST http://localhost:3003/api/chat \
  -H "Content-Type: application/json" \
  -b cookies.txt \
  -d '{"sessionId": "...", "message": "List all users"}'

技术栈

组件 技术
框架 Next.js 16(应用路由器)
语言 TypeScript 5
数据库 SQLite(libSQL/Turso)
ORM 喷洒ORM
UI shadcn/UI+顺风CSS 4
状态 状态
LLM SDK Vercel AI SDK模式
MCP 模型上下文协议SDK
测试 Vitest
容器 Docker+Docker组合

项目结构

swaggbot/
├── app/                 # Next.js App Router
│   ├── api/            # API routes
│   ├── sessions/       # Session UI
│   └── settings/       # Settings page
├── components/         # shadcn/ui components
├── lib/
│   ├── db/            # Database schema & migrations
│   ├── llm/           # LLM provider implementations
│   ├── services/      # Business logic
│   ├── auth/          # Session & encryption
│   └── prompts/       # LLM prompt management
├── scripts/           # MCP server & entrypoint
└── data/              # SQLite storage (Docker volume)

安全

  • 本地优先:本地存储在SQLite中的所有数据
  • 加密令牌:使用AES-256-GCM加密的身份验证令牌
  • 基于会话的身份验证:密码保护访问
  • CSP标头:内容安全策略保护
  • 速率限制:可配置每个端点的限制
  • 无遥测:零分析或跟踪

许可证

MIT© TechBloom