mcp-x-poster

Zaki-Mohd/mcp-x-poster

3.2

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.

Tools
  1. createPost

    Posts a tweet on the platform.

  2. 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

  1. Clone the repository:
https://github.com/Zaki-Mohd/mcp-x-poster.git
cd mcp-x-poster
  1. Install dependencies:
npm install
  1. 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 tweet
    • addTwoNumbers: 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!