grok-oauth-mcp
This stdio MCP server lets local MCP clients authenticate to xAI Grok via web OAuth PKCE and use Grok chat, X search, speech, image, video, and transcription tools.
auth_login: start xAI OAuth PKCE login; optionally wait for the localhost callback and store tokens.auth_status: check local OAuth token status and expiry without revealing token values.auth_logout: delete the local OAuth token store.grok_chat: send Grok chat/responses requests, defaulting togrok-build-0.1.x_search: query Grok with X search enabled, supporting filters, dates, handles, and image/video understanding.grok_tts: generate speech through/tts.grok_image: generate or edit images through/images/generationsor/images/edits.grok_video: generate text-to-video or image-to-video and optionally poll job status.grok_transcribe: transcribe a local audio file through multipart upload to/audio/transcriptions.
Click on "Deploy 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., "@grok-oauth-mcp chat with Grok about existential risks"
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.
grok-oauth-mcp
Standalone TypeScript stdio MCP server for xAI Grok using web OAuth PKCE. It is intended for local MCP clients such as Claude Desktop, ChatGPT-compatible MCP hosts, and other stdio MCP launchers.
This server does not require XAI_API_KEY for normal usage. The primary auth path is xAI web OAuth with a local token store.
Requirements
Node.js 20+
A local MCP client that can launch stdio servers, such as Claude Desktop or another MCP-compatible host.
An xAI account with an active SuperGrok subscription or an X Premium+ subscription linked to the X account you sign in with. This matches the Hermes xAI Grok OAuth connector: the browser login works through
accounts.x.ai, and xAI links X Premium+ entitlement to the xAI session automatically.
No XAI_API_KEY is used for the normal OAuth path. xAI may still gate OAuth API access by subscription tier; if OAuth succeeds but xAI API calls return 403, your account may not be entitled for that OAuth API surface yet.
Related MCP server: Grok MCP
Features
xAI web OAuth PKCE login with the Hermes client ID.
Token storage at
~/.config/grok-oauth-mcp/tokens.jsonby default.Configurable token directory with
GROK_OAUTH_MCP_CONFIG_DIR.Refresh-token flow before access token expiry.
Configurable xAI API base with
XAI_BASE_URL, defaulting tohttps://api.x.ai/v1.MCP stdio tools for auth, Grok chat, X search, image, video, TTS, and transcription.
Multipart upload support for local image/audio paths.
Quick Start
This is the shortest path for a human or agent to get the MCP running, authenticate, and verify that Grok works.
1. Install
From source:
git clone https://github.com/bowtieswan/grok-oauth-mcp.git
cd grok-oauth-mcp
npm install
npm run buildRun directly from the built checkout:
node /absolute/path/to/grok-oauth-mcp/dist/index.jsOr install it globally from the checkout:
npm install -g .
grok-oauth-mcpPackage-runner form:
npx grok-oauth-mcp2. Add It To Your MCP Client
Use absolute paths when possible. This avoids PATH differences between your shell and GUI apps.
Claude Desktop
Add an MCP server entry that points at your local build or global executable. Local build example:
{
"mcpServers": {
"grok-oauth": {
"command": "node",
"args": ["/absolute/path/to/grok-oauth-mcp/dist/index.js"]
}
}
}If you installed globally and know the executable path:
{
"mcpServers": {
"grok-oauth": {
"command": "/absolute/path/to/node",
"args": ["/absolute/path/to/grok-oauth-mcp"]
}
}
}OpenCode
Add a local MCP server entry under the top-level mcp object in your OpenCode config, usually ~/.config/opencode/opencode.json:
{
"mcp": {
"grok-oauth": {
"command": [
"/absolute/path/to/node",
"/absolute/path/to/grok-oauth-mcp"
],
"enabled": true,
"type": "local"
}
}
}Then restart the MCP client or reload MCP servers. In OpenCode, verify discovery with:
opencode mcp listYou should see grok-oauth connected.
3. Authenticate
Use the MCP tool auth_login with wait=false first. This is the safest mode for most MCP clients because the tool returns the URL immediately.
Input:
{
"wait": false,
"timeout_ms": 600000
}The result contains:
auth_url: open this in your browser.state: the OAuth state for this attempt.redirect_uri: normallyhttp://127.0.0.1:56121/callback.token_path: where tokens will be written after success.
Open auth_url, sign in to xAI, then complete one of these two paths.
Path A: Browser Redirects To Localhost
If the browser redirects to http://127.0.0.1:56121/callback?... and shows a success message, login is complete. Run auth_status to confirm.
Path B: xAI Shows A Grok Build Code
Sometimes xAI shows a page saying:
Enter this code to finish signing in
Copy the code below into Grok Build to finish signing inIf that happens, copy the code and call auth_exchange_code immediately:
{
"code": "paste-the-grok-build-code-here"
}The code is tied to the most recent auth_login attempt and the saved PKCE verifier. If it expires or you started another login attempt, run auth_login again and use the fresh code from the fresh URL.
If you have a full callback URL instead of a bare code, pass it as callback_url:
{
"callback_url": "http://127.0.0.1:56121/callback?code=...&state=..."
}4. Verify Auth
Run auth_status. A successful login returns authenticated: true, has_refresh_token: true, and an expiry time. Token values are never returned.
Tokens are stored at:
~/.config/grok-oauth-mcp/tokens.jsonTemporary pending OAuth state is stored at:
~/.config/grok-oauth-mcp/pending_oauth.jsonBoth files are written with mode 0600 where the local filesystem supports POSIX permissions.
5. Test Grok
After auth_status is authenticated, try a small call. For X search:
{
"query": "latest xAI Grok updates",
"filters": {
"max_results": 5
}
}If the first broad search times out, retry with a narrower query and fewer results.
OAuth Details
Discovery:
https://auth.x.ai/.well-known/openid-configurationDisplayed authorization server:
accounts.x.aiClient ID:
b1a00492-073a-47ea-816f-4c329264a828Scope:
openid profile email offline_access grok-cli:access api:accessRedirect URI:
http://127.0.0.1:56121/callbackAuthorize URL includes
plan=genericandreferrer=hermes-agent.
Authentication Notes For Agents
Prefer
auth_loginwithwait=false. Do not usewait=trueunless your MCP host surfaces stderr or tool output while the call is still running.Always open the exact
auth_urlfrom the latestauth_loginresult.If the page shows a Grok Build code, call
auth_exchange_codewith that code. Do not try to open/callbackmanually.If
auth_exchange_codereturnsNo pending OAuth login foundorPending OAuth login is expired, runauth_loginagain and use the fresh URL/code.If xAI returns
invalid_grant, the code is stale, already used, or from a different login attempt. Runauth_loginagain.
Tools
auth_login
Starts OAuth login and returns an authorization URL.
Input:
{
"wait": false,
"timeout_ms": 300000
}Set wait=true only for clients that can show stderr or otherwise surface the URL while the tool is still running.
auth_exchange_code
Exchanges a pasted xAI/Grok Build OAuth code, or a full callback URL, using pending PKCE state from the last auth_login call.
Input with a bare Grok Build code:
{
"code": "paste-the-grok-build-code-here"
}Input with a callback URL:
{
"callback_url": "http://127.0.0.1:56121/callback?code=...&state=..."
}auth_status
Reports whether a token is stored, whether a refresh token exists, and approximate expiry. Token values are never returned.
auth_refresh
Refreshes the stored token when it expires within min_validity_seconds (default 900) and returns the same status as auth_status plus refreshed: true|false. Use it as a preflight before long jobs so a token never expires mid-run. Token values are never returned.
auth_logout
Deletes the local token file and any pending OAuth state.
grok_chat
Posts to /responses with store=false. Default model: grok-build-0.1.
Example:
{
"input": "Explain what this MCP server can do."
}x_search
Posts to /responses with tools: [{ "type": "x_search" }] and optional filters.
Example:
{
"query": "latest xAI Grok updates",
"filters": {
"max_results": 5
}
}grok_tts
Posts to /tts.
Example:
{
"text": "Hello from Grok.",
"voice_id": "eve",
"language": "en"
}grok_image
Posts to /images/generations for text-to-image and /images/edits when image_path is present.
Defaults:
Generation model:
grok-imagine-imageEdit model:
grok-imagine-image-quality
Common image options include aspect_ratio, resolution, size, n, and response_format. Pass values supported by the current xAI/Hermes image surface, such as common aspect ratios like 1:1, 16:9, 9:16, 4:3, and 3:4 when available on your account.
grok_video
Posts to /videos/generations. Supports text-to-video and image-to-video when image_path is present.
Defaults:
Text-to-video model:
grok-imagine-videoImage-to-video model:
grok-imagine-video-1.5-preview
Set poll=true to poll /videos/{request_id} until the request leaves a queued or processing state.
grok_transcribe
Posts a local audio file to /stt with multipart form data, matching xAI Grok STT.
Example:
{
"file_path": "/path/to/audio.wav",
"language": "en"
}Troubleshooting
Not authenticated. Run auth_login first.: Runauth_loginwithwait=false, open the returnedauth_url, then complete the redirect or useauth_exchange_codewith the Grok Build code.Browser cannot reach callback: If xAI showed a Grok Build code, do not manually open
/callback; callauth_exchange_codewith the code instead. If you expected a redirect, make sure nothing else is using port56121, then runauth_loginagain.No pending OAuth login foundorPending OAuth login is expired: Runauth_loginagain and use the fresh URL/code.invalid_grant: The pasted code is stale, already used, or belongs to a different login attempt. Runauth_loginagain and paste the fresh code.403from xAI: Your xAI account may not have the required SuperGrok or X Premium+ entitlement for the requested Grok API surface.Token refresh fails: Run
auth_logout, thenauth_loginagain.Custom API gateway or mock server: Set
XAI_BASE_URLto the replacement base URL.Custom token location: Set
GROK_OAUTH_MCP_CONFIG_DIRto a directory path. The server writestokens.jsoninside it.
Development
npm test
npm run buildTests mock all OAuth and xAI network calls. They must not call real xAI OAuth or xAI APIs.
License
MIT
Available Tools
9 toolsauth_loginA
Start xAI web OAuth PKCE login using the Hermes Agent client. Use wait=true to capture the localhost callback and store tokens.
Inputs: wait, timeout_ms.
auth_logoutB
Delete the local OAuth token store.
Inputs: no named parameters.
auth_statusA
Show local xAI OAuth token status without revealing token values.
Inputs: no named parameters.
grok_chatC
Send a Grok chat or responses request to /responses with store=false. Defaults to model grok-build-0.1.
Inputs: input, messages, prompt, model.
grok_imageC
Generate or edit images through /images/generations or /images/edits. Defaults to grok-imagine-image and grok-imagine-image-quality.
Inputs: prompt, image_path, mask_path, model, +5 more.
grok_transcribeC
Transcribe a local audio file through /audio/transcriptions using multipart form upload.
Inputs: file_path (required), model, language, prompt, +2 more.
grok_ttsD
Generate speech through /tts.
Inputs: input, text, voice_id, voice, +5 more.
grok_videoB
Generate text-to-video or image-to-video through /videos/generations, optionally polling /videos/{request_id}.
Inputs: prompt, image_path, model, aspect_ratio, +5 more.
x_searchD
Ask Grok with the x_search tool enabled through /responses and optional x_search filters.
Inputs: query, input, filters, model, +6 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 9 tools
Each tool targets a distinct operation: authentication (login/logout/status), Grok modalities (chat, image, transcribe, TTS, video), and search. No overlap in functionality.
Tools use consistent verb_noun naming with subdomain prefixes (auth_, grok_), but 'x_search' breaks the pattern by not using a prefix consistent with others. Still predictable overall.
With 9 tools, the server covers authentication and main Grok API capabilities without being bloated or sparse. Each tool serves a clear purpose.
Covers core auth lifecycle and major Grok features (chat, image, audio, video, search). Missing potential management tools (e.g., model listing) but not necessary for primary use cases.
Maintenance
Related MCP Connectors
Hosted X (Twitter) MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Remote streamable-HTTP MCP server running on a single Cloudflare Worker. Your assistant gets live Airbnb, Amazon, Booking.com, Google Flights, Maps and Reddit data, social search on X, Instagram and TikTok, the Meta Ad Library, and image/video generation without any keys. Connect your own accounts to let it send WhatsApp or Telegram messages, work an IMAP inbox, manage Meta Ads campaigns and publish to X and LinkedIn. OAuth 2.1 with PKCE; stored credentials are AES-256-GCM encrypted.
Official Fibery MCP server: query and update your workspace from any AI client via OAuth.
Talk to your public-facing AI from any MCP client — Claude, ChatGPT, Cursor, Cline, Windsurf.
Related MCP Servers
- AlicenseBqualityDmaintenanceEnables interaction with the Grok AI through an MCP server, supporting chat completions, text completions, embeddings, and model operations with streaming capabilities.57MIT
- AlicenseAqualityBmaintenanceUse XAI's latest api functionalities with Grok MCP. It supports image understanding and generation, live search, latest models and more.2256MIT
- AlicenseAqualityCmaintenanceMCP server for live X/Twitter and web search, driven by your locally logged-in Grok CLI and leveraging your X Premium or SuperGrok subscription quota.31MIT
- AlicenseAqualityDmaintenanceMCP server for integrating xAI's Grok model into OpenAI Codex Desktop/GUI, enabling direct Grok calls via chat completions or responses with OAuth or API key authentication.9MIT