Skip to main content
Glama
cnych

Backlinks MCP

by cnych

get_traffic

Check estimated search traffic for any website by domain or URL, with options for country-specific data and query modes.

Instructions

Check the estimated search traffic for any website. 

Args:
    domain_or_url (str): The domain or URL to query
    country (str): The country to query, default is "None"
    mode (["subdomains", "exact"]): The mode to use for the query
Returns:
    Traffic data for the specified domain or URL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
domain_or_urlYes
countryNoNone
modeNosubdomains

Implementation Reference

  • The get_traffic tool handler, registered via @mcp.tool() decorator. Handles captcha token acquisition and delegates to check_traffic for core logic.
    @mcp.tool()
    def get_traffic(domain_or_url: str, country: str = "None", mode: Literal["subdomains", "exact"] = "subdomains") -> Optional[Dict[str, Any]]:
        """
        Check the estimated search traffic for any website. 
    
        Args:
            domain_or_url (str): The domain or URL to query
            country (str): The country to query, default is "None"
            mode (["subdomains", "exact"]): The mode to use for the query
        Returns:
            Traffic data for the specified domain or URL
        """
        site_url = f"https://ahrefs.com/traffic-checker/?input={domain_or_url}&mode={mode}"
        token = get_capsolver_token(site_url)
        if not token:
            raise Exception(f"Failed to get verification token for domain: {domain_or_url}")
        return check_traffic(token, domain_or_url, mode, country)
  • Core helper function implementing the traffic check by making authenticated request to Ahrefs API and parsing the response.
    def check_traffic(token: str, domain_or_url: str, mode: Literal["subdomains", "exact"] = "subdomains", country: str = "None") -> Optional[Dict[str, Any]]:
        """
        Check the estimated search traffic for any website.
        
        Args:
            domain_or_url (str): The domain or URL to query
            token (str): Verification token
            mode (str): Query mode, default is "subdomains"
            country (str): Country, default is "None"
        
        Returns:
            Optional[Dict[str, Any]]: Dictionary containing traffic data, returns None if request fails
        """
        if not token:
            return None
        
        url = "https://ahrefs.com/v4/stGetFreeTrafficOverview"
        
        # 将参数转换为JSON字符串,然后作为单个input参数传递
        params = {
            "input": json.dumps({
                "captcha": token,
                "country": country,
                "protocol": "None",
                "mode": mode,
                "url": domain_or_url
            })
        }
        
        headers = {
            "accept": "*/*",
            "content-type": "application/json",
            "referer": f"https://ahrefs.com/traffic-checker/?input={domain_or_url}&mode={mode}"
        }
    
        try:
            response = requests.get(url, params=params, headers=headers)
            if response.status_code != 200:
                return None
            
            data: Optional[List[Any]] = response.json()
    
            # 检查响应数据格式
            if not isinstance(data, list) or len(data) < 2 or data[0] != "Ok":
                return None
            
            # 提取有效数据
            traffic_data = data[1]
            
            # 格式化返回结果
            result = {
                "traffic_history": traffic_data.get("traffic_history", []),
                "traffic": {
                    "trafficMonthlyAvg": traffic_data.get("traffic", {}).get("trafficMonthlyAvg", 0),
                    "costMontlyAvg": traffic_data.get("traffic", {}).get("costMontlyAvg", 0)
                },
                "top_pages": traffic_data.get("top_pages", []),
                "top_countries": traffic_data.get("top_countries", []),
                "top_keywords": traffic_data.get("top_keywords", [])
            }
            
            return result
        except Exception as e:

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.9/5.0
Behavior2/5

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

No annotations are present, so the description carries the full burden. It does not disclose whether the tool is read-only, destructive, requires authentication, or has rate limits. For a data query tool, this is a significant gap.

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 at two sentences plus an Args/Returns list. It is front-loaded with the purpose and structured for easy scanning. No wasted words.

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 no output schema, the description only vaguely states 'Traffic data' without specifying structure. Combined with missing behavioral context, the description is incomplete for a 3-parameter tool.

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?

The description includes an Args section that lists parameters and their types, adding some meaning beyond the schema (e.g., domain_or_url is 'The domain or URL to query'). However, it does not explain the difference between 'subdomains' and 'exact' modes, nor the effect of the country parameter, beyond default values.

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 states 'Check the estimated search traffic for any website', which clearly identifies the verb and resource. It distinguishes from sibling tools like get_backlinks_list and keyword_difficulty by focusing on traffic estimation, but does not explicitly differentiate.

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 alternatives, nor does it specify prerequisites or exclusions. It simply states the tool's function without context for decision-making.

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