feat(read): target any tab for page info and extraction
- Add --tab option to all extract commands and page info - Thread tab_id through the SDK extract and page namespaces - Route page.info with a tab_id to tabs.status for cross-tab metadata - Accept tab_id in the MCP page_info, extract_text, extract_markdown tools - Forward tabId in the extension page.info and extract.html handlers - Keep the active tab as default when no tab is given - Cover tab-scoped reads in API, CLI, and MCP tests - Bump package and extension version to 0.16.7 - Refresh uv.lock with current dependency versions
This commit is contained in:
@@ -120,31 +120,37 @@ def create_server(*, client_factory: ClientFactory = BrowserCLI, tool_prefix: st
|
||||
|
||||
@mcp.tool(name=tool_name("page_info", prefix))
|
||||
def page_info(
|
||||
tab_id: int | None = None,
|
||||
browser: str | None = None,
|
||||
remote: str | None = None,
|
||||
key: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""Return title, URL, readiness, language, and metadata for the active page."""
|
||||
return structured(_client(client_factory, browser, remote, key).page.info())
|
||||
"""Return title, URL, readiness, language, and metadata for the active page or tab_id."""
|
||||
client = _client(client_factory, browser, remote, key)
|
||||
if tab_id is not None:
|
||||
return structured(client.tabs.status(tab_id))
|
||||
return structured(client.page.info())
|
||||
|
||||
@mcp.tool(name=tool_name("extract_text", prefix))
|
||||
def extract_text(
|
||||
tab_id: int | None = None,
|
||||
browser: str | None = None,
|
||||
remote: str | None = None,
|
||||
key: str | None = None,
|
||||
) -> str:
|
||||
"""Extract plain text from the active page."""
|
||||
return _client(client_factory, browser, remote, key).extract.text()
|
||||
"""Extract plain text from the active page or tab_id."""
|
||||
return _client(client_factory, browser, remote, key).extract.text(tab_id)
|
||||
|
||||
@mcp.tool(name=tool_name("extract_markdown", prefix))
|
||||
def extract_markdown(
|
||||
selector: str | None = None,
|
||||
tab_id: int | None = None,
|
||||
browser: str | None = None,
|
||||
remote: str | None = None,
|
||||
key: str | None = None,
|
||||
) -> str:
|
||||
"""Extract clean Markdown from the active page or an optional CSS selector."""
|
||||
return _client(client_factory, browser, remote, key).extract.markdown(selector)
|
||||
"""Extract clean Markdown from the active page or tab_id, optionally scoped by CSS selector."""
|
||||
return _client(client_factory, browser, remote, key).extract.markdown(selector, tab_id)
|
||||
|
||||
@mcp.tool(name=tool_name("dom_query", prefix))
|
||||
def dom_query(
|
||||
|
||||
Reference in New Issue
Block a user