File size: 973 Bytes
68b80a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from .tool import Tool
from firecrawl import FirecrawlApp
from dotenv import load_dotenv
import os

load_dotenv()

class FirecrawlScrapeTool(Tool):
    def __init__(self):
        super().__init__(
            name="firecrawl_scrape",
            description="Scrape a website and return the markdownified version of the content",
            inputSchema={
                "type": "object",
                "properties": {
                    "url": {"type": "string", "description": "The URL to scrape"}
                }
            }
        )

    def __call__(self, url: str):
        try:
            if not url:
                return "Error: URL parameter is required"

            app = FirecrawlApp(api_key=os.getenv("FIRECRAWL_API_KEY"))

            scrape_result = app.scrape_url(url, formats=['markdown', 'html'])
            return scrape_result["data"]["markdown"]

        except Exception as e:
            return f"Error scraping URL: {str(e)}"