Skip to main content
Glama

qq-onebot-mcp

A lightweight MCP server that connects QQ (NapCat / OneBot 11) to any MCP host (DSH, Claude, Cursor...). Zero npm dependencies, pure Node.js ≥ 20, using only the built-in WebSocket.

  • Private chat (whitelisted owner) → messages go to inbox → host agent processes (full tool permissions) → replies.

  • Group chat @bot (whitelisted groups) → bridge answers directly via LLM API, without going through the agent, without touching the local machine.

Architecture

QQ 老大 ──私聊──▶ NapCat(QQ小号) ──OneBot11/WS:3001──▶ qq-mcp-server.mjs ──MCP──▶ 宿主 agent
                                                                   ▲
                                                              (inbox / 工具)

Layer

File

Responsibility

Access

NapCat

QQ protocol → OneBot 11 (WS 3001)

Bridge

qq-mcp-server.mjs

MCP server: tools, exclusive lock, inbox

Bridge

onebot.mjs

OneBot WS client (zero dependencies)

Bridge

group_llm.mjs

Group chat pure LLM direct replies

Wake-up

qq-listener.mjs

Resident listener + host session injection (optional closed loop)

Control

qqctl.mjs

Process lifecycle (start/stop/status)

Related MCP server: NapCat MCP Server

Quick Start

  1. NapCat: Install it and log in with a QQ alt account, enable OneBot WS (default ws://127.0.0.1:3001).

  2. Configuration: cp .env.example .env, fill in QQ_BOT, QQ_ALLOWED_SENDERS (optionally add LLM_API_KEY to enable group chat).

  3. Register MCP: Point the host to qq-mcp-server.mjs (stdio). For DSH use the dsh-bundle/ template, see INSTALL-DSH.md.

  4. Go online: Tell the agent "get on QQ" → follow skills/qq-online/SKILL.md to attach → wait for messages → reply.

Environment variable

Required

Description

QQ_BOT

✅

Bot QQ number

QQ_ALLOWED_SENDERS

✅

Private chat whitelist, comma-separated

ONEBOT_WS_URL

NapCat WS address (default ws://127.0.0.1:3001)

QQ_ALLOWED_GROUPS

Static group whitelist (empty = dynamic)

LLM_API_KEY / LLM_BASE_URL / LLM_MODEL

For group chat direct replies

.env is git-ignored, never commit it.

MCP Tools

Tool

Description

qq_attach / qq_detach

Exclusive acquire / release the bridge (file lock, cross-host; auto-preempts crash leftovers)

qq_wait_inbox

Blocking wait for private messages (zero polling, recommended for loops)

qq_poll_inbox

Fetch inbox (with optional timeout)

qq_send

Reply to the current conversation partner (whitelist only)

qq_status

Bridge status

qq_get_agent_profile

Read AGENTS.md role settings

Standby mode: the server does not connect to NapCat on startup; it connects only on qq_attach and disconnects on qq_detach — zero resource usage.

Fully Automatic Closed Loop (Optional)

To have QQ messages automatically wake the agent (no need to say "get online" every time): run qq-listener.mjs as a separate process:

DSH_API_URL=http://127.0.0.1:3080 DSH_SESSION_ID=<session-id> \
  node qq-listener.mjs <tag> <workdir> 0
QQ 消息 → 监听器(wait_inbox) → 写入 <workdir>/inbox/ + POST http://127.0.0.1:3080/api/session.prompt
                                                                        │
                                                    agent 自动醒来处理 → <workdir>/outbox/ → qq_send 回复
  • The listener stays resident independently of the agent session; session.prompt (mode: queue) injects messages into the host session to trigger a turn.

  • Replies go to <workdir>/outbox/*.json ({type:"send", message}), and the listener sends them (connects directly to OneBot WS when there is no chat target).

  • Graceful stop: write stop.flag in <workdir>.

⚠️ session.prompt has no authentication and is loopback-only; use it only in a trusted local environment.

Security

  • Private chat: whitelist only; unknown private messages are discarded.

  • Group chat: pure LLM, never touches local files/commands.

  • qq_send can only reply to the current conversation partner (within the whitelist).

  • When a whitelisted user pulls the bot into a group → auto-whitelist and announce.

Personalization

Edit AGENTS.md (persona/responsibilities/security boundaries); the bridge reloads it every session, no restart needed.

Local privacy (e.g., important personal relationships) can go in data/ (git-ignored) and be referenced from AGENTS_MD — never uploaded to GitHub.

Dynamic Session Discovery (Closed Loop)

The listener no longer hardcodes DSH_SESSION_ID: on each incoming message it first calls session.list to find a running session whose title contains 上号/QQ/布卡, and falls back to env if none is found. This way the closed loop still works after the "get online" session is replaced or reopened.

Development

npm test   # 全部入口语法检查

Files

├── qq-mcp-server.mjs   # MCP server(主入口)
├── onebot.mjs          # OneBot WS 客户端
├── group_llm.mjs       # 群聊 LLM 直答
├── bridge.mjs          # 独立触发桥(无 MCP 宿主)
├── bridge-acp.mjs      # ACP 连接器(持久 DSH 会话)
├── qq-listener.mjs     # 闭环监听器
├── qqctl.mjs           # 进程控制
├── dsh-bundle/         # DSH profile bundle 模板
├── skills/qq-online/   # 「上QQ号」技能
├── INSTALL-DSH.md      # 新用户自装指南
└── .env.example        # 配置模板

License

MIT

Available Tools

8 tools
qq_attachA

Claims the QQ bridge for THIS conversation (exclusive). Pass a unique tag (e.g. your session id) to identify the owner. Fails if another conversation already claimed it. Call once when you start handling QQ.

Inputs: tag (required).

qq_detachA

Releases the QQ bridge. Only the current owner (matching tag) can release; others get an error. Call when done or on /布卡换碟 new-conversation.

Inputs: tag (required).

qq_get_agent_profileA

Get the AGENTS.md role profile (personality, duties, security boundaries) that defines how this QQ bridge agent should behave. Load it once and treat it as your system prompt while chatting through QQ. Path overridable via AGENTS_MD env.

Inputs: no named parameters.

qq_poll_inboxA

Fetch private messages received by the bot (whitelisted owner only). Returns immediately if new messages; else waits up to timeoutMs (max 30000, batch max 50).

Inputs: timeoutMs.

qq_sendA

Send a private message to the current chat user (the whitelisted owner from inbox). message is the content.

Inputs: message (required).

qq_statusA

Query bridge status: connection, bot QQ, private whitelist, group whitelist, inbox count.

Inputs: no named parameters.

qq_take_disc_changeA

Check if the owner requested a DISC CHANGE (换碟) in private chat. Returns true once if a new-conversation signal is pending (connector should start a fresh session), false otherwise. Poll after handling inbox messages.

Inputs: no named parameters.

qq_wait_inboxA

BLOCK until new private messages arrive (zero polling/cost while waiting). Returns immediately when messages arrive; or after maxWaitMs. Call in a loop to idle efficiently waiting for QQ messages.

Inputs: maxWaitMs.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.2/5.0

    Scored across 8 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose: sending, receiving (with two variants for context), status, profile retrieval, disc-change signal, and lifecycle management (attach/detach). No overlap causes ambiguity.

    Naming Consistency5/5

    All tools follow the consistent `qq_` prefix followed by an action verb (send, poll, wait, status, get, take, attach, detach). Naming is uniform, snake_case, and predictable.

    Tool Count5/5

    With 8 tools, the server is well-scoped for a QQ bridge: it covers messaging, inbox handling, status, profile, and session control without excess. This is within the ideal 3-15 tool range.

    Completeness4/5

    Core private-message workflows and lifecycle are covered: send, receive, status, claim/release, and disc-change. Missing group-message tools and whitelist management, though these may be intentionally out of scope for a private-owner bridge.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      Not graded
      maintenance
      An MCP server that enables AI clients to send and receive QQ messages through NapCatQQ (OneBot v11) for both private and group chats. It supports message context management, real-time WebSocket listening, and human-like typing simulation.
      7
      26
      MIT
    • F
      license
      C
      quality
      D
      maintenance
      Enables interaction with NapCat QQ bot APIs for group management, messaging, and system operations. Supports HTTP and WebSocket modes with security features like group restrictions and readonly mode.
      57
      4
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      A MCP server that exposes QQ bot capabilities over Streamable HTTP, enabling clients to query bot status, read group and friend info, fetch chat history, and send group/private text messages.
      3
      MIT
    • A
      license
      B
      quality
      C
      maintenance
      Connects QQ via NapCat OneBot v11 to an Astral Code app-server, exposing MCP tools for sending messages, files, images, and fetching conversation history.
      10
      2
      Apache 2.0