Files
2026-11-22 04:45:52 -08:00

40 lines
1.5 KiB
Python

import asyncio
from typing import Any, Dict
from tools.utils import ToolError
async def handle(args: Dict[str, Any], bridge: Any) -> list:
"""
Returns detailed attributes and HTML for a specific element mcp-id.
"""
eid = args.get("id")
if eid is None:
raise ToolError("Missing required argument: 'id'")
request_id = f"req_{asyncio.get_event_loop().time()}_{id(args)}"
params: Dict[str, Any] = {"id": int(eid)}
if args.get("window_id") is not None:
params["window_id"] = int(args["window_id"])
if args.get("tab_id") is not None:
params["tab_id"] = int(args["tab_id"])
result = await bridge.send_to_extension(request_id, "get_element_details", params)
if not result:
raise ToolError(f"Element with mcp-id {eid} not found or has no details")
lines = [f"# Element Details (mcp-id={eid})\n"]
for key, value in result.items():
if key == "html":
lines.append(f"## HTML\n```html\n{value}\n```")
elif key == "bounding_box":
lines.append(f"## Bounding Box\n- x: {value.get('x', 'N/A')}\n- y: {value.get('y', 'N/A')}\n- width: {value.get('width', 'N/A')}\n- height: {value.get('height', 'N/A')}")
elif key == "attributes" and isinstance(value, dict):
lines.append("## Attributes")
for k, v in value.items():
lines.append(f"- {k}: {v}")
else:
lines.append(f"- **{key}**: {value}")
return [{"type": "text", "text": "\n".join(lines)}]