Skip to content

Automate browser based workflows with AI

Streamline CLI quickstart: browser setup, LLM models, Ollama support (#5214)

Suchintan0afc59348eab
diff --git a/skyvern/cli/browser.py b/skyvern/cli/browser.py
index bdf2e8fa9..31a42681f 100644
--- a/skyvern/cli/browser.py
+++ b/skyvern/cli/browser.py
@@ -1,5 +1,8 @@
+import json
import os
+import platform
import subprocess
+import time
from typing import Optional
from urllib.parse import urlparse
@@ -8,173 +11,348 @@ from rich.panel import Panel
from rich.prompt import Confirm, Prompt
from skyvern.analytics import capture_setup_event
-from skyvern.utils import detect_os
from .console import console
+from .core.browser_launcher import (
+ SKYVERN_DATA_DIR,
+ clone_local_chrome_profile,
+ get_local_chrome_profile_dir,
+)
+# Ports to scan when auto-discovering a CDP debugging server
+_CDP_SCAN_PORTS = [9222, 9223, 9224, 9225, 9226, 9229]
-def get_default_chrome_location(host_system: str) -> str:
- """Get the default Chrome/Chromium location based on OS."""
- if host_system == "darwin":
- return "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
- if host_system == "linux":
- chrome_paths = ["/usr/bin/google-chrome", "/usr/bin/chromium", "/usr/bin/chromium-browser"]
- for path in chrome_paths:
- if os.path.exists(path):
- return path
- return "/usr/bin/google-chrome"
- if host_system == "wsl":
- return "/mnt/c/Program Files/Google/Chrome/Application/chrome.exe"
- return "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
+def _check_cdp_ws(port: int) -> Optional[dict]:
+ """Try a WebSocket CDP handshake on the given port.
-def setup_browser_config() -> tuple[str, Optional[str], Optional[str]]:
- """Configure browser settings for Skyvern."""
- console.print(Panel("\n[bold blue]Configuring web browser for scraping...[/bold blue]", border_style="cyan"))
- browser_types = ["chromium-headless", "chromium-headful", "cdp-connect"]
-
- for i, browser_type in enumerate(browser_types, 1):
- console.print(f"[cyan]{i}.[/cyan] [bold]{browser_type}[/bold]")
- if browser_type == "chromium-headless":
- console.print(" - Runs Chrome in [italic]headless[/italic] mode (no visible window)")
- elif browser_type == "chromium-headful":
- console.print(" - Runs Chrome with [italic]visible window[/italic]")
- elif browser_type == "cdp-connect":
- console.print(" - Connects to an [italic]existing Chrome instance[/italic]")
- console.print(" - [yellow]Requires Chrome to be running with remote debugging enabled[/yellow]")
-
- selected_browser_idx = Prompt.ask(
- "\nChoose browser type", choices=[str(i) for i in range(1, len(browser_types) + 1)]
- )
- selected_browser = browser_types[int(selected_browser_idx) - 1]
- console.print(f"Selected browser: [bold green]{selected_browser}[/bold green]")
-
- browser_location = None
- remote_debugging_url = None
-
- if selected_browser == "cdp-connect":
- host_system = detect_os()
- default_location = get_default_chrome_location(host_system)
- console.print(f"\n[italic]Default Chrome location for your system:[/italic] [cyan]{default_location}[/cyan]")
- browser_location = Prompt.ask(
- "Enter Chrome executable location (press Enter to use default)", default=default_location
- )
- if not browser_location:
- browser_location = default_location
+ Chrome's chrome://inspect#remote-debugging exposes a WS-only CDP server
+ (no /json/version HTTP endpoint). This sends Browser.getVersion over WS
+ to detect it.
- if not os.path.exists(browser_location):
- capture_setup_event(
- "chrome-detect",
- success=False,
- error_type="chrome_not_found",
- error_message=f"Chrome not found at {browser_location}",
- extra_data={"path": browser_location},
+ Returns the version info dict if successful, else None.
+ """
+ # Lazy import — websockets is only needed for CDP WS probing and may not
+ # be installed in all environments.
+ try:
+ import websockets.sync.client as ws_sync
+ except ImportError:
+ return None
+
+ url = f"ws://127.0.0.1:{port}/devtools/browser"
+ try:
+ with ws_sync.connect(url, close_timeout=2, open_timeout=1) as ws:
+ ws.send(json.dumps({"id": 1, "method": "Browser.getVersion"}))
+ raw = ws.recv(timeout=3)
+ data = json.loads(raw)
+ result = data.get("result", {})
+ if result.get("product"):
+ return result
+ except Exception:
+ pass
+ return None
+
+
+def _discover_cdp_server() -> Optional[tuple[str, dict | None]]:
+ """Scan common ports for a running Chrome CDP server.
+
+ Tries the HTTP /json/version endpoint first (standard CDP), then falls back
+ to a WebSocket probe (chrome://inspect WS-only mode).
+
+ Returns (url, version_info) where url is suitable for Playwright connect_over_cdp:
+ - "http://127.0.0.1:{port}" if HTTP API is available
+ - "ws://127.0.0.1:{port}/devtools/browser" if only WS is available
+ version_info is cached to avoid a redundant probe in _print_cdp_info.
+ """
+ for port in _CDP_SCAN_PORTS:
+ http_url = f"http://127.0.0.1:{port}"
+ # Try HTTP first (standard --remote-debugging-port)
+ try:
+ response = requests.get(f"{http_url}/json/version", timeout=1)
+ if response.status_code == 200:
+ data = response.json()
+ if "webSocketDebuggerUrl" in data or "Browser" in data:
+ return http_url, data
+ except (requests.RequestException, ValueError):
+ pass
+
+ # Try WS probe (chrome://inspect WS-only mode)
+ ws_info = _check_cdp_ws(port)
+ if ws_info:
+ return f"ws://127.0.0.1:{port}/devtools/browser", ws_info
+
+ return None
+
+
+def _print_cdp_info(url: str, cached_info: dict | None = None) -> None:
+ """Print details about a discovered CDP server."""
+ if url.startswith("ws://"):
+ info = cached_info
+ if not info:
+ parsed = urlparse(url)
+ port = parsed.port
+ if not port:
+ return
+ info = _check_cdp_ws(port)
+ if info:
+ console.print(f" Browser: [bold]{info.get('product', 'Unknown')}[/bold]")
+ console.print(f" WebSocket URL: [dim]{url}[/dim]")
+ return
+
+ # Standard HTTP CDP server
+ info = cached_info
+ if not info:
+ try:
+ response = requests.get(f"{url}/json/version", timeout=2)
+ if response.status_code == 200:
+ info = response.json()
+ except (requests.RequestException, ValueError):
+ pass
+ if info:
+ if "Browser" in info:
+ console.print(f" Browser: [bold]{info['Browser']}[/bold]")
+ if "webSocketDebuggerUrl" in info:
+ console.print(f" WebSocket URL: [dim]{info['webSocketDebuggerUrl']}[/dim]")
+
+
+def _open_chrome_inspect() -> None:
+ """Open chrome://inspect/#remote-debugging in the user's default browser."""
+ system = platform.system()
+ url = "chrome://inspect/#remote-debugging"
+ try:
+ if system == "Darwin":
+ subprocess.Popen(
+ ["open", "-a", "Google Chrome", url],
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL,
)
- console.print(
- f"[yellow]Warning: Chrome not found at {browser_location}. Please verify the location is correct.[/yellow]"
+ elif system == "Windows":
+ subprocess.Popen(
+ ["start", "chrome", url],
+ shell=True,
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL,
)
else:
+ # Linux — try common Chrome names
+ for cmd in ["google-chrome", "chromium", "chromium-browser"]:
+ if os.path.exists(f"/usr/bin/{cmd}"):
+ subprocess.Popen(
+ [cmd, url],
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL,
+ )
+ return
+ console.print(f"[yellow]Could not open Chrome automatically. Please navigate to: {url}[/yellow]")
+ except Exception:
+ console.print(f"[yellow]Could not open Chrome automatically. Please navigate to: {url}[/yellow]")
+
+
+def _setup_local_browser_clone() -> tuple[str, Optional[str], Optional[str]]:
+ """Set up a new browser with the user's Chrome profile cloned."""
+ chrome_profile_dir = get_local_chrome_profile_dir()
+ if not chrome_profile_dir.is_dir():
+ console.print(
+ f"[red]Chrome profile directory not found at {chrome_profile_dir}. Is Google Chrome installed?[/red]"
+ )
+ capture_setup_event(
+ "browser-clone-profile",
+ success=False,
+ error_type="profile_not_found",
+ error_message=f"Chrome profile dir not found at {chrome_profile_dir}",
+ )
+ return "chromium-headful", None, None
+
+ # List available profiles
+ profiles = sorted(
+ [d.name for d in chrome_profile_dir.iterdir() if d.is_dir() and not d.name.startswith(".")],
+ )
+ # Filter to actual Chrome profile directories (contain a Preferences file)
+ profile_dirs = [p for p in profiles if (chrome_profile_dir / p / "Preferences").exists()]
+ if not profile_dirs:
+ # Fallback to name-based heuristic
+ profile_dirs = [p for p in profiles if p == "Default" or p.startswith("Profile ")]
+ if not profile_dirs:
+ console.print("[red]No Chrome profiles found. Falling back to a fresh browser profile.[/red]")
+ return "chromium-headful", None, None
+
+ if len(profile_dirs) == 1:
+ chosen_profile = profile_dirs[0]
+ console.print(f" Found Chrome profile: [bold]{chosen_profile}[/bold]")
+ else:
+ console.print("\n[bold]Available Chrome profiles:[/bold]")
+ for i, p in enumerate(profile_dirs, 1):
+ console.print(f" [cyan]{i}.[/cyan] {p}")
+ idx = Prompt.ask(
+ "Choose a profile to clone",
+ choices=[str(i) for i in range(1, len(profile_dirs) + 1)],
+ default="1",
+ )
+ chosen_profile = profile_dirs[int(idx) - 1]
+
+ dest = SKYVERN_DATA_DIR / "chrome-profile"
+ console.print(f"\n Cloning [bold]{chosen_profile}[/bold] profile to [dim]{dest}[/dim]...")
+
+ with console.status("[bold green]Copying profile (this may take a moment)..."):
+ try:
+ clone_local_chrome_profile(chosen_profile, dest, full=False)
capture_setup_event(
- "chrome-detect",
+ "browser-clone-profile",
success=True,
- extra_data={"path": browser_location},
+ extra_data={"profile": chosen_profile, "dest": str(dest)},
+ )
+ console.print(" ✅ [green]Profile cloned successfully.[/green]")
+ console.print(" [dim]Your cookies, logins, and extensions from this profile will be available.[/dim]")
+ except Exception as e:
+ capture_setup_event(
+ "browser-clone-profile",
+ success=False,
+ error_type="clone_failed",
+ error_message=str(e),
)
+ console.print(f" [red]Failed to clone profile: {e}[/red]")
+ use_fresh = Confirm.ask(
+ "Continue with a fresh browser profile instead?",
+ default=True,
+ )
+ if not use_fresh:
+ console.print("[yellow]Browser setup cancelled. Please fix the issue and try again.[/yellow]")
+ raise SystemExit(1)
- console.print("\n[bold]To use CDP connection, Chrome must be running with remote debugging enabled.[/bold]")
- console.print("Example: [code]chrome --remote-debugging-port=9222[/code]")
- console.print("[italic]Default debugging URL: [cyan]http://localhost:9222[/cyan][/italic]")
-
- default_port = "9222"
- if remote_debugging_url is None:
- remote_debugging_url = "http://localhost:9222"
- elif urlparse(remote_debugging_url).port is not None:
- default_port = remote_debugging_url.split(":")[-1].split("/")[0]
-
- parsed_url = urlparse(remote_debugging_url)
- version_url = f"{parsed_url.scheme}://{parsed_url.netloc}/json/version"
-
- with console.status(
- f"[bold green]Checking if Chrome is already running with remote debugging on port {default_port}..."
- ) as status:
- try:
- response = requests.get(version_url, timeout=2)
- if response.status_code == 200:
- try:
- browser_info = response.json()
- capture_setup_event(
- "chrome-debug-connect",
- success=True,
- extra_data={"url": remote_debugging_url, "browser": browser_info.get("Browser")},
- )
- console.print("✅ [green]Chrome is already running with remote debugging![/green]")
- if "Browser" in browser_info:
- console.print(f" Browser: [bold]{browser_info['Browser']}[/bold]")
- if "webSocketDebuggerUrl" in browser_info:
- console.print(f" WebSocket URL: [link]{browser_info['webSocketDebuggerUrl']}[/link]")
- console.print(f" Connected to [link]{remote_debugging_url}[/link]")
- return selected_browser, browser_location, remote_debugging_url
- except ValueError:
- capture_setup_event(
- "chrome-debug-connect",
- success=False,
- error_type="port_not_chrome",
- error_message="Port is in use but doesn't appear to be Chrome with remote debugging",
- extra_data={"url": remote_debugging_url},
- )
- console.print(
- "[yellow]Port is in use, but doesn't appear to be Chrome with remote debugging.[/yellow]"
- )
- else:
- capture_setup_event(
- "chrome-debug-connect",
- success=False,
- error_type="chrome_bad_response",
- error_message=f"Chrome responded with status code {response.status_code}",
- extra_data={"url": remote_debugging_url, "status_code": response.status_code},
- )
- console.print(f"[yellow]Chrome responded with status code {response.status_code}.[/yellow]")
- except requests.RequestException:
+ return "chromium-headful", None, None
+
+
+def _setup_local_browser_actual() -> tuple[str, Optional[str], Optional[str]]:
+ """Connect to the user's actual running Chrome browser via CDP."""
+ # Step 1: Check if debugging is already enabled
+ console.print("\n Checking for an existing remote debugging server...")
+ result = _discover_cdp_server()
+ if result:
+ existing, info = result
+ console.print(f" ✅ [green]Found Chrome debugging server at {existing}[/green]")
+ _print_cdp_info(existing, cached_info=info)
+ capture_setup_event(
+ "browser-actual-connect",
+ success=True,
+ extra_data={"url": existing, "method": "auto-discovered"},
+ )
+ return "cdp-connect", None, existing
+
+ # Step 2: Guide the user to enable remote debugging
+ console.print(
+ Panel(
+ "[bold]Enable Remote Debugging in Chrome[/bold]\n\n"
+ "1. We'll open [cyan]chrome://inspect/#remote-debugging[/cyan] in your browser\n"
+ "2. Click [bold]Enable[/bold] to start the debugging server\n"
+ "3. You should see: [green]Server running at: 127.0.0.1:9222[/green]",
+ border_style="cyan",
+ )
+ )
+
+ open_page = Confirm.ask("Open chrome://inspect/#remote-debugging now?", default=True)
+ if open_page:
+ _open_chrome_inspect()
+
+ console.print("\n[bold yellow]Enable remote debugging in Chrome, then press Enter to continue...[/bold yellow]")
+ Prompt.ask("Press Enter when ready", default="")
+
+ # Step 3: Auto-discover the debugging server with retries
+ console.print()
+ with console.status("[bold green]Scanning for Chrome debugging server...") as status:
+ for attempt in range(6):
+ result = _discover_cdp_server()
+ if result:
+ found, info = result
+ status.stop()
+ console.print(f" ✅ [green]Found Chrome debugging server at {found}[/green]")
+ _print_cdp_info(found, cached_info=info)
capture_setup_event(
- "chrome-debug-connect",
- success=False,
- error_type="chrome_not_running",
- error_message=f"No Chrome instance detected on {remote_debugging_url}",
- extra_data={"url": remote_debugging_url},
+ "browser-actual-connect",
+ success=True,
+ extra_data={"url": found, "method": "user-enabled", "attempts": attempt + 1},
)
- console.print(f"[red]No Chrome instance detected on {remote_debugging_url}[/red]")
+ return "cdp-connect", None, found
+ time.sleep(1)
status.stop()
- console.print("\n[bold]Executing Chrome with remote debugging enabled:[/bold]")
+ # Step 4: Fallback — ask for manual URL
+ console.print("[yellow]Could not auto-detect the debugging server.[/yellow]")
+ console.print("[dim]Make sure you clicked 'Enable' on the chrome://inspect page.[/dim]")
+ manual_url = Prompt.ask(
+ "Enter the debugging URL manually (e.g. http://127.0.0.1:9222)",
+ default="http://127.0.0.1:9222",
+ )
- if host_system == "darwin" or host_system == "linux":
- chrome_cmd = f'{browser_location} --remote-debugging-port={default_port} --user-data-dir="$HOME/chrome-cdp-profile" --no-first-run --no-default-browser-check'
- console.print(f" [code]{chrome_cmd}[/code]")
- elif host_system == "windows" or host_system == "wsl":
- chrome_cmd = f'"{browser_location}" --remote-debugging-port={default_port} --user-data-dir="C:\\chrome-cdp-profile" --no-first-run --no-default-browser-check'
- console.print(f" [code]{chrome_cmd}[/code]")
+ # Verify the manual URL
+ try:
+ response = requests.get(f"{manual_url}/json/version", timeout=2)
+ if response.status_code == 200:
+ console.print(f" ✅ [green]Connected to {manual_url}[/green]")
+ _print_cdp_info(manual_url)
+ capture_setup_event(
+ "browser-actual-connect",
+ success=True,
+ extra_data={"url": manual_url, "method": "manual"},
+ )
else:
- console.print("[red]Unsupported OS for Chrome configuration. Please set it up manually.[/red]")
-
- execute_browser = Confirm.ask("\nWould you like to start Chrome with remote debugging now?")
- if execute_browser:
- console.print(
- f"🚀 [bold green]Starting Chrome with remote debugging on port {default_port}...\n[/bold green]"
+ console.print(f"[yellow]Warning: Server responded with status {response.status_code}[/yellow]")
+ capture_setup_event(
+ "browser-actual-connect",
+ success=False,
+ error_type="bad_status",
+ error_message=f"Status {response.status_code}",
)
- try:
- if host_system in ["darwin", "linux"]:
- subprocess.Popen(f"nohup {chrome_cmd} > /dev/null 2>&1 &", shell=True)
- elif host_system == "windows":
- subprocess.Popen(f"start {chrome_cmd}", shell=True)
- elif host_system == "wsl":
- subprocess.Popen(f"cmd.exe /c start {chrome_cmd}", shell=True)
- except Exception as e: # pragma: no cover - CLI safeguards
- console.print(f"[red]Error starting Chrome: {e}[/red]")
- console.print("[italic]Please start Chrome manually using the command above.[/italic]")
-
- remote_debugging_url = Prompt.ask(
- "Enter remote debugging URL (press Enter for default)", default="http://localhost:9222"
+ except requests.RequestException:
+ console.print(f"[yellow]Warning: Could not connect to {manual_url}. Make sure debugging is enabled.[/yellow]")
+ capture_setup_event(
+ "browser-actual-connect",
+ success=False,
+ error_type="connection_failed",
+ error_message=f"Could not connect to {manual_url}",
)
- if not remote_debugging_url:
- remote_debugging_url = "http://localhost:9222"
- return selected_browser, browser_location, remote_debugging_url
+ return "cdp-connect", None, manual_url
+
+
+def setup_browser_config() -> tuple[str, Optional[str], Optional[str]]:
+ """Configure browser settings for Skyvern.
+
+ Returns:
+ (browser_type, browser_location, remote_debugging_url)
+ """
+ console.print(Panel("[bold blue]Configuring web browser...[/bold blue]", border_style="cyan"))
+
+ console.print("[cyan]1.[/cyan] [bold]Local browser[/bold]")
+ console.print(" - Use your existing Chrome with your cookies, logins, and extensions")
+ console.print("[cyan]2.[/cyan] [bold]New browser (headful)[/bold]")
+ console.print(" - Launch a fresh Chrome window (visible)")
+ console.print("[cyan]3.[/cyan] [bold]New browser (headless)[/bold]")
+ console.print(" - Launch Chrome in the background (no visible window)")
+
+ selected_idx = Prompt.ask("\nChoose browser type", choices=["1", "2", "3"])
+
+ if selected_idx == "2":
+ console.print("Selected: [bold green]New browser (headful)[/bold green]")
+ capture_setup_event("browser-config-select", success=True, extra_data={"type": "chromium-headful"})
+ return "chromium-headful", None, None
+
+ if selected_idx == "3":
+ console.print("Selected: [bold green]New browser (headless)[/bold green]")
+ capture_setup_event("browser-config-select", success=True, extra_data={"type": "chromium-headless"})
+ return "chromium-headless", None, None
+
+ # Local browser selected
+ console.print("Selected: [bold green]Local browser[/bold green]")
+ capture_setup_event("browser-config-select", success=True, extra_data={"type": "local-browser"})
+
+ console.print("\n[cyan]a.[/cyan] [bold]Clone Chrome profile[/bold]")
+ console.print(" - Copy your cookies and logins into a separate browser (Chrome can stay open)")
+ console.print("[cyan]b.[/cyan] [bold]Use actual browser[/bold]")
+ console.print(" - Connect directly to your running Chrome instance")
+
+ local_choice = Prompt.ask("\nChoose local browser mode", choices=["a", "b"])
+
+ if local_choice == "a":
+ return _setup_local_browser_clone()
+
+ return _setup_local_browser_actual()
diff --git a/skyvern/cli/init_command.py b/skyvern/cli/init_command.py
index 767ad3c11..f6261de2f 100644
--- a/skyvern/cli/init_command.py
+++ b/skyvern/cli/init_command.py
@@ -1,4 +1,5 @@
import asyncio
+import os
import subprocess
import uuid
@@ -148,8 +149,16 @@ def init_env(
update_or_add_env_var("SKYVERN_API_KEY", api_key)
console.print(f"✅ [green]{resolve_backend_env_path()} file has been initialized.[/green]")
+ # Retrieve browser config for MCP setup (set during local init)
+ _mcp_browser_type = os.environ.get("BROWSER_TYPE") if run_local else None
+ _mcp_browser_url = os.environ.get("BROWSER_REMOTE_DEBUGGING_URL") if run_local else None
+
if Confirm.ask("\nWould you like to [bold yellow]configure the MCP server[/bold yellow]?", default=True):
- setup_mcp(local=run_local)
+ setup_mcp(
+ local=run_local,
+ browser_type=_mcp_browser_type,
+ browser_remote_debugging_url=_mcp_browser_url,
+ )
if not run_local:
console.print(
diff --git a/skyvern/cli/llm_setup.py b/skyvern/cli/llm_setup.py
index c36b53bff..ac2112a94 100644
--- a/skyvern/cli/llm_setup.py
+++ b/skyvern/cli/llm_setup.py
@@ -33,8 +33,6 @@ def update_or_add_env_var(key: str, value: str) -> None:
"AZURE_GPT4O_MINI_API_VERSION": "",
"ENABLE_GEMINI": "false",
"GEMINI_API_KEY": "",
- "ENABLE_NOVITA": "false",
- "NOVITA_API_KEY": "",
"LLM_KEY": "",
"SECONDARY_LLM_KEY": "",
"BROWSER_TYPE": "chromium-headful",
@@ -78,6 +76,7 @@ def setup_llm_providers() -> None:
enabled_providers.append("openai")
model_options.extend(
[
+ "OPENAI_GPT5_4",
"OPENAI_GPT5",
"OPENAI_GPT5_2",
"OPENAI_GPT4_1",
@@ -102,10 +101,9 @@ def setup_llm_providers() -> None:
enabled_providers.append("anthropic")
model_options.extend(
[
+ "ANTHROPIC_CLAUDE4.6_OPUS",
"ANTHROPIC_CLAUDE4.5_OPUS",
"ANTHROPIC_CLAUDE4.5_SONNET",
- "ANTHROPIC_CLAUDE4_OPUS",
- "ANTHROPIC_CLAUDE4_SONNET",
"ANTHROPIC_CLAUDE4.5_HAIKU",
]
)
@@ -147,82 +145,30 @@ def setup_llm_providers() -> None:
else:
update_or_add_env_var("ENABLE_GEMINI", "false")
- console.print("\n[bold blue]--- Novita Configuration ---[/bold blue]")
- console.print("To enable Novita, you must have a Novita API key.")
- enable_novita = Confirm.ask("Do you want to enable Novita?")
- if enable_novita:
- novita_api_key = Prompt.ask("Enter your Novita API key", password=True)
- if not novita_api_key:
- console.print("[red]Error: Novita API key is required. Novita will not be enabled.[/red]")
- else:
- update_or_add_env_var("NOVITA_API_KEY", novita_api_key)
- update_or_add_env_var("ENABLE_NOVITA", "true")
- enabled_providers.append("novita")
- model_options.extend(
- [
- "NOVITA_LLAMA_3_2_11B_VISION",
- "NOVITA_LLAMA_3_1_8B",
- "NOVITA_LLAMA_3_1_70B",
- "NOVITA_LLAMA_3_1_405B",
- "NOVITA_LLAMA_3_8B",
- "NOVITA_LLAMA_3_70B",
- ]
- )
- else:
- update_or_add_env_var("ENABLE_NOVITA", "false")
-
- console.print("\n[bold blue]--- VolcEngine Configuration ---[/bold blue]")
- console.print("To enable VolcEngine, you must have a ByteDance Doubao API key.")
- enable_volcengine = Confirm.ask("Do you want to enable VolcEngine?")
- if enable_volcengine:
- volcengine_api_key = Prompt.ask("Enter your VolcEngine(ByteDance Doubao) API key", password=True)
- if not volcengine_api_key:
- console.print("[red]Error: VolcEngine key is required. VolcEngine will not be enabled.[/red]")
- else:
- update_or_add_env_var("VOLCENGINE_API_KEY", volcengine_api_key)
- update_or_add_env_var("ENABLE_VOLCENGINE", "true")
- enabled_providers.append("volcengine")
- model_options.extend(
- [
- "VOLCENGINE_DOUBAO_SEED_1_6",
- "VOLCENGINE_DOUBAO_SEED_1_6_FLASH",
- "VOLCENGINE_DOUBAO_1_5_THINKING_VISION_PRO",
- ]
- )
- else:
- update_or_add_env_var("ENABLE_VOLCENGINE", "false")
-
- console.print("\n[bold blue]--- OpenAI-Compatible Provider Configuration ---[/bold blue]")
- console.print("To enable an OpenAI-compatible provider, you must have a model name, API key, and API base URL.")
- enable_openai_compatible = Confirm.ask("Do you want to enable an OpenAI-compatible provider?")
- if enable_openai_compatible:
- openai_compatible_model_name = Prompt.ask("Enter the model name (e.g., 'yi-34b', 'mistral-large')")
- openai_compatible_api_key = Prompt.ask("Enter your API key", password=True)
- openai_compatible_api_base = Prompt.ask("Enter the API base URL (e.g., 'https://api.together.xyz/v1')")
- openai_compatible_vision = Confirm.ask("Does this model support vision?")
-
- if not all([openai_compatible_model_name, openai_compatible_api_key, openai_compatible_api_base]):
- console.print(
- "[red]Error: All required fields must be populated. OpenAI-compatible provider will not be enabled.[/red]"
- )
+ console.print("\n[bold blue]--- Ollama / Local LLM Configuration ---[/bold blue]")
+ console.print("Use any locally-running model via Ollama (e.g. llama3, mistral, qwen).")
+ console.print("[dim]Requires Ollama running locally: https://ollama.com[/dim]")
+ enable_ollama = Confirm.ask("Do you want to enable a local Ollama model?")
+ if enable_ollama:
+ ollama_server_url = Prompt.ask(
+ "Enter Ollama server URL",
+ default="http://localhost:11434",
+ )
+ ollama_model = Prompt.ask(
+ "Enter model name (e.g. llama3.3, mistral, qwen2.5)",
+ )
+ if not ollama_model:
+ console.print("[red]Error: Model name is required. Ollama will not be enabled.[/red]")
else:
- update_or_add_env_var("OPENAI_COMPATIBLE_MODEL_NAME", openai_compatible_model_name)
- update_or_add_env_var("OPENAI_COMPATIBLE_API_KEY", openai_compatible_api_key)
- update_or_add_env_var("OPENAI_COMPATIBLE_API_BASE", openai_compatible_api_base)
- if openai_compatible_vision:
- update_or_add_env_var("OPENAI_COMPATIBLE_SUPPORTS_VISION", "true")
- else:
- update_or_add_env_var("OPENAI_COMPATIBLE_SUPPORTS_VISION", "false")
-
- openai_compatible_api_version = Prompt.ask("Enter API version (optional, press enter to skip)", default="")
- if openai_compatible_api_version:
- update_or_add_env_var("OPENAI_COMPATIBLE_API_VERSION", openai_compatible_api_version)
-
- update_or_add_env_var("ENABLE_OPENAI_COMPATIBLE", "true")
- enabled_providers.append("openai_compatible")
- model_options.append("OPENAI_COMPATIBLE")
+ ollama_vision = Confirm.ask("Does this model support vision?", default=False)
+ update_or_add_env_var("OLLAMA_SERVER_URL", ollama_server_url)
+ update_or_add_env_var("OLLAMA_MODEL", ollama_model)
+ update_or_add_env_var("OLLAMA_SUPPORTS_VISION", str(ollama_vision).lower())
+ update_or_add_env_var("ENABLE_OLLAMA", "true")
+ enabled_providers.append("ollama")
+ model_options.append("OLLAMA")
else:
- update_or_add_env_var("ENABLE_OPENAI_COMPATIBLE", "false")
+ update_or_add_env_var("ENABLE_OLLAMA", "false")
if not model_options:
capture_setup_event(
diff --git a/skyvern/cli/mcp.py b/skyvern/cli/mcp.py
index 46cd52db5..4f093ce05 100644
--- a/skyvern/cli/mcp.py
+++ b/skyvern/cli/mcp.py
@@ -42,7 +42,12 @@ async def setup_local_organization() -> str:
return org_auth_token.token if org_auth_token else ""
-def setup_mcp(*, local: bool = False) -> None:
+def setup_mcp(
+ *,
+ local: bool = False,
+ browser_type: str | None = None,
+ browser_remote_debugging_url: str | None = None,
+) -> None:
console.print(Panel("[bold green]MCP Server Setup[/bold green]", border_style="green"))
if local:
console.print(
@@ -63,6 +68,8 @@ def setup_mcp(*, local: bool = False) -> None:
project=False,
global_config=False,
skip_skills=False,
+ browser_type=browser_type,
+ browser_remote_debugging_url=browser_remote_debugging_url,
)
if Confirm.ask("Would you like to set up MCP integration for Claude Desktop?", default=True):
@@ -73,6 +80,8 @@ def setup_mcp(*, local: bool = False) -> None:
local=local,
use_python_path=True,
url=None,
+ browser_type=browser_type,
+ browser_remote_debugging_url=browser_remote_debugging_url,
)
if Confirm.ask("Would you like to set up MCP integration for Cursor?", default=True):
@@ -83,6 +92,8 @@ def setup_mcp(*, local: bool = False) -> None:
local=local,
use_python_path=True,
url=None,
+ browser_type=browser_type,
+ browser_remote_debugging_url=browser_remote_debugging_url,
)
if Confirm.ask("Would you like to set up MCP integration for Windsurf?", default=True):
@@ -93,6 +104,8 @@ def setup_mcp(*, local: bool = False) -> None:
local=local,
use_python_path=True,
url=None,
+ browser_type=browser_type,
+ browser_remote_debugging_url=browser_remote_debugging_url,
)
console.print("\n🎉 [bold green]MCP server configuration completed.[/bold green]")
diff --git a/skyvern/cli/mcp_tools/session.py b/skyvern/cli/mcp_tools/session.py
index 3e64ea4d8..ea3e7e3b3 100644
--- a/skyvern/cli/mcp_tools/session.py
+++ b/skyvern/cli/mcp_tools/session.py
@@ -1,5 +1,6 @@
from __future__ import annotations
+import os
from typing import Annotated, Any
from pydantic import Field
@@ -27,6 +28,15 @@ def _session_api_key_hash() -> str | None:
return hash_api_key_for_cache(api_key)
+def _should_default_to_cdp() -> tuple[bool, str | None]:
+ """Check if BROWSER_TYPE is cdp-connect and return the configured debugging URL."""
+ browser_type = os.environ.get("BROWSER_TYPE", "")
+ if browser_type == "cdp-connect":
+ cdp_url = os.environ.get("BROWSER_REMOTE_DEBUGGING_URL", "http://127.0.0.1:9222")
+ return True, cdp_url
+ return False, None
+
+
async def skyvern_browser_session_create(
timeout: Annotated[int | None, Field(description="Session timeout in minutes (5-1440)")] = 60,
proxy_location: Annotated[str | None, Field(description="Proxy location: RESIDENTIAL, US, etc.")] = None,
@@ -38,6 +48,34 @@ async def skyvern_browser_session_create(
Use local=true for a local Chromium instance.
The session persists across tool calls until explicitly closed.
"""
+ # When BROWSER_TYPE=cdp-connect, auto-connect to the user's local browser via CDP.
+ # resolve_browser() stores the browser in session state via set_current_session()
+ # internally, so we don't need to call it again here.
+ use_cdp, cdp_url = _should_default_to_cdp()
+ if use_cdp and not local and cdp_url:
+ with Timer() as timer:
+ try:
+ _browser, ctx = await resolve_browser(cdp_url=cdp_url)
+ timer.mark("sdk")
+ except Exception as e:
+ return make_result(
+ "skyvern_browser_session_create",
+ ok=False,
+ timing_ms=timer.timing_ms,
+ error=make_error(
+ ErrorCode.SDK_ERROR,
+ str(e),
+ f"Failed to connect to local browser at {cdp_url}. "
+ "Make sure Chrome is running with remote debugging enabled.",
+ ),
+ )
+ return make_result(
+ "skyvern_browser_session_create",
+ browser_context=ctx,
+ data={"local": True, "cdp_url": cdp_url},
+ timing_ms=timer.timing_ms,
+ )
+
with Timer() as timer:
try:
if is_stateless_http_mode() and local:
diff --git a/skyvern/cli/setup_commands.py b/skyvern/cli/setup_commands.py
index 9f633f7a4..eac18b664 100644
--- a/skyvern/cli/setup_commands.py
+++ b/skyvern/cli/setup_commands.py
@@ -115,6 +115,8 @@ def _build_local_mcp_entry(
base_url: str,
use_python_path: bool = False,
command: str | None = None,
+ browser_type: str | None = None,
+ browser_remote_debugging_url: str | None = None,
) -> dict:
"""Build a stdio MCP entry for local self-hosted mode.
@@ -126,6 +128,10 @@ def _build_local_mcp_entry(
env_block["SKYVERN_BASE_URL"] = base_url
if api_key:
env_block["SKYVERN_API_KEY"] = api_key
+ if browser_type:
+ env_block["BROWSER_TYPE"] = browser_type
+ if browser_remote_debugging_url:
+ env_block["BROWSER_REMOTE_DEBUGGING_URL"] = browser_remote_debugging_url
_ = use_python_path
@@ -313,9 +319,17 @@ def _build_entry(
use_python_path: bool,
url: str | None,
use_mcp_remote_bridge: bool = False,
+ browser_type: str | None = None,
+ browser_remote_debugging_url: str | None = None,
) -> dict:
if local:
- return _build_local_mcp_entry(api_key, base_url, use_python_path=use_python_path)
+ return _build_local_mcp_entry(
+ api_key,
+ base_url,
+ use_python_path=use_python_path,
+ browser_type=browser_type,
+ browser_remote_debugging_url=browser_remote_debugging_url,
+ )
remote_url = url or _DEFAULT_REMOTE_URL
parsed = urlparse(remote_url)
if parsed.scheme not in ("http", "https"):
@@ -602,6 +616,8 @@ def _run_setup(
url: str | None,
*,
use_mcp_remote_bridge: bool = False,
+ browser_type: str | None = None,
+ browser_remote_debugging_url: str | None = None,
) -> None:
if tool_name == "Claude Desktop" and not local and use_mcp_remote_bridge and not _has_node_runtime():
console.print(f"[yellow]{_claude_desktop_bundle_message()}[/yellow]")
@@ -615,6 +631,8 @@ def _run_setup(
use_python_path=use_python_path,
url=url,
use_mcp_remote_bridge=use_mcp_remote_bridge,
+ browser_type=browser_type,
+ browser_remote_debugging_url=browser_remote_debugging_url,
)
_upsert_mcp_config(config_path, tool_name, entry, dry_run=dry_run, yes=yes)
@@ -768,6 +786,9 @@ def setup_guided(
f"[yellow]Skipping Claude Desktop JSON setup.[/yellow] {_claude_desktop_bundle_message()}"
)
continue
+ # Pass browser config from env for local mode
+ env_browser_type = os.environ.get("BROWSER_TYPE") if local else None
+ env_browser_url = os.environ.get("BROWSER_REMOTE_DEBUGGING_URL") if local else None
entry = _build_entry(
resolved_key,
env_url,
@@ -775,6 +796,8 @@ def setup_guided(
use_python_path=use_python_path,
url=url,
use_mcp_remote_bridge=use_bridge,
+ browser_type=env_browser_type,
+ browser_remote_debugging_url=env_browser_url,
)
_upsert_mcp_config(config_path, tool.name, entry, dry_run=dry_run, yes=True)
if tool.name == "Claude Code":
@@ -839,6 +862,8 @@ def setup_claude(
local: bool = _local_opt,
use_python_path: bool = _python_path_opt,
url: str | None = _url_opt,
+ browser_type: str | None = None,
+ browser_remote_debugging_url: str | None = None,
) -> None:
"""Register Skyvern MCP with Claude Desktop (remote mode requires Node.js; bundle is recommended otherwise)."""
_run_setup(
@@ -851,6 +876,8 @@ def setup_claude(
use_python_path,
url,
use_mcp_remote_bridge=not local,
+ browser_type=browser_type,
+ browser_remote_debugging_url=browser_remote_debugging_url,
)
@@ -864,7 +891,9 @@ def setup_claude_desktop_alias(
url: str | None = _url_opt,
) -> None:
"""Backward-compatible alias for `skyvern setup claude`."""
- setup_claude(api_key, dry_run, yes, local, use_python_path, url)
+ setup_claude(
+ api_key, dry_run, yes, local, use_python_path, url, browser_type=None, browser_remote_debugging_url=None
+ )
@setup_app.command("claude-code")
@@ -884,13 +913,26 @@ def setup_claude_code(
help="Write Claude Code MCP config to ~/.claude.json even if the current directory is a project",
),
skip_skills: bool = typer.Option(False, "--skip-skills", help="Don't install Claude Code skills (e.g. /qa)"),
+ browser_type: str | None = None,
+ browser_remote_debugging_url: str | None = None,
) -> None:
"""Register Skyvern MCP with Claude Code and install skills (remote by default)."""
config_path, install_skills = _claude_code_config_target(project=project, global_config=global_config)
if not project and not global_config:
target_label = ".mcp.json in the current project" if install_skills else "~/.claude.json"
console.print(f"[dim]Claude Code target: {target_label}[/dim]")
- _run_setup("Claude Code", config_path, api_key, dry_run, yes, local, use_python_path, url)
+ _run_setup(
+ "Claude Code",
+ config_path,
+ api_key,
+ dry_run,
+ yes,
+ local,
+ use_python_path,
+ url,
+ browser_type=browser_type,
+ browser_remote_debugging_url=browser_remote_debugging_url,
+ )
if not skip_skills:
if install_skills:
@@ -910,9 +952,22 @@ def setup_cursor(
local: bool = _local_opt,
use_python_path: bool = _python_path_opt,
url: str | None = _url_opt,
+ browser_type: str | None = None,
+ browser_remote_debugging_url: str | None = None,
) -> None:
"""Register Skyvern MCP with Cursor (remote by default)."""
- _run_setup("Cursor", _cursor_config_path(), api_key, dry_run, yes, local, use_python_path, url)
+ _run_setup(
+ "Cursor",
+ _cursor_config_path(),
+ api_key,
+ dry_run,
+ yes,
+ local,
+ use_python_path,
+ url,
+ browser_type=browser_type,
+ browser_remote_debugging_url=browser_remote_debugging_url,
+ )
@setup_app.command("windsurf")
@@ -923,6 +978,19 @@ def setup_windsurf(
local: bool = _local_opt,
use_python_path: bool = _python_path_opt,
url: str | None = _url_opt,
+ browser_type: str | None = None,
+ browser_remote_debugging_url: str | None = None,
) -> None:
"""Register Skyvern MCP with Windsurf (remote by default)."""
- _run_setup("Windsurf", _windsurf_config_path(), api_key, dry_run, yes, local, use_python_path, url)
+ _run_setup(
+ "Windsurf",
+ _windsurf_config_path(),
+ api_key,
+ dry_run,
+ yes,
+ local,
+ use_python_path,
+ url,
+ browser_type=browser_type,
+ browser_remote_debugging_url=browser_remote_debugging_url,
+ )
diff --git a/tests/unit/test_init_mcp.py b/tests/unit/test_init_mcp.py
index f686b2488..9cdcd45f2 100644
--- a/tests/unit/test_init_mcp.py
+++ b/tests/unit/test_init_mcp.py
@@ -29,6 +29,8 @@ def test_setup_mcp_local_claude_code_uses_local_stdio(monkeypatch) -> None:
"project": False,
"global_config": False,
"skip_skills": False,
+ "browser_type": None,
+ "browser_remote_debugging_url": None,
}
]