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
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | ||
| model | No | grok-4-1-fast-reasoning | |
| allowed_domains | No | ||
| excluded_domains | No | ||
| enable_image_understanding | No | ||
| include_inline_citations | No | ||
| max_turns | No |
Implementation Reference
- src/server.py:243-290 (handler)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)