session_identity

Browser identity (cookies, User-Agent) sent with Google Scholar requests.

Scholar answers plain HTTP clients with a JavaScript bot check. A real browser passes it once and keeps the resulting cookies. Passing those cookies (and the matching User-Agent) from the user’s own browser lets scholarly reuse that verified session. This is experimental: the cookies expire and are typically tied to the IP address and User-Agent they were issued for.

Cookie values are credentials. They are never logged or printed here, and Config hides them from repr. Only cookie names are ever shown.

google_scholar_search_mcp.session_identity.parse_cookies(text)[source]

Parse copied cookies into a name -> value mapping.

Accepts a Cookie header (a=1; b=2, optional leading Cookie:, possibly wrapped over several lines) or the tab-separated table copied from the browser’s Application/Storage tab (one cookie per line, name first, value second).

Parameters:

text (str | None) – Cookie text as copied from the browser.

Returns:

dict[str, str] – Cookies in order; empty for blank input. Parts without a name or value separator are ignored.

Return type:

dict[str, str]

Where set-cookies saves the identity and the server looks for it.

Returns:

Path – $XDG_CONFIG_HOME/google-scholar-mcp/cookies (~/.config when the variable is unset). The file need not exist.

Return type:

Path

google_scholar_search_mcp.session_identity.split_identity(text)[source]

Split the contents of a cookie file into cookies and User-Agent.

A cookie file may carry the browser’s User-Agent on a line of its own (User-Agent: Mozilla/5.0 ...), as set-cookies writes it, so one file describes the whole identity.

Parameters:

text (str | None) – File contents.

Returns:

tuple[str | None, str | None] – Cookie text (everything else) and the User-Agent, each None when absent.

Return type:

tuple[str | None, str | None]

google_scholar_search_mcp.session_identity.write_identity_file(path, cookies, user_agent)[source]

Save cookies and User-Agent to a file only the owner can read.

Parameters:
  • path (Path) – Destination; parent directories are created.

  • cookies (dict[str, str]) – Cookie names and values.

  • user_agent (str) – The browser’s User-Agent.

Return the names of any Google login cookies in a cookie set.

Parameters:

cookies (dict[str, str]) – Parsed cookies.

Returns:

list[str] – Offending cookie names (never values), sorted.

Return type:

list[str]

google_scholar_search_mcp.session_identity.set_identity(cookies, user_agent)[source]

Configure the identity used for all following Scholar requests.

Parameters:
  • cookies (str | None) – Cookie header text, or None for none.

  • user_agent (str | None) – User-Agent to send, or None to keep scholarly’s own.

Names of the configured cookies (for diagnostics; never the values).

Returns:

list[str] – Cookie names in configured order.

Return type:

list[str]

google_scholar_search_mcp.session_identity.apply_identity(request)[source]

Add the configured cookies and User-Agent to a Scholar request.

Cookies already on the request (from the client’s own jar, e.g. refreshed by Scholar’s Set-Cookie) win over the configured ones of the same name. Requests to other hosts are left alone.

Parameters:

request (httpx.Request) – Request about to be sent; modified in place.