Content
# mcp-grok-websearch
An MCP server that exposes [Grok Build CLI](https://x.ai/cli)'s built-in `web_search` as a standard MCP tool. Any MCP-compatible agent (Codex, Claude Desktop, Cursor, etc.) can use it for real-time web search.
## Prerequisites
1. **Grok Build CLI** installed and authenticated:
```bash
curl -fsSL https://x.ai/cli/install.sh | bash
grok login # OAuth, or set GROK_CODE_XAI_API_KEY below
```
2. **uv** (for `uvx` usage): https://docs.astral.sh/uv/
## Usage
### Run directly with uvx (no install needed)
```bash
uvx mcp-grok-websearch
```
### Configure in an MCP-compatible agent
Add to your agent's MCP config (e.g. `~/.codex/config.json`, `claude_desktop_config.json`, etc.):
```json
{
"mcpServers": {
"websearch": {
"command": "uvx",
"args": ["mcp-grok-websearch"]
}
}
}
```
If you use an API key instead of `grok login`:
```json
{
"mcpServers": {
"websearch": {
"command": "uvx",
"args": ["mcp-grok-websearch"],
"env": {
"GROK_CODE_XAI_API_KEY": "xai-..."
}
}
}
}
```
## MCP Tool
### `web_search`
Search the web in real time using Grok's built-in search capability.
| Parameter | Type | Default | Description |
|---|---|---|---|
| `query` | `str` | required | Search query |
| `max_results` | `int` | `5` | Number of results (1–20) |
**Returns:** Formatted results, each with `Title`, `URL`, and `Summary`, separated by `---`.
**Example result:**
```
Title: Model Context Protocol – Anthropic
URL: https://modelcontextprotocol.io
Summary: The official site for MCP, the open standard for connecting AI to external tools and data sources.
---
Title: MCP GitHub Repository
URL: https://github.com/modelcontextprotocol
Summary: Source code and SDKs for the Model Context Protocol.
---
```
## Authentication
The server supports two modes, tried in this order:
1. **API key** – set `GROK_CODE_XAI_API_KEY` (or `XAI_API_KEY`) in the environment.
2. **OAuth session** – if no key is present, the existing `grok login` session on the machine is used.
## License
MIT