Zaki-Mohd/mcp-x-poster
If you are the rightful owner of mcp-x-poster and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This project demonstrates how to build a Model Context Protocol (MCP) server and client using Google Gemini to post tweets and run dynamic tools.
createPost
Posts a tweet on the platform.
addTwoNumbers
A simple math tool for testing purposes.
š§ MCP Twitter Bot
An example project demonstrating how to build a Model Context Protocol (MCP) server and client that uses Google Gemini to post tweets (formerly on Twitter, now X) and run dynamic tools.
š Built with:
- @modelcontextprotocol/sdk
- @google/genai
- twitter-api-v2
- Node.js, Express, dotenv
⨠Features
- Interactive CLI chat that uses Google Gemini to understand user prompts.
- MCP tools dynamically listed and called via Gemini.
- Posts tweets using Twitter API.
- Real-time communication with the server via Server-Sent Events (SSE).
- Easy to extend: add your own tools quickly.
š Project Structure
.
āāā client
ā āāā node_modules/
ā āāā .env
ā āāā index.js
ā āāā package-lock.json
ā āāā package.json
ā
āāā server
ā āāā node_modules/
ā āāā .env
ā āāā index.js
ā āāā mcp.tool.js
ā āāā package-lock.json
ā āāā package.json
ā
š Installation
- Clone the repository:
https://github.com/Zaki-Mohd/mcp-x-poster.git
cd mcp-x-poster
- Install dependencies:
npm install
- Configure environment variables:
Create a
.env
file in the root folder and add:
GEMINI_API_KEY=your_google_gemini_api_key
TWITTER_API_KEY=your_twitter_api_key
TWITTER_API_SECRET=your_twitter_api_secret
TWITTER_ACCESS_TOKEN=your_twitter_access_token
TWITTER_ACCESS_TOKEN_SECRET=your_twitter_access_token_secret
ā ļø Make sure not to commit .env
to version control.
š Running the project
1ļøā£ Start the MCP server:
npx nodemon index.js
2ļøā£ Start the MCP client (in a separate terminal):
node index.js
The client will prompt for your message; Google Gemini decides whether to answer directly or call a tool like createPost
.
āļø How it works
-
The MCP server exposes tools:
createPost
: posts a tweetaddTwoNumbers
: simple math tool for testing
-
The MCP client:
- Lists tools from the server
- Sends chat history and tool list to Google Gemini
- If Gemini returns a
functionCall
, the client calls the tool on the server and includes the result in the next request
This loop creates a dynamic, AI-assisted workflow.
š§© Adding your own tools
In index.js
, add a new tool like this:
server.tool(
"toolName",
"Tool description",
{
param1: z.string(), // validate parameters with zod
param2: z.number()
},
async (args) => {
// Your logic here
return {
content: [
{ type: "text", text: "Result text" }
]
}
}
)
The client will automatically discover it via listTools()
.
š¦ Requirements
- Node.js v18 or newer
- Twitter Developer credentials (API keys & tokens)
- Google Gemini API key
ā¤ļø Contributing
PRs and suggestions are welcome!