Skip to main content
Glama

web_search

Search the web for information using Grok MCP to find answers, verify facts, and gather data from online sources.

Input Schema

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

Implementation Reference

  • Main handler function for web_search tool. Validates domain parameters (allowed_domains/excluded_domains cannot both be specified, max 5 each), creates chat client with xai_sdk's web_search tool, executes search and returns formatted results with citations if available.
    @mcp.tool() async def web_search( prompt: str, model: str = "grok-4-1-fast", 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)
  • src/server.py:7-7 (registration)
    Imports the web_search tool from xai_sdk.tools as xai_web_search, which is the underlying SDK implementation used by the MCP tool.
    from xai_sdk.tools import web_search as xai_web_search, x_search as xai_x_search, code_execution
  • src/server.py:172-172 (registration)
    Tool registration via @mcp.tool() decorator that registers the web_search function as an MCP tool.
    @mcp.tool()
  • Helper function build_params that filters out None values from keyword arguments, used to construct tool parameters for web_search.
    def build_params(**kwargs): result = {} for key, value in kwargs.items(): if value: result[key] = value return 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