Agent Reach Upstream CLI Tools for Twitter, Bilibili, and Weibo Explained
Agent Reach delegates all platform-specific work to external command-line utilities, routing Twitter/X requests to twitter-cli, Bilibili media to yt-dlp and optionally bili-cli, and Weibo operations to mcporter paired with mcp-server-weibo, discovering each binary via shutil.which at runtime.
Agent Reach is a lightweight Python framework that connects AI agents to social media channels without embedding proprietary protocol logic. Rather than implementing its own Twitter, Bilibili, or Weibo clients, the repository acts as a thin glue layer that discovers and invokes upstream CLI tools already present on the host system. This design keeps the codebase small, decoupled, and easy to maintain as underlying platforms evolve.
How Agent Reach Discovers Upstream CLI Tools
The Channel Base Interface
In agent_reach/channels/base.py, the abstract Channel class defines the interface that every platform module must implement. Each concrete channel provides a can_handle method and a check() method that validates whether the required external binaries are installed.
Runtime Binary Detection with shutil.which
Rather than bundling dependencies, every channel calls Python’s standard library shutil.which() to probe the system PATH. If the expected binary is missing, the channel returns a warn or off status and surfaces installation instructions to the user.
Twitter / X Channel: twitter-cli and Legacy Fallbacks
In agent_reach/channels/twitter.py (lines 22–29), the TwitterChannel class declares its backends. The primary target is the modern twitter-cli utility, invoked through the twitter binary. For legacy environments, Agent Reach falls back to the older bird or birdx binaries (bird / birdx).
During initialization, the channel runs shutil.which("twitter") to locate the modern CLI, then falls back to shutil.which("bird") or shutil.which("birdx"). If none of these are found, the channel reports itself as unavailable.
Bilibili Channel: yt-dlp and Optional bili-cli
The Bilibili implementation in agent_reach/channels/bilibili.py relies on two distinct tools. Lines 30–31 enumerate the backends list, while lines 38–45 contain the runtime detection logic.
The channel checks for:
yt-dlp— used for downloading video streams and extracting media metadata.bili-cli(binarybili) — optional tool that provides richer browsing and search capabilities.
If bili-cli is absent, Agent Reach transparently falls back to the public Bilibili search API. This means the channel can still operate in a degraded mode without the optional binary.
Weibo Channel: mcporter and mcp-server-weibo
Weibo support in agent_reach/channels/weibo.py (lines 21–53) is the most specialized. Instead of a direct platform client, the channel expects an npm-based command-line tool called mcporter. This utility acts as a bridge to Model Context Protocol (MCP) servers.
The validation sequence is:
- Locate
mcporterviashutil.which("mcporter"). - Execute
mcporter config listto confirm global configuration. - Execute
mcporter list weiboto verify that the Weibo MCP server is registered. - Confirm that the Python package mcp-server-weibo is installed and loadable.
Only after all four steps succeed does the channel return an ok status.
Running Platform Diagnostics from the CLI
Agent Reach exposes a unified diagnostic command through agent_reach/cli.py. Running the built-in doctor subcommand performs the same check() routine for every configured channel and prints a summary.
python -m agent_reach.cli doctor
The output lists each platform alongside its status—ok, warn, or off—and names the exact upstream CLI tool that needs to be installed or configured.
Code Examples: Checking Upstream Tool Availability
You can programmatically inspect whether the required binaries are present by instantiating the channel classes directly.
Verify the Twitter Channel
from agent_reach.channels.twitter import TwitterChannel
tw = TwitterChannel()
status, msg = tw.check()
print(f"Twitter status: {status} – {msg}")
If twitter-cli is installed and authenticated, the result is ("ok", ...). Otherwise you receive warn or off with installation hints.
Verify the Bilibili Channel
from agent_reach.channels.bilibili import BilibiliChannel
bl = BilibiliChannel()
status, msg = bl.check()
print(f"Bilibili status: {status} – {msg}")
This reports whether yt-dlp is present and whether the optional bili-cli or the fallback Bilibili API is usable.
Verify the Weibo Channel
from agent_reach.channels.weibo import WeiboChannel
wb = WeiboChannel()
status, msg = wb.check()
print(f"Weibo status: {status} – {msg}")
This validates that mcporter is installed, the Weibo MCP configuration exists, and the mcp-server-weibo service loads correctly.
Summary
- Agent Reach does not implement native Twitter, Bilibili, or Weibo clients; it acts as a router to upstream CLI tools.
- For Twitter/X, it searches for
twitter-cli(binarytwitter), falling back tobirdorbirdx, as defined inagent_reach/channels/twitter.py. - For Bilibili, it requires
yt-dlpfor video handling and optionally usesbili-cli(binarybili) or the public API, as declared inagent_reach/channels/bilibili.py. - For Weibo, it depends on the npm tool
mcporterand the Python packagemcp-server-weibo, validated inagent_reach/channels/weibo.py. - Every channel relies on
shutil.which()for runtime discovery and reports status via a commoncheck()interface. - Use
python -m agent_reach.cli doctorto audit all channels at once.
Frequently Asked Questions
What upstream CLI tool does Agent Reach use for Twitter?
Agent Reach routes Twitter/X requests to the twitter-cli binary (twitter). If that is unavailable, it falls back to the legacy utilities bird or birdx, detecting each with shutil.which() inside agent_reach/channels/twitter.py.
Is bili-cli mandatory for the Bilibili channel?
No. While Agent Reach will use bili-cli (binary bili) if it is present to provide richer search and browse features, the channel only strictly requires yt-dlp for video downloading. Without bili-cli, operations fall back to the public Bilibili search API.
How does Agent Reach validate Weibo support?
In agent_reach/channels/weibo.py, the channel verifies Weibo support by locating mcporter via shutil.which(), then running mcporter config list and mcporter list weibo to confirm the MCP server configuration. It also checks that the Python package mcp-server-weibo is operational.
Can I check all upstream CLI tools at once?
Yes. Running python -m agent_reach.cli doctor executes the check() method for every registered channel. The command reports whether each upstream binary—twitter, yt-dlp, bili, or mcporter—is installed and ready.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →