iflow-mcp_vmlia-books-mcp-server 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- iflow_mcp_vmlia_books_mcp_server-0.1.0/PKG-INFO +75 -0
- iflow_mcp_vmlia_books_mcp_server-0.1.0/README.md +63 -0
- iflow_mcp_vmlia_books_mcp_server-0.1.0/iflow_mcp_vmlia_books_mcp_server.egg-info/PKG-INFO +75 -0
- iflow_mcp_vmlia_books_mcp_server-0.1.0/iflow_mcp_vmlia_books_mcp_server.egg-info/SOURCES.txt +9 -0
- iflow_mcp_vmlia_books_mcp_server-0.1.0/iflow_mcp_vmlia_books_mcp_server.egg-info/dependency_links.txt +1 -0
- iflow_mcp_vmlia_books_mcp_server-0.1.0/iflow_mcp_vmlia_books_mcp_server.egg-info/entry_points.txt +2 -0
- iflow_mcp_vmlia_books_mcp_server-0.1.0/iflow_mcp_vmlia_books_mcp_server.egg-info/requires.txt +5 -0
- iflow_mcp_vmlia_books_mcp_server-0.1.0/iflow_mcp_vmlia_books_mcp_server.egg-info/top_level.txt +1 -0
- iflow_mcp_vmlia_books_mcp_server-0.1.0/main.py +145 -0
- iflow_mcp_vmlia_books_mcp_server-0.1.0/pyproject.toml +19 -0
- iflow_mcp_vmlia_books_mcp_server-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: iflow-mcp_vmlia-books-mcp-server
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: beautifulsoup4>=4.13.3
|
|
8
|
+
Requires-Dist: httpx>=0.28.1
|
|
9
|
+
Requires-Dist: lxml
|
|
10
|
+
Requires-Dist: mcp[cli]>=1.6.0
|
|
11
|
+
Requires-Dist: openai>=1.72.0
|
|
12
|
+
|
|
13
|
+
## Get the Project and Initialize
|
|
14
|
+
```
|
|
15
|
+
git clone https://github.com/VmLia/books-mcp-server.git
|
|
16
|
+
cd books-mcp-server
|
|
17
|
+
uv venv
|
|
18
|
+
```
|
|
19
|
+
if macbook or linux
|
|
20
|
+
````
|
|
21
|
+
source .venv/bin/activate
|
|
22
|
+
````
|
|
23
|
+
if windows
|
|
24
|
+
````
|
|
25
|
+
.venv\Scripts\activate.bat
|
|
26
|
+
````
|
|
27
|
+
|
|
28
|
+
### Install Python Packages
|
|
29
|
+
```
|
|
30
|
+
uv add "mcp[cli]" httpx openai beautifulsoup4 lxml
|
|
31
|
+
```
|
|
32
|
+
If the network is slow, you can set up a domestic mirror source.
|
|
33
|
+
```
|
|
34
|
+
uv add "mcp[cli]" httpx openai beautifulsoup4 lxml --index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Example of Using cherry-studio
|
|
38
|
+
**Method 1**: On the setting page of cherry-studio, click on the MCP server, then click "Add Server", and subsequently configure it on the page.
|
|
39
|
+
### Type
|
|
40
|
+
```
|
|
41
|
+
STDIO
|
|
42
|
+
```
|
|
43
|
+
### Command
|
|
44
|
+
```
|
|
45
|
+
uv
|
|
46
|
+
```
|
|
47
|
+
### Parameters
|
|
48
|
+
```
|
|
49
|
+
--directory
|
|
50
|
+
# your project dir
|
|
51
|
+
run
|
|
52
|
+
main.py
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Method 2**: Use the configuration parameters
|
|
56
|
+
```
|
|
57
|
+
{
|
|
58
|
+
"mcpServers": {
|
|
59
|
+
"books-mcp-server": {
|
|
60
|
+
"name": "books-mcp",
|
|
61
|
+
"type": "stdio",
|
|
62
|
+
"description": "",
|
|
63
|
+
"isActive": true,
|
|
64
|
+
"registryUrl": "",
|
|
65
|
+
"command": "uv",
|
|
66
|
+
"args": [
|
|
67
|
+
"--directory",
|
|
68
|
+
"/Enter your local project directory/books-mcp-server",
|
|
69
|
+
"run",
|
|
70
|
+
"main.py"
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
## Get the Project and Initialize
|
|
2
|
+
```
|
|
3
|
+
git clone https://github.com/VmLia/books-mcp-server.git
|
|
4
|
+
cd books-mcp-server
|
|
5
|
+
uv venv
|
|
6
|
+
```
|
|
7
|
+
if macbook or linux
|
|
8
|
+
````
|
|
9
|
+
source .venv/bin/activate
|
|
10
|
+
````
|
|
11
|
+
if windows
|
|
12
|
+
````
|
|
13
|
+
.venv\Scripts\activate.bat
|
|
14
|
+
````
|
|
15
|
+
|
|
16
|
+
### Install Python Packages
|
|
17
|
+
```
|
|
18
|
+
uv add "mcp[cli]" httpx openai beautifulsoup4 lxml
|
|
19
|
+
```
|
|
20
|
+
If the network is slow, you can set up a domestic mirror source.
|
|
21
|
+
```
|
|
22
|
+
uv add "mcp[cli]" httpx openai beautifulsoup4 lxml --index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Example of Using cherry-studio
|
|
26
|
+
**Method 1**: On the setting page of cherry-studio, click on the MCP server, then click "Add Server", and subsequently configure it on the page.
|
|
27
|
+
### Type
|
|
28
|
+
```
|
|
29
|
+
STDIO
|
|
30
|
+
```
|
|
31
|
+
### Command
|
|
32
|
+
```
|
|
33
|
+
uv
|
|
34
|
+
```
|
|
35
|
+
### Parameters
|
|
36
|
+
```
|
|
37
|
+
--directory
|
|
38
|
+
# your project dir
|
|
39
|
+
run
|
|
40
|
+
main.py
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Method 2**: Use the configuration parameters
|
|
44
|
+
```
|
|
45
|
+
{
|
|
46
|
+
"mcpServers": {
|
|
47
|
+
"books-mcp-server": {
|
|
48
|
+
"name": "books-mcp",
|
|
49
|
+
"type": "stdio",
|
|
50
|
+
"description": "",
|
|
51
|
+
"isActive": true,
|
|
52
|
+
"registryUrl": "",
|
|
53
|
+
"command": "uv",
|
|
54
|
+
"args": [
|
|
55
|
+
"--directory",
|
|
56
|
+
"/Enter your local project directory/books-mcp-server",
|
|
57
|
+
"run",
|
|
58
|
+
"main.py"
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: iflow-mcp_vmlia-books-mcp-server
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: beautifulsoup4>=4.13.3
|
|
8
|
+
Requires-Dist: httpx>=0.28.1
|
|
9
|
+
Requires-Dist: lxml
|
|
10
|
+
Requires-Dist: mcp[cli]>=1.6.0
|
|
11
|
+
Requires-Dist: openai>=1.72.0
|
|
12
|
+
|
|
13
|
+
## Get the Project and Initialize
|
|
14
|
+
```
|
|
15
|
+
git clone https://github.com/VmLia/books-mcp-server.git
|
|
16
|
+
cd books-mcp-server
|
|
17
|
+
uv venv
|
|
18
|
+
```
|
|
19
|
+
if macbook or linux
|
|
20
|
+
````
|
|
21
|
+
source .venv/bin/activate
|
|
22
|
+
````
|
|
23
|
+
if windows
|
|
24
|
+
````
|
|
25
|
+
.venv\Scripts\activate.bat
|
|
26
|
+
````
|
|
27
|
+
|
|
28
|
+
### Install Python Packages
|
|
29
|
+
```
|
|
30
|
+
uv add "mcp[cli]" httpx openai beautifulsoup4 lxml
|
|
31
|
+
```
|
|
32
|
+
If the network is slow, you can set up a domestic mirror source.
|
|
33
|
+
```
|
|
34
|
+
uv add "mcp[cli]" httpx openai beautifulsoup4 lxml --index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Example of Using cherry-studio
|
|
38
|
+
**Method 1**: On the setting page of cherry-studio, click on the MCP server, then click "Add Server", and subsequently configure it on the page.
|
|
39
|
+
### Type
|
|
40
|
+
```
|
|
41
|
+
STDIO
|
|
42
|
+
```
|
|
43
|
+
### Command
|
|
44
|
+
```
|
|
45
|
+
uv
|
|
46
|
+
```
|
|
47
|
+
### Parameters
|
|
48
|
+
```
|
|
49
|
+
--directory
|
|
50
|
+
# your project dir
|
|
51
|
+
run
|
|
52
|
+
main.py
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Method 2**: Use the configuration parameters
|
|
56
|
+
```
|
|
57
|
+
{
|
|
58
|
+
"mcpServers": {
|
|
59
|
+
"books-mcp-server": {
|
|
60
|
+
"name": "books-mcp",
|
|
61
|
+
"type": "stdio",
|
|
62
|
+
"description": "",
|
|
63
|
+
"isActive": true,
|
|
64
|
+
"registryUrl": "",
|
|
65
|
+
"command": "uv",
|
|
66
|
+
"args": [
|
|
67
|
+
"--directory",
|
|
68
|
+
"/Enter your local project directory/books-mcp-server",
|
|
69
|
+
"run",
|
|
70
|
+
"main.py"
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
main.py
|
|
3
|
+
pyproject.toml
|
|
4
|
+
iflow_mcp_vmlia_books_mcp_server.egg-info/PKG-INFO
|
|
5
|
+
iflow_mcp_vmlia_books_mcp_server.egg-info/SOURCES.txt
|
|
6
|
+
iflow_mcp_vmlia_books_mcp_server.egg-info/dependency_links.txt
|
|
7
|
+
iflow_mcp_vmlia_books_mcp_server.egg-info/entry_points.txt
|
|
8
|
+
iflow_mcp_vmlia_books_mcp_server.egg-info/requires.txt
|
|
9
|
+
iflow_mcp_vmlia_books_mcp_server.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
iflow_mcp_vmlia_books_mcp_server-0.1.0/iflow_mcp_vmlia_books_mcp_server.egg-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
main
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from bs4 import BeautifulSoup
|
|
3
|
+
import httpx
|
|
4
|
+
from mcp.server import FastMCP
|
|
5
|
+
|
|
6
|
+
# 配置日志记录
|
|
7
|
+
logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
8
|
+
|
|
9
|
+
# 初始化 FastMCP 服务器
|
|
10
|
+
app = FastMCP('books-mcp-server')
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@app.tool()
|
|
14
|
+
async def book_search(query: str) -> str:
|
|
15
|
+
"""
|
|
16
|
+
搜索图书信息
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
query: 要搜索的图书关键词
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
搜索到的图书信息总结
|
|
23
|
+
"""
|
|
24
|
+
service_url = f"http://www.shuchacha.net/s?wd={query}"
|
|
25
|
+
headers = {}
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
# 使用 httpx 发送异步 GET 请求
|
|
29
|
+
async with httpx.AsyncClient() as client:
|
|
30
|
+
response = await client.get(service_url, headers=headers)
|
|
31
|
+
# 检查响应状态码
|
|
32
|
+
response.raise_for_status()
|
|
33
|
+
|
|
34
|
+
# 使用日志记录 response.text
|
|
35
|
+
|
|
36
|
+
# 修改解析器为 html.parser
|
|
37
|
+
soup = BeautifulSoup(response.text, 'lxml')
|
|
38
|
+
|
|
39
|
+
# 查找所有图书结果的容器
|
|
40
|
+
book_containers = soup.find_all('div', class_='result c-container')
|
|
41
|
+
|
|
42
|
+
# 存储提取的图书信息
|
|
43
|
+
books = []
|
|
44
|
+
|
|
45
|
+
for container in book_containers:
|
|
46
|
+
# 提取书名
|
|
47
|
+
h3_tag = container.find('h3', class_='t c-title-en')
|
|
48
|
+
if h3_tag:
|
|
49
|
+
title_tag = h3_tag.find('a')
|
|
50
|
+
if title_tag:
|
|
51
|
+
title = title_tag.text.strip()
|
|
52
|
+
# 提取书本对应的 URL
|
|
53
|
+
book_url = title_tag.get('href')
|
|
54
|
+
else:
|
|
55
|
+
title = '未找到书名信息'
|
|
56
|
+
book_url = '未找到URL信息'
|
|
57
|
+
else:
|
|
58
|
+
title = '未找到书名信息'
|
|
59
|
+
book_url = '未找到URL信息'
|
|
60
|
+
|
|
61
|
+
# 提取作者、页数、出版社和出版日期
|
|
62
|
+
info_span = container.find('span', class_='c-showurl')
|
|
63
|
+
if info_span:
|
|
64
|
+
author_tag = info_span.find('b', string='作者:')
|
|
65
|
+
if author_tag and author_tag.next_sibling and isinstance(author_tag.next_sibling, str):
|
|
66
|
+
author = author_tag.next_sibling.strip()
|
|
67
|
+
else:
|
|
68
|
+
author = '未找到作者信息'
|
|
69
|
+
|
|
70
|
+
pages_tag = info_span.find('b', string='页数:')
|
|
71
|
+
if pages_tag and pages_tag.next_sibling and isinstance(pages_tag.next_sibling, str):
|
|
72
|
+
pages = pages_tag.next_sibling.strip()
|
|
73
|
+
else:
|
|
74
|
+
pages = '未找到页数信息'
|
|
75
|
+
|
|
76
|
+
publisher_tag = info_span.find('b', string='出版社:')
|
|
77
|
+
if publisher_tag and publisher_tag.next_sibling and isinstance(publisher_tag.next_sibling, str):
|
|
78
|
+
publisher = publisher_tag.next_sibling.strip()
|
|
79
|
+
else:
|
|
80
|
+
publisher = '未找到出版社信息'
|
|
81
|
+
|
|
82
|
+
publish_date_tag = info_span.find('b', string='出版日期:')
|
|
83
|
+
if publish_date_tag and publish_date_tag.next_sibling and isinstance(publish_date_tag.next_sibling, str):
|
|
84
|
+
publish_date = publish_date_tag.next_sibling.strip()
|
|
85
|
+
else:
|
|
86
|
+
publish_date = '未找到出版日期信息'
|
|
87
|
+
else:
|
|
88
|
+
author = '未找到作者信息'
|
|
89
|
+
pages = '未找到页数信息'
|
|
90
|
+
publisher = '未找到出版社信息'
|
|
91
|
+
publish_date = '未找到出版日期信息'
|
|
92
|
+
|
|
93
|
+
# 提取简介
|
|
94
|
+
abstract_spans = container.find_all('span', class_='c-abstract')
|
|
95
|
+
abstracts = []
|
|
96
|
+
for span in abstract_spans:
|
|
97
|
+
# 跳过主题词的 span
|
|
98
|
+
if '主题词:' not in span.text:
|
|
99
|
+
abstracts.append(span.text.strip())
|
|
100
|
+
if abstracts:
|
|
101
|
+
# 若有多个简介段落,合并为一个字符串
|
|
102
|
+
book_abstract = ' '.join(abstracts)
|
|
103
|
+
else:
|
|
104
|
+
book_abstract = '未找到简介信息'
|
|
105
|
+
|
|
106
|
+
# 将提取的信息存储为字典
|
|
107
|
+
book_info = {
|
|
108
|
+
'书名': title,
|
|
109
|
+
'作者': author,
|
|
110
|
+
'页数': pages,
|
|
111
|
+
'出版社': publisher,
|
|
112
|
+
'出版日期': publish_date,
|
|
113
|
+
'URL': "http://www.shuchacha.net" + book_url,
|
|
114
|
+
'简介': book_abstract
|
|
115
|
+
}
|
|
116
|
+
books.append(book_info)
|
|
117
|
+
|
|
118
|
+
# 生成搜索结果总结
|
|
119
|
+
result_summary = ""
|
|
120
|
+
for book in books:
|
|
121
|
+
result_summary += f"书名: {book['书名']}\n"
|
|
122
|
+
result_summary += f"作者: {book['作者']}\n"
|
|
123
|
+
result_summary += f"页数: {book['页数']}\n"
|
|
124
|
+
result_summary += f"出版社: {book['出版社']}\n"
|
|
125
|
+
result_summary += f"出版日期: {book['出版日期']}\n"
|
|
126
|
+
result_summary += f"URL: {book['URL']}\n"
|
|
127
|
+
result_summary += f"简介: {book['简介']}\n"
|
|
128
|
+
result_summary += "=" * 10 + "\n"
|
|
129
|
+
|
|
130
|
+
return result_summary+"【请帮我整理以上书本信息,要求格式规范整齐,将书名显示成超链接点击打开URL对应的地址,对每本书的简介进行扩写介绍100字以上。】"
|
|
131
|
+
|
|
132
|
+
except httpx.ConnectTimeout:
|
|
133
|
+
logging.error("连接超时,请检查网络或服务配置。")
|
|
134
|
+
return "连接超时,请检查网络或服务配置。"
|
|
135
|
+
except httpx.RequestError as e:
|
|
136
|
+
logging.error(f"请求发生错误: {e}")
|
|
137
|
+
return f"请求发生错误: {e}"
|
|
138
|
+
except Exception as e:
|
|
139
|
+
logging.error(f"执行 book_search 工具时发生未知错误: {e}", exc_info=True)
|
|
140
|
+
return f"执行 book_search 工具时发生未知错误: {e}"
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
if __name__ == "__main__":
|
|
144
|
+
app.run(transport='stdio')
|
|
145
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "iflow-mcp_vmlia-books-mcp-server"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Add your description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"beautifulsoup4>=4.13.3",
|
|
9
|
+
"httpx>=0.28.1",
|
|
10
|
+
"lxml",
|
|
11
|
+
"mcp[cli]>=1.6.0",
|
|
12
|
+
"openai>=1.72.0",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[project.scripts]
|
|
16
|
+
iflow-mcp_vmlia-books-mcp-server = "main:app"
|
|
17
|
+
|
|
18
|
+
[tool.uv.workspace]
|
|
19
|
+
members = ["books-mcp-server"]
|