2121SERPER_API_KEY = os .environ .get ("SERPER_API_KEY" , "" )
2222
2323
24- async def search_tool (query : str , ctx = None ) -> dict :
24+ async def search_tool (query : str , ctx = None , max_results : int = 5 ) -> dict :
2525 """Search the web for information on a given query.
2626
2727 This MCP tool searches the web using Serper API (premium) or DuckDuckGo
@@ -30,11 +30,12 @@ async def search_tool(query: str, ctx=None) -> dict:
3030 Args:
3131 query: The search query string
3232 ctx: Optional MCP context (may contain authentication headers)
33+ max_results: Maximum number of results to return (default: 5)
3334
3435 Returns:
3536 Dict representation of SearchResponse model (for MCP JSON serialization)
3637 """
37- logger .info (f"Processing search request: { query } " )
38+ logger .info (f"Processing search request: { query } (max { max_results } results) " )
3839
3940 # Validate authentication if WEBCAT_API_KEY is set
4041 is_valid , error_msg = validate_bearer_token (ctx )
@@ -49,7 +50,7 @@ async def search_tool(query: str, ctx=None) -> dict:
4950 return response .model_dump ()
5051
5152 # Fetch results with automatic fallback
52- api_results , search_source = fetch_with_fallback (query , SERPER_API_KEY )
53+ api_results , search_source = fetch_with_fallback (query , SERPER_API_KEY , max_results )
5354
5455 # Check if we got any results
5556 if not api_results :
0 commit comments