import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; //#region packages/browser/src/types.d.ts type BrowserMode = 'ui' | 'headless'; type AgentBrowserEngine = 'chrome' | 'lightpanda'; interface BrowserConfig { defaultMode: BrowserMode; /** Directory where agent-browser binary + Chrome will be cached */ browsersPath: string | null; /** User data directory for persistent browser profiles */ userDataDirRoot: string | null; /** Minutes of inactivity before the browser session is closed */ idleShutdownMinutes: number; /** Allow internal browser schemes (file:, chrome:, etc.) */ allowInternalSchemes: boolean; /** Allow loopback/localhost addresses (default: false for security) */ allowLoopback?: boolean; /** Timeout for eval operations in ms */ evalTimeoutMs: number; /** Max bytes for eval results before truncation */ evalMaxResultBytes: number; /** Mask password fields in screenshots */ redactPasswordFieldsInScreenshots: boolean; /** Browser engine: 'chrome' (default) or 'lightpanda' */ engine?: AgentBrowserEngine; /** Proxy server URL */ proxy?: string; /** Viewport size "width,height" */ viewport?: string; } declare const DEFAULT_BROWSER_CONFIG: BrowserConfig; interface TabInfo { tabId: string; url: string; title: string; label?: string; snapshot?: string; createdAt: Date; } /** * Replaces the old PageInfo. agent-browser uses stable tab IDs (t0, t1, t2...). * We alias them through the PageInfo shape for backward compat. */ interface PageInfo { pageId: string; url: string; title: string; label?: string; createdAt: Date; } interface SecurityCheckResult { allowed: boolean; reason?: string; } interface EvalValidationResult { valid: boolean; result?: string; truncated?: boolean; reason?: string; } /** * Result from an agent-browser CLI command execution. */ interface AgentBrowserResult { stdout: string; stderr: string; exitCode: number; } //#endregion //#region packages/browser/src/session.d.ts /** * TabRegistry manages agent-browser's stable tab IDs (t0, t1, t2...). * * agent-browser assigns stable string IDs to tabs that don't shift on close. * We track tab metadata alongside these IDs. */ declare class TabRegistry { private tabs; private labelToId; /** * Register a tab and return its ID. */ register(tabId: string, url: string, title?: string, label?: string): string; /** * Resolve a pageId or label to a tab ID. * If it's a valid tab ID, returns it as-is. * If it's a registered label, returns the tab ID. * Otherwise passes through (agent-browser also supports labels natively). */ resolve(pageIdOrLabel: string): string; getTab(tabId: string): TabInfo; updateTabInfo(tabId: string, url: string, title: string): void; setSnapshot(tabId: string, snapshot: string): void; getSnapshot(tabId: string): string | undefined; removeTab(tabId: string): Promise; listTabs(): TabInfo[]; /** * Return tabs as PageInfo array for backward compatibility with * the old SessionRegistry API. */ listPages(): PageInfo[]; closeAll(): Promise; clear(): void; get size(): number; } /** * Legacy SessionRegistry re-exported for backward compat. * Uses the new TabRegistry internally. */ declare class SessionRegistry { private tabs; registerPage(pageId: string, url: string, title: string, label?: string): string; getPage(_pageId: string): never; getPageInfo(pageId: string): PageInfo; resolvePageId(pageIdOrLabel: string): string; setSnapshot(pageId: string, snapshot: string): void; getSnapshot(pageId: string): string | undefined; updatePageInfo(pageId: string, url: string, title: string): void; removePage(pageId: string): Promise; listPages(): PageInfo[]; closeAll(): Promise; get size(): number; } //#endregion //#region packages/browser/src/engine.d.ts /** * BrowserEngine manages the agent-browser runtime. * * Rather than running a long-lived daemon process ourselves, we use the * per-command CLI approach: each call to exec() spawns agent-browser . * agent-browser's own daemon auto-starts on the first call and persists * between commands — so subsequent calls are fast (~5ms overhead). * * Tab tracking is done via the TabRegistry which maps agent-browser's * stable tab IDs (t0, t1, t2...) to page metadata. */ declare class BrowserEngine { private binaryPath; private _currentMode; private _isLaunched; private idleTimer; readonly tabs: TabRegistry; private config; constructor(config?: Partial); get currentMode(): BrowserMode | null; launch(mode?: BrowserMode, onProgress?: (msg: string) => void): Promise; /** * Execute a single agent-browser CLI command. * Returns stdout/stderr/exitCode. */ exec(command: string, ...args: string[]): Promise; /** Run a command via execFile (no shell). */ private execViaExecFile; /** Run a command via exec() (goes through cmd.exe shell). */ private execViaShell; /** * Execute a command scoped to a specific tab. * Prepends "tab " to the command automatically. */ tabExec(tabId: string, command: string, ...args: string[]): Promise; /** * Open a URL in a new tab and register it. * Returns the tab ID (t0, t1, t2...). */ open(url: string, mode?: BrowserMode, label?: string): Promise; /** * Take a screenshot of the active tab and return the base64-encoded PNG. * screenshot is a TOP-LEVEL command in agent-browser (not under `tab`). * It captures whatever tab is currently active. * exec() handles .cmd wrappers via shell on Windows automatically. */ screenshot(_tabId: string, options?: { fullPage?: boolean; format?: 'png' | 'jpeg'; quality?: number; selector?: string; /** Output directory for screenshot file. Defaults to tmpdir. */ screenshotDir?: string; /** Annotate screenshot with numbered element labels */ annotate?: boolean; }): Promise<{ base64: string; mimeType: string; bytes: number; }>; /** * Read the accessibility snapshot of a tab. */ readSnapshot(tabId: string, compact?: boolean): Promise; navigate(tabId: string, url: string): Promise; /** * Close the engine and all browser tabs. */ close(): Promise; isLaunched(): boolean; getConfig(): BrowserConfig; getBinaryPath(): string | null; /** * Resolve a pageId (or label) to a tab ID. * Accepts both agent-browser tab IDs (t0, t1) and named labels. */ resolvePageId(pageIdOrLabel: string): string; resetIdleTimer(): void; private stopIdleTimer; } declare function getEngine(config?: Partial): BrowserEngine; declare function closeEngine(): Promise; //#endregion //#region packages/browser/src/install.d.ts declare function getDefaultBrowsersPath(): string; declare function resolveBrowsersPath(config: BrowserConfig): string; /** * Ensure agent-browser binary is available. If not found globally, download it * via npx and cache the binary path. Returns the path to the agent-browser binary. */ declare function ensureAgentBrowserInstalled(config: BrowserConfig, onProgress?: (msg: string) => void): Promise; /** * Show the current agent-browser version. */ declare function getAgentBrowserVersion(binaryPath: string): Promise; /** * Check if the browser runtime is ready (binary exists + Chrome installed). */ declare function isBrowserReady(config: BrowserConfig): boolean; //#endregion //#region packages/browser/src/modes.d.ts declare function autoSelectMode(mode: BrowserMode | string): BrowserMode; /** * Get CLI arguments to pass to agent-browser daemon for the given mode. * agent-browser handles headless vs headed via its internal daemon config. * We just signal which mode we want. */ declare function getDaemonArgs(mode: BrowserMode): string[]; /** * Get the launch args to pass when opening a page. */ declare function getLaunchArgs(mode: BrowserMode): { headless: boolean; args: string[]; }; //#endregion //#region packages/browser/src/security.d.ts /** * Check whether the given URL is allowed to be navigated to. * Blocks dangerous schemes and cloud metadata endpoints. * * Same security policy as before — only the scheme check mechanism changes * (agent-browser receives the URL after we validate it, rather than Playwright). */ declare function isUrlAllowed(url: string, _config?: BrowserConfig): SecurityCheckResult; /** * Validate eval result size and optionally truncate. */ declare function validateEvalResult(result: string, maxBytes: number): { valid: boolean; result: string; truncated: boolean; reason?: string; }; //#endregion //#region packages/browser/src/tools/index.d.ts declare function registerBrowserTools(server: McpServer, config: Record): void; //#endregion export { AgentBrowserEngine, AgentBrowserResult, BrowserConfig, BrowserEngine, BrowserMode, DEFAULT_BROWSER_CONFIG, EvalValidationResult, PageInfo, SecurityCheckResult, SessionRegistry, TabInfo, TabRegistry, autoSelectMode, closeEngine, ensureAgentBrowserInstalled, getAgentBrowserVersion, getDaemonArgs, getDefaultBrowsersPath, getEngine, getLaunchArgs, isBrowserReady, isUrlAllowed, registerBrowserTools, resolveBrowsersPath, validateEvalResult };