Skip to content

Commit 4649ce6

Browse files
author
kunxin.lkx
committed
1 parent 0a388b6 commit 4649ce6

File tree

5 files changed

+98
-0
lines changed

5 files changed

+98
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

mcp-server-demo/mcp-server-demo/README.md

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def main():
2+
print("Hello from mcp-server-demo!")
3+
4+
5+
if __name__ == "__main__":
6+
main()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[project]
2+
name = "mcp-server-demo"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.10"
7+
dependencies = [
8+
"mcp[cli]",
9+
"requests>=2.31.0",
10+
]
11+
12+
[tool.uv.sources]
13+
mcp = { workspace = true }
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

Comments
 (0)