Skip to main content
Glama
Xuzan9396

YST KPI Daily Report Collector

by Xuzan9396

save_cookies_from_browser

Save browser cookies for automated login to KPI systems. Store authentication tokens from Chrome DevTools to enable persistent session management in daily report collection workflows.

Instructions

保存浏览器 Cookie(用于首次登录)

使用方法:

  1. 使用 chrome_devtools_mcp 登录 https://kpi.drojian.dev

  2. 登录成功后,从浏览器复制 Cookie 字符串

  3. 调用此工具保存 Cookie

Args: cookie_string: Cookie 字符串,格式如 "name1=value1; name2=value2" 或者完整的 curl 命令中的 -b 参数内容

Returns: 保存结果

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cookie_stringYes

Implementation Reference

  • Primary handler function decorated with @mcp.tool(), which registers the tool. Executes the core logic by loading cookies from string into ReportCollector session and saving them.
    @mcp.tool()
    async def save_cookies_from_browser(cookie_string: str) -> str:
        """
        保存浏览器 Cookie(用于首次登录)
    
        使用方法:
        1. 使用 chrome_devtools_mcp 登录 https://kpi.drojian.dev
        2. 登录成功后,从浏览器复制 Cookie 字符串
        3. 调用此工具保存 Cookie
    
        Args:
            cookie_string: Cookie 字符串,格式如 "name1=value1; name2=value2"
            或者完整的 curl 命令中的 -b 参数内容
    
        Returns:
            保存结果
        """
        collector = ReportCollector()
    
        try:
            # 加载 Cookie
            if collector.load_cookies_from_string(cookie_string):
                # 保存到文件
                if collector.save_current_cookies():
                    return safe_text("✓ Cookie 保存成功!现在可以使用 collect_reports 工具采集数据了")
                else:
                    return safe_text("❌ Cookie 保存失败")
            else:
                return safe_text("❌ Cookie 格式错误")
        except Exception as e:
            return safe_text(f"保存失败: {str(e)}")
  • Helper method in ReportCollector that parses the cookie_string input (semicolon-separated) into a dict and loads it into the requests Session cookies.
    def load_cookies_from_string(self, cookie_string: str) -> bool:
        """
        从 Cookie 字符串加载(浏览器复制的格式)
    
        Args:
            cookie_string: Cookie 字符串,格式如 "name1=value1; name2=value2"
    
        Returns:
            是否加载成功
        """
        try:
            cookie_dict = {}
            for item in cookie_string.split('; '):
                if '=' in item:
                    name, value = item.split('=', 1)
                    cookie_dict[name] = value
            return self.load_cookies_from_dict(cookie_dict)
        except Exception as e:
            print(f"解析 Cookie 字符串失败: {e}")
            return False
  • Helper method in ReportCollector that extracts current cookies from the requests Session and persists them using CookieManager.save_cookies.
    def save_current_cookies(self) -> bool:
        """保存当前 session 的 Cookie"""
        cookies = []
        for cookie in self.session.cookies:
            cookies.append({
                'name': cookie.name,
                'value': cookie.value,
                'domain': cookie.domain,
                'path': cookie.path,
            })
        return self.cookie_manager.save_cookies(cookies)
  • server.py:163-163 (registration)
    The @mcp.tool() decorator registers the save_cookies_from_browser function as an MCP tool in the FastMCP instance.
    @mcp.tool()
  • Docstring providing input schema description (cookie_string format) and usage instructions, used by MCP for tool schema.
    """
    保存浏览器 Cookie(用于首次登录)
    
    使用方法:
    1. 使用 chrome_devtools_mcp 登录 https://kpi.drojian.dev
    2. 登录成功后,从浏览器复制 Cookie 字符串
    3. 调用此工具保存 Cookie
    
    Args:
        cookie_string: Cookie 字符串,格式如 "name1=value1; name2=value2"
        或者完整的 curl 命令中的 -b 参数内容
    
    Returns:
        保存结果
    """

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