Skip to main content
Glama

get_astrbot_logs

Retrieve AstrBot operational logs for debugging and monitoring, supporting immediate access to historical data or real-time streaming of new events.

Instructions

获取 AstrBot 日志。

  • 如果 wait_seconds <= 0:立即返回 /api/log-history 的数据。

  • 如果 wait_seconds > 0:通过 /api/live-log SSE 持续读取指定秒数内的新日志。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
wait_secondsNo
max_eventsNo

Implementation Reference

  • The main handler function for the 'get_astrbot_logs' tool. It fetches AstrBot logs either from history (if wait_seconds <= 0) or live stream (if > 0), handling errors gracefully and returning structured JSON.
    async def get_astrbot_logs(
        wait_seconds: int = 0,
        max_events: int = 200,
    ) -> Dict[str, Any]:
        """
        获取 AstrBot 日志。
    
        - 如果 wait_seconds <= 0:立即返回 /api/log-history 的数据。
        - 如果 wait_seconds > 0:通过 /api/live-log SSE 持续读取指定秒数内的新日志。
        """
        client = AstrBotClient.from_env()
    
        if wait_seconds > 0:
            try:
                events = await client.get_live_logs(
                    wait_seconds=wait_seconds,
                    max_events=max_events,
                )
                return {
                    "mode": "live",
                    "wait_seconds": wait_seconds,
                    "events": events,
                }
            except Exception as e:
                # 避免异常直接向 MCP 宿主抛出导致 "Error calling tool",
                # 而是把错误信息封装到正常的返回结构中,方便前端展示。
                return {
                    "mode": "live",
                    "wait_seconds": wait_seconds,
                    "status": "error",
                    "message": str(e),
                }
    
        try:
            history = await client.get_log_history()
        except Exception as e:
            return {
                "mode": "history",
                "status": "error",
                "message": f"AstrBot API error: {e.response.status_code if hasattr(e, 'response') else 'Unknown'}",
                "base_url": client.base_url,
                "detail": _httpx_error_detail(e),
            }
    
        status = history.get("status")
        if status != "ok":
            return {
                "mode": "history",
                "status": status,
                "message": history.get("message"),
                "raw": history,
            }
    
        return {
            "mode": "history",
            "logs": history.get("data", {}).get("logs", []),
        }
  • Registers the get_astrbot_logs tool with the FastMCP server instance.
    server.tool(astrbot_tools.get_astrbot_logs, name="get_astrbot_logs")
  • Lists 'get_astrbot_logs' in the server info resource for discovery.
    "get_astrbot_logs",
  • Re-exports the get_astrbot_logs function from log_tools for convenient import.
    from .log_tools import get_astrbot_logs

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/xunxiing/astrbotmcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server