"""Base tool implementation."""
from abc import ABC, abstractmethod
from typing import Any
import mcp.types as types
class BaseTool(ABC):
"""Base class for MCP tools."""
def __init__(self, name: str, description: str = "", schema: dict[str, Any] | None = None) -> None:
"""Initialize the tool.
Args:
name: Tool name
description: Tool description
schema: JSON schema for tool arguments
"""
self.name = name
self.description = description
self.schema = schema or {"type": "object", "properties": {}}
@abstractmethod
async def execute(self, arguments: dict[str, Any]) -> list[types.ContentBlock]:
"""Execute the tool with given arguments.
Args:
arguments: Tool arguments
Returns:
List of content blocks
"""
pass
def to_mcp_tool(self) -> types.Tool:
"""Convert to MCP Tool type.
Returns:
MCP Tool instance
"""
return types.Tool(
name=self.name,
description=self.description,
inputSchema=self.schema,
)