
MCP TweetBot

2025.04.15
0
JavaScript聊天机器人社交媒体工具交流协作内容生成
MCP TweetBot 是一个轻量级的、基于 Gemini 的聊天机器人,集成了 Model Context Protocol (MCP),允许用户通过命令行交互调用自定义工具,如在 X(原 Twitter)上发布推文。该项目展示了如何通过 Google Gemini 和 MCP SDK 实现 AI 与工具的结合。用户只需插入 API 密钥,运行客户端,即可通过终端进行聊天、发布推文或获取励志名言。
View on GitHub
Overview
✨ 核心功能
- 🤖 由 Gemini 驱动的 AI 聊天
- 🔧 支持多种 MCP 工具
addTwoNumbers
: 两个数字相加createPost
: 在 X (Twitter) 上发布推文getMotivation
: 从 ZenQuotes API 获取实时励志名言- 📡 使用 Server-Sent Events (SSE) 进行实时通信
- 💬 基于 CLI 的聊天机器人,支持工具执行
🛠️ 使用教程
1. 克隆仓库
git clone https://github.com/yourusername/mcp-tweetbot.git
cd mcp-tweetbot
2. 安装依赖
npm install
3. 创建 .env
文件
For Client Side -
GEMINI_API_KEY='Your API Key'
For Server Side -
TWITTER_API_KEY='Your API key'
TWITTER_API_SECRET='Your API Secret'
TWITTER_ACCESS_TOKEN='Your Token'
TWITTER_ACCESS_TOKEN_SECRET='Your Token Secret'
📦 所需依赖
npm install express zod dotenv readline @google/genai @modelcontextprotocol/sdk twitter-api-v2 axios
4. 运行 MCP 服务器
node server/index.js
5. 运行 MCP 客户端
node client/index.js
🧪 示例用法
You: What is 12 + 34?
AI: calling tool addTwoNumbers
AI: Tool Result: The sum of 12 and 34 is 46
You: Post "Hello world from my bot!" on Twitter
AI: calling tool createPost
AI: Tool Result: Tweeted: Hello world from my bot!
You: I'm feeling low, motivate me
AI: calling tool getMotivation
AI: Tool Result: "Push yourself, because no one else is going to do it for you." — Anonymous
📌 要求
- Node.js v18+
- Twitter 开发者账户(具有读写权限)
- 来自 Google AI Studio 的 Gemini API 密钥
- 互联网连接(用于获取励志名言)