Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

1.4 KB
Raw Blame
"""The one error shape every MCP Hub layer raises and serializes."""

from __future__ import annotations

from typing import Any, Optional


class McpHubError(Exception):
    """A categorized failure: ``type`` is the stable ``error.type`` callers branch on."""

    def __init__(
        self,
        type: str,
        message: str,
        *,
        field: Optional[str] = None,
        hint: Optional[str] = None,
        usage: bool = False,
    ) -> None:
        super().__init__(message)
        self.type = type
        self.message = message
        self.field = field
        self.hint = hint
        # Usage errors exit 2 at the CLI; everything else exits 1.
        self.usage = usage

    def payload(self) -> dict[str, Any]:
        data: dict[str, Any] = {"type": self.type, "message": self.message}
        if self.field:
            data["field"] = self.field
        if self.hint:
            data["hint"] = self.hint
        if self.usage:
            data["usage"] = True
        return data

    @classmethod
    def from_payload(cls, data: Any) -> "McpHubError":
        if not isinstance(data, dict):
            return cls("internal", "Unexpected MCP Hub response")
        return cls(
            str(data.get("type") or "internal"),
            str(data.get("message") or ""),
            field=data.get("field"),
            hint=data.get("hint"),
            usage=data.get("usage") is True,
        )