Jarvis-Brain 0.1.5.11__py3-none-any.whl → 0.1.6.1__py3-none-any.whl
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.
- {jarvis_brain-0.1.5.11.dist-info → jarvis_brain-0.1.6.1.dist-info}/METADATA +1 -1
- jarvis_brain-0.1.6.1.dist-info/RECORD +10 -0
- mcp_tools/dp_tools.py +18 -21
- tools/browser_manager.py +3 -1
- jarvis_brain-0.1.5.11.dist-info/RECORD +0 -10
- {jarvis_brain-0.1.5.11.dist-info → jarvis_brain-0.1.6.1.dist-info}/WHEEL +0 -0
- {jarvis_brain-0.1.5.11.dist-info → jarvis_brain-0.1.6.1.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
mcp_tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
mcp_tools/dp_tools.py,sha256=hijWdWQ9fhAQXrtrtqkaUd3CUH5sORAoQaF7BVtljfY,9078
|
|
3
|
+
mcp_tools/main.py,sha256=SiLF-tcEdApkzMjTZJEpVYX5d-LPW7aqy6A6lCBA7YQ,829
|
|
4
|
+
tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
tools/browser_manager.py,sha256=EXM7n-sDOtdQGpWkVTAZHWhepVU-7PAoUTDNgGF9_fQ,1938
|
|
6
|
+
tools/tools.py,sha256=TaWs-CNXy-py9BFmCnJrQ09ke938xXpImf-N2Qo_Rvc,4708
|
|
7
|
+
jarvis_brain-0.1.6.1.dist-info/METADATA,sha256=1CSoEWNLJzbP1L_4Gz3ElX2jANUxnsMh8EqtwM5D6Pw,241
|
|
8
|
+
jarvis_brain-0.1.6.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
9
|
+
jarvis_brain-0.1.6.1.dist-info/entry_points.txt,sha256=YFQT4xpkUqt5dM5wlKPQQOqcjMuFrT9iuRAzIpAyH7U,51
|
|
10
|
+
jarvis_brain-0.1.6.1.dist-info/RECORD,,
|
mcp_tools/dp_tools.py
CHANGED
|
@@ -5,6 +5,7 @@ from typing import Any
|
|
|
5
5
|
|
|
6
6
|
from fastmcp import FastMCP
|
|
7
7
|
|
|
8
|
+
from tools.browser_manager import BrowserManager
|
|
8
9
|
from tools.tools import compress_html, requests_html, dp_headless_html, assert_waf_cookie, dp_mcp_message_pack
|
|
9
10
|
|
|
10
11
|
html_source_code_local_save_path = os.path.join(os.getcwd(), "html-source-code")
|
|
@@ -16,15 +17,19 @@ waf_status_code_dict = {
|
|
|
16
17
|
ont_turn_max_token = 25000
|
|
17
18
|
|
|
18
19
|
|
|
19
|
-
def register_visit_url(mcp: FastMCP, browser_manager):
|
|
20
|
-
@mcp.tool(name="visit_url",
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
def register_visit_url(mcp: FastMCP, browser_manager: BrowserManager):
|
|
21
|
+
@mcp.tool(name="visit_url",
|
|
22
|
+
description="使用Drissionpage打开url访问某个网站,并开始监听初始tab页的所有的XHR请求,当需要使用手机版浏览器Ua时use_mobile_user_agent为True")
|
|
23
|
+
async def visit_url(url: str, use_mobile_user_agent=False) -> dict[str, Any]:
|
|
24
|
+
mobile_user_agent = None
|
|
25
|
+
if use_mobile_user_agent:
|
|
26
|
+
mobile_user_agent = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Mobile Safari/537.36"
|
|
27
|
+
port, _browser = browser_manager.create_browser(mobile_user_agent)
|
|
23
28
|
tab = _browser.get_tab()
|
|
24
29
|
tab.get(url)
|
|
25
30
|
tab_id = tab.tab_id
|
|
26
31
|
return dp_mcp_message_pack(
|
|
27
|
-
f"已在[{port}]端口创建浏览器对象,并已打开链接:{url}",
|
|
32
|
+
f"已在[{port}]端口创建浏览器对象,并已打开链接:{url},打开的模式是:{'手机版' if use_mobile_user_agent else '电脑版'}",
|
|
28
33
|
tab_id=tab_id,
|
|
29
34
|
browser_port=port
|
|
30
35
|
)
|
|
@@ -50,8 +55,10 @@ def register_get_html(mcp: FastMCP, browser_manager):
|
|
|
50
55
|
message = f"已保存tab页:【{tab_id}】的html源码片段共{len(html_file_list)}个"
|
|
51
56
|
return dp_mcp_message_pack(message, tab_id=tab_id, htmls_local_path=html_file_list)
|
|
52
57
|
|
|
58
|
+
|
|
53
59
|
def register_get_new_tab(mcp: FastMCP, browser_manager):
|
|
54
|
-
@mcp.tool(name="get_new_tab",
|
|
60
|
+
@mcp.tool(name="get_new_tab",
|
|
61
|
+
description="使用Drissionpage创建一个新的tab页,在新的tab页中打开url,并开始监听新的tab页的所有XHR请求")
|
|
55
62
|
async def get_new_tab(browser_port: int, url: str) -> dict[str, Any]:
|
|
56
63
|
_browser = browser_manager.get_browser(browser_port)
|
|
57
64
|
tab = _browser.new_tab(url)
|
|
@@ -59,6 +66,7 @@ def register_get_new_tab(mcp: FastMCP, browser_manager):
|
|
|
59
66
|
tab_id = tab.tab_id
|
|
60
67
|
return dp_mcp_message_pack(f"已创建新的tab页,并打开链接:{url}", tab_id=tab_id)
|
|
61
68
|
|
|
69
|
+
|
|
62
70
|
def register_switch_tab(mcp: FastMCP, browser_manager):
|
|
63
71
|
@mcp.tool(name="switch_tab", description="根据传入的tab_id切换到对应的tab页", )
|
|
64
72
|
async def switch_tab(browser_port: int, tab_id: str) -> dict[str, Any]:
|
|
@@ -66,6 +74,7 @@ def register_switch_tab(mcp: FastMCP, browser_manager):
|
|
|
66
74
|
_browser.activate_tab(tab_id)
|
|
67
75
|
return dp_mcp_message_pack(f"已将tab页:【{tab_id}】切换至最前端")
|
|
68
76
|
|
|
77
|
+
|
|
69
78
|
def register_close_tab(mcp: FastMCP, browser_manager):
|
|
70
79
|
@mcp.tool(name="close_tab", description="根据传入的tab_id关闭tab页", )
|
|
71
80
|
async def close_tab(browser_port, tab_id) -> dict[str, Any]:
|
|
@@ -73,6 +82,7 @@ def register_close_tab(mcp: FastMCP, browser_manager):
|
|
|
73
82
|
_browser.close_tabs(tab_id)
|
|
74
83
|
return dp_mcp_message_pack(f"已将tab页:【{tab_id}】关闭")
|
|
75
84
|
|
|
85
|
+
|
|
76
86
|
def register_check_selector(mcp: FastMCP, browser_manager):
|
|
77
87
|
@mcp.tool(name="check_selector", description="查找tab页中是否包含元素,并返回元素attr_name所对应的值")
|
|
78
88
|
async def check_selector(browser_port: int, tab_id: str, css_selector: str, attr_name: str = "text") -> dict[
|
|
@@ -99,6 +109,7 @@ def register_check_selector(mcp: FastMCP, browser_manager):
|
|
|
99
109
|
attr_output=attr_output
|
|
100
110
|
)
|
|
101
111
|
|
|
112
|
+
|
|
102
113
|
def register_quit_browser(mcp: FastMCP, browser_manager):
|
|
103
114
|
@mcp.tool(name="quit_browser", description="退出浏览器会话,关闭浏览器")
|
|
104
115
|
async def quit_browser(browser_port: int) -> dict[str, Any]:
|
|
@@ -111,6 +122,7 @@ def register_quit_browser(mcp: FastMCP, browser_manager):
|
|
|
111
122
|
quit_flag=flag
|
|
112
123
|
)
|
|
113
124
|
|
|
125
|
+
|
|
114
126
|
def register_assert_waf(mcp: FastMCP, browser_manager):
|
|
115
127
|
@mcp.tool(name="assert_waf",
|
|
116
128
|
description="通过对比requests、有头浏览器、无头浏览器获取到的html,判断网页是否使用了waf以及是否为动态渲染的网页")
|
|
@@ -159,18 +171,3 @@ def register_assert_waf(mcp: FastMCP, browser_manager):
|
|
|
159
171
|
raw_headless_rate_difference=h_hless_rate_diff,
|
|
160
172
|
head_headless_rate_difference=h_hless_rate_diff
|
|
161
173
|
)
|
|
162
|
-
|
|
163
|
-
def register_highlight_element_captcha(mcp: FastMCP, browser_manager):
|
|
164
|
-
@mcp.tool(name="highlight_element_captcha", description="将传入的Selector在页面上高亮,并截屏")
|
|
165
|
-
async def highlight_element_captcha(browser_port: int, tab_id: str, css_selector: str) -> dict[str, Any]:
|
|
166
|
-
_browser = browser_manager.get_browser(browser_port)
|
|
167
|
-
tab = _browser.get_tab(tab_id)
|
|
168
|
-
highlight_style = 'background-color: rgba(255, 255, 0, 0.2); outline: 2px solid yellow !important; outline-offset: 2px'
|
|
169
|
-
css_selector = css_selector
|
|
170
|
-
if "css:" not in css_selector:
|
|
171
|
-
css_selector = "css:" + css_selector
|
|
172
|
-
|
|
173
|
-
target_eles = tab.eles(css_selector)
|
|
174
|
-
exist_flag = False
|
|
175
|
-
if len(target_eles) != 0:
|
|
176
|
-
exist_flag = True
|
tools/browser_manager.py
CHANGED
|
@@ -16,13 +16,15 @@ class BrowserManager:
|
|
|
16
16
|
cls._instance.browser_pool = {}
|
|
17
17
|
return cls._instance
|
|
18
18
|
|
|
19
|
-
def create_browser(self) -> Tuple[int, ChromiumPage]:
|
|
19
|
+
def create_browser(self, user_agent: str = None) -> Tuple[int, ChromiumPage]:
|
|
20
20
|
"""创建新的浏览器实例"""
|
|
21
21
|
random_port = random.randint(9223, 9934)
|
|
22
22
|
while random_port in self.browser_pool:
|
|
23
23
|
random_port = random.randint(9223, 9934)
|
|
24
24
|
|
|
25
25
|
co = ChromiumOptions().set_local_port(random_port)
|
|
26
|
+
if user_agent:
|
|
27
|
+
co.set_user_agent(user_agent)
|
|
26
28
|
if platform.system() != 'Windows':
|
|
27
29
|
co.set_argument('--no-sandbox')
|
|
28
30
|
custom_data_dir = os.path.join(os.path.expanduser('~'), 'DrissionPage', "userData", f"{random_port}")
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
mcp_tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
mcp_tools/dp_tools.py,sha256=-U7e4OpMEAyJywlvqsU63baBF7iHMdQpMM5hwdCHctE,9238
|
|
3
|
-
mcp_tools/main.py,sha256=SiLF-tcEdApkzMjTZJEpVYX5d-LPW7aqy6A6lCBA7YQ,829
|
|
4
|
-
tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
tools/browser_manager.py,sha256=J8aNQECiQvucsUjLJQ9N-3f2xoyoCIxjV-kJ7YcoHv4,1849
|
|
6
|
-
tools/tools.py,sha256=TaWs-CNXy-py9BFmCnJrQ09ke938xXpImf-N2Qo_Rvc,4708
|
|
7
|
-
jarvis_brain-0.1.5.11.dist-info/METADATA,sha256=p_WvRkpQoyYzfHuQ-uFDqScHeJLxQokPmI8jFolXfZ0,242
|
|
8
|
-
jarvis_brain-0.1.5.11.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
9
|
-
jarvis_brain-0.1.5.11.dist-info/entry_points.txt,sha256=YFQT4xpkUqt5dM5wlKPQQOqcjMuFrT9iuRAzIpAyH7U,51
|
|
10
|
-
jarvis_brain-0.1.5.11.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|