Skip to main content
Glama
Xuzan9396

YST KPI Daily Report Collector

by Xuzan9396

collect_reports

Collect daily KPI report data for specified month ranges using browser automation, generating structured Markdown reports with session management.

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

  • server.py:46-46 (registration)
    Registers the 'collect_reports' tool using the FastMCP @mcp.tool() decorator.
    @mcp.tool()
  • Main handler function for 'collect_reports' tool. Performs login verification, optional auto-login, and delegates to ReportCollector for data collection.
    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)}"
  • Core helper method in ReportCollector class that implements the actual report fetching, month range generation, and Markdown file output generation.
    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}")
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure and does so effectively. It reveals critical behavioral traits: the login prerequisite ('使用前请先确保已登录' - ensure logged in before use), potential blocking issues ('避免采集过程被登录流程阻塞' - avoid collection process being blocked by login flow), and the auto_login option behavior. It doesn't mention rate limits, error handling, or data format specifics, but provides substantial operational context for a tool with zero annotation coverage.

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

Conciseness5/5

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

The description is well-structured and appropriately sized. It front-loads the core purpose, uses a warning symbol for critical information, provides a numbered workflow, and organizes parameter explanations clearly. Every sentence serves a purpose: purpose statement, prerequisite warning, workflow guidance, parameter documentation, and return indication. No wasted text.

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 tool's complexity (login-dependent data collection with 4 parameters), zero annotation coverage, but presence of an output schema, the description is quite complete. It covers prerequisites, workflow, all parameters, and behavioral constraints. The output schema existence means the description doesn't need to detail return values. It could potentially mention data format or collection scope more explicitly, but overall provides strong contextual understanding.

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

Parameters4/5

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

With 0% schema description coverage for 4 parameters, the description compensates well by explaining all parameters: start_month and end_month formats (YYYY-MM), output_file default locations, and auto_login behavior and recommendation. It adds meaningful semantics beyond what the bare schema provides, though it could elaborate more on output_file path resolution or edge cases for month ranges.

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

Purpose4/5

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

The description clearly states the tool's purpose: '采集指定月份范围的日报数据' (collect daily report data for a specified month range). It uses a specific verb ('采集' - collect) and resource ('日报数据' - daily report data), but doesn't explicitly differentiate from sibling tools beyond the login context. The purpose is clear but could better distinguish this data collection tool from other tools in the login/cookie management family.

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 provides excellent usage guidelines with explicit when-to-use instructions. It specifies a recommended workflow involving check_login_status and browser_login before calling this tool, warns about login blocking, and mentions sibling tools by name. It also provides guidance on the auto_login parameter ('不推荐设为 True' - not recommended to set to True). This is comprehensive guidance for proper tool sequencing.

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