"""ToolProtocolProvider - MCP adapter abstraction."""
from __future__ import annotations

from dataclasses import dataclass, field
from typing import Any, Protocol, runtime_checkable


@dataclass
class ToolContext:
    """Context passed through nested tool calls."""

    tool_name: str
    arguments: dict[str, Any] = field(default_factory=dict)
    call_depth: int = 0
    parent_tool: str | None = None
    task_id: str | None = None


@runtime_checkable
class ToolProtocolProvider(Protocol):
    """Provider pro MCP nebo jiny tool protocol.

    Interni Tool Contract NESMI byt totozny s MCP wire contractem.
    MCP verze (napr. 2026-07-28) je zapouzdrena v adapteru.
    """

    @property
    def protocol_name(self) -> str:
        ...

    async def list_tools(self) -> list[dict[str, Any]]:
        ...

    async def call_tool(
        self,
        tool_name: str,
        arguments: dict[str, Any],
        *,
        call_depth: int = 0,
    ) -> dict[str, Any]:
        ...

    def validate_call_depth(self, call_depth: int, max_depth: int = 10) -> bool:
        """Return True if call_depth is within the allowed limit."""
        return call_depth < max_depth


__all__ = ["ToolContext", "ToolProtocolProvider"]
