x-search-mcp
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@x-search-mcpWhat's the latest on the Mars mission from NASA?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
x-search-mcp
A self-contained Model Context Protocol (MCP) server that gives Codex, Claude Code, and other MCP clients access to xAI's built-in X Search.
It calls xAI's Responses API with the server-side x_search tool. The result is a Grok-generated research answer with citations from X, rather than a raw firehose or a replacement for the official X API.
Features
Search current X posts, profiles, and threads with natural-language queries.
Include or exclude specific X handles.
Restrict searches to a date range.
Optionally analyze images and videos attached to matching posts.
Return both top-level and inline citation metadata.
Mark filtered responses as
degradedwhen xAI returns no citations.Authenticate with standalone xAI device-code OAuth or
XAI_API_KEY.Refresh rotating OAuth tokens automatically with a cross-process file lock.
Expose a narrow, read-only stdio MCP surface containing one tool:
x_search.
Related MCP server: Grok MCP Server
Requirements
Python 3.11 or newer
An xAI account eligible for OAuth API access, or an xAI API key
An MCP client such as Codex or Claude Code
Installation
Clone the repository and install the command with uv:
git clone https://github.com/kamellperry/x-search-mcp.git
cd x-search-mcp
uv tool install .For local development, use uv sync instead:
uv syncAuthentication
Device-code OAuth
Run the login command once:
x-search-mcp loginThe command opens xAI's device authorization page, waits for approval, and stores the resulting tokens in:
~/.config/x-search-mcp/auth.jsonThe auth directory and token file are created with user-only permissions. The server refreshes expiring access tokens automatically and persists rotated refresh tokens atomically. It does not read Hermes, Codex, Claude, browser, or shell credential stores.
Check credential state without printing any token:
x-search-mcp statusOAuth access depends on xAI account tier and entitlement. If xAI rejects OAuth API access, use an API key instead.
API key fallback
Set an xAI API key in the environment that launches the MCP server:
export XAI_API_KEY="your-api-key"Stored OAuth is preferred when both credential methods are present.
Connect an MCP client
Codex
If the command was installed with uv tool install .:
codex mcp add x-search -- x-search-mcp serve
codex mcp get x-searchFor a development checkout, use the included launcher:
codex mcp add x-search -- /absolute/path/to/x-search-mcp/run-serverThen start a fresh Codex session so it receives the new tool manifest.
Claude Code
If the command was installed globally:
claude mcp add --scope user x-search -- x-search-mcp serve
claude mcp get x-searchFor a development checkout:
claude mcp add --scope user x-search -- /absolute/path/to/x-search-mcp/run-serverOther MCP clients
Configure a stdio server with either of these commands:
x-search-mcp serve/absolute/path/to/x-search-mcp/run-serverDo not run the stdio server through a wrapper that writes ordinary output to stdout. MCP protocol messages use stdout; diagnostics belong on stderr.
Tool reference
x_search
Argument | Type | Required | Description |
| string | yes | Natural-language description of what to find on X. |
| string[] | no | Search only these handles, maximum 10. Leading |
| string[] | no | Exclude these handles, maximum 10. Cannot be combined with |
| string | no | Inclusive start date in |
| string | no | End date in |
| boolean | no | Ask xAI to inspect images attached to matching posts. |
| boolean | no | Ask xAI to inspect videos attached to matching posts. |
Example tool arguments:
{
"query": "What has xAI announced recently?",
"allowed_x_handles": ["xai"],
"from_date": "2026-07-01"
}The result includes:
answer: synthesized answer from the configured Grok modelcitations: citations returned at the response levelinline_citations: URL annotations attached to generated textcredential_source:xai-oauthorxai-api-keydegraded: true when narrowing filters were active but no citations were returneddegraded_reason: explanation whendegradedis true
Treat a degraded answer as unsourced model output. Broaden the filters, retry, or verify the claim another way.
Configuration
Environment variable | Default | Description |
|
| Directory containing the standalone OAuth state and lock. |
|
| xAI model used for the Responses API request. |
| unset | Optional |
|
| HTTP request timeout, clamped to at least 30 seconds. |
| unset | Optional API-key fallback when standalone OAuth is unavailable. |
Security notes
auth.json,.envfiles, virtual environments, caches, and build outputs are ignored by Git.OAuth and inference endpoints are restricted to HTTPS hosts on the
x.aidomain.The inference bearer is sent only to
https://api.x.ai/v1.The status command reports metadata only and never prints tokens.
Refresh tokens may rotate after each refresh. Do not copy one OAuth token store between concurrently running installations.
Never commit
~/.config/x-search-mcp/auth.jsonor pass its contents to an MCP client configuration.
Troubleshooting
No xAI credentials
Run x-search-mcp login, or provide XAI_API_KEY to the MCP server process.
OAuth login succeeds but API calls are denied
xAI may restrict OAuth API access by subscription tier. Configure XAI_API_KEY if your account is not entitled to OAuth API access.
The MCP client does not show x_search
Run
x-search-mcp status.Run the client's MCP inspection command, such as
codex mcp get x-search.Use an absolute launcher path if the client does not inherit your shell
PATH.Restart the client so it reloads the MCP tool manifest.
A filtered result is marked degraded
xAI returned a synthesized response without citations matching the requested handle or date filters. Remove or broaden filters and retry.
Development
Install development dependencies and run the complete test suite:
uv sync
uv run ruff check src tests
uv run ruff format --check src tests
uv run pytest
uv run python tests/mcp_smoke.pyThe smoke test starts the real stdio server, initializes an MCP client session, and confirms that x_search is discoverable with the expected schema.
Build distribution artifacts with:
uv buildProject scope
This project intentionally exposes X Search only. It does not post, like, follow, send messages, or mutate an X account. It does not provide deterministic raw-post pagination or full X API semantics.
License
MIT. See LICENSE.
Acknowledgments
Available Tools
1 toolx_searchA
Search current X posts, profiles, and threads using xAI's X Search.
Use this instead of general web search for current discussion or claims on X. Handle allow/exclude filters each support at most 10 handles and cannot be combined. Dates use YYYY-MM-DD. Media understanding may increase latency.
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| to_date | No | ||
| from_date | No | ||
| allowed_x_handles | No | ||
| excluded_x_handles | No | ||
| enable_image_understanding | No | ||
| enable_video_understanding | No |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description bears full responsibility. It discloses that media understanding may increase latency, date format is YYYY-MM-DD, and that allow and exclude filters cannot be combined with a max of 10 handles each. However, it does not describe return behavior, pagination, authentication needs, or other effects, leaving gaps.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is extremely concise with 4 sentences, no redundancy. The first sentence states the core purpose, the second provides usage guidance, the third lists constraints, and the fourth mentions a behavioral note. Every sentence adds value.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given 7 parameters, no output schema, and no annotations, the description addresses key constraints and usage context but lacks details on pagination, result format, error handling, and rate limits. It is adequate but not fully comprehensive.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 0%, so the description must provide parameter meaning. It explains the constraints on allowed/excluded handles (max 10, cannot combine) and date format, and mentions latency impacts of media understanding. However, it does not individually explain all 7 parameters, leaving some underspecified.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states 'Search current X posts, profiles, and threads using xAI's X Search.' It uses a specific verb ('search'), identifies the resource (X posts, profiles, threads), and indicates the scope ('current'). It distinguishes from general web search, providing purpose clarity.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description advises using this tool for 'current discussion or claims on X' and explicitly mentions constraints like handle filter limits and date format. It implies an alternative (general web search) but does not explicitly state when not to use or list other alternatives beyond that single mention.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
1 tool update
v0.1.0- First observed
x_search
TDQS
With only one tool, there is no possibility of confusion between tools. The agent will always select the correct tool for searching X content.
The single tool name 'x_search' follows a clear verb_noun convention. Since there is only one tool, naming consistency is inherently perfect.
One tool is slightly below the typical 3-15 range, but it is appropriate for a focused search service. The tool combines searching posts, profiles, and threads into a single operation, making the count reasonable.
The tool covers the full domain of searching X: posts, profiles, and threads, with support for filters and date formats. No obvious gaps exist for the stated purpose.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
X/Twitter reads, search, monitors and posting. Pay-per-call in USDC — no signup, no API keys.
Collaborative, cache-first web search for agents — cited answers from a shared live-web pool.
X (formerly Twitter): X (formerly Twitter) public and private data API for search, posts (Tweets).
LLM-ready web search + instant answers + URL-to-clean-text fetch for agents and RAG.
Related MCP Servers
- AlicenseBqualityDmaintenanceEnables searching X (formerly Twitter) using xAI's Responses API with support for filtering by handles, date ranges, and media understanding, returning structured results with citations.1311MIT
- AlicenseAqualityDmaintenanceEnables real-time search of X.com (Twitter) posts, users, threads, and trends via xAI's Grok API, directly from Claude.53MIT
- FlicenseNot gradedqualityDmaintenanceEnables real-time search of X (Twitter) posts, user timelines, and trends using either xAI's Responses API or the official X API v2.4-
- FlicenseAqualityDmaintenanceEnables searching X (Twitter) using the xAI Grok API to get summarised answers with citations. Supports filtering by handles, date range, and image/video understanding.12-
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/kamellperry/x-search-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server