check_login_status
Verify login status for the KPI daily report collector to determine if authentication is required before data collection. Returns current session validity status.
Instructions
检查当前登录状态(建议第一步调用)
✅ 推荐工作流程:
首先调用此工具检查登录状态
如果返回"未登录",则调用 browser_login 进行登录
登录成功后,调用 collect_reports 采集数据
Returns: 登录状态信息: - "✓ 已登录,Cookie 有效" -> 可以直接采集数据 - "❌ Cookie 已过期" -> 需要调用 browser_login 重新登录 - "❌ 未找到保存的 Cookie" -> 需要调用 browser_login 首次登录
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- server.py:196-228 (handler)MCP tool registration and handler implementation for 'check_login_status'. Instantiates ReportCollector, loads saved cookies if available, and invokes the helper method to verify login status, returning a descriptive status message.@mcp.tool() async def check_login_status() -> str: """ 检查当前登录状态(建议第一步调用) ✅ 推荐工作流程: 1. 首先调用此工具检查登录状态 2. 如果返回"未登录",则调用 browser_login 进行登录 3. 登录成功后,调用 collect_reports 采集数据 Returns: 登录状态信息: - "✓ 已登录,Cookie 有效" -> 可以直接采集数据 - "❌ Cookie 已过期" -> 需要调用 browser_login 重新登录 - "❌ 未找到保存的 Cookie" -> 需要调用 browser_login 首次登录 """ collector = ReportCollector() try: # 尝试加载已保存的 Cookie if collector.cookie_manager.has_cookies(): collector.load_saved_cookies() # 检查登录状态 if collector.check_login_status(): return safe_text("✓ 已登录,Cookie 有效") else: return safe_text("❌ Cookie 已过期,请重新登录并保存 Cookie") else: return safe_text("❌ 未找到保存的 Cookie,请先使用 save_cookies_from_browser 工具保存登录信息") except Exception as e: return safe_text(f"检查失败: {str(e)}")
- report_collector.py:153-167 (helper)Helper method in ReportCollector class that performs the actual login status check by sending a GET request to the report list URL without following redirects and verifying the response status and URL.def check_login_status(self) -> bool: """ 检查是否已登录 Returns: 是否已登录 """ try: response = self.session.get(self.REPORT_LIST_URL, allow_redirects=False) # 如果返回 200 且不是重定向到登录页,说明已登录 return response.status_code == 200 and 'login' not in response.url.lower() except Exception as e: print(f"检查登录状态失败: {e}") return False