home / mcp / x-search mcp server

x-search MCP Server

Provides an MCP endpoint for xAI X search that returns structured outputs and normalized citations via the Responses API.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "konarkm-x-search-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "x-search-mcp"
      ],
      "env": {
        "XAI_MODEL": "grok-4-1-fast",
        "XAI_API_KEY": "YOUR_API_KEY",
        "XAI_TIMEOUT": "30000",
        "XAI_BASE_URL": "https://api.x.ai/v1"
      }
    }
  }
}

You can run this MCP server as an integration point for xAI X search, enabling structured outputs and normalized citations when you search X. It exposes a single tool named x_search that communicates with the Responses API to return typed results suitable for downstream apps.

How to use

Use a compatible MCP client to connect to the server. You will invoke the x_search tool with your search query and optional filters. The tool returns a structured response that includes an answer, citations, and a normalized raw response. You can enable or disable raw responses and citations as needed for display in your app.

How to install

Prerequisites: you must have Node.js version 18 or newer installed on your machine.

Install dependencies and build the local MCP package.

npm install
npm run build

Additional sections

MCP client configuration allows you to connect to the server using a stdio-based runtime. The following config shows how to run the MCP server locally with an API key supplied via environment variables.

{
  "mcpServers": {
    "x-search": {
      "command": "npx",
      "args": ["-y", "x-search-mcp"],
      "env": {
        "XAI_API_KEY": "your-key-here"
      }
    }
  }
}

Notes

You must provide the XAI_API_KEY in your environment. Other environment variables that may be used by the server include XAI_MODEL, XAI_BASE_URL, and XAI_TIMEOUT with their typical defaults noted below.

Tip: the local development workflow uses npm install and npm run build to prepare the MCP server. A smoke test is available to verify the setup, but it requires network access.

Available tools

x_search

Searches X with optional filters and returns a structured answer, citations, and raw response payload when requested. The tool supports filtering by date, handle whitelists/blacklists, and content type toggles.