MCPcopy Create free account
hub / github.com/ScrapeGraphAI/scrapecraft / validate_urls_tool

Function validate_urls_tool

backend/app/agents/tools/scraping_tools.py:251–289  ·  view source on GitHub ↗

Validate a list of URLs to check if they are accessible. This tool checks if URLs are valid and accessible, helping to filter out broken links before scraping. Args: urls: List of URLs to validate Returns: Dictionary with validation results for

(urls: List[str])

Source from the content-addressed store, hash-verified

249
250@tool("validate_urls")
251async def validate_urls_tool(urls: List[str]) -> Dict[str, Any]:
252 """
253 Validate a list of URLs to check if they are accessible.
254
255 This tool checks if URLs are valid and accessible, helping to
256 filter out broken links before scraping.
257
258 Args:
259 urls: List of URLs to validate
260
261 Returns:
262 Dictionary with validation results for each URL
263 """
264 import aiohttp
265
266 results = []
267
268 async with aiohttp.ClientSession() as session:
269 for url in urls:
270 try:
271 async with session.head(url, timeout=5, allow_redirects=True) as response:
272 results.append({
273 "url": url,
274 "valid": response.status < 400,
275 "status_code": response.status,
276 "final_url": str(response.url)
277 })
278 except Exception as e:
279 results.append({
280 "url": url,
281 "valid": False,
282 "error": str(e)
283 })
284
285 return {
286 "urls_checked": len(urls),
287 "valid_urls": sum(1 for r in results if r.get("valid", False)),
288 "results": results
289 }
290
291
292# Export all tools

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected