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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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:
        保存结果
    """
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It discloses that the tool saves cookies for first-time login, implying persistence and authentication purposes. However, it lacks details on storage location, security implications, or error handling. The description adds some context (e.g., used after login) but doesn't fully cover behavioral traits like whether it overwrites existing cookies or requires specific permissions.

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 sections for purpose, usage steps, args, and returns. It's appropriately sized—each sentence adds value, such as clarifying the cookie format. However, the 'Returns' section is vague ('保存结果' meaning 'save result'), which slightly reduces efficiency. Overall, it's front-loaded with clear purpose and steps.

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 1 parameter with 0% schema coverage and an output schema (which exists, so return values needn't be detailed), the description is mostly complete. It covers purpose, usage, and parameter semantics adequately. The main gap is in behavioral transparency (e.g., storage details), but with an output schema, it's sufficient for basic tool invocation.

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?

Schema description coverage is 0%, so the description must compensate. It provides meaningful semantics for the single parameter 'cookie_string': explains it's a cookie string from the browser, gives format examples ('name1=value1; name2=value2'), and mentions it can be from a curl command's -b parameter. This adds significant value beyond the bare schema, though it doesn't detail validation or constraints.

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's purpose: '保存浏览器 Cookie(用于首次登录)' which translates to 'Save browser cookies (for first-time login)'. It specifies the verb 'save' and the resource 'browser cookies', and distinguishes from siblings like 'clear_saved_cookies' (which removes cookies) and 'browser_login' (which might involve login flow). The purpose is specific and differentiated.

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 explicit, step-by-step guidelines on when and how to use this tool: '1. 使用 chrome_devtools_mcp 登录 https://kpi.drojian.dev 2. 登录成功后,从浏览器复制 Cookie 字符串 3. 调用此工具保存 Cookie'. It specifies prerequisites (login via another tool), timing (after login), and the source of data (browser). This clearly guides usage versus alternatives like 'check_login_status' or 'collect_reports'.

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