mcp-query-table 0.3.4__tar.gz → 0.3.6__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.4 → mcp_query_table-0.3.6}/PKG-INFO +16 -3
  2. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/README.md +15 -2
  3. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/mcp_query_table/__main__.py +2 -2
  4. mcp_query_table-0.3.6/mcp_query_table/_version.py +1 -0
  5. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/mcp_query_table/server.py +10 -11
  6. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/mcp_query_table/sites/iwencai.py +1 -0
  7. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/mcp_query_table/sites/tdx.py +1 -1
  8. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/mcp_query_table/tool.py +26 -11
  9. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/mcp_query_table.egg-info/PKG-INFO +16 -3
  10. mcp_query_table-0.3.4/mcp_query_table/_version.py +0 -1
  11. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/LICENSE +0 -0
  12. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/mcp_query_table/__init__.py +0 -0
  13. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/mcp_query_table/enums.py +0 -0
  14. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/mcp_query_table/providers/__init__.py +0 -0
  15. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/mcp_query_table/providers/baidu.py +0 -0
  16. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/mcp_query_table/providers/n.py +0 -0
  17. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/mcp_query_table/providers/yuanbao.py +0 -0
  18. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/mcp_query_table/sites/__init__.py +0 -0
  19. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/mcp_query_table/sites/eastmoney.py +0 -0
  20. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/mcp_query_table.egg-info/SOURCES.txt +0 -0
  21. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/mcp_query_table.egg-info/dependency_links.txt +0 -0
  22. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/mcp_query_table.egg-info/requires.txt +0 -0
  23. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/mcp_query_table.egg-info/top_level.txt +0 -0
  24. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/pyproject.toml +0 -0
  25. {mcp_query_table-0.3.4 → mcp_query_table-0.3.6}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mcp_query_table
3
- Version: 0.3.4
3
+ Version: 0.3.6
4
4
  Summary: query table from website, support MCP
5
5
  Author-email: wukan <wu-kan@163.com>
6
6
  License: MIT License
@@ -70,7 +70,7 @@ from mcp_query_table import *
70
70
 
71
71
 
72
72
  async def main() -> None:
73
- async with BrowserManager(cdp_endpoint="http://127.0.0.1:9222", executable_path=None, debug=True) as bm:
73
+ async with BrowserManager(endpoint="http://127.0.0.1:9222", executable_path=None, debug=True) as bm:
74
74
  # 问财需要保证浏览器宽度>768,防止界面变成适应手机
75
75
  page = await bm.get_page()
76
76
  df = await query(page, '收益最好的200只ETF', query_type=QueryType.ETF, max_page=1, site=Site.THS)
@@ -135,6 +135,13 @@ if __name__ == '__main__':
135
135
  在`Cline`中可以配置如下。其中`command`是`python`的绝对路径,`executable_path`是`Chrome`的绝对路径,`timeout`是超时时间,单位为秒。
136
136
  在各`AI`平台中由于返回时间常需1分钟以上,所以需要设置大的超时时间。
137
137
 
138
+ `endpoint`支持两方式,一种是`cdp_endpoint`方式,一种是`ws_endpoint`方式。
139
+
140
+ - cdp方式:通过启动时加参数`--remote-debugging-port=9222`来启动浏览器
141
+ - ws方式:服务器上`docker run -p 3000:3000 --rm --init -it --workdir /home/pwuser --user pwuser mcr.microsoft.com/playwright:v1.51.0-noble /bin/sh -c "npx -y playwright@1.51.0 run-server --port 3000 --host 0.0.0.0"`
142
+
143
+ 参考:https://playwright.dev/python/docs/docker#remote-connection
144
+
138
145
  ### STDIO方式
139
146
 
140
147
  ```json
@@ -148,7 +155,7 @@ if __name__ == '__main__':
148
155
  "mcp_query_table",
149
156
  "--format",
150
157
  "markdown",
151
- "--cdp_endpoint",
158
+ "--endpoint",
152
159
  "http://127.0.0.1:9222",
153
160
  "--executable_path",
154
161
  "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
@@ -205,6 +212,12 @@ npx @modelcontextprotocol/inspector python -m mcp_query_table --format markdown
205
212
  - 向东方财富板块查询 “去年涨的最差的行业板块”,再查询此板块中去年涨的最好的5只股票
206
213
  > 分成两步查询,先查询板块,再查询股票。但最好不要全自动,因为第一步的结果它不理解“今日涨幅”和“区间涨幅”,需要交互修正
207
214
 
215
+ ## 支持`Streamlit`
216
+
217
+ 实现在同一页面中查询金融数据,并手工输入到`AI`中进行深度分析。参考`streamlit`目录下的`README.md`文件。
218
+
219
+ ![streamlit](docs/img/streamlit.png)
220
+
208
221
  ## 参考
209
222
 
210
223
  - [Playwright](https://playwright.dev/python/docs/intro)
@@ -31,7 +31,7 @@ from mcp_query_table import *
31
31
 
32
32
 
33
33
  async def main() -> None:
34
- async with BrowserManager(cdp_endpoint="http://127.0.0.1:9222", executable_path=None, debug=True) as bm:
34
+ async with BrowserManager(endpoint="http://127.0.0.1:9222", executable_path=None, debug=True) as bm:
35
35
  # 问财需要保证浏览器宽度>768,防止界面变成适应手机
36
36
  page = await bm.get_page()
37
37
  df = await query(page, '收益最好的200只ETF', query_type=QueryType.ETF, max_page=1, site=Site.THS)
@@ -96,6 +96,13 @@ if __name__ == '__main__':
96
96
  在`Cline`中可以配置如下。其中`command`是`python`的绝对路径,`executable_path`是`Chrome`的绝对路径,`timeout`是超时时间,单位为秒。
97
97
  在各`AI`平台中由于返回时间常需1分钟以上,所以需要设置大的超时时间。
98
98
 
99
+ `endpoint`支持两方式,一种是`cdp_endpoint`方式,一种是`ws_endpoint`方式。
100
+
101
+ - cdp方式:通过启动时加参数`--remote-debugging-port=9222`来启动浏览器
102
+ - ws方式:服务器上`docker run -p 3000:3000 --rm --init -it --workdir /home/pwuser --user pwuser mcr.microsoft.com/playwright:v1.51.0-noble /bin/sh -c "npx -y playwright@1.51.0 run-server --port 3000 --host 0.0.0.0"`
103
+
104
+ 参考:https://playwright.dev/python/docs/docker#remote-connection
105
+
99
106
  ### STDIO方式
100
107
 
101
108
  ```json
@@ -109,7 +116,7 @@ if __name__ == '__main__':
109
116
  "mcp_query_table",
110
117
  "--format",
111
118
  "markdown",
112
- "--cdp_endpoint",
119
+ "--endpoint",
113
120
  "http://127.0.0.1:9222",
114
121
  "--executable_path",
115
122
  "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
@@ -166,6 +173,12 @@ npx @modelcontextprotocol/inspector python -m mcp_query_table --format markdown
166
173
  - 向东方财富板块查询 “去年涨的最差的行业板块”,再查询此板块中去年涨的最好的5只股票
167
174
  > 分成两步查询,先查询板块,再查询股票。但最好不要全自动,因为第一步的结果它不理解“今日涨幅”和“区间涨幅”,需要交互修正
168
175
 
176
+ ## 支持`Streamlit`
177
+
178
+ 实现在同一页面中查询金融数据,并手工输入到`AI`中进行深度分析。参考`streamlit`目录下的`README.md`文件。
179
+
180
+ ![streamlit](docs/img/streamlit.png)
181
+
169
182
  ## 参考
170
183
 
