Skip to main content
Glama

vs_error_logs

Read-onlyIdempotent

Fetch recent error logs for a Virtual Service to diagnose HTTP 5xx errors and latency spikes, showing client IPs, URIs, and response times.

Instructions

[READ] Show recent request error logs for a Virtual Service — HTTP status codes, client IPs, URIs, and response times.

Use to diagnose 5xx errors or latency spikes.

Args: vs_name: Virtual Service name. since: Time window, e.g. '1h', '30m', '2d' (default '1h').

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
vs_nameYes
sinceNo1h

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core handler function that queries the AVI analytics/logs endpoint for error logs (non-200 responses) for a given Virtual Service, filtering by duration.
    def show_error_logs(vs_name: str, since: str = "1h") -> None:
        """Show request error logs for a VS.
    
        ``since`` accepts an integer number of seconds or a suffixed shorthand
        such as ``'1h'``, ``'30m'``, ``'24h'``, ``'7d'``.
        """
        cfg = load_config()
        mgr = AviConnectionManager(cfg)
        session = mgr.connect()
    
        vs = session.get_object_by_name("virtualservice", vs_name)
        if not vs:
            console.print(f"[red]Virtual Service '{vs_name}' not found.[/red]")
            raise SystemExit(1)
    
        try:
            duration_seconds = _parse_duration_seconds(since)
        except ValueError as e:
            console.print(f"[red]Invalid duration: {e}[/red]")
            raise SystemExit(1) from None
    
        uuid = vs["uuid"]
        # AVI 22.x requires the VS UUID as an explicit ``virtualservice`` URL
        # parameter on /analytics/logs; passing it only inside ``filter`` as
        # ``co(vs_uuid,<uuid>)`` yields HTTP 400 "VirtualService ID required".
        resp = session.get("analytics/logs", params={
            "type": "1",
            "virtualservice": uuid,
            "filter": "ne(response_code,200)",
            "page_size": "50",
            "duration": str(duration_seconds),
        })
        logs = (resp.json() if hasattr(resp, "json") else resp).get("results", [])
    
        console.print(f"\n[bold]Error Logs: {vs_name} (last {since} = {duration_seconds}s)[/bold]")
        for log in logs:
            ts = log.get("report_timestamp", "")
            code = log.get("response_code", "")
            uri = log.get("uri_path", "")[:80]
            client = log.get("client_ip", "")
            console.print(f"  [{ts}] {code} {uri} from {client}")
    
        if not logs:
            console.print("  [green]No errors found.[/green]")
        console.print()
  • Registration of the vs_error_logs tool as an MCP tool via @mcp.tool decorator with read-only annotations. Delegates to show_error_logs in analytics module.
    @mcp.tool(annotations={"readOnlyHint": True, "destructiveHint": False, "idempotentHint": True, "openWorldHint": True})
    @vmware_tool(risk_level="low")
    def vs_error_logs(vs_name: str, since: str = "1h") -> str:
        """[READ] Show recent request error logs for a Virtual Service — HTTP status codes, client IPs, URIs, and response times.
    
        Use to diagnose 5xx errors or latency spikes.
    
        Args:
            vs_name: Virtual Service name.
            since: Time window, e.g. '1h', '30m', '2d' (default '1h').
        """
        from vmware_avi.ops.analytics import show_error_logs
        return _capture_output(show_error_logs, vs_name, since)
  • Output capture helper used by vs_error_logs to redirect Rich console output from show_error_logs into a string for MCP response.
    def _capture_output(func, *args, **kwargs) -> str:
        """Run a function and capture its Rich console output as plain text."""
        import importlib  # noqa: F401 — used via sys.modules lookup
        import sys
    
        buf = StringIO()
        from rich.console import Console
        capture_console = Console(file=buf, force_terminal=False, width=120)
    
        mod_name = func.__module__
        mod = sys.modules.get(mod_name)
        original_console = getattr(mod, "console", None) if mod else None
    
        if mod and original_console is not None:
            mod.console = capture_console
    
        try:
            func(*args, **kwargs)
        except SystemExit:
            pass
        finally:
            if mod and original_console is not None:
                mod.console = original_console
    
        return buf.getvalue()
  • Duration parsing helper used by show_error_logs to convert user-friendly time strings (e.g. '1h', '30m') to seconds for the AVI API.
    def _parse_duration_seconds(value: str | int) -> int:
        """Parse a duration string (e.g. '1h', '30m', '24h', '7d') to seconds.
    
        The AVI analytics API requires duration as a non-negative integer number
        of seconds. Accept shorthand suffixes so users can pass '1h' naturally.
        """
        if isinstance(value, int):
            if value < 0:
                raise ValueError("duration must be non-negative")
            return value
    
        s = str(value).strip().lower()
        if not s:
            raise ValueError("duration must be non-empty")
    
        m = re.fullmatch(r"(\d+)\s*([smhd]?)", s)
        if not m:
            raise ValueError(
                f"invalid duration {value!r}: expected integer seconds or suffix "
                "s/m/h/d (e.g. '1h', '30m', '3600')"
            )
        n = int(m.group(1))
        unit = m.group(2) or "s"
        return n * {"s": 1, "m": 60, "h": 3600, "d": 86400}[unit]
  • Test expectation list confirming vs_error_logs is one of the 29 expected tool names.
    EXPECTED_TOOL_NAMES = {
        # Traditional mode
        "vs_list",
        "vs_status",
        "vs_toggle",
        "pool_members",
        "pool_member_enable",
        "pool_member_disable",
        "ssl_list",
        "ssl_expiry_check",
        "vs_analytics",
        "vs_error_logs",
        "se_list",
        "se_health",
        # AKO mode
        "ako_status",
        "ako_logs",
        "ako_restart",
        "ako_version",
        "ako_config_show",
        "ako_config_diff",
        "ako_config_upgrade",
        "ako_ingress_check",
        "ako_ingress_map",
        "ako_ingress_diagnose",
        "ako_ingress_fix_suggest",
        "ako_sync_status",
        "ako_sync_diff",
        "ako_sync_force",
        "ako_clusters",
        "ako_cluster_overview",
        "ako_amko_status",
    }
Behavior4/5

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

The description adds the '[READ]' prefix and 'Show...' which aligns with the readOnlyHint annotation. It provides behavioral context about what data is returned (status codes, IPs, etc.) and the time window parameter. No contradictions with annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise: a single line for purpose, one line for usage, and two lines for parameters. No wasted words, and the most important information (read hint, purpose) is front-loaded.

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?

The description covers the key aspects: input parameters, return data fields, and usage context. The presence of an output schema relieves the need to detail the exact output format. It could mention that logs are recent, but 'recent' is stated.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description explains both parameters (vs_name and since) with examples and default values, compensating for the 0% schema description coverage. This adds meaning beyond the schema's basic type and title information.

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 it shows recent request error logs for a Virtual Service, listing specific data (HTTP status codes, client IPs, URIs, response times). It also includes a use case (diagnose 5xx errors or latency spikes). The tool name vs_error_logs reinforces the purpose, and it is distinct from sibling tools like vs_analytics or vs_status.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly says 'Use to diagnose 5xx errors or latency spikes,' providing clear context for when to use the tool. While it does not mention when not to use or list alternatives, the purpose is specific enough that an agent can infer appropriate usage from the sibling tool names.

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/zw008/VMware-AVI'

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