throttle

Spacing between individual HTTP requests to Google Scholar.

One tool call can send several requests (a title lookup searches first and then fetches the record; scholarly also retries internally). Spacing whole tool calls would let those requests go out back to back, which is exactly the burst pattern Scholar’s bot detection looks for. This throttle sits at the HTTP layer (see block_detector) and spaces every request instead.

class google_scholar_search_mcp.throttle.RequestThrottle(min_delay=0.0, max_delay=0.0)[source]

Bases: object

Make consecutive requests wait a random delay, measured from the last reply.

Requests are also serialized: wait() takes a slot that only mark() gives back, so two threads can never have a request in flight at the same time.

configure(min_delay, max_delay)[source]

Change the delays.

Parameters:
  • min_delay (float) – Minimum seconds between requests.

  • max_delay (float) – Maximum seconds between requests.

reset()[source]

Forget when the last request finished (the next one goes at once).

wait()[source]

Take the request slot, sleeping until the next request may be sent.

Must be paired with mark(), in a try/finally. Concurrent callers queue up on the slot, so their requests go out one after another.

mark()[source]

Record that the request finished and give the slot back.