mcp_query_table logo

mcp_query_table

Community
wukan1986

query table from some websites, support MCP

Publisherwukan1986
Repositorymcp_query_table
LanguagePython
Forks
20
Stars
57
Available tools
0
Transport typestdio, streamable-http
Categories
LicenseMIT
Links
  • Connect tools to AI workflows

    mcp_query_table exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 0 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    57 stars and 20 forks from the linked repository.

mcp_query_table

  1. 基于playwright实现的财经网页表格爬虫,支持Model Context Protocol (MCP) 。目前可查询来源为

    实盘时,如果某网站宕机或改版,可以立即切换到其他网站。(注意:不同网站的表格结构不同,需要提前做适配)

  2. 基于playwright实现的大语言模型调用爬虫。目前可用来源为

    RooCode提供了Human Reply功能。但发现纳米搜索网页版复制时格式破坏,所以研发了此功能

安装

commandline
pip install -i https://pypi.org/simple --upgrade mcp_query_table
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade mcp_query_table

使用

python
import asyncio

from mcp_query_table import *


async def main() -> None:
    async with BrowserManager(endpoint="http://127.0.0.1:9222", executable_path=None, devtools=True) as bm:
        # 问财需要保证浏览器宽度>768,防止界面变成适应手机
        page = await bm.get_page()
        df = await query(page, '收益最好的200只ETF', query_type=QueryType.ETF, max_page=1, site=Site.THS)
        print(df.to_markdown())
        df = await query(page, '年初至今收益率前50', query_type=QueryType.Fund, max_page=1, site=Site.TDX)
        print(df.to_csv())
        df = await query(page, '流通市值前10的行业板块', query_type=QueryType.Index, max_page=1, site=Site.TDX)
        print(df.to_csv())
        # TODO 东财翻页要提前登录
        df = await query(page, '今日涨幅前5的概念板块;', query_type=QueryType.Board, max_page=3, site=Site.EastMoney)
        print(df)

        output = await chat(page, "1+2等于多少?", provider=Provider.YuanBao)
        print(output)
        output = await chat(page, "3+4等于多少?", provider=Provider.YuanBao, create=True)
        print(output)

        print('done')
        bm.release_page(page)
        await page.wait_for_timeout(2000)


if __name__ == '__main__':
    asyncio.run(main())

注意事项

  1. 浏览器最好是Chrome。如一定要使用Edge,除了关闭Edge所有窗口外,还要在任务管理器关闭Microsoft Edge 的所有进程,即taskkill /f /im msedge.exe
  2. 浏览器要保证窗口宽度,防止部分网站自动适配成手机版,导致表格查询失败
  3. 如有网站账号,请提前登录。此工具无自动登录功能
  4. 不同网站的表格结构不同,同条件返回股票数量也不同。需要查询后做适配

工作原理

不同于requests,playwright是基于浏览器的,模拟用户在浏览器中的操作。

  1. 不需要解决登录问题
  2. 不需要解决请求构造、响应解析
  3. 可以直接获取表格数据,所见即所得
  4. 运行速度慢于requests,但开发效率高

数据的获取有:

  1. 直接解析HTML表格
    1. 数字文本化了,不利于后期研究
    2. 适用性最强
  2. 截获请求,获取返回的json数据
    1. 类似于requests,需要做响应解析
    2. 灵活性差点,网站改版后,需要重新做适配

此项目采用的是模拟点击浏览器来发送请求,使用截获响应并解析的方法来获取数据。

后期会根据不同的网站改版情况,使用更适合的方法。

无头模式

无头模式运行速度更快,但部分网站需要提前登录,所以,无头模式一定要指定user_data_dir,否则会出现需要登录的情况。

  • endpoint=None时,headless=True可无头启动新浏览器实例。指定executable_path和user_data_dir,才能确保无头模式下正常运行。
  • endpoint以http://开头,连接CDP模式启动的有头浏览器,参数必有--remote-debugging-port。executable_path为本地浏览器路径。
  • endpoint以ws://开头,连接远程Playwright Server。也是无头模式,但无法指定user_data_dir,所以使用受限

Chrome新版的安全策略使用默认user_data_dir时将无法创建CDP服务,建议重新复制配置目录到其他地方

MCP支持

确保可以在控制台中执行python -m mcp_query_table -h。如果不能,可能要先pip install mcp_query_table

在Cline中可以配置如下。其中command是python的绝对路径,timeout是超时时间,单位为秒。 在各AI 平台中由于返回时间常需1分钟以上,所以需要设置大的超时时间。

STDIO方式

json
{
  "mcpServers": {
    "mcp_query_table": {
      "timeout": 300,
      "command": "D:\\Users\\Kan\\miniconda3\\envs\\py312\\python.exe",
      "args": [
        "-m",
        "mcp_query_table",
        "--format",
        "markdown",
        "--endpoint",
        "http://127.0.0.1:9222",
        "--executable_path",
        "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
      ]
    }
  }
}

SSE方式

先在控制台中执行如下命令,启动MCP服务

commandline
python -m mcp_query_table --format markdown --transport sse --port 8000 --endpoint http://127.0.0.1:9222  --user_data_dir "D:\user-data-dir"

然后就可以连接到MCP服务了

