Skip to main content
Glama
cnych

Backlinks MCP

by cnych

keyword_generator

Generate keyword ideas for SEO content by analyzing search trends and related terms to improve backlink strategies.

Instructions

Get keyword ideas for the specified keyword

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keywordYes
countryNous
search_engineNoGoogle

Implementation Reference

  • Handler function for 'keyword_generator' tool. Registers the tool via @mcp.tool(), handles captcha solving, and delegates to get_keyword_ideas for core logic.
    @mcp.tool()
    def keyword_generator(keyword: str, country: str = "us", search_engine: str = "Google") -> Optional[List[str]]:
        """
        Get keyword ideas for the specified keyword
        """
        site_url = f"https://ahrefs.com/keyword-generator/?country={country}&input={urllib.parse.quote(keyword)}"
        token = get_capsolver_token(site_url)
        if not token:
            raise Exception(f"Failed to get verification token for keyword: {keyword}")
        return get_keyword_ideas(token, keyword, country, search_engine)
  • Core helper function that makes API request to Ahrefs for keyword ideas and formats the response.
    def get_keyword_ideas(token: str, keyword: str, country: str = "us", search_engine: str = "Google") -> Optional[List[str]]:
        if not token:
            return None
        
        url = "https://ahrefs.com/v4/stGetFreeKeywordIdeas"
        payload = {
            "withQuestionIdeas": True,
            "captcha": token,
            "searchEngine": search_engine,
            "country": country,
            "keyword": ["Some", keyword]
        }
        
        headers = {
            "Content-Type": "application/json"
        }
        
        response = requests.post(url, json=payload, headers=headers)
        if response.status_code != 200:
            return None
        
        data = response.json()
    
        return format_keyword_ideas(data)
  • Helper function to parse and format the raw keyword ideas data from Ahrefs API into a structured list.
    def format_keyword_ideas(keyword_data: Optional[List[Any]]) -> List[str]:
        if not keyword_data or len(keyword_data) < 2:
            return ["\n❌ No valid keyword ideas retrieved"]
        
        data = keyword_data[1]
    
        result = []
        
        # 处理常规关键词推荐
        if "allIdeas" in data and "results" in data["allIdeas"]:
            all_ideas = data["allIdeas"]["results"]
            # total = data["allIdeas"].get("total", 0)
            for idea in all_ideas:
                simplified_idea = {
                    "keyword": idea.get('keyword', 'No keyword'),
                    "country": idea.get('country', '-'),
                    "difficulty": idea.get('difficultyLabel', 'Unknown'),
                    "volume": idea.get('volumeLabel', 'Unknown'),
                    "updatedAt": idea.get('updatedAt', '-')
                }
                result.append({
                    "label": "keyword ideas",
                    "value": simplified_idea
                })
        
        # 处理问题类关键词推荐
        if "questionIdeas" in data and "results" in data["questionIdeas"]:
            question_ideas = data["questionIdeas"]["results"]
            # total = data["questionIdeas"].get("total", 0)
            for idea in question_ideas:
                simplified_idea = {
                    "keyword": idea.get('keyword', 'No keyword'),
                    "country": idea.get('country', '-'),
                    "difficulty": idea.get('difficultyLabel', 'Unknown'),
                    "volume": idea.get('volumeLabel', 'Unknown'),
                    "updatedAt": idea.get('updatedAt', '-')
                }
                result.append({
                    "label": "question ideas",
                    "value": simplified_idea
                })
        
        if not result:
            return ["\n❌ No valid keyword ideas retrieved"]
        
        return result
  • Shared helper to obtain Cloudflare Turnstile token using CapSolver for bypassing Ahrefs captcha.
    def get_capsolver_token(site_url: str) -> Optional[str]:
        """
        Use CapSolver to solve the captcha and get a token
        
        Args:
            site_url: Site URL to query
            
        Returns:
            Verification token or None if failed
        """
        if not api_key:
            return None
        
        payload = {
            "clientKey": api_key,
            "task": {
                "type": 'AntiTurnstileTaskProxyLess',
                "websiteKey": "0x4AAAAAAAAzi9ITzSN9xKMi",  # site key of your target site: ahrefs.com,
                "websiteURL": site_url,
                "metadata": {
                    "action": ""  # optional
                }
            }
        }
        res = requests.post("https://api.capsolver.com/createTask", json=payload)
        resp = res.json()
        task_id = resp.get("taskId")
        if not task_id:
            return None
     
        while True:
            time.sleep(1)  # delay
            payload = {"clientKey": api_key, "taskId": task_id}
            res = requests.post("https://api.capsolver.com/getTaskResult", json=payload)
            resp = res.json()
            status = resp.get("status")
            if status == "ready":
                token = resp.get("solution", {}).get('token')
                return token
            if status == "failed" or resp.get("errorId"):
                return None
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states 'Get keyword ideas' but doesn't explain how it works (e.g., API calls, data sources), potential limitations (e.g., rate limits, freshness of data), or output format. This leaves significant gaps in understanding the tool's behavior beyond a basic read operation.

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

Conciseness5/5

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

The description is a single, straightforward sentence with no wasted words. It's front-loaded with the core action and resource, making it easy to parse quickly, though this brevity contributes to gaps in other dimensions.

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 complexity (3 parameters, no annotations, no output schema), the description is incomplete. It doesn't address how results are returned, error handling, or the tool's scope compared to siblings. For a tool that likely involves external data queries, more 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.

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It mentions 'specified keyword' but doesn't explain the 'keyword' parameter's semantics (e.g., seed term, phrase) or the purpose of 'country' and 'search_engine' parameters (e.g., localization, platform-specific results). The description adds minimal value beyond what the schema's property titles imply.

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

Purpose3/5

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

The description 'Get keyword ideas for the specified keyword' clearly states the verb ('Get') and resource ('keyword ideas'), but it's vague about what 'keyword ideas' entails (e.g., related keywords, search volume suggestions). It doesn't differentiate from sibling tools like 'keyword_difficulty', which might also involve keywords but for a different purpose.

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 like 'keyword_difficulty' or other siblings. It lacks context such as use cases (e.g., SEO research, content planning) or prerequisites, leaving the agent to infer usage based on the tool name alone.

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

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/cnych/backlinks-mcp'

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