Skip to content

Commit 93ae0ac

Browse files
committed
fix(mcp): Set the session proxy to be browser-level argument
Thanks for @Yigtwxx for pointing that out in #418
1 parent 73ad18b commit 93ae0ac

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

docs/ai/mcp-server.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ Since version 0.4.15, the MCP server is reworked. If you are upgrading, note:
6060

6161
1. **The Streamable HTTP transport now requires authentication and binds to localhost.** `scrapling-mcp --http` on its own refuses to start; pass `--auth-token` (or the `SCRAPLING_MCP_AUTH_TOKEN` environment variable), or `--no-auth` to serve it unauthenticated on purpose. The default host is now `127.0.0.1` instead of `0.0.0.0`; pass `--host 0.0.0.0` to accept connections from the network.
6262
2. **The one-shot fetch tools no longer accept `session_id`.** `fetch`, `bulk_fetch`, `stealthy_fetch`, and `bulk_stealthy_fetch` always launch their own browser. To fetch through a session, use the new **`session_fetch`** tool (one URL per call, works with dynamic and stealthy sessions).
63-
3. **`open_session` takes browser-level parameters only.** The per-request options (`wait`, `timeout`, `google_search`, `network_idle`, `disable_resources`, `wait_selector`, `wait_selector_state`, `extra_headers`, `proxy`, `solve_cloudflare`) moved to `session_fetch` and are supplied on each call. `max_pages` was removed too, since a session manages a single page per call now.
63+
3. **`open_session` takes browser-level parameters only.** The per-request options (`wait`, `timeout`, `google_search`, `network_idle`, `disable_resources`, `wait_selector`, `wait_selector_state`, `extra_headers`, `solve_cloudflare`) moved to `session_fetch` and are supplied on each call. `proxy` stays on `open_session` (it applies to the whole session, which runs a single tab). `max_pages` was removed too, since a session manages a single page per call now.
64+
4. **The `get` tool is renamed to `make_request`.** It now takes a `method` parameter and supports GET (default), POST, PUT, and DELETE, with `data`/`json` for request bodies. `bulk_get` is unchanged.
6465

6566
## Installation
6667

scrapling/core/ai.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _typed_dict_keys(typed_dict: Any) -> frozenset:
6060
return frozenset(typed_dict.__required_keys__ | typed_dict.__optional_keys__)
6161

6262

63-
_EXCLUDED_FETCH_KEYS = frozenset({"page_action", "page_setup", "selector_config"})
63+
_EXCLUDED_FETCH_KEYS = frozenset({"page_action", "page_setup", "selector_config", "proxy"})
6464
_PLAYWRIGHT_FETCH_KEYS = _typed_dict_keys(PlaywrightFetchParams) - _EXCLUDED_FETCH_KEYS
6565
_STEALTH_FETCH_KEYS = _typed_dict_keys(StealthFetchParams) - _EXCLUDED_FETCH_KEYS
6666

@@ -208,6 +208,7 @@ async def open_session(
208208
timezone_id: str | None = None,
209209
locale: str | None = None,
210210
useragent: Optional[str] = None,
211+
proxy: Optional[str | Dict[str, str]] = None,
211212
cdp_url: Optional[str] = None,
212213
executable_path: Optional[str] = None,
213214
cookies: Sequence[SetCookieParam] | None = None,
@@ -228,6 +229,7 @@ async def open_session(
228229
:param timezone_id: Changes the timezone of the browser. Defaults to the system timezone.
229230
:param locale: Specify user locale, for example, `en-GB`, `de-DE`, etc.
230231
:param useragent: Pass a useragent string to be used. Otherwise the fetcher will generate a real Useragent of the same browser and use it.
232+
:param proxy: The proxy used for every request in this session, as a string or a dictionary with the keys 'server', 'username', and 'password' only.
231233
:param cdp_url: Instead of launching a new browser instance, connect to this CDP URL to control real browsers through CDP.
232234
:param executable_path: Absolute path to a custom Chromium-compatible browser executable. Overrides the server-wide default for this session.
233235
:param cookies: Set cookies for the session. It should be in a dictionary format that Playwright accepts.
@@ -243,6 +245,7 @@ async def open_session(
243245
)
244246

245247
common_kwargs: Dict[str, Any] = dict(
248+
proxy=proxy,
246249
locale=locale,
247250
cookies=cookies,
248251
cdp_url=cdp_url,
@@ -872,7 +875,6 @@ async def session_fetch(
872875
wait_selector_state: SelectorWaitStates = "attached",
873876
extra_headers: Optional[Dict[str, str]] = None,
874877
blocked_domains: Optional[Set[str]] = None,
875-
proxy: Optional[str | Dict[str, str]] = None,
876878
solve_cloudflare: bool = False,
877879
) -> ResponseModel:
878880
"""Fetch a URL through a browser session previously opened with `open_session` and return a structured output of the result.
@@ -894,7 +896,6 @@ async def session_fetch(
894896
:param wait_selector_state: The state to wait for the selector given with `wait_selector`.
895897
:param extra_headers: A dictionary of extra headers to add to the request. _The referer set by `google_search` takes priority over the referer set here if used together._
896898
:param blocked_domains: A list of domain names to block requests to for this request. Subdomains are also matched.
897-
:param proxy: The proxy to be used with this request, it can be a string or a dictionary with the keys 'server', 'username', and 'password' only.
898899
:param solve_cloudflare: (Stealthy sessions only) Solves all types of the Cloudflare's Turnstile/Interstitial challenges before returning the response.
899900
"""
900901
entry = self._get_session(session_id, expected_type=None)
@@ -916,7 +917,6 @@ async def session_fetch(
916917
wait_selector_state=wait_selector_state,
917918
extra_headers=extra_headers,
918919
blocked_domains=blocked_domains,
919-
proxy=proxy,
920920
solve_cloudflare=solve_cloudflare,
921921
)
922922
page = await entry.session.fetch(

0 commit comments

Comments
 (0)