171
184
  - [Playwright](https://playwright.dev/python/docs/intro)
@@ -10,7 +10,7 @@ def main():
10
10
 
11
11
  parser.add_argument("--format", type=str, help="输出格式",
12
12
  default='markdown', choices=['markdown', 'csv', 'json'])
13
- parser.add_argument("--cdp_endpoint", type=str, help="浏览器CDP调试地址",
13
+ parser.add_argument("--endpoint", type=str, help="浏览器CDP地址/WS地址",
14
14
  default="http://127.0.0.1:9222")
15
15
  parser.add_argument("--executable_path", type=str, help="浏览器类型",
16
16
  default=r'C:\Program Files\Google\Chrome\Application\chrome.exe')
@@ -22,7 +22,7 @@ def main():
22
22
  parser.add_argument("--port", type=int, help="MCP服务端绑定端口",
23
23
  default='8000')
24
24
  args = parser.parse_args()
25
- serve(args.format, args.cdp_endpoint, args.executable_path,
25
+ serve(args.format, args.endpoint, args.executable_path,
26
26
  args.transport, args.host, args.port)
27
27
 
28
28
 
@@ -0,0 +1 @@
1
+ __version__ = "0.3.6"
@@ -1,4 +1,4 @@
1
- from typing import Annotated, Optional, List
1
+ from typing import Annotated, List
2
2
 
3
3
  from loguru import logger
4
4
  from mcp.server.fastmcp import FastMCP
@@ -10,12 +10,13 @@ from mcp_query_table.tool import BrowserManager
10
10
 
11
11
 
12
12
  class QueryServer:
13
- def __init__(self,
14
- format: str = 'markdown',
15
- cdp_endpoint: Optional[str] = 'http://127.0.0.1:9222',
16
- executable_path: Optional[str] = None) -> None:
13
+ def __init__(self) -> None:
14
+ self.format: str = "markdown"
15
+ self.browser = None
16
+
17
+ def start(self, format, endpoint, executable_path):
17
18
  self.format: str = format
18
- self.browser = BrowserManager(cdp_endpoint=cdp_endpoint, executable_path=executable_path, debug=False)
19
+ self.browser = BrowserManager(endpoint=endpoint, executable_path=executable_path, debug=False)
19
20
 
20
21
  async def query(self, query_input: str, query_type: QueryType, max_page: int, site: Site):
21
22
  page = await self.browser.get_page()
@@ -64,12 +65,10 @@ async def chat(
64
65
  return await qsv.chat(prompt, create, files, provider)
65
66
 
66
67
 
67
- def serve(format, cdp_endpoint, executable_path, transport, host, port):
68
- qsv.format = format
69
- qsv.cdp_endpoint = cdp_endpoint
70
- qsv.executable_path = executable_path
68
+ def serve(format, endpoint, executable_path, transport, host, port):
69
+ qsv.start(format, endpoint, executable_path)
71
70
  logger.info(f"{format=},{transport=}")
72
- logger.info(f"{cdp_endpoint=},{executable_path=}")
71
+ logger.info(f"{endpoint=},{executable_path=}")
73
72
  if transport == 'sse':
74
73
  logger.info(f"{host=},{port=}", transport, host, port)
75
74
 
@@ -140,6 +140,7 @@ json_data['answer']['components'][0]['data']['meta']['extra']['row_count']
140
140
 
141
141
  async def on_response(response):
142
142
  if response.url == _PAGE1_:
143
+ # TODO 不支持headless模式,需要以后解决
143
144
  P.update(*get_robot_data(await response.json()))
144
145
  if response.url == _PAGE2_:
145
146
  P.update(*getDataList(await response.json()))
@@ -21,7 +21,7 @@ _queryType_ = {
21
21
  QueryType.Fund: 'JJ',
22
22
  QueryType.Index: 'ZS',
23
23
  QueryType.Info: 'ZX',
24
- QueryType.Board: 'ZX', # 板块也走指数
24
+ QueryType.Board: 'ZS', # 板块也走指数
25
25
  }
26
26
 
27
27
 
@@ -3,6 +3,7 @@ import sys
3
3
  import time
4
4
  from pathlib import Path
5
5
  from typing import Optional, List, Tuple
6
+ from urllib.parse import urlparse
6
7
 
7
8
  import pandas as pd
8
9
  from loguru import logger
@@ -36,6 +37,13 @@ def is_local_url(url: str) -> bool:
36
37
  return False
37
38
 
38
39
 
40
+ def is_cdp_url(url: str) -> bool:
41
+ """判断url是否是CDP地址"""
42
+ if url.startswith('ws://') or url.startswith('wss://'):
43
+ return False
44
+ return True
45
+
46
+
39
47
  def get_executable_path(executable_path) -> Optional[str]:
40
48
  """获取浏览器可执行文件路径"""
41
49
  browsers = {
@@ -59,22 +67,22 @@ class BrowserManager:
59
67
  await self.cleanup()
60
68
 
61
69
  def __init__(self,
62
- cdp_endpoint: Optional[str] = None,
70
+ endpoint: Optional[str] = None,
63
71
  executable_path: Optional[str] = None,
64
72
  debug: bool = False):
65
73
  """
66
74
 
67
75
  Parameters
68
76
  ----------
69
- cdp_endpoint:str
70
- 浏览器CDP地址
77
+ endpoint:str
78
+ 浏览器CDP地址/WS地址
71
79
  executable_path:str
72
80
  浏览器可执行文件路径。推荐使用chrome,因为Microsoft Edge必须在任务管理器中完全退出才能启动调试端口
73
81
  debug:bool
74
82
  是否显示开发者工具
75
83
 
76
84
  """
77
- self.cdp_endpoint = cdp_endpoint or 'http://127.0.0.1:9222'
85
+ self.endpoint = endpoint or 'http://127.0.0.1:9222'
78
86
  self.executable_path = executable_path
79
87
  self.debug = debug
80
88
 
@@ -92,7 +100,7 @@ class BrowserManager:
92
100
 
93
101
  async def _connect_to_local(self) -> None:
94
102
  """连接本地浏览器"""
95
- port = self.cdp_endpoint.split(':')[-1]
103
+ port = urlparse(self.endpoint).port
96
104
  executable_path = get_executable_path(self.executable_path)
97
105
  command = [executable_path, f'--remote-debugging-port={port}', '--start-maximized']
98
106
  if self.debug:
@@ -100,7 +108,7 @@ class BrowserManager:
100
108
 
101
109
  for i in range(2):
102
110
  try:
103
- self.browser = await self.playwright.chromium.connect_over_cdp(self.cdp_endpoint,
111
+ self.browser = await self.playwright.chromium.connect_over_cdp(self.endpoint,
104
112
  timeout=10000, slow_mo=1000)
105
113
  break
106
114
  except:
@@ -116,10 +124,14 @@ class BrowserManager:
116
124
  async def _connect_to_remote(self) -> None:
117
125
  """连接远程浏览器"""
118
126
  try:
119
- self.browser = await self.playwright.chromium.connect_over_cdp(self.cdp_endpoint,
120
- timeout=10000, slow_mo=1000)
127
+ if is_cdp_url(self.endpoint):
128
+ self.browser = await self.playwright.chromium.connect_over_cdp(self.endpoint,
129
+ timeout=10000, slow_mo=1000)
130
+ else:
131
+ self.browser = await self.playwright.chromium.connect(self.endpoint,
132
+ timeout=10000, slow_mo=1000)
121
133
  except:
122
- raise ConnectionError(f"连接远程浏览器失败,请检查CDP地址和端口是否正确。{self.cdp_endpoint}")
134
+ raise ConnectionError(f"连接远程浏览器失败,请检查CDP/WS地址和端口是否正确。{self.endpoint}")
123
135
 
124
136
  async def _launch(self) -> None:
125
137
  """启动浏览器,并连接CDP协议
@@ -131,12 +143,15 @@ class BrowserManager:
131
143
  """
132
144
  self.playwright = await async_playwright().start()
133
145
 
134
- if is_local_url(self.cdp_endpoint):
146
+ if is_local_url(self.endpoint) and is_cdp_url(self.endpoint):
135
147
  await self._connect_to_local()
136
148
  else:
137
149
  await self._connect_to_remote()
138
150
 
139
- self.context = self.browser.contexts[0]
151
+ if len(self.browser.contexts) == 0:
152
+ self.context = await self.browser.new_context()
153
+ else:
154
+ self.context = self.browser.contexts[0]
140
155
  # 复用打开的page
141
156
  for page in self.context.pages:
142
157
  # 防止开发者工具被使用
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mcp_query_table
3
- Version: 0.3.4
3
+ Version: 0.3.6
4
4
  Summary: query table from website, support MCP
5
5
  Author-email: wukan <wu-kan@163.com>
6
6
  License: MIT License
@@ -70,7 +70,7 @@ from mcp_query_table import *
70
70
 
71
71
 
72
72
  async def main() -> None:
73
- async with BrowserManager(cdp_endpoint="http://127.0.0.1:9222", executable_path=None, debug=True) as bm:
73
+ async with BrowserManager(endpoint="http://127.0.0.1:9222", executable_path=None, debug=True) as bm:
74
74
  # 问财需要保证浏览器宽度>768,防止界面变成适应手机
75
75
  page = await bm.get_page()
76
76
  df = await query(page, '收益最好的200只ETF', query_type=QueryType.ETF, max_page=1, site=Site.THS)
@@ -135,6 +135,13 @@ if __name__ == '__main__':
135
135
  在`Cline`中可以配置如下。其中`command`是`python`的绝对路径,`executable_path`是`Chrome`的绝对路径,`timeout`是超时时间,单位为秒。
136
136
  在各`AI`平台中由于返回时间常需1分钟以上,所以需要设置大的超时时间。
137
137
 
138
+ `endpoint`支持两方式,一种是`cdp_endpoint`方式,一种是`ws_endpoint`方式。
139
+
140
+ - cdp方式:通过启动时加参数`--remote-debugging-port=9222`来启动浏览器
141
+ - ws方式:服务器上`docker run -p 3000:3000 --rm --init -it --workdir /home/pwuser --user pwuser mcr.microsoft.com/playwright:v1.51.0-noble /bin/sh -c "npx -y playwright@1.51.0 run-server --port 3000 --host 0.0.0.0"`
142
+
143
+ 参考:https://playwright.dev/python/docs/docker#remote-connection
144
+
138
145
  ### STDIO方式
139
146
 
140
147
  ```json
@@ -148,7 +155,7 @@ if __name__ == '__main__':
148
155
  "mcp_query_table",
149
156
  "--format",
150
157
  "markdown",
151
- "--cdp_endpoint",
158
+ "--endpoint",
152
159
  "http://127.0.0.1:9222",
153
160
  "--executable_path",
154
161
  "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
@@ -205,6 +212,12 @@ npx @modelcontextprotocol/inspector python -m mcp_query_table --format markdown
205
212
  - 向东方财富板块查询 “去年涨的最差的行业板块”,再查询此板块中去年涨的最好的5只股票
206
213
  > 分成两步查询,先查询板块,再查询股票。但最好不要全自动,因为第一步的结果它不理解“今日涨幅”和“区间涨幅”,需要交互修正
207
214
 
215
+ ## 支持`Streamlit`
216
+
217
+ 实现在同一页面中查询金融数据,并手工输入到`AI`中进行深度分析。参考`streamlit`目录下的`README.md`文件。
218
+
219
+ ![streamlit](docs/img/streamlit.png)
220
+
208
221
  ## 参考
209
222
 
210
223
  - [Playwright](https://playwright.dev/python/docs/intro)
@@ -1 +0,0 @@
1
- __version__ = "0.3.4"
File without changes