Skip to content

Commit 46379f2

Browse files
VinciGit00claude
andcommitted
Add time_range parameter to searchscraper
Add support for filtering search results by time range in the searchscraper tool. This aligns with the API changes in sgai-api#386. The time_range parameter accepts: past_hour, past_24_hours, past_week, past_month, or past_year to filter search results by recency. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 07dcf30 commit 46379f2

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

src/scrapegraph_mcp/server.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
import json
5656
import logging
5757
import os
58-
from typing import Any, Dict, Optional, List, Union, Annotated
58+
from typing import Any, Dict, Optional, List, Union, Annotated, Literal
5959

6060
import httpx
6161
from fastmcp import Context, FastMCP
@@ -235,14 +235,15 @@ def smartscraper_status(self, request_id: str) -> Dict[str, Any]:
235235

236236
return response.json()
237237

238-
def searchscraper(self, user_prompt: str, num_results: int = None, number_of_scrolls: int = None) -> Dict[str, Any]:
238+
def searchscraper(self, user_prompt: str, num_results: int = None, number_of_scrolls: int = None, time_range: str = None) -> Dict[str, Any]:
239239
"""
240240
Perform AI-powered web searches with structured results.
241241
242242
Args:
243243
user_prompt: Search query or instructions
244244
num_results: Number of websites to search (optional, default: 3 websites = 30 credits)
245245
number_of_scrolls: Number of infinite scrolls to perform on each website (optional)
246+
time_range: Filter results by time range (optional). Valid values: past_hour, past_24_hours, past_week, past_month, past_year
246247
247248
Returns:
248249
Dictionary containing search results and reference URLs
@@ -251,15 +252,19 @@ def searchscraper(self, user_prompt: str, num_results: int = None, number_of_scr
251252
data = {
252253
"user_prompt": user_prompt
253254
}
254-
255+
255256
# Add num_results to the request if provided
256257
if num_results is not None:
257258
data["num_results"] = num_results
258-
259+
259260
# Add number_of_scrolls to the request if provided
260261
if number_of_scrolls is not None:
261262
data["number_of_scrolls"] = number_of_scrolls
262263

264+
# Add time_range to the request if provided
265+
if time_range is not None:
266+
data["time_range"] = time_range
267+
263268
response = self.client.post(url, headers=self.headers, json=data)
264269

265270
if response.status_code != 200:
@@ -1829,7 +1834,8 @@ def searchscraper(
18291834
user_prompt: str,
18301835
ctx: Context,
18311836
num_results: Optional[int] = None,
1832-
number_of_scrolls: Optional[int] = None
1837+
number_of_scrolls: Optional[int] = None,
1838+
time_range: Optional[Literal["past_hour", "past_24_hours", "past_week", "past_month", "past_year"]] = None
18331839
) -> Dict[str, Any]:
18341840
"""
18351841
Perform AI-powered web searches with structured data extraction.
@@ -1877,6 +1883,22 @@ def searchscraper(
18771883
* 5: Extensive feeds, long-form content with infinite scroll
18781884
- Note: Increases processing time significantly (adds 5-10 seconds per scroll per page)
18791885
1886+
time_range (Optional[str]): Filter search results by time range.
1887+
- Default: None (no time filter applied)
1888+
- Valid values:
1889+
* "past_hour": Results from the last hour
1890+
* "past_24_hours": Results from the last 24 hours
1891+
* "past_week": Results from the last 7 days
1892+
* "past_month": Results from the last 30 days
1893+
* "past_year": Results from the last 365 days
1894+
- Examples:
1895+
* Use "past_hour" for breaking news or real-time updates
1896+
* Use "past_24_hours" for recent developments
1897+
* Use "past_week" for current events and trending topics
1898+
* Use "past_month" for recent but not immediate information
1899+
* Use "past_year" for relatively recent content
1900+
- Note: Useful for finding recent information or filtering out outdated content
1901+
18801902
Returns:
18811903
Dictionary containing:
18821904
- search_results: Array of extracted data from each website found
@@ -1903,7 +1925,7 @@ def searchscraper(
19031925
try:
19041926
api_key = get_api_key(ctx)
19051927
client = ScapeGraphClient(api_key)
1906-
return client.searchscraper(user_prompt, num_results, number_of_scrolls)
1928+
return client.searchscraper(user_prompt, num_results, number_of_scrolls, time_range)
19071929
except Exception as e:
19081930
return {"error": str(e)}
19091931

0 commit comments

Comments
 (0)