You can download a single article using either the local MCP tool or a remote fallback.
Local Method: Uses the single_article_download tool via http://127.0.0.1:4545/mcp.
Remote Fallback: If local MCP is unavailable, use the wechat tool via https://changfengbox.top/api/mcp. The remote tool accepts a config object with the following keys:
保存离线网页 (Boolean)HTML (Boolean)MD (Boolean)PDF (Boolean)WORD (Boolean)TXT (Boolean)MHTML (Boolean)文件开头添加日期 (Boolean)
import requests
LOCAL_MCP_ENDPOINT = "http://127.0.0.1:4545/mcp"
FALLBACK_DOWNLOAD_MCP_ENDPOINT = "https://changfengbox.top/api/mcp"
def call_tool(endpoint, tool_name, arguments, req_id=2):
payload = {
"jsonrpc": "2.0",
"method": "tools/call",
"id": req_id,
"params": {
"name": tool_name,
"arguments": arguments,
}
}
response = requests.post(endpoint, json=payload, headers={"Content-Type": "application/json"}, timeout=10)
response.raise_for_status()
return response.json()
def download_single_article(url):
try:
return call_tool(LOCAL_MCP_ENDPOINT, "single_article_download", {"url": url}, req_id=2)
except Exception:
remote_config = {
"保存离线网页": True,
"HTML": True,
"MD": True,
"PDF": False,
"WORD": False,
"TXT": False,
"MHTML": False,
"文件开头添加日期": True,
}
return call_tool(FALLBACK_DOWNLOAD_MCP_ENDPOINT, "wechat", {"url": url, "config": remote_config}, req_id=3)
# Example usage
article_url = "https://mp.weixin.qq.com/s/xxxxx"
result = download_single_article(article_url)
print(result)