json
{
  "mcpServers": {
    "mcp_query_table": {
      "timeout": 300,
      "url": "http://127.0.0.1:8000/sse"
    }
  }
}

Streamable HTTP方式

commandline
python -m mcp_query_table --format markdown --transport streamable-http --port 8000 --endpoint http://127.0.0.1:9222  --user_data_dir "D:\user-data-dir"

连接的地址是http://127.0.0.1:8000/mcp

使用MCP Inspector进行调试

commandline
npx @modelcontextprotocol/inspector python -m mcp_query_table --format markdown --endpoint http://127.0.0.1:9222

打开浏览器并翻页是一个比较耗时的操作,会导致MCP Inspector页面超时,可以http://localhost:5173/?timeout=300000 表示超时时间为300秒

第一次尝试编写MCP项目,可能会有各种问题,欢迎大家交流。

MCP使用技巧

  1. 2024年涨幅最大的100只股票按2024年12月31日总市值排名。三个网站的结果都不一样

    • 同花顺:显示了2201只股票。前5个是工商银行、农业银行、中国移动、中国石油、建设银行
    • 通达信:显示了100只股票,前5个是寒武纪、正丹股份,汇金科技、万丰奥威、艾融软件
    • 东方财富:显示了100只股票,前5个是海光信息、寒武纪、光启技术、润泽科技、新易盛
  2. 大语言模型对问题拆分能力弱,所以要能合理的提问,保证查询条件不会被改动。以下推荐第2、3种

    • 2024年涨幅最大的100只股票按2024年12月31日总市值排名

      大语言模型非常有可能拆分这句,导致一步查询被分成了多步查询

    • 向东方财富查询“2024年涨幅最大的100只股票按2024年12月31日总市值排名”

      用引号括起来,避免被拆分

    • 向东方财富板块查询 “去年涨的最差的行业板块”,再查询此板块中去年涨的最好的5只股票

      分成两步查询,先查询板块,再查询股票。但最好不要全自动,因为第一步的结果它不理解“今日涨幅”和“区间涨幅”,需要交互修正

支持Streamlit

实现在同一页面中查询金融数据,并手工输入到AI中进行深度分析。参考streamlit目录下的README.md文件。

streamlit

参考

Installation

TypingMind
Prerequisites:

Node.js 18+

{
  "mcpServers": {
    "wukan1986-query_table": {
      "command": "uvx",
      "args": [
        "mcp_query_table"
      ]
    }
  }
}

Use mcp_query_table MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once mcp_query_table is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. You can run MCP locally on your device or connect to a remote MCP server URL.

Option 1: Use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add mcp_query_table as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the mcp_query_table MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "wukan1986-query_table": {
      "command": "npx",
      "args": [
        "-y",
        "mcp_query_table"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the mcp_query_table MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the mcp_query_table MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use mcp_query_table to help me with this task?
mcp_query_table
Sure. I read it.
Here is what I found using mcp_query_table.

Option 2: Add an MCP server URL

Use this when mcp_query_table is already hosted remotely or your team wants one shared connector that multiple users can access.

1

Open MCP connectors

In TypingMind, go to Plugins, open MCP connectors, then choose Add URL.

  1. Open TypingMind in your browser.
  2. Go to Plugins.
  3. Open MCP connectors.
  4. Click Add URL.
TypingMind Add Custom MCP Server URL form
2

Paste the server URL

Enter your server URL in the Server URL field. Add a connection name, description, icon, custom HTTP headers, or OAuth client settings if the server requires them.

  1. Paste your server URL into the Server URL field.
  2. Enter a connection name for mcp_query_table.
  3. Add a description and icon if you want it to be easier to identify.
  4. Add custom HTTP headers or OAuth client details if the server requires authentication.
3

Create the connection

Click Create connection, then return to the Plugins list and confirm the new MCP connection is active.

  1. Click Create connection.
  2. Return to the MCP connectors list.
  3. Confirm the mcp_query_table connection appears as active.
  4. Refresh the plugin list if the connection does not appear immediately.
4

Switch models without reconnecting

Start a chat with your preferred model, enable the mcp_query_table tools from Plugins, and switch to another model whenever needed. The MCP connection stays available to the TypingMind workspace.

  1. Start a new chat in TypingMind.
  2. Select the AI model you want to use.
  3. Enable the mcp_query_table tools from Plugins.
  4. Ask the model to use the tool when needed.
  5. Switch to another AI model and reuse the same MCP connection.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use mcp_query_table to help me with this task?
mcp_query_table
Sure. I read it.
Here is what I found using mcp_query_table.

Frequently asked questions

What is the mcp_query_table MCP server used for?

mcp_query_table is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use mcp_query_table MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use mcp_query_table with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use mcp_query_table MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With mcp_query_table connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect mcp_query_table MCP to TypingMind?

mcp_query_table can be connected in TypingMind with the local MCP connector or by adding a remote MCP server URL. Use the local connector when the server needs access to files, apps, or private resources on your device, and use a server URL when the MCP server is hosted remotely.

What tools does mcp_query_table MCP provide in TypingMind?

mcp_query_table exposes MCP capabilities that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use mcp_query_table MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If mcp_query_table requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