Skip to main content
Glama

web_search

Search the web to find information, answer questions, and gather data for the Grok MCP server using customizable parameters like domains and citations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYes
modelNogrok-4-1-fast-reasoning
allowed_domainsNo
excluded_domainsNo
enable_image_understandingNo
include_inline_citationsNo
max_turnsNo

Implementation Reference

  • The 'web_search' MCP tool implementation, which utilizes the xai_sdk's web_search tool within a Grok chat interaction.
    @mcp.tool(annotations=READONLY)
    async def web_search(
        prompt: str,
        model: str = "grok-4-1-fast-reasoning",
        allowed_domains: Optional[List[str]] = None,
        excluded_domains: Optional[List[str]] = None,
        enable_image_understanding: bool = False,
        include_inline_citations: bool = False,
        max_turns: Optional[int] = None
    ):
    
        if allowed_domains and excluded_domains:
            raise ValueError("Cannot specify both allowed_domains and excluded_domains")
        if allowed_domains and len(allowed_domains) > 5:
            raise ValueError("allowed_domains max 5")
        if excluded_domains and len(excluded_domains) > 5:
            raise ValueError("excluded_domains max 5")
        
        client = Client(api_key=XAI_API_KEY)
        
        tool_params = build_params(
            allowed_domains=allowed_domains,
            excluded_domains=excluded_domains,
            enable_image_understanding=enable_image_understanding,
        )
        
        include_options = []
        if include_inline_citations:
            include_options.append("inline_citations")
        
        chat_params = {"model": model, "tools": [xai_web_search(**tool_params)]}
        if include_options:
            chat_params["include"] = include_options
        if max_turns:
            chat_params["max_turns"] = max_turns
        
        chat = client.chat.create(**chat_params)
        chat.append(user(prompt))
        response = chat.sample()
        
        client.close()
    
        result = [response.content]
        if response.citations:
            result.append("\n\n**Sources:**")
            for url in response.citations:
                result.append(f"- {url}")
        return "\n".join(result)

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/merterbak/Grok-MCP'

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