Skip to content

MCP Server

WeiLink provides an optional MCP (Model Context Protocol) server that exposes bot capabilities as tools for AI agents.

Install

pip install weilink[mcp]

This installs toolregistry-server with MCP support alongside the core package.

MCP + OpenAPI

To install both MCP and OpenAPI server support in one go:

pip install weilink[server]

See OpenAPI Server for details on the REST API mode.

Run

WeiLink MCP server supports three transports: stdio (default), SSE, and streamable-http.

stdio (default)

# Via unified CLI
weilink mcp

# Or via Python module
python -m weilink.server

stdio transport is launched by an MCP client (Claude Desktop, Cursor, etc.) rather than run standalone.

SSE / HTTP

# SSE transport
weilink mcp -t sse -p 8000

# Streamable HTTP transport (recommended for network access)
weilink mcp -t http -p 8000

# With admin panel in the same process
weilink mcp -t http -p 8000 --admin-port 8080

# Bind to all interfaces
weilink mcp -t http --host 0.0.0.0 -p 8000

CLI Options

Option Description Default
-t, --transport Transport: stdio, sse, streamable-http (or http) stdio
--host Host address for SSE / HTTP 127.0.0.1
-p, --port Port for SSE / HTTP 8000
-d, --base-path Data directory (profile path) ~/.weilink/
--admin-port Also start admin panel on this port (same host) (disabled)
--log-level Logging level (DEBUG, INFO, WARNING, ERROR) INFO
--no-banner Suppress the ASCII banner on startup (off)

Client Configuration

Claude Desktop

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "weilink": {
      "command": "weilink",
      "args": ["mcp"]
    }
  }
}

Claude Code (stdio)

claude mcp add weilink -- weilink mcp

Claude Code (HTTP)

First start the MCP server:

weilink mcp -t http -p 8000

Then add it to Claude Code settings (~/.claude/settings.json):

{
  "mcpServers": {
    "weilink": {
      "type": "http",
      "url": "http://127.0.0.1:8000/mcp"
    }
  }
}

Why HTTP?

HTTP transport lets the MCP server persist across Claude Code sessions. You start it once and all Claude Code sessions can connect to the same server instance — no need to restart the server when you start a new conversation.

One-command setup

For Claude Code and Codex, weilink setup automates the entire configuration including hooks for auto-polling new messages. See IDE Integration.

Cursor / VS Code

Add to MCP settings:

{
  "mcpServers": {
    "weilink": {
      "command": "python",
      "args": ["-m", "weilink.server"]
    }
  }
}

Available Tools

recv

Poll for new messages from WeChat users.

Parameter Type Default Description
timeout float 5.0 Max wait time in seconds

Returns a JSON array of messages. Each message includes message_id, from_user, msg_type, text, timestamp, bot_id, and media metadata if applicable.

send

Send text and/or media to a WeChat user.

Parameter Type Default Description
to str (required) Target user ID
text str "" Text content
image_path str "" Local image file path
file_path str "" Local file path
file_name str "" Display name for the file
video_path str "" Local video file path
voice_path str "" Local voice file path

Auto-recv

The MCP server automatically calls recv() before each send to refresh context tokens. This ensures the bot has a valid token even if recv hasn't been called recently.

download

Download media from a previously received message.

Parameter Type Default Description
message_id str (required) Message ID from recv
save_dir str ~/.weilink/downloads/ Directory to save the file

Returns the saved file path and size.

history

Query message history from the persistent store.

Parameter Type Default Description
user_id str "" Filter by WeChat user ID
bot_id str "" Filter by bot session ID
msg_type str "" Filter by type: TEXT, IMAGE, VOICE, FILE, VIDEO
direction str "" Filter: received or sent
since str "" Start time (ISO 8601 or unix ms)
until str "" End time (ISO 8601 or unix ms)
text_contains str "" Case-insensitive text search
limit int 50 Max results (up to 200)
offset int 0 Pagination offset

Returns JSON with messages array, total count, limit, and offset.

sessions

List all sessions with their connection status. No parameters.

login

QR code login with built-in polling. The tool is stateful — its behavior depends on whether a login flow is already in progress:

Parameter Type Default Description
session_name str "" Session name (empty for default)
timeout float 30.0 Max seconds to poll for status change
force bool false Restart QR flow even if one is pending

Typical agent workflow:

  1. Call login() — returns {"status": "pending", "qr_url": "..."}. Show the QR URL to the user.
  2. Call login() again — polls for up to 30s, returns {"status": "scanned"} or {"status": "confirmed", ...}.
  3. If still pending, call login() once more until confirmed or expired.

Pre-login recommended

The server auto-discovers existing sessions from ~/.weilink/ on startup. If you have already logged in via the SDK, the MCP server picks up your sessions automatically — no need to call the login tool.

logout

Log out a session and remove its persisted credentials.

Parameter Type Default Description
session_name str "" Session to log out (empty for default)

rename_session

Rename a session.

Parameter Type Default Description
old_name str (required) Current session name
new_name str (required) New session name

set_default

Set a session as the default.

Parameter Type Default Description
session_name str (required) Session name to make default

Architecture

graph LR
    A[AI Agent] -->|MCP protocol| B[WeiLink MCP]
    B -->|WeiLink SDK| C[iLink API]
    C --> D[WeChat]

The MCP server wraps a WeiLink instance internally. Messages received via recv are cached (up to 1000) so their media can be downloaded later via download.

Skills Metadata

WeiLink ships two metadata files for registry discovery:

  • server.jsonOfficial MCP standard, used by MCP registries and package managers.
  • smithery.yamlSmithery registry format for auto-configuration.