mcp-query-table 0.3.3__tar.gz → 0.3.4__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.
Files changed (25) hide show
  1. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/PKG-INFO +1 -1
  2. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/mcp_query_table/__init__.py +2 -1
  3. mcp_query_table-0.3.4/mcp_query_table/_version.py +1 -0
  4. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/mcp_query_table/providers/baidu.py +19 -5
  5. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/mcp_query_table/providers/n.py +1 -1
  6. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/mcp_query_table/providers/yuanbao.py +5 -10
  7. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/mcp_query_table/tool.py +19 -1
  8. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/mcp_query_table.egg-info/PKG-INFO +1 -1
  9. mcp_query_table-0.3.3/mcp_query_table/_version.py +0 -1
  10. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/LICENSE +0 -0
  11. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/README.md +0 -0
  12. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/mcp_query_table/__main__.py +0 -0
  13. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/mcp_query_table/enums.py +0 -0
  14. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/mcp_query_table/providers/__init__.py +0 -0
  15. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/mcp_query_table/server.py +0 -0
  16. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/mcp_query_table/sites/__init__.py +0 -0
  17. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/mcp_query_table/sites/eastmoney.py +0 -0
  18. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/mcp_query_table/sites/iwencai.py +0 -0
  19. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/mcp_query_table/sites/tdx.py +0 -0
  20. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/mcp_query_table.egg-info/SOURCES.txt +0 -0
  21. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/mcp_query_table.egg-info/dependency_links.txt +0 -0
  22. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/mcp_query_table.egg-info/requires.txt +0 -0
  23. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/mcp_query_table.egg-info/top_level.txt +0 -0
  24. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/pyproject.toml +0 -0
  25. {mcp_query_table-0.3.3 → mcp_query_table-0.3.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mcp_query_table
3
- Version: 0.3.3
3
+ Version: 0.3.4
4
4
  Summary: query table from website, support MCP
5
5
  Author-email: wukan <wu-kan@163.com>
6
6
  License: MIT License
@@ -3,4 +3,5 @@ from ._version import __version__
3
3
  from .enums import QueryType, Site, Provider
4
4
  from .tool import BrowserManager, query, chat
5
5
 
6
- TIMEOUT = 1000 * 60 * 2 # 2分钟,在抓取EventStream数据时等待数据返回,防止外层30秒超时
6
+ TIMEOUT = 1000 * 60 * 3 # 3分钟,在抓取EventStream数据时等待数据返回,防止外层30秒超时
7
+ TIMEOUT_60 = 1000 * 60 # 1分钟
@@ -0,0 +1 @@
1
+ __version__ = "0.3.4"
@@ -5,14 +5,14 @@
5
5
  """
6
6
  import json
7
7
 
8
- from loguru import logger
9
8
  from playwright.async_api import Page
10
9
 
11
10
  import mcp_query_table
12
- from mcp_query_table.tool import GlobalVars
11
+ from mcp_query_table.tool import GlobalVars, split_images
13
12
 
14
13
  _PAGE0_ = "https://chat.baidu.com/search"
15
14
  _PAGE1_ = "https://chat.baidu.com/aichat/api/conversation"
15
+ _PAGE2_ = "https://chat.baidu.com/aichat/api/file/upload"
16
16
 
17
17
  G = GlobalVars()
18
18
 
@@ -69,16 +69,30 @@ async def chat(page: Page,
69
69
  create: bool,
70
70
  files: list[str],
71
71
  ) -> str:
72
+ async def on_file_chooser(file_chooser):
73
+ # 文件选择对话框
74
+ await file_chooser.set_files(files)
75
+
72
76
  if not page.url.startswith(_PAGE0_):
73
77
  create = True
74
78
 
75
79
  if create:
76
80
  await page.goto(_PAGE0_)
77
81
 
82
+ # 文件上传
78
83
  if len(files) > 0:
79
- # TODO
80
- logger.warning("抱歉,百度AI搜索的上传文件功能未突破")
81
-
84
+ imgs, docs = split_images(files)
85
+ assert len(imgs) == 0 or len(docs) == 0, "不能同时包含图片和文档"
86
+
87
+ page.on("filechooser", on_file_chooser)
88
+ async with page.expect_response(f"{_PAGE2_}*", timeout=mcp_query_table.TIMEOUT_60) as response_info:
89
+ if len(imgs) > 0:
90
+ await page.locator(".cs-input-upload-icon").last.click()
91
+ else:
92
+ await page.locator(".cs-input-upload-icon").first.click()
93
+ page.remove_listener("filechooser", on_file_chooser)
94
+
95
+ # 提交问题
82
96
  await page.route(_PAGE1_, on_route)
83
97
  async with page.expect_response(_PAGE1_, timeout=mcp_query_table.TIMEOUT) as response_info:
84
98
  await page.locator("#chat-input-box").fill(prompt)
@@ -93,7 +93,7 @@ async def chat(page: Page,
93
93
  await page.goto(_PAGE0_)
94
94
  if len(files) > 0:
95
95
  # 只能在新会话中上传文件
96
- async with page.expect_response(_PAGE3_, timeout=mcp_query_table.TIMEOUT) as response_info:
96
+ async with page.expect_response(_PAGE3_, timeout=mcp_query_table.TIMEOUT_60) as response_info:
97
97
  await page.locator("input[type=\"file\"]").set_input_files(files)
98
98
  else:
99
99
  name = "提出后续问题,Enter发送,Shift+Enter 换行"
@@ -7,7 +7,7 @@ import re
7
7
  from playwright.async_api import Page
8
8
 
9
9
  import mcp_query_table
10
- from mcp_query_table.tool import GlobalVars, is_image
10
+ from mcp_query_table.tool import GlobalVars, split_images
11
11
 
12
12
  _PAGE0_ = "https://yuanbao.tencent.com/"
13
13
  _PAGE1_ = "https://yuanbao.tencent.com/api/chat"
@@ -76,20 +76,15 @@ async def chat(page: Page,
76
76
  await page.goto(_PAGE0_)
77
77
 
78
78
  if len(files) > 0:
79
- is_img, is_doc = False, False
80
- for f in files:
81
- if is_image(f):
82
- is_img = True
83
- else:
84
- is_doc = True
85
- assert is_img ^ is_doc, "不能同时包含图片和文档"
79
+ imgs, docs = split_images(files)
80
+ assert len(imgs) == 0 or len(docs) == 0, "不能同时包含图片和文档"
86
81
 
87
82
  # 点击上传文件按钮,才会出现上传文件的input
88
83
  await page.get_by_role("button").filter(has_text=re.compile(r"^$")).last.click()
89
84
 
90
85
  # 上传文件
91
- async with page.expect_response(_PAGE2_, timeout=mcp_query_table.TIMEOUT) as response_info:
92
- if is_img:
86
+ async with page.expect_response(_PAGE2_, timeout=mcp_query_table.TIMEOUT_60) as response_info:
87
+ if len(imgs) > 0:
93
88
  await page.locator("input[type=\"file\"]").nth(-2).set_input_files(files)
94
89
  else:
95
90
  await page.locator("input[type=\"file\"]").last.set_input_files(files)
@@ -2,7 +2,7 @@ import subprocess
2
2
  import sys
3
3
  import time
4
4
  from pathlib import Path
5
- from typing import Optional
5
+ from typing import Optional, List, Tuple
6
6
 
7
7
  import pandas as pd
8
8
  from loguru import logger
@@ -142,6 +142,12 @@ class BrowserManager:
142
142
  # 防止开发者工具被使用
143
143
  if page.url.startswith("devtools://"):
144
144
  continue
145
+ # 防止chrome扩展被使用
146
+ if page.url.startswith("chrome-extension://"):
147
+ continue
148
+ # 防止edge扩展被使用
149
+ if page.url.startswith("extension://"):
150
+ continue
145
151
  self.pages.append(page)
146
152
 
147
153
  async def _try_launch(self) -> None:
@@ -275,3 +281,15 @@ def is_image(path: str) -> bool:
275
281
  img_ext = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp']
276
282
  ext = Path(path).suffix.lower()
277
283
  return ext in img_ext
284
+
285
+
286
+ def split_images(files: List[str]) -> Tuple[List[str], List[str]]:
287
+ """图片列表分成两部分"""
288
+ imgs = []
289
+ docs = []
290
+ for f in files:
291
+ if is_image(f):
292
+ imgs.append(f)
293
+ else:
294
+ docs.append(f)
295
+ return imgs, docs
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mcp_query_table
3
- Version: 0.3.3
3
+ Version: 0.3.4
4
4
  Summary: query table from website, support MCP
5
5
  Author-email: wukan <wu-kan@163.com>
6
6
  License: MIT License
@@ -1 +0,0 @@
1
- __version__ = "0.3.3"
File without changes