list_cookies
Retrieve browser cookies for the current domain to inspect session data, authentication tokens, and user preferences during Selenium automation.
Instructions
Return browser cookies for the current domain.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/selenium_mcp_server/server.py:201-204 (registration)Tool registration for 'list_cookies' using @mcp.tool() decorator on FastMCP instance. Delegates to browser.cookies via _run helper.
@mcp.tool() def list_cookies() -> dict[str, list[dict[str, Any]]]: """Return browser cookies for the current domain.""" return _run("list_cookies", browser.cookies) - Actual handler in BrowserManager. Calls Selenium's get_cookies() on the current WebDriver under thread lock and returns them wrapped in a dict.
def cookies(self) -> dict[str, list[dict[str, Any]]]: with self._lock: return {"cookies": self._require_driver().get_cookies()} - Generic execution helper that invokes the handler function, converts result using _as_dict, and wraps exceptions into BrowserError.
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 - Utility to convert pydantic models to dicts; cookies are plain dicts so this is a pass-through.
def _as_dict(value: Any) -> Any: if hasattr(value, "model_dump"): return value.model_dump() return value