diff --git a/webEvalAgent/mcp_server.py b/webEvalAgent/mcp_server.py index 664254e..eac7f2c 100644 --- a/webEvalAgent/mcp_server.py +++ b/webEvalAgent/mcp_server.py @@ -15,7 +15,7 @@ # MCP imports from mcp.server.fastmcp import FastMCP, Context -from mcp.types import TextContent +from mcp.types import TextContent, ImageContent # Removing the problematic import # from mcp.server.tool import Tool, register_tool @@ -54,7 +54,7 @@ class BrowserTools(str, Enum): print("Error: No API key provided. Please set the OPERATIVE_API_KEY environment variable.") @mcp.tool(name=BrowserTools.WEB_EVAL_AGENT) -async def web_eval_agent(url: str, task: str, ctx: Context, headless_browser: bool = False) -> list[TextContent]: +async def web_eval_agent(url: str, task: str, ctx: Context, headless_browser: bool = False) -> list[list[TextContent | ImageContent]]: """Evaluate the user experience / interface of a web application. This tool allows the AI to assess the quality of user experience and interface design @@ -84,7 +84,7 @@ async def web_eval_agent(url: str, task: str, ctx: Context, headless_browser: bo error_message_str = "❌ Error: API Key validation failed when running the tool.\n" error_message_str += " Reason: Free tier limit reached.\n" error_message_str += " 👉 Please subscribe at https://operative.sh to continue." - return [TextContent(type="text", text=error_message_str)] + return [[TextContent(type="text", text=error_message_str)]] try: # Generate a new tool_call_id for this specific tool call tool_call_id = str(uuid.uuid4()) @@ -95,10 +95,10 @@ async def web_eval_agent(url: str, task: str, ctx: Context, headless_browser: bo ) except Exception as e: tb = traceback.format_exc() - return [TextContent( + return [[TextContent( type="text", text=f"Error executing web_eval_agent: {str(e)}\n\nTraceback:\n{tb}" - )] + )]] @mcp.tool(name=BrowserTools.SETUP_BROWSER_STATE) async def setup_browser_state(url: str = None, ctx: Context = None) -> list[TextContent]: diff --git a/webEvalAgent/src/tool_handlers.py b/webEvalAgent/src/tool_handlers.py index b82ec2d..113787e 100644 --- a/webEvalAgent/src/tool_handlers.py +++ b/webEvalAgent/src/tool_handlers.py @@ -40,7 +40,7 @@ def get_browser_manager() -> PlaywrightBrowserManager: """ return PlaywrightBrowserManager.get_instance() -async def handle_web_evaluation(arguments: Dict[str, Any], ctx: Context, api_key: str) -> list[TextContent]: +async def handle_web_evaluation(arguments: Dict[str, Any], ctx: Context, api_key: str) -> list[list[TextContent | ImageContent]]: """Handle web_eval_agent tool calls This function evaluates the user experience of a web application by using @@ -86,16 +86,16 @@ async def handle_web_evaluation(arguments: Dict[str, Any], ctx: Context, api_key send_log(f"Added https:// protocol to URL: {url}", "🔗") if not url or not isinstance(url, str): - return [TextContent( + return [[TextContent( type="text", text="Error: 'url' must be a non-empty string containing the web application URL to evaluate." - )] + )]] if not task or not isinstance(task, str): - return [TextContent( + return [[TextContent( type="text", text="Error: 'task' must be a non-empty string describing the UX/UI aspect to test." - )] + )]] # Send initial status to dashboard send_log(f"🚀 Received web evaluation task: {task}", "🚀")