Back to MCP directory
publicPublicdnsLocal runtime

X MCP Server

一个用于X(推特)集成的MCP服务器,提供读取时间线和互动推文的功能,专为Claude桌面应用设计。

article

README

🚀 X MCP 服务器

X MCP 服务器是一款用于集成 Twitter 和 Claude 桌面应用的工具。它具备获取推文、发布新推文以及回复推文等功能,同时还内置了速率限制处理功能,能有效保障使用的稳定性和合规性。

🚀 快速开始

X MCP 服务器的使用非常便捷,你可以按照以下步骤快速搭建并运行:

  1. 克隆此仓库到本地。
  2. 打开终端,进入项目目录。
  3. 运行 npm run build 构建 TypeScript 代码。
  4. 选择开发模式(带自动监听)运行 npm run dev,或者选择生产模式运行 npm start

📦 安装指南

下载代码

  1. 克隆此仓库到本地。
  2. 打开终端,进入项目目录。

构建

运行以下命令构建 TypeScript 代码:

npm run build

运行

  • 开发模式(带自动监听):
    npm run dev
    
  • 生产模式:
    npm start
    

✨ 主要特性

功能丰富

  • 获取主页推文:可获取你关注的用户最新发布的推文,还能通过 limit 参数指定获取数量。
  • 发布新推文:支持发布最多 280 个字符的新推文。
  • 回复推文:能针对指定的推文进行回复,回复内容同样最多 280 个字符。

速率限制处理

内置了针对 Twitter 免费 tier 的速率限制功能:

  • 每月限制:
    • 用户级:每月最多 500 次发布操作。
    • 应用级:每月最多 500 次发布操作。
    • 读取操作:每月最多 100 次。
  • 特性:
    • 跟踪每月使用量。
    • 提供指数回退功能以处理速率限制错误。
    • 达到限制时会给出清晰的错误消息。
    • 自动重试直到速率限制窗口过期。

💻 使用示例

基础用法

获取主页推文

await use_mcp_tool({
  server_name: "x",
  tool_name: "get_home_timeline",
  arguments: { limit: 5 }
});

发布新推文

await use_mcp_tool({
  server_name: "x",
  tool_name: "create_tweet",
  arguments: { text: "Hello from MCP! 🤖" }
});

回复推文

await use_mcp_tool({
  server_name: "x",
  tool_name: "reply_to_tweet",
  arguments: {
    tweet_id: "1234567890",
    text: "Great tweet! 👍"
  }
});

📚 详细文档

配置

环境变量

claude_desktop_config.json 文件中添加以下配置,替换占位符为你的实际 API 凭据:

{
  "mcpServers": {
    "x": {
      "command": "node",
      "args": ["%USERPROFILE%/Projects/MCP Basket/x-server/build/index.js"],
      "env": {
        "TWITTER_API_KEY": "paste-your-api-key-here",
        "TWITTER_API_SECRET": "paste-your-api-key-secret-here",
        "TWITTER_ACCESS_TOKEN": "paste-your-access-token-here",
        "TWITTER_ACCESS_SECRET": "paste-your-access-token-secret-here"
      }
    }
  }
}

开发

构建

npm run build

开发模式

npm run dev

运行服务器

npm start

贡献指南

  1. 叉仓库。
  2. 创建你的功能分支(git checkout -b feature/amazing-feature)。
  3. 提交更改(git commit -m 'Add some amazing feature')。
  4. 推送到分支(git push origin feature/amazing-feature)。
  5. 打开 Pull Request。

📄 许可证

本项目采用 MIT 许可证。

⚠️ 重要提示

请勿泄露你的 API 凭据。

💡 使用建议

建议将敏感信息加密存储。

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client