clear_saved_cookies
Clears saved cookies to reset session state and require re-authentication, maintaining secure access for automated KPI report collection.
Instructions
清除已保存的 Cookie
Returns: 清除结果
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- server.py:301-317 (handler)The async function clear_saved_cookies() decorated with @mcp.tool() — the handler that clears saved cookies by delegating to CookieManager.clear_cookies()
@mcp.tool() async def clear_saved_cookies() -> str: """ 清除已保存的 Cookie Returns: 清除结果 """ manager = CookieManager() try: if manager.clear_cookies(): return safe_text("✓ Cookie 已清除") else: return safe_text("❌ 清除失败") except Exception as e: return safe_text(f"清除失败: {str(e)}") - server.py:301-301 (registration)The @mcp.tool() decorator registers clear_saved_cookies as an MCP tool on the FastMCP instance 'yst-mcp'
@mcp.tool() - cookie_manager.py:96-110 (helper)CookieManager.clear_cookies() — the helper method that deletes the cookies.json file from disk
def clear_cookies(self) -> bool: """ 清除保存的 Cookie Returns: 是否清除成功 """ if os.path.exists(self.cookie_file): try: os.remove(self.cookie_file) return True except Exception as e: print(f"清除 Cookie 失败: {e}") return False return True - cookie_manager.py:31-43 (helper)CookieManager.__init__() — constructor that determines the cookie file path (either user home directory or project data directory)
def __init__(self, cookie_file: str = None): """ 初始化 Cookie 管理器 Args: cookie_file: Cookie 保存文件路径(可选,默认使用自动检测的路径) """ if cookie_file is None: base_dir = self._get_base_dir() self.cookie_file = str(base_dir / 'cookies.json') else: self.cookie_file = cookie_file self._ensure_data_dir() - cookie_manager.py:13-29 (helper)CookieManager._get_base_dir() — static method that resolves the base data directory (user home vs project directory) where cookies.json is stored
@staticmethod def _get_base_dir() -> Path: """ 获取基础数据目录 打包后使用用户主目录 ~/.yst_mcp/data/ 开发时使用项目目录 ./data/ Returns: 数据目录路径 """ if getattr(sys, 'frozen', False): # 打包后:使用用户主目录 return Path.home() / '.yst_mcp' / 'data' else: # 开发时:使用项目目录 return Path(__file__).parent / 'data'