Skip to main content
Glama
tsmndev

tavily-mcp-python

by tsmndev

tavily-crawl

Initiate a structured web crawl from a specified URL, controlling depth, breadth, and focus on specific sections or domains using regex and predefined categories. Extract content in markdown or text format for targeted data retrieval.

Instructions

A powerful web crawler that initiates a structured web crawl starting from a specified base URL. The crawler expands from that point like a tree, following internal links across pages. You can control how deep and wide it goes, and guide it to focus on specific sections of the site.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
allow_externalNoWhether to allow following links that go to external domains
categoriesNoFilter URLs using predefined categories like documentation, blog, api, etc
extract_depthNoAdvanced extraction retrieves more data, including tables and embedded content, with higher success but may increase latencybasic
formatNoThe format of the extracted web page content. markdown returns content in markdown format. text returns plain text and may increase latency.markdown
instructionsYesNatural language instructions for the crawler
limitNoTotal number of links the crawler will process before stopping
max_breadthNoMax number of links to follow per level of the tree (i.e., per page)
max_depthNoMax depth of the crawl. Defines how far from the base URL the crawler can explore.
select_domainsNoRegex patterns to select crawling to specific domains or subdomains (e.g., ^docs\.example\.com$)
select_pathsNoRegex patterns to select only URLs with specific path patterns (e.g., /docs/.*, /api/v1.*)
urlYesRoot URL to begin the crawl

Implementation Reference

  • The handler function for 'tavily-crawl' tool. It defines input parameters with descriptions and defaults, makes an HTTP POST request to Tavily's crawl API with the parameters, handles errors, validates the response using TavilyCrawlResponse Pydantic model, and returns the dumped model.
    @mcp_server.tool(name='tavily-crawl')
    async def crawl(
        url: Annotated[str, Field(
            description="""Root URL to begin the crawl"""
        )],
        instructions: Annotated[str, Field(
            description="""Natural language instructions for the crawler"""
        )],
        max_depth: Annotated[int, Field(
            default=1,
            ge=1,
            description="""Max depth of the crawl. Defines how far from the base URL the crawler can explore."""
        )],
        max_breadth: Annotated[int, Field(
            default=20,
            ge=1,
            description="""Max number of links to follow per level of the tree (i.e., per page)"""
        )],
        limit: Annotated[int, Field(
            default=50,
            ge=1,
            description="""Total number of links the crawler will process before stopping"""
        )],
        select_paths: Annotated[list[str], Field(
            default_factory=list,
            description="""Regex patterns to select only URLs with specific path patterns (e.g., /docs/.*, /api/v1.*)"""
        )],
        select_domains: Annotated[list[str], Field(
            default_factory=list,
            description="""Regex patterns to select crawling to specific domains or subdomains (e.g., ^docs\\.example\\.com$)"""
        )],
        allow_external: Annotated[bool, Field(
            default=False,
            description="""Whether to allow following links that go to external domains"""
        )],
        categories: Annotated[list[CrawlCategoriesLiteral], Field(
            default_factory=list,
            description="""Filter URLs using predefined categories like documentation, blog, api, etc"""
        )],
        extract_depth: Annotated[ExtractDepthLiteral, Field(
            default="basic",
            description="Advanced extraction retrieves more data, including tables and embedded content, with higher success but may increase latency"
        )],
        format: Annotated[FormatLiteral, Field(
            default="markdown",
            description="""The format of the extracted web page content. markdown returns content in markdown format. text returns plain text and may increase latency."""
        )]
    ) -> dict[str, Any]:
        """A powerful web crawler that initiates a structured web crawl starting from a specified base URL. The crawler expands from that point like a tree, following internal links across pages. You can control how deep and wide it goes, and guide it to focus on specific sections of the site."""
        endpoint = base_urls['crawl']
        search_params = {
            "url": url,
            "instructions": instructions,
            "max_depth": max_depth,
            "max_breadth": max_breadth,
            "limit": limit,
            "select_paths": select_paths,
            "select_domains": select_domains,
            "allow_external": allow_external,
            "categories": categories,
            "extract_depth": extract_depth,
            "format": format,
            "api_key": TAVILY_API_KEY,
        }
        try:
            async with httpx.AsyncClient(headers=headers) as client:
                response = await client.post(endpoint, json=search_params)
                if not response.is_success:
                    if response.status_code == 401:
                        raise ValueError("Invalid API Key")
                    elif response.status_code == 429:
                        raise ValueError("Usage limit exceeded")
                    _ = response.raise_for_status()
    
        except BaseException as e:
            raise e
    
        response_dict: dict[str, Any] = response.json()
        return  TavilyCrawlResponse.model_validate(response_dict).model_dump()
  • Pydantic schemas for the output of the tavily-crawl tool, including the main TavilyCrawlResponse model and nested CrawlResult model used for response validation.
    # Tavily Crawl Response Schema
    class CrawlResult(BaseModel):
        url: str
        raw_content: str
    
    class TavilyCrawlResponse(BaseModel):
        base_url: str
        results: list[CrawlResult]
        response_time: float
  • The decorator that registers the crawl function as the 'tavily-crawl' tool in the FastMCP server.
    @mcp_server.tool(name='tavily-crawl')
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes the crawling mechanism (tree-like expansion) and some controls, but lacks critical details like rate limits, authentication needs, error handling, or what the output looks like (e.g., format, structure). For a complex tool with 11 parameters, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and front-loaded, stating the core purpose in the first sentence. Each subsequent sentence adds relevant context about crawling behavior and controls without unnecessary fluff. However, it could be slightly more structured by explicitly mentioning key parameters.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (11 parameters, no annotations, no output schema), the description is incomplete. It doesn't explain the output format, potential side effects (e.g., network usage), or error scenarios. For a web crawler with many controls, more behavioral and output context is needed to guide effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds minimal value by mentioning depth, breadth, and focusing on site sections, which loosely relates to max_depth, max_breadth, and categories/select_paths, but doesn't provide additional syntax or usage context beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as initiating a structured web crawl from a base URL, following internal links like a tree, with control over depth and breadth. It specifies the verb 'crawl' and resource 'web pages' but doesn't explicitly distinguish it from sibling tools like tavily-extract or tavily-map, which likely have different functions.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus its siblings (tavily-extract, tavily-map, tavily-search). It mentions controlling depth and width and focusing on site sections, but this is more about parameter usage rather than contextual application or alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tsmndev/tavily-mcp-python'

If you have feedback or need assistance with the MCP directory API, please join our Discord server