Jarvis-Brain 0.0.1__py3-none-any.whl → 0.0.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Jarvis_Brain
3
- Version: 0.0.1
3
+ Version: 0.0.3
4
4
  Summary: Jarvis brain
5
5
  Requires-Python: >=3.10
6
6
  Requires-Dist: drissionpage
@@ -0,0 +1,7 @@
1
+ mcp_tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ mcp_tools/dp_tools.py,sha256=TsBJM_Fdr6IreZvqoUZnDv2OJi-oMEYCLzO5cIIUVe4,5991
3
+ mcp_tools/main.py,sha256=udTCzVeYLhYK_sFBuKQ9_idbF_qKY-0oTfJaigZc2_g,394
4
+ jarvis_brain-0.0.3.dist-info/METADATA,sha256=OVAipWel585XsqFvWoETCsYA_RQVEakHo2l_EAa1N_I,176
5
+ jarvis_brain-0.0.3.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
6
+ jarvis_brain-0.0.3.dist-info/entry_points.txt,sha256=YFQT4xpkUqt5dM5wlKPQQOqcjMuFrT9iuRAzIpAyH7U,51
7
+ jarvis_brain-0.0.3.dist-info/RECORD,,
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ jarvis-mcp = mcp_tools.main:main
mcp_tools/dp_tools.py CHANGED
@@ -9,7 +9,7 @@ from DrissionPage._elements.none_element import NoneElement
9
9
  from fastmcp import FastMCP
10
10
  from lxml import html, etree
11
11
 
12
- mcp = FastMCP("JARVIS_DP_TOOLS")
12
+ # mcp = FastMCP("JARVIS_DP_TOOLS")
13
13
 
14
14
  html_source_code_local_save_path = os.path.join(os.getcwd(), "html-source-code")
15
15
 
@@ -57,99 +57,99 @@ def get_page(port):
57
57
  return browser_pool.get(port, None)
58
58
 
59
59
 
