Skip to main content
Glama
base_tool.py1.93 kB
"""Abstract base class for all MCP tools.""" from abc import ABC, abstractmethod from typing import Any, Dict, Optional class BaseTool(ABC): """ Abstract base class for all MCP tools. All tools must inherit from this class and implement required methods. """ @abstractmethod def get_name(self) -> str: """ Return the unique name of this tool. Returns: Tool name """ pass @abstractmethod async def execute(self, params: Dict[str, Any]) -> Dict[str, Any]: """ Execute the tool with given parameters. Args: params: Validated input parameters Returns: Tool execution result """ pass def validate_input(self, params: Dict[str, Any]) -> Dict[str, Any]: """ Validate input parameters against the tool's schema. Override for custom validation logic. Args: params: Input parameters Returns: Validated parameters """ # Default implementation - subclasses can override return params def get_cache_key(self, params: Dict[str, Any]) -> Optional[str]: """ Generate cache key for this tool execution. Return None to disable caching for this execution. Args: params: Input parameters Returns: Cache key or None """ return None def get_cache_ttl(self) -> int: """ Get cache TTL for this tool. Returns: TTL in seconds """ return 3600 # Default 1 hour def should_retry(self, error: Exception) -> bool: """ Determine if the operation should be retried on this error. Args: error: Exception that occurred Returns: True if should retry, False otherwise """ return False

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/CTD-Techs/CTD-MCP'

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