b0e010c6cc
Extracted from #318 (the UTF-8/doctor core, minus the env-wrapper feature): - new agent_reach/utils/process.py: utf8_subprocess_env() + mcporter_utf8_env_args() — Windows GBK consoles otherwise corrupt Chinese output from mcporter/MCP child processes - weibo/douyin/linkedin checks and weibo install/registration now pass the UTF-8 env (and register the MCP server with --env PYTHONUTF8=1) - youtube: extract _has_js_runtime_config() with an OSError guard so an unreadable yt-dlp config can't crash doctor - test_skill_command: open SKILL.md with explicit utf-8 (Windows GBK default broke these tests) Co-authored-by: chidao <2980933590@qq.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
60 lines
2.4 KiB
Python
60 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Weibo (微博) — check if mcporter + mcp-server-weibo is available."""
|
|
|
|
import shutil
|
|
import subprocess
|
|
|
|
from agent_reach.utils.process import utf8_subprocess_env
|
|
|
|
from .base import Channel
|
|
|
|
|
|
class WeiboChannel(Channel):
|
|
name = "weibo"
|
|
description = "微博动态与热搜"
|
|
backends = ["mcp-server-weibo"]
|
|
tier = 1
|
|
|
|
def can_handle(self, url: str) -> bool:
|
|
from urllib.parse import urlparse
|
|
d = urlparse(url).netloc.lower()
|
|
return "weibo.com" in d or "weibo.cn" in d
|
|
|
|
def check(self, config=None):
|
|
mcporter = shutil.which("mcporter")
|
|
if not mcporter:
|
|
return "off", (
|
|
"需要 mcporter + mcp-server-weibo。安装步骤:\n"
|
|
" 1. npm install -g mcporter\n"
|
|
" 2. pip install git+https://github.com/Panniantong/mcp-server-weibo.git\n"
|
|
" 3. mcporter config add weibo --command 'mcp-server-weibo' "
|
|
"--env PYTHONUTF8=1 --env PYTHONIOENCODING=utf-8\n"
|
|
" 详见 https://github.com/Panniantong/mcp-server-weibo"
|
|
)
|
|
try:
|
|
r = subprocess.run(
|
|
[mcporter, "config", "list"], capture_output=True,
|
|
encoding="utf-8", errors="replace", timeout=5,
|
|
env=utf8_subprocess_env(),
|
|
)
|
|
if "weibo" not in r.stdout:
|
|
return "off", (
|
|
"mcporter 已装但微博 MCP 未配置。运行:\n"
|
|
" pip install git+https://github.com/Panniantong/mcp-server-weibo.git\n"
|
|
" mcporter config add weibo --command 'mcp-server-weibo' "
|
|
"--env PYTHONUTF8=1 --env PYTHONIOENCODING=utf-8"
|
|
)
|
|
except Exception:
|
|
return "off", "mcporter 连接异常"
|
|
try:
|
|
r = subprocess.run(
|
|
[mcporter, "list", "weibo"], capture_output=True,
|
|
encoding="utf-8", errors="replace", timeout=15,
|
|
env=utf8_subprocess_env(),
|
|
)
|
|
if r.returncode == 0 and "search_users" in r.stdout:
|
|
return "ok", "完整可用(热搜、搜索、用户动态、评论)"
|
|
return "warn", "MCP 已配置但工具加载失败,检查 mcp-server-weibo 版本"
|
|
except Exception:
|
|
return "warn", "MCP 连接异常,检查 mcp-server-weibo 是否可用"
|