Skip to content

MCP Protocol

MCP (Model Context Protocol) is an open protocol by Anthropic for standardizing how AI Agents interact with external tools. OneBots exposes IM platform capabilities as MCP tools, allowing AI coding assistants like Cursor, Claude Code, and Cline to directly operate on messages, groups, friends, and more.

Quick Start

Three steps to connect an AI Agent to your IM platform:

Step 1: Start the manager and configure an account

bash
onebots serve --data-dir /path/to/onebots-data

Use the TUI or Web installation and configuration workflows to select the platform adapter and MCP protocol, enter account settings, enable mcp.v1, validate, and apply. Keep the manager and gateway running. The AI client below connects to the same workspace.

Step 2: Configure Your AI Agent

For Cursor, add to ~/.cursor/mcp.json:

json
{
  "mcpServers": {
    "onebots": {
      "command": "npx",
      "args": ["onebots", "mcp", "--data-dir", "/path/to/onebots-data", "--account", "qq/my-bot"]
    }
  }
}

Step 3: Start Using

Tell your AI: "Send a message to group 123456" — it will automatically call the send_message tool.

Features

  • AI Agent Native: Built for Cursor, Claude Code, Cline, and similar assistants
  • Standardized Tools: JSON-RPC 2.0, MCP 2025-03-26 spec compliant
  • Dual Transport: stdio (local) and HTTP/SSE (remote)
  • Access Control: Bearer Token auth + tool whitelist/blacklist

Installation

bash
# Connect to the manager and install MCP plus the required adapter
onebots tui --data-dir /path/to/onebots-data

# Client SDK (only for programmatic access — AI Agents don't need this)
npm install @onebots/mcp-client

Configuration

Basic

yaml
qq.my-bot:
  appid: "xxx"
  secret: "xxx"
  mcp.v1: {}                    # Defaults are fine

Full

yaml
general:
  mcp.v1:
    access_token: "your_token"
    tools_blacklist:
      - kick_group_member
      - delete_friend

qq.my-bot:
  appid: "xxx"
  secret: "xxx"
  mcp.v1:
    access_token: "bot-specific-token"    # Bearer token
    tools_whitelist: []                   # Empty = all enabled
    tools_blacklist: []                   # Tools to hide
OptionTypeDefaultDescription
access_tokenstringnoneBearer Token auth; empty = no auth
tools_whiteliststring[][]Only expose listed tools; empty = all
tools_blackliststring[][]Hide listed tools

Transport

JSON-RPC over stdin/stdout. The standard connection method for desktop AI Agents — no network config needed.

bash
onebots mcp --data-dir /path/to/onebots-data --account qq/my-bot

onebots mcp connects to the existing manager through the private workspace control socket. The manager forwards requests to an MCP account in the current gateway. First run onebots serve --data-dir /path/to/onebots-data, then use TUI or Web to install the platform adapter and MCP protocol, configure the account, and apply it. The command does not install dependencies, load accounts, start the gateway, or enable MCP. Select --account platform/account when multiple MCP accounts exist. Requests run in input order and stdout contains only JSON-RPC. Normal stdin closure drains accepted requests and closes only this session. A stopped or restarted gateway or an unknown connection outcome ends the session without replaying tool calls. HTTP/SSE protocol tokens remain separate from manager device pairing credentials.

HTTP/SSE (Remote)

Automatically exposed when OneBots starts:

EndpointMethodDescription
/{platform}/{account_id}/mcp/v1/sseGETSSE stream for events
/{platform}/{account_id}/mcp/v1/messagePOSTJSON-RPC requests

Flow: GET /sse → receive endpoint event → POST requests to that endpoint → responses and events arrive via SSE.

AI Agent Configuration

json
{
  "mcpServers": {
    "onebots": {
      "command": "npx",
      "args": ["onebots", "mcp", "--data-dir", "/path/to/onebots-data", "--account", "qq/my-bot"]
    }
  }
}
json
{
  "mcpServers": {
    "onebots": {
      "command": "npx",
      "args": ["onebots", "mcp", "--data-dir", "/path/to/onebots-data", "--account", "qq/my-bot"]
    }
  }
}
json
{
  "cline.mcpServers": {
    "onebots": {
      "command": "npx",
      "args": ["onebots", "mcp", "--data-dir", "/path/to/onebots-data", "--account", "qq/my-bot"]
    }
  }
}

Available Tools

MCP v1 exposes 32 tools. Each accepts JSON arguments and returns structured results.

Read-Only

ToolDescription
get_login_infoCurrent bot account info (ID, name, avatar)
get_user_infoUser info by ID
get_friend_listFriend list
get_friend_infoFriend info by ID
get_group_listGroup list
get_group_infoGroup info by ID
get_group_member_listGroup member list
get_group_member_infoGroup member details
get_guild_listJoined guild list
get_guild_infoGuild details
get_channel_listChannel list in a guild
get_channel_infoChannel details
get_guild_member_infoGuild member info
get_channel_member_listChannel member list
get_messageMessage details by ID
get_supported_actionsSupported API list
get_statusBot runtime status
get_versionImplementation version

Actions

ToolDescriptionRisk
send_messageSend message (group/private/channel)Low
delete_messageRecall/delete a messageLow
upload_fileUpload file (image/video/audio/file)Low
handle_friend_requestAccept/reject friend requestMedium
handle_group_requestAccept/reject group join requestMedium
set_group_nameSet group nameMedium
set_group_cardSet member card/nicknameMedium
set_group_adminSet/unset group adminMedium
mute_group_memberMute a group memberHigh
mute_group_allMute/unmute all membersHigh
kick_group_memberKick a group memberHigh
delete_friendDelete a friendHigh
leave_groupLeave a groupHigh

Tool Filtering

yaml
mcp.v1:
  # Whitelist — only expose these tools
  tools_whitelist:
    - get_login_info
    - get_group_list
    - get_friend_list
    - send_message

  # Or blacklist — block dangerous operations
  tools_blacklist:
    - kick_group_member
    - mute_group_member
    - mute_group_all
    - delete_friend
    - leave_group

Event Push

After connection, MCP pushes platform events in real time as JSON-RPC notifications.

Message Events

json
{
  "jsonrpc": "2.0",
  "method": "notifications/message",
  "params": {
    "platform": "qq",
    "account_id": "my-bot",
    "message_type": "group",
    "message_id": "123",
    "sender": { "id": "456", "name": "User A" },
    "group": { "id": "789", "name": "Test Group" },
    "raw_message": "Hello",
    "timestamp": 1700000000
  }
}

Notice Events

json
{
  "jsonrpc": "2.0",
  "method": "notifications/notice",
  "params": {
    "platform": "qq",
    "account_id": "my-bot",
    "notice_type": "group_member_increase",
    "user": { "id": "456", "name": "New Member" },
    "group": { "id": "789", "name": "Test Group" },
    "timestamp": 1700000000
  }
}

Client SDK

For programmatic access (not via AI Agent):

bash
npm install @onebots/mcp-client
typescript
import { McpStdioClient } from '@onebots/mcp-client';

const client = new McpStdioClient({
  command: 'onebots',
  args: ['mcp', '--data-dir', '/path/to/onebots-data', '--account', 'qq/my-bot'],
});

await client.connect();

const tools = await client.listTools();
const result = await client.callTool('send_message', {
  scene_type: 'group',
  scene_id: '123456',
  message: 'Hello from MCP!',
});

await client.close();

See Client SDK Guide for more details.

Protocol Comparison

MCPOneBot V11/V12SatoriMilky
PurposeAI Agent tool callsBot framework integrationCross-platform unifiedLightweight direct
Wire ProtocolJSON-RPC 2.0HTTP / WebSocketWebSocketHTTP / WebSocket
Transportstdio / HTTP+SSEHTTP / WS / Reverse WSWebSocketHTTP / WS
Message FormatPlain text (LLM-friendly)CQ codes / segmentsHTML elementsSegments
Typical ClientsCursor, Claude CodeNoneBot2, KoishiKoishiCustom apps
Best ForAI automationMature ecosystemModern cross-platformSimple and direct