navigate
Navigate the browser to specified HTTP, HTTPS, or allowed file URLs using Selenium for controlled web interactions.
Instructions
Navigate the browser to an http, https, or allowed file URL.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/selenium_mcp_server/browser.py:85-93 (handler)The core handler that executes the navigate tool logic. It validates the URL, calls Selenium's driver.get(url), and returns the BrowserState.
def navigate(self, url: str) -> BrowserState: self._validate_url(url) with self._lock: driver = self._require_driver() try: driver.get(url) except TimeoutException as exc: raise BrowserError(f"Timed out loading {url}") from exc return self.state() - src/selenium_mcp_server/server.py:59-62 (registration)The MCP tool registration for 'navigate'. Decorated with @mcp.tool(), it delegates to browser.navigate via the _run helper.
@mcp.tool() def navigate(url: str) -> dict[str, Any]: """Navigate the browser to an http, https, or allowed file URL.""" return _run("navigate", browser.navigate, url) - URL validation helper called by navigate(). Checks that the URL scheme is http, https, or optionally file, and that http/https URLs have a hostname.
def _validate_url(self, url: str) -> None: parsed = urlparse(url) allowed_schemes = {"http", "https"} if self._settings.allow_file_urls: allowed_schemes.add("file") if parsed.scheme not in allowed_schemes: raise BrowserError(f"URL scheme must be one of: {', '.join(sorted(allowed_schemes))}") if parsed.scheme in {"http", "https"} and not parsed.netloc: raise BrowserError("HTTP and HTTPS URLs must include a hostname") - BrowserState Pydantic model, the return type of navigate(). Contains session_id, current_url, title, window_handles, and active_window_handle.
class BrowserState(BaseModel): session_id: str | None current_url: str | None title: str | None window_handles: list[str] active_window_handle: str | None - The _run helper used by navigate() to call the browser method, catch errors, and convert results to dict.
def _run(action: str, func: Any, *args: Any, **kwargs: Any) -> Any: try: return _as_dict(func(*args, **kwargs)) except BrowserError: logger.exception("Browser action failed: %s", action) raise except Exception as exc: logger.exception("Unexpected Selenium MCP error during %s", action) raise BrowserError(f"{action} failed: {exc}") from exc