browser_run_python
Run Python scripts to automate the current browser session: read pages, click, fill forms, scroll, hover, drag, type, wait, and return results.
Instructions
Browse with Python: read, click, scroll, hover, drag, type, fill and wait in one call. Trusted local Python with host file/network access, NOT a sandbox. The supplied browser uses this client's session and permissions. No imports or kitsune.connect() are needed. Variables reset each call; tabs persist. tab is the MCP-selected Tab, else the tab the user views (None with several windows). Scripts need no browser_tabs list/select first: browser.tabs() lists tabs and browser.tab(id) reads or acts on any of them. browser.tabs() returns list[dict] (id, url, title, owned); browser.tab(id) wraps a tab ID, NOT a list index. browser.new_tab(url) returns a Tab; scripts do not change MCP selection. Return JSON via result or print selected output. Group actions whose targets are already known, then read the needed result once. Do not guess refs or replay a failed script. Print/result share 16,000 UTF-8 bytes: scope reads, filter locally, return evidence with coverage.
Action/scoped-snapshot targets: refs like e12 or supported selectors, not DOM ref attributes. tab.snapshot(target=None, max_depth=None, text=True) includes visible text; no depth/boxes args. tab.find(query) searches descriptions, not text/regex; filter scoped reads in Python for those. tab.query(selector, fields=['text', 'href'], limit=20) is CSS-only, current document; no refs. tab.text(); tab.forms(); tab.info(). tab.click(target); tab.double_click(target); tab.hover(target); tab.drag(source, destination). tab.scroll('down', 700, target=None) scrolls window or element; also up/left/right/top/bottom. tab.fill(target, value) replaces; tab.type(target, text): fields append, editors insert at caret. tab.fill_form({'#name': 'Ada'}); tab.check(target, True); tab.select_option(target, value). tab.press('Enter', target=None, modifiers={'ctrl': True}); omitted target uses focus, not the last target. tab.navigate(url); tab.back(). tab.wait_for(text='Done', timeout=10000) or target/url/text_gone (one condition, timeout in ms). wait_for(target=...) accepts CSS/refs, not :has-text or text=/role=; actions may use those. Example: tab.fill('e12', 'Ada'); tab.click('e15'); result = tab.snapshot(text=True). help(tab.scroll) prints a specific method's signature. Prefer this API over page evaluate.
Limits: 16 KB output/result, 100 API calls, fresh variables, no top-level await. A failed API call stops even if caught; earlier writes remain. For needs_user use the failed operation's direct tool via browser_tools_call, then run ONLY remaining work. Never put confirm/resume tokens in scripts. Use browser_tabs for handoff (request), browser_ask_user for human help, and browser_take_screenshot for images. For a page dict t from browser.tabs(), use browser.tab(t["id"]).snapshot(text=True).
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"code": "<code>"
},
"name": "browser_run_python"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Python code. Use the supplied browser; assign a JSON result or print selected output. | |
| timeout | No | Execution deadline in seconds, including browser calls. |