Skip to content

feat: add Weibo channel via mcp-server-weibo (addresses #75)#107

Merged
Panniantong merged 1 commit intoPanniantong:mainfrom
AICodeLion:feature/weibo-channel
Mar 8, 2026
Merged

feat: add Weibo channel via mcp-server-weibo (addresses #75)#107
Panniantong merged 1 commit intoPanniantong:mainfrom
AICodeLion:feature/weibo-channel

Conversation

@AICodeLion
Copy link
Contributor

Summary

Adds a Weibo (微博) channel that integrates qinyuanpei/mcp-server-weibo (34+ ⭐, MIT license, 10 tools) via mcporter.

This addresses #75 — a user requested Weibo support for monitoring bloggers' new posts.

Why a dedicated channel?

Weibo's mobile API (m.weibo.cn) is not accessible via curl or Jina Reader:

  • Without cookies: returns HTTP 302 (redirect to visitor passport) from foreign IPs, or HTTP 432 from datacenter IPs
  • The visitor passport flow involves a multi-step JavaScript-based cookie acquisition process (genvisitor2crossdomain → set 9 cookies)
  • The SUB cookie obtained through this flow is valid for 1 year
  • Once cookies are obtained, all API endpoints work reliably without proxy

The upstream MCP server (mcp-server-weibo) wraps this complexity and provides 10 structured tools.

Changes

3 files, +57 lines:

File Change
agent_reach/channels/weibo.py New WeiboChannel (54 lines)
agent_reach/channels/__init__.py Register WeiboChannel
tests/test_channel_contracts.py Add weibo URL sample

Channel design

  • can_handle(): matches weibo.com and weibo.cn (including subdomains like m.weibo.cn, s.weibo.com)
  • check(): two-layer detection:
    1. mcporter config list — verify MCP server is configured
    2. mcporter list weibo — verify tools load correctly (lightweight, no live API call)
  • tier=1: requires installing mcp-server-weibo but no paid API key
  • Style: follows existing patterns (same "domain" in d matching as other channels, same subprocess.run + mcporter pattern as XiaoHongShu/Douyin/BossZhipin)

Upstream MCP server capabilities

mcp-server-weibo v1.0.7 provides 10 tools:

Tool Description
search_users Search users by keyword
get_profile Get user profile (name, bio, follower count, verification)
get_feeds Get user's posts with pagination
get_hot_feeds Get user's popular posts
get_trendings Get real-time trending topics (热搜)
search_content Search posts by keyword
search_topics Search hashtag topics with read/discussion counts
get_comments Get comments for a specific post
get_followers Get user's following list
get_fans Get user's fan list

Install: uvx mcp-server-weibo or pip install mcp-server-weibo

Test results

Unit tests: 9/9 passed

tests/test_channel_contracts.py::test_channel_registry_contract PASSED
tests/test_channel_contracts.py::test_channel_check_contract_with_minimal_runtime PASSED
tests/test_channel_contracts.py::test_channel_can_handle_contract PASSED
tests/test_channels.py (3 tests) PASSED
tests/test_core.py (3 tests) PASSED

E2E tool tests: 10/10 passed

All 10 MCP tools verified with live Weibo API:

  • search_users: ✅ (found @雷军, @人民日报)
  • get_profile: ✅ (11 fields complete)
  • get_feeds: ✅ (with engagement metrics, location, media)
  • get_hot_feeds: ✅
  • get_trendings: ✅ (returns up to 53 items)
  • search_content: ✅ (includes pic thumbnails + video stream URLs)
  • search_topics: ✅ (includes read count + discussion count)
  • get_comments: ✅
  • get_followers/get_fans: ✅

Stability test: 8/8 consecutive calls, avg 1.9s/call

Edge cases tested

Case Result
Non-existent uid MCP returns error (upstream issue)
uid=0 MCP returns error (upstream issue)
Empty search Returns empty array ✅
Emoji search (🐻) Works ✅
Japanese text search Works ✅
Deactivated account Returns empty array ✅
limit=100 (over max) Returns 53 (actual max) ✅

User flow verified

agent-reach doctor  →  "-- 微博: mcporter 已装但微博 MCP 未配置"
    ↓ mcporter config add weibo --command 'uvx mcp-server-weibo'
agent-reach doctor  →  "-- 微博: MCP 已配置但工具加载失败" (if no cookie)
    ↓ configure WEIBO_COOKIE env
agent-reach doctor  →  "✅ 微博: 完整可用(热搜、搜索、用户动态、评论)"

Known issues in upstream MCP server

These are bugs in mcp-server-weibo, not in this PR:

  1. search_users() has debug print(result) on line 156 that corrupts MCP stdio transport — causes mcporter to hang. Workaround: remove the print statement. (Will file upstream issue.)
  2. get_comments() omits like_count field — the raw API returns it but the data mapping drops it. Hot comments require the hotflow endpoint which isn't exposed.
  3. No error handling for invalid uid — throws KeyError: 'userInfo' instead of returning empty.

Cookie notes for overseas users

The MCP server supports WEIBO_COOKIE env var. For servers outside mainland China:

  • Weibo's mobile API requires a visitor cookie obtained via the visitor.passport.weibo.cn flow
  • The SUB cookie alone is sufficient and valid for 1 year
  • Chinese users likely won't need this step (direct access works from domestic IPs)

Adds WeiboChannel integrating qinyuanpei/mcp-server-weibo (34+ stars,
MIT, 10 tools) via mcporter. Addresses Panniantong#75.

Files changed (3 files, +57 lines):
- agent_reach/channels/weibo.py — new channel (54 lines)
- agent_reach/channels/__init__.py — register WeiboChannel
- tests/test_channel_contracts.py — add weibo URL sample
@Panniantong Panniantong merged commit db20c5d into Panniantong:main Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants