Initial commit
This commit is contained in:
commit
52ddc6ba9a
27 files changed
+2166
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import asyncio
|
||||
from typing import Any, Dict
|
||||
from tools.utils import ToolError
|
||||
|
||||
async def handle(args: Dict[str, Any], bridge: Any) -> list:
|
||||
"""
|
||||
Scans the specified tab for interactive elements, assigns mcp-ids,
|
||||
and returns a simplified list.
|
||||
"""
|
||||
request_id = f"req_{asyncio.get_event_loop().time()}_{id(args)}"
|
||||
params: Dict[str, Any] = {}
|
||||
if args.get("tab_id") is not None:
|
||||
params["tab_id"] = int(args["tab_id"])
|
||||
if args.get("window_id") is not None:
|
||||
params["window_id"] = int(args["window_id"])
|
||||
result = await bridge.send_to_extension(request_id, "get_page_summary", params)
|
||||
|
||||
elements = result if isinstance(result, list) else []
|
||||
|
||||
lines = ["# Page Summary - Interactive Elements\n"]
|
||||
lines.append("The following interactive elements have been indexed on the current page.")
|
||||
lines.append("Use the `id` (mcp-id) with `click_element`, `type_text`, or `get_element_details`.\n")
|
||||
|
||||
if not elements:
|
||||
lines.append("No interactive elements found on this page.")
|
||||
else:
|
||||
for el in elements:
|
||||
eid = el.get("id", "?")
|
||||
role = el.get("role", "unknown")
|
||||
text = el.get("text", "") or el.get("label", "")
|
||||
tag = el.get("tag", "")
|
||||
href = el.get("href", "")
|
||||
line = f"- **id={eid}** [{role}]"
|
||||
if text:
|
||||
line += f" - \"{text[:100]}\""
|
||||
if tag:
|
||||
line += f" (<{tag}>"
|
||||
if href:
|
||||
line += f" href={href}"
|
||||
line += ")"
|
||||
lines.append(line)
|
||||
|
||||
lines.append("\nTotal elements indexed: " + str(len(elements)))
|
||||
|
||||
return [{"type": "text", "text": "\n".join(lines)}]
|
||||
Reference in new issue
Block a user