Skip to main content
Glama
Xuzan9396

YST KPI Daily Report Collector

by Xuzan9396

collect_reports

Collect daily report data from KPI systems for a specified month range and output as a structured Markdown file.

Instructions

采集指定月份范围的日报数据

⚠️ 重要:使用前请先确保已登录!

推荐流程:

  1. 先调用 check_login_status 检查登录状态

  2. 如果未登录,调用 browser_login 进行登录

  3. 登录成功后,再调用本工具采集数据

这样可以避免采集过程被登录流程阻塞。

Args: start_month: 起始月份,格式 YYYY-MM (例如: 2025-07) end_month: 结束月份,格式 YYYY-MM (例如: 2025-09) output_file: 输出文件路径(可选,默认为 ~/.yst_mcp/output/new.md 或项目目录下 data/new.md) auto_login: 未登录时是否自动启动浏览器登录(默认 False,不推荐设为 True)

Returns: 采集结果描述

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
start_monthYes
end_monthYes
output_fileNo
auto_loginNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The 'collect_reports' MCP tool handler function. It is decorated with @mcp.tool(), accepts parameters start_month, end_month, output_file, auto_login, performs login checks, and delegates to ReportCollector.collect().
    @mcp.tool()
    async def collect_reports(start_month: str, end_month: str, output_file: str = None, auto_login: bool = False) -> str:
        """
        采集指定月份范围的日报数据
    
        ⚠️ 重要:使用前请先确保已登录!
    
        推荐流程:
        1. 先调用 check_login_status 检查登录状态
        2. 如果未登录,调用 browser_login 进行登录
        3. 登录成功后,再调用本工具采集数据
    
        这样可以避免采集过程被登录流程阻塞。
    
        Args:
            start_month: 起始月份,格式 YYYY-MM (例如: 2025-07)
            end_month: 结束月份,格式 YYYY-MM (例如: 2025-09)
            output_file: 输出文件路径(可选,默认为 ~/.yst_mcp/output/new.md 或项目目录下 data/new.md)
            auto_login: 未登录时是否自动启动浏览器登录(默认 False,不推荐设为 True)
    
        Returns:
            采集结果描述
        """
        collector = ReportCollector()
        cookie_manager = CookieManager()
    
        try:
            # 检查是否有保存的 Cookie
            if cookie_manager.has_cookies():
                collector.load_saved_cookies()
    
            # 检查登录状态
            if not collector.check_login_status():
                if auto_login:
                    print(safe_text("❌ 未登录,正在启动浏览器..."))
                    # 启动浏览器登录
                    browser_login = BrowserLogin()
                    if await browser_login.launch_persistent_browser():
                        # 重新加载 Cookie
                        collector.load_saved_cookies()
                    else:
                        return safe_text("❌ 登录失败或超时,请重试")
                else:
                    return safe_text(
                        "❌ 未登录或 Cookie 已过期\n\n"
                        "请使用以下方法之一:\n"
                        "1. 调用 browser_login 工具启动浏览器登录\n"
                        "2. 将 auto_login 参数设置为 true,自动打开浏览器"
                    )
    
            # 执行采集
            result = await collector.collect(start_month, end_month, output_file)
            return result
        except Exception as e:
            return f"采集失败: {str(e)}"
  • The async collect() method on ReportCollector that does the actual data collection: loads cookies, checks login, generates month ranges, fetches reports per month, and generates a Markdown output file.
    async def collect(self, start_month: str, end_month: str, output_file: str = None) -> str:
        """
        采集指定月份范围的日报并保存
    
        Args:
            start_month: 起始月份
            end_month: 结束月份
            output_file: 输出文件路径(可选,默认使用自动检测的路径)
    
        Returns:
            采集结果描述
        """
        # 处理输出文件路径
        if output_file is None:
            # 使用默认路径
            output_file = str(self.default_output_dir / 'new.md')
        elif not os.path.isabs(output_file):
            # 如果是相对路径,转换为绝对路径(相对于默认输出目录)
            output_file = str(self.default_output_dir / output_file)
    
        # 确保输出目录存在
        output_path = Path(output_file)
        output_path.parent.mkdir(parents=True, exist_ok=True)
    
        # 加载已保存的 Cookie
        if self.cookie_manager.has_cookies():
            self.load_saved_cookies()
    
        # 检查登录状态
        if not self.check_login_status():
            return safe_text(
                "❌ 未登录或登录已过期\n\n"
                "请先使用以下步骤登录:\n"
                "1. 使用 chrome_devtools_mcp 打开登录页面\n"
                f"2. 访问 {self.LOGIN_URL}\n"
                "3. 手动登录\n"
                "4. 登录成功后,使用 save_cookies 工具保存 Cookie\n"
                "5. 重新调用 collect_reports 工具"
            )
    
        # 生成月份范围
        months = self.generate_month_range(start_month, end_month)
    
        # 采集所有月份的数据
        all_reports = {}
        for month in months:
            print(f"正在采集 {month} 月份日报...")
            reports = self.fetch_month_reports(month)
            all_reports[month] = reports
            print(safe_text(f"  ✓ 采集到 {len(reports)} 条日报"))
    
        # 生成 Markdown 文件
        self._generate_markdown(all_reports, output_file)
    
        total_count = sum(len(reports) for reports in all_reports.values())
        return safe_text(f"✓ 采集完成!共采集 {len(months)} 个月份,{total_count} 条日报,已保存到 {output_file}")
  • The function signature and docstring define the input parameters (start_month, end_month, output_file, auto_login) and the output (str) for the collect_reports tool.
    @mcp.tool()
    async def collect_reports(start_month: str, end_month: str, output_file: str = None, auto_login: bool = False) -> str:
        """
        采集指定月份范围的日报数据
    
        ⚠️ 重要:使用前请先确保已登录!
    
        推荐流程:
        1. 先调用 check_login_status 检查登录状态
        2. 如果未登录,调用 browser_login 进行登录
        3. 登录成功后,再调用本工具采集数据
    
        这样可以避免采集过程被登录流程阻塞。
    
        Args:
            start_month: 起始月份,格式 YYYY-MM (例如: 2025-07)
            end_month: 结束月份,格式 YYYY-MM (例如: 2025-09)
            output_file: 输出文件路径(可选,默认为 ~/.yst_mcp/output/new.md 或项目目录下 data/new.md)
            auto_login: 未登录时是否自动启动浏览器登录(默认 False,不推荐设为 True)
    
        Returns:
            采集结果描述
        """
  • fetch_month_reports (line 168-201) helper that fetches daily reports for a given month using requests/BeautifulSoup and parses the HTML list.
    def fetch_month_reports(self, month: str) -> List[Dict]:
        """
        获取指定月份的日报列表
    
        Args:
            month: 月份,格式 YYYY-MM
    
        Returns:
            日报列表
        """
        url = f"{self.REPORT_LIST_URL}?month={month}"
        reports = []
    
        try:
            # 禁用自动解压缩,手动处理编码
            response = self.session.get(url, stream=True)
            response.raise_for_status()
    
            # 手动处理响应内容
            response.raw.decode_content = True
            content = response.content.decode('utf-8', errors='ignore')
    
            soup = BeautifulSoup(content, 'html.parser')
            report_list = soup.select('#report_list li')
    
            for li in report_list:
                report = self._parse_report_item(li)
                if report:
                    reports.append(report)
    
            return reports
        except Exception as e:
            print(f"获取 {month} 月份日报失败: {e}")
            return []
  • server.py:46-46 (registration)
    The @mcp.tool() decorator registers the collect_reports function as an MCP tool on the FastMCP server instance.
    @mcp.tool()
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must carry the burden. It warns about potential blocking due to login requirements and states auto_login is not recommended, but lacks details on error handling, data source, or post-collection actions.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with a clear header, warning, recommended workflow, and parameter list. It is slightly verbose but every sentence adds value, making it appropriately concise for the information conveyed.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the output schema existence (though vague), the description covers prerequisites, parameter details, and usage workflow. It could elaborate on the return value format or collection behavior, but overall it is sufficient for a data collection tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description fully explains all parameters: date formats, output file default path options, and the auto_login flag's default and advisory against enabling.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool collects daily report data for a specified month range, using a specific verb ('采集') and resource ('日报数据'). It is distinct from sibling tools which handle login or system checks.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly recommends a workflow: first check login status, then login if needed, then collect. It warns against setting auto_login to True and provides clear alternatives via sibling tool names.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Xuzan9396/yst_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server