60
- # @tool("visit_url", "使用Drissionpage打开url访问某个网站", {"url": str})
61
- @mcp.tool(name="visit_url", description="使用Drissionpage打开url访问某个网站")
62
- async def visit_url(url: str) -> dict[str, Any]:
63
- port, _browser = create_browser()
64
- tab = _browser.get_tab()
65
- tab.get(url)
66
- tab_id = tab.tab_id
67
- return {
68
- "content": [{
69
- "type": "text",
70
- "text": json.dumps({
71
- "message": f"已在[{port}]端口创建浏览器对象,并已打开链接:{url}",
72
- "tab_id": tab_id,
73
- "browser_port": port,
74
- }, ensure_ascii=False)
75
- }]
76
- }
77
-
78
-
79
- @mcp.tool(name="get_html", description="使用Drissionpage获取某一个tab页的html")
80
- async def get_html(browser_port: int, tab_id: str) -> dict[str, Any]:
81
- _browser = get_page(browser_port)
82
- tab = _browser.get_tab(tab_id)
83
- file_name = tab.title + f"_{tab_id}.html"
84
- abs_path = os.path.join(html_source_code_local_save_path, file_name)
85
- with open(abs_path, "w", encoding="utf-8") as f:
86
- f.write(compress_html(tab.html))
87
- return {
88
- "content": [{
89
- "type": "text",
90
- "text": json.dumps({
91
- "message": f"已保存tab页:【{tab_id}】的html源码",
92
- "tab_id": tab_id,
93
- "html_local_path": abs_path
94
- }, ensure_ascii=False)
95
- }]
96
- }
97
-
98
-
99
- @mcp.tool(name="get_new_tab", description="使用Drissionpage创建一个新的tab页,在新的tab页中打开url")
100
- async def get_new_tab(browser_port: int, url: str) -> dict[str, Any]:
101
- _browser = get_page(browser_port)
102
- tab = _browser.new_tab(url)
103
- _browser.activate_tab(tab)
104
- tab_id = tab.tab_id
105
- return {
106
- "content": [{
107
- "type": "text",
108
- "text": json.dumps({
109
- "message": f"已创建新的tab页,并打开链接:{url}",
110
- "tab_id": tab_id,
111
- }, ensure_ascii=False)
112
- }]
113
- }
114
-
115
-
116
- @mcp.tool(name="switch_tab", description="根据传入的tab_id切换到对应的tab页", )
117
- async def switch_tab(browser_port: int, tab_id: str) -> dict[str, Any]:
118
- _browser = get_page(browser_port)
119
- _browser.activate_tab(tab_id)
120
- return {
121
- "content": [{
122
- "type": "text",
123
- "text": json.dumps({
124
- "message": f"已将tab页:【{tab_id}】切换至最前端",
125
- }, ensure_ascii=False)
126
- }]
127
- }
128
-
129
-
130
- @mcp.tool(name="close_tab", description="根据传入的tab_id关闭tab页", )
131
- async def close_tab(browser_port, tab_id) -> dict[str, Any]:
132
- _browser = get_page(browser_port)
133
- _browser.close_tabs(tab_id)
134
- return {
135
- "content": [{
136
- "type": "text",
137
- "text": json.dumps({
138
- "message": f"已将tab页:【{tab_id}】关闭",
139
- }, ensure_ascii=False)
140
- }]
141
- }
142
-
143
-
144
- @mcp.tool(name="check_selector", description="查找tab页中是否包含元素")
145
- async def check_selector(browser_port: int, tab_id: str, css_selector: str) -> dict[str, Any]:
146
- _browser = get_page(browser_port)
147
- target_tab = _browser.get_tab(tab_id)
148
- css_selector = css_selector
149
- if "css:" not in css_selector:
150
- css_selector = "css:" + css_selector
151
- target_ele = target_tab.ele(css_selector)
152
- return {
60
+ def register_visit_url(mcp: FastMCP):
61
+ @mcp.tool(name="visit_url", description="使用Drissionpage打开url访问某个网站")
62
+ async def visit_url(url: str) -> dict[str, Any]:
63
+ port, _browser = create_browser()
64
+ tab = _browser.get_tab()
65
+ tab.get(url)
66
+ tab_id = tab.tab_id
67
+ return {
68
+ "content": [{
69
+ "type": "text",
70
+ "text": json.dumps({
71
+ "message": f"已在[{port}]端口创建浏览器对象,并已打开链接:{url}",
72
+ "tab_id": tab_id,
73
+ "browser_port": port,
74
+ }, ensure_ascii=False)
75
+ }]
76
+ }
77
+
78
+ def register_get_html(mcp: FastMCP):
79
+ @mcp.tool(name="get_html", description="使用Drissionpage获取某一个tab页的html")
80
+ async def get_html(browser_port: int, tab_id: str) -> dict[str, Any]:
81
+ _browser = get_page(browser_port)
82
+ tab = _browser.get_tab(tab_id)
83
+ file_name = tab.title + f"_{tab_id}.html"
84
+ abs_path = os.path.join(html_source_code_local_save_path, file_name)
85
+ with open(abs_path, "w", encoding="utf-8") as f:
86
+ f.write(compress_html(tab.html))
87
+ return {
88
+ "content": [{
89
+ "type": "text",
90
+ "text": json.dumps({
91
+ "message": f"已保存tab页:【{tab_id}】的html源码",
92
+ "tab_id": tab_id,
93
+ "html_local_path": abs_path
94
+ }, ensure_ascii=False)
95
+ }]
96
+ }
97
+
98
+ def register_get_new_tab(mcp: FastMCP):
99
+ @mcp.tool(name="get_new_tab", description="使用Drissionpage创建一个新的tab页,在新的tab页中打开url")
100
+ async def get_new_tab(browser_port: int, url: str) -> dict[str, Any]:
101
+ _browser = get_page(browser_port)
102
+ tab = _browser.new_tab(url)
103
+ _browser.activate_tab(tab)
104
+ tab_id = tab.tab_id
105
+ return {
106
+ "content": [{
107
+ "type": "text",
108
+ "text": json.dumps({
109
+ "message": f"已创建新的tab页,并打开链接:{url}",
110
+ "tab_id": tab_id,
111
+ }, ensure_ascii=False)
112
+ }]
113
+ }
114
+
115
+ def register_switch_tab(mcp: FastMCP):
116
+ @mcp.tool(name="switch_tab", description="根据传入的tab_id切换到对应的tab页", )
117
+ async def switch_tab(browser_port: int, tab_id: str) -> dict[str, Any]:
118
+ _browser = get_page(browser_port)
119
+ _browser.activate_tab(tab_id)
120
+ return {
121
+ "content": [{
122
+ "type": "text",
123
+ "text": json.dumps({
124
+ "message": f"已将tab页:【{tab_id}】切换至最前端",
125
+ }, ensure_ascii=False)
126
+ }]
127
+ }
128
+
129
+ def register_close_tab(mcp: FastMCP):
130
+ @mcp.tool(name="close_tab", description="根据传入的tab_id关闭tab页", )
131
+ async def close_tab(browser_port, tab_id) -> dict[str, Any]:
132
+ _browser = get_page(browser_port)
133
+ _browser.close_tabs(tab_id)
134
+ return {
135
+ "content": [{
136
+ "type": "text",
137
+ "text": json.dumps({
138
+ "message": f"已将tab页:【{tab_id}】关闭",
139
+ }, ensure_ascii=False)
140
+ }]
141
+ }
142
+
143
+ def register_check_selector(mcp: FastMCP):
144
+ @mcp.tool(name="check_selector", description="查找tab页中是否包含元素")
145
+ async def check_selector(browser_port: int, tab_id: str, css_selector: str) -> dict[str, Any]:
146
+ _browser = get_page(browser_port)
147
+ target_tab = _browser.get_tab(tab_id)
148
+ css_selector = css_selector
149
+ if "css:" not in css_selector:
150
+ css_selector = "css:" + css_selector
151
+ target_ele = target_tab.ele(css_selector)
152
+ return {
153
153
  "content": [{
154
154
  "type": "text",
155
155
  "text": json.dumps({
@@ -162,9 +162,9 @@ async def check_selector(browser_port: int, tab_id: str, css_selector: str) -> d
162
162
  }
163
163
 
164
164
 
165
- def main():
166
- mcp.run()
167
-
168
-
169
- if __name__ == '__main__':
170
- main()
165
+ # def main():
166
+ # mcp.run()
167
+ #
168
+ #
169
+ # if __name__ == '__main__':
170
+ # main()
mcp_tools/main.py ADDED
@@ -0,0 +1,19 @@
1
+ # main.py
2
+ import os
3
+ from src.mcp_tools.dp_tools import *
4
+ from fastmcp import FastMCP
5
+
6
+ mcp = FastMCP("Jarvis Brain DrissionPage mcp")
7
+
8
+ # 根据环境变量加载模块
9
+ enabled_modules = os.getenv("MCP_MODULES", "DrissionPage").split(",")
10
+
11
+ if "DrissionPage" in enabled_modules:
12
+ register_visit_url(mcp)
13
+
14
+
15
+ # if "api" in enabled_modules:
16
+ # register_api_tools(mcp)
17
+
18
+ def main():
19
+ mcp.run()
@@ -1,6 +0,0 @@
1
- mcp_tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- mcp_tools/dp_tools.py,sha256=hnxybSDa8KWEFYfrfFqMNbnO9f3VQNUhZFK-L1F34IM,5505
3
- jarvis_brain-0.0.1.dist-info/METADATA,sha256=ipfhv5W4pSRBTQNwBHTTECNp0wKFoxJF9pjXy8-RUPk,176
4
- jarvis_brain-0.0.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
5
- jarvis_brain-0.0.1.dist-info/entry_points.txt,sha256=_6gPuZq_ipnObk2O6CtFIRWmUQrUIDGc_NcdNNhuOr0,54
6
- jarvis_brain-0.0.1.dist-info/RECORD,,
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- jarvis-dp = mcp_tools.dp_tools:main