1+ # server.py
2+ from mcp .server .fastmcp import FastMCP
3+ import requests
4+
5+ # Create an MCP server
6+ mcp = FastMCP ("Demo" )
7+
8+
9+ # Add an addition tool
10+ @mcp .tool ()
11+ def add (a : int , b : int ) -> int :
12+ """Add two numbers"""
13+ return a + b
14+
15+
16+ # Add a dynamic greeting resource
17+ @mcp .resource ("greeting://{name}" )
18+ def get_greeting (name : str ) -> str :
19+ """Get a personalized greeting"""
20+ return f"Hello, { name } !"
21+
22+ @mcp .tool ()
23+ def request_wxread_gongzhonghao_articles (book_id : str ,token : str ) -> str :
24+ """请求微信阅读公众号文章
25+ 真实请求头参考:
26+
27+ GET /book/articles?count=20&offset=0&bookId=MP_WXS_1432156401&synckey=0 HTTP/1.1
28+ accessToken: fcMfiJf6
29+ vid: 919870732
30+ baseapi: 29
31+ appver: 9.3.0.10165975
32+ User-Agent: WeRead/9.3.0 WRBrand/huawei Dalvik/2.1.0 (Linux; U; Android 10; HMA-AL00 Build/HUAWEIHMA-AL00)
33+ osver: 10
34+ channelId: 6
35+ basever: 9.3.0.10165973
36+ Host: i.weread.qq.com
37+ Connection: Keep-Alive
38+ Accept-Encoding: gzip
39+
40+ """
41+ host = "https://i.weread.qq.com"
42+
43+ headers = {
44+ 'accessToken' : token if token else get_wxread_token (),
45+ 'vid' : '919870732' ,
46+ 'baseapi' : '29' ,
47+ 'appver' : '9.3.0.10165975' ,
48+ 'User-Agent' : 'WeRead/9.3.0 WRBrand/huawei Dalvik/2.1.0 (Linux; U; Android 10; HMA-AL00 Build/HUAWEIHMA-AL00)' ,
49+ 'osver' : '10' ,
50+ 'channelId' : '6' ,
51+ 'basever' : '9.3.0.10165973' ,
52+ 'Host' : 'i.weread.qq.com' ,
53+ 'Connection' : 'Keep-Alive' ,
54+ 'Accept-Encoding' : 'gzip'
55+ }
56+
57+ params = {
58+ 'count' : '20' ,
59+ 'offset' : '0' ,
60+ 'bookId' : book_id ,
61+ 'synckey' : '0'
62+ }
63+
64+ try :
65+ response = requests .get (
66+ f"{ host } /book/articles" ,
67+ headers = headers ,
68+ params = params
69+ )
70+ response .raise_for_status ()
71+ return response .text
72+ except requests .exceptions .RequestException as e :
73+ return f"Error fetching articles: { str (e )} "
74+
75+
76+ def get_wxread_token ():
77+ """获取微信阅读token"""
78+ return "fcMfiJf6"
0 commit comments