This repository hosts a lightweight, step-by-step guide for setting up an autonomous X (Twitter) agent system that acts based on thread context & reasoning, through Grok via the xMCP server.
- Go to https://developer.x.com and sign in with the account you want the bot to run on.
- Create a new app/project (free tier is fine to start).
- Set app permissions to Read + Write + Direct Messages so the agent can post replies.
- Generate and record the OAuth 1.0a credentials:
- API Key
- API Secret
- Access Token (user context)
- Access Token Secret
- Create a new X account for the bot (for example,
@MyXMCPBot). - Link the bot account to your developer app via the OAuth flow.
- Note the bot user ID (you can fetch this via the API later).
- Visit https://console.x.ai, open the API keys section, and create a key that starts with
xai-. - Store the key securely.
- Install Python 3.9+ (3.10–3.13 recommended).
- Ensure
gitis installed for cloning.
- Clone your fork of the xMCP server:
git clone https://github.com/groupthinking/xMCP.git cd xMCP - Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activate - Install dependencies:
pip install -r requirements.txt
- Create your
.env:cp env.example .env
- Fill in the
.envvalues you need:# OAuth user token for posting replies X_OAUTH_ACCESS_TOKEN=your_access_token_here X_OAUTH_ACCESS_TOKEN_SECRET=your_access_token_secret_here # Optional read-only bearer token # X_BEARER_TOKEN=your_bearer_token_here # Grok / xAI XAI_API_KEY=your_xai_key_here XAI_MODEL=grok-4-1-fast # Optional tuning MCP_HOST=127.0.0.1 MCP_PORT=8000 X_API_DEBUG=1 - If you need to generate OAuth user tokens, add
CLIENT_IDandCLIENT_SECRETto.env, update the redirect URI ingenerate_authtoken.py, and run:python generate_authtoken.py
- Start the MCP server:
You should see
python server.py
Server running on http://127.0.0.1:8000. - In another terminal, test Grok integration:
python test_grok_mcp.py
- Try prompts like:
Search recent posts about MCPGet my user infoPost a test reply saying 'Hello from MCP' to tweet ID 1234567890
If these work, the core pipe (Grok → xMCP → X API) is live.
A simple polling listener is provided in listener.py at the repo root. It uses Tweepy to poll for mentions and posts a placeholder reply. The listener requires OAuth user credentials (plus a bearer token for reads). Install Tweepy, export your environment variables, and run it while the xMCP server is up:
pip install tweepy
export X_API_KEY=your_api_key
export X_API_SECRET=your_api_secret
export X_OAUTH_ACCESS_TOKEN=your_access_token
export X_OAUTH_ACCESS_TOKEN_SECRET=your_access_token_secret
export X_BEARER_TOKEN=your_bearer_token
export POLL_INTERVAL_SECONDS=60
python listener.pyThen tag your bot from another account to see it respond. Replace the placeholder Grok call with your real xMCP/Grok invocation when ready.
- Wire the listener to call Grok through the xMCP server.
- Add Docker/Docker Compose if you want a containerized workflow.
- Persist state (SQLite) to avoid reprocessing old mentions.
- Extend with proxies, CrewAI/AutoGen, or other agent frameworks.
- Deploy to Railway/Render/VPS for 24/7 operation.
Start with Phases 1–4 today. If you hit a snag, share the exact output/error and we can debug together.