
How to Post to Twitter from Gemini CLI with MCP (2026 Guide)
Google's Gemini CLI is a free, powerful AI tool that runs in your terminal. It supports MCP natively, which means you can connect it to external services -- including Twitter -- through a simple JSON config file.
With the OpenTweet MCP server, you can schedule tweets, create threads, check analytics, and manage your evergreen content queue directly from Gemini CLI. No browser tabs. No context switching. Just type what you want in natural language and Gemini handles the rest.
This guide walks through the complete setup from scratch, shows you what's possible once connected, and covers the Gemini-specific details you need to know.
Why Post to Twitter from Gemini CLI
If you're a developer who lives in the terminal, Gemini CLI fits into your existing workflow without adding another app to manage.
It's free. Gemini CLI has a free tier that covers a generous amount of usage. Combined with an OpenTweet subscription (starting at $11.99/month), you get a complete Twitter management system without paying for another AI subscription.
Native MCP support. Unlike some AI clients that require workarounds, Gemini CLI supports the MCP standard out of the box. You add a JSON config, set an environment variable, and you're connected. No tunneling, no remote server requirements.
Secure API key handling. Gemini CLI supports environment variable expansion in config files using the $VAR_NAME syntax. Your OpenTweet API key stays in your shell environment, not hardcoded in a config file that might end up in version control.
Works alongside your dev tools. If you're already using Gemini CLI for coding, debugging, or research, adding Twitter management is just one more thing you can do without leaving the terminal.
Prerequisites
Before starting, make sure you have:
- Node.js 18+ -- Run
node --versionin your terminal to check. Download from nodejs.org if needed. - Gemini CLI installed -- If you don't have it yet, the next section covers installation.
- An OpenTweet account with an API key -- Sign up at opentweet.io (7-day free trial, no credit card required), connect your X/Twitter account, then generate an API key from the Developer Dashboard.
- A Google account -- Needed to authenticate with Gemini CLI. Any Google account works, including free ones.
You do not need a Twitter developer account. OpenTweet handles the X API connection for you.
Step 1: Install Gemini CLI
If you already have Gemini CLI installed, skip to Step 2.
Install it globally via npm:
npm install -g @google/gemini-cli
After installation, run the CLI once to authenticate with your Google account:
gemini
Gemini CLI will prompt you to sign in through your browser. Complete the authentication flow, and you're set. You can exit the session for now -- we need to configure the MCP server before it's useful for Twitter.
Step 2: Get Your OpenTweet API Key
If you don't have an OpenTweet account yet:
- Go to opentweet.io and sign up. The 7-day free trial gives you full access, no credit card required.
- Connect your X/Twitter account through the dashboard. This is a one-time OAuth flow -- click "Connect X Account," authorize in Twitter, and you're done.
- Navigate to the Developer page.
- Click "Generate API Key." Your key starts with
ot_and looks something likeot_abc123def456. - Copy the key. You'll use it in the next step.
Step 3: Configure the MCP Server
Gemini CLI reads MCP server configurations from a settings.json file. You can set this up globally (for all Gemini sessions) or per-project.
Global Configuration
Create or edit the file at ~/.gemini/settings.json:
{
"mcpServers": {
"opentweet": {
"command": "npx",
"args": ["-y", "@opentweet/mcp-server"],
"env": {
"OPENTWEET_API_KEY": "$OPENTWEET_API_KEY"
}
}
}
}
Notice the $OPENTWEET_API_KEY syntax. Gemini CLI expands environment variables in the config, so your actual API key doesn't need to be written in the file.
Now set the environment variable in your terminal:
export OPENTWEET_API_KEY="ot_your_key_here"
Replace ot_your_key_here with your actual API key.
To make this permanent so you don't have to set it every time you open a terminal, add the export line to your shell profile:
For zsh (default on macOS):
echo 'export OPENTWEET_API_KEY="ot_your_key_here"' >> ~/.zshrc
source ~/.zshrc
For bash:
echo 'export OPENTWEET_API_KEY="ot_your_key_here"' >> ~/.bashrc
source ~/.bashrc
Project-Scoped Configuration
If you want OpenTweet available only within a specific project (useful if you have different API keys for different projects or accounts), create the config in your project directory instead:
your-project/
.gemini/
settings.json
The file contents are identical to the global config. Gemini CLI checks for a local .gemini/settings.json first, then falls back to the global one.
Step 4: Verify the Connection
Start Gemini CLI:
gemini
Ask it to confirm the OpenTweet tools are available:
What OpenTweet tools do you have access to?
Gemini should list the 18 available tools, including opentweet_create_tweet, opentweet_create_thread, opentweet_get_analytics, opentweet_batch_schedule, and others.
To test the full connection end to end:
Show me my OpenTweet account status
Gemini will call the opentweet_get_account tool and return your plan details, connected X accounts, daily post limits, and current usage. If you see your account information, everything is working correctly.
Step 5: Start Posting
You're connected. Here's what you can do.
Schedule a Tweet
Schedule a tweet for tomorrow at 9am about why developers should write more documentation
Gemini writes the tweet, calls the OpenTweet API to create it, and schedules it for your specified time. You get a confirmation with the tweet text and scheduled date.
Create a Thread
Create a 4-tweet thread about the benefits of trunk-based development. Make it practical with real examples. Schedule it for Monday at 10am EST.
Gemini builds the complete thread -- hook, supporting points, strong close -- and schedules the whole chain.
Batch Schedule a Week of Content
Generate 5 tweets about web performance optimization for this week. Cover lazy loading, image formats, caching headers, bundle splitting, and Core Web Vitals. Schedule one per day at 10am.
Five tweets created, scheduled, and done. One prompt, one week of content.
Check Your Analytics
Show me my posting analytics for the last 30 days. What are my best posting times?
Gemini fetches your stats and gives you a breakdown of your performance, streaks, and optimal posting windows.
Manage Your Evergreen Queue
List my evergreen queue. Which posts have the longest cooldown?
Add a new evergreen post about our free trial with a 7-day cooldown.
The evergreen queue automatically reposts your best content on rotation, keeping your feed active without constant manual effort.
Example Workflows
Here are some practical workflows that take advantage of Gemini CLI being in your terminal alongside your development tools.
Share What You Just Built
After shipping a feature or merging a PR:
I just finished migrating our authentication from JWT to session-based tokens. Create a build-in-public thread about why we made the switch, the challenges we hit, and the performance improvement we saw. Schedule it for tomorrow morning.
Content from a README
If your project has a README or changelog:
Read the README.md in this directory and create 3 tweet variations highlighting the key features. Save them as drafts so I can review before scheduling.
Because Gemini CLI has access to your local files, it can read your project context and generate tweets that accurately reflect what you're building.
Weekly Content Planning
Generate 7 tweets for next week about building a SaaS product. Mix tactical tips (Monday, Wednesday, Friday), behind-the-scenes updates (Tuesday, Thursday), and an engagement question (Saturday). Schedule them at 10am each day.
Audit Your Scheduled Content
Show me all my scheduled tweets for the next 7 days. Are there any gaps? If so, suggest tweets to fill them.
Multi-Account Support
If you manage more than one X account, OpenTweet's multi-account feature lets you target any of them from Gemini CLI.
First, make sure your additional accounts are connected in the OpenTweet dashboard. Multi-account is available on the Advanced plan (3 accounts) and Agency plan (10 accounts).
Then ask Gemini:
List my connected X accounts
To post to a specific account:
Schedule a product announcement on my @companyhandle account for tomorrow at 9am
Gemini uses the x_account_id parameter behind the scenes to route the tweet to the right account.
Gemini-Specific Notes
A few things to keep in mind that are specific to Gemini CLI's MCP implementation:
Environment variable syntax. Use $VAR_NAME (not ${VAR_NAME}) in the config file. Gemini CLI uses the dollar-sign prefix format for variable expansion.
Tools only. Gemini CLI currently only accesses tools from MCP servers. It does not support MCP resources or prompts. This doesn't limit functionality -- all 18 OpenTweet capabilities are exposed as tools.
Consumer Gemini web app is different. The Gemini web app at gemini.google.com does not support custom MCP servers. This setup is for Gemini CLI only.
Gemini Code Assist. If you use Gemini Code Assist in an IDE like VS Code, it also supports MCP servers, but the configuration is done through the IDE's settings rather than the Gemini CLI config file. Consult your IDE's MCP documentation for details.
Controlling MCP Server Access
Gemini CLI lets you manage which MCP servers are allowed or blocked globally. This is useful if you have multiple servers configured and want fine-grained control.
In your ~/.gemini/settings.json, add a top-level mcp section:
{
"mcp": {
"allowed": ["opentweet"],
"excluded": ["some-other-server"]
},
"mcpServers": {
"opentweet": {
"command": "npx",
"args": ["-y", "@opentweet/mcp-server"],
"env": {
"OPENTWEET_API_KEY": "$OPENTWEET_API_KEY"
}
}
}
}
The allowed list whitelists servers by name. The excluded list blocks specific servers. If you only use OpenTweet, you don't need this section -- it's here for users managing multiple MCP servers.
Troubleshooting
"Command not found" when running gemini
Make sure Gemini CLI is installed globally:
npm install -g @google/gemini-cli
If it's installed but not found, check that your npm global bin directory is in your PATH. Run npm bin -g to find the path and add it to your shell profile.
"Server error" or tools not loading
The most likely cause is the environment variable not being set. Verify it:
echo $OPENTWEET_API_KEY
If it prints nothing, the variable isn't set. Re-run the export command or check your shell profile. Also ensure the variable name in your config exactly matches -- it's OPENTWEET_API_KEY, not OPENTWEET_KEY or OT_API_KEY.
"OPENTWEET_API_KEY is required"
This means the MCP server started but couldn't find the API key. Double-check that your settings.json uses $OPENTWEET_API_KEY (with the dollar sign) in the env section, and that the environment variable is set in your shell.
Invalid API key (401 error)
Your API key may have been regenerated or entered incorrectly. Go to opentweet.io/developer, generate a new key, and update the environment variable.
Rate limit errors (429)
OpenTweet's API has rate limits to prevent abuse. The Pro plan allows 60 requests per minute. If you're hitting limits, wait a moment and retry. For batch operations, use the opentweet_batch_schedule tool which handles multiple tweets in a single request.
Frequently Asked Questions
Does this work with the Gemini web app?
No. The consumer Gemini web app (gemini.google.com) does not support custom MCP servers. This setup works only with Gemini CLI, Google's terminal-based AI tool.
Is Gemini CLI free?
Yes, Gemini CLI has a free tier with a generous daily usage allowance. Combined with OpenTweet (plans starting at $11.99/month with a 7-day free trial), you can manage your Twitter presence without an additional AI subscription cost.
Can I use this with Gemini Code Assist in my IDE?
Gemini Code Assist in IDEs like VS Code also supports MCP servers, but it uses the IDE's own MCP configuration system rather than the Gemini CLI config file. Set up the OpenTweet MCP server through your IDE's MCP settings instead.
How does this compare to Claude Desktop?
Both offer native MCP support with straightforward setup. The main difference is the interface: Claude Desktop is a GUI application, while Gemini CLI is terminal-based. If you prefer working in the terminal, Gemini CLI is a natural fit. If you prefer a desktop app with a visual chat interface, Claude Desktop is an excellent option. Both connect to the same OpenTweet MCP server and have access to all 18 tools.
Do I need a Twitter developer account?
No. OpenTweet handles the X API connection entirely. You connect your X account through OpenTweet's OAuth flow (a few clicks in the dashboard), and the MCP server uses your OpenTweet API key to communicate. You never touch Twitter API credentials.
Getting Started
Here's the complete path from zero to scheduling tweets from Gemini CLI:
- Sign up for OpenTweet (7-day free trial, no credit card)
- Connect your X/Twitter account in the dashboard
- Generate an API key
- Install Gemini CLI:
npm install -g @google/gemini-cli - Add the OpenTweet MCP server to
~/.gemini/settings.json - Set the
OPENTWEET_API_KEYenvironment variable - Run
geminiand schedule your first tweet
Your terminal just became a Twitter management tool. Write content, schedule it, track performance, and manage your queue -- all from the command line you already have open.
For more advanced workflows, check out the MCP integration guide, the OpenTweet API documentation, and our guide on how to build in public on Twitter.
The OpenTweet MCP server is open-source and available on npm. Works with any MCP-compatible AI client including Gemini CLI, Claude Desktop, Claude Code, Cursor, Windsurf, and more. 18 tools, natural language control, no Twitter API key required.
Start Scheduling Your X Posts Today
Join hundreds of creators using OpenTweet to stay consistent, save time, and grow their audience.