Spaces:
Sleeping
Sleeping
File size: 2,756 Bytes
cdfcef9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | """
Base tool class for OuiComply MCP Server tools.
"""
from abc import ABC, abstractmethod
from typing import Any, Dict, List
from mcp.types import TextContent
class BaseTool(ABC):
"""
Base class for all MCP tools in the OuiComply server.
All tools should inherit from this class and implement the required methods.
"""
def __init__(self, name: str, description: str):
self.name = name
self.description = description
@abstractmethod
def get_schema(self) -> Dict[str, Any]:
"""
Return the JSON schema for this tool's input parameters.
Returns:
Dict containing the JSON schema for tool inputs
"""
pass
@abstractmethod
async def execute(self, arguments: Dict[str, Any]) -> List[TextContent]:
"""
Execute the tool with the given arguments.
Args:
arguments: Dictionary of input arguments
Returns:
List of TextContent responses
"""
pass
def validate_arguments(self, arguments: Dict[str, Any]) -> bool:
"""
Validate the input arguments against the tool's schema.
Args:
arguments: Dictionary of input arguments
Returns:
True if arguments are valid, False otherwise
"""
# Basic validation - can be extended with jsonschema validation
schema = self.get_schema()
required_fields = schema.get("required", [])
for field in required_fields:
if field not in arguments:
return False
return True
class PlaceholderTool(BaseTool):
"""
Placeholder tool implementation for demonstration purposes.
Replace this with actual tool implementations.
"""
def __init__(self):
super().__init__(
name="placeholder_tool",
description="A placeholder tool for demonstration"
)
def get_schema(self) -> Dict[str, Any]:
return {
"type": "object",
"properties": {
"input_text": {
"type": "string",
"description": "Input text to process"
}
},
"required": ["input_text"]
}
async def execute(self, arguments: Dict[str, Any]) -> List[TextContent]:
input_text = arguments.get("input_text", "")
result = f"""
Placeholder Tool Result:
Input: {input_text}
This is a placeholder implementation. Replace with actual tool logic.
"""
return [TextContent(type="text", text=result)]
|