base_tool.py•1.36 kB
"""
Base Tool Class
All security tools inherit from this base class
"""
from typing import Dict, Any, List
from abc import ABC, abstractmethod
class BaseTool(ABC):
"""Base class for all security tools"""
def __init__(self):
self.name = ""
self.description = ""
@abstractmethod
def get_tool_definition(self) -> Dict[str, Any]:
"""
Return tool definition in MCP format
Returns:
Dict with name, description, and inputSchema
"""
pass
@abstractmethod
async def execute(self, arguments: Dict[str, Any]) -> List[Dict[str, Any]]:
"""
Execute the tool with given arguments
Args:
arguments: Tool arguments from MCP client
Returns:
List of content dictionaries in MCP format
"""
pass
def format_success(self, output: str) -> List[Dict[str, Any]]:
"""Format successful tool output"""
return [
{
"type": "text",
"text": output
}
]
def format_error(self, error: str) -> List[Dict[str, Any]]:
"""Format error output"""
return [
{
"type": "text",
"text": f"❌ Error: {error}"
}
]