MX

mbelinky/x-mcp-server

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

24 stars 9 forks 质量 65 趋势 0MIT

一个全面的MCP服务器,x.com 发布,包含OUsup v1和v2,以及v1.1和v2 x API实现

概览

一款增强型模型上下文协议(MCP)服务器,为 X 平台增加了 OAuth 2.0 支持、v2 API 媒体上传功能,并实现了全面的速率限制。 - : 创建带有可选媒体附件(图片、GIF)的文本推文 - : 搜索X并可自定义结果计数 - : 通过程序移除推文 - : 支持 OAuth 1.0a 和 OAuth 2.0 - : 使用每种认证方法的相应 API 版本发布图片 - : 内置保护 X 的 API 限制 - : 完整的 TypeScript 实现,支持 Zod 验证 该服务器智能地使用基于认证方法和操作的不同 X API 版本: - : 使用 v2 API 端点 - : 使用 v1.1 端点(upload.twitter.com) - : v2 失败时自动退回 v1.1 - :仅使用 v2 API 端点 - :使用 v2 端点(api.x.com/2/media/upload) - :由于认证限制,无法退回 v1.1 - :遗留API,正在逐步淘汰,但仍支持OAuth 1。

概述(AI 翻译)

一款增强型模型上下文协议(MCP)服务器,为 X 平台增加了 OAuth 2.0 支持、v2 API 媒体上传功能,并实现了全面的速率限制。

✨ 特色

  • 发布推文:创建带有可选媒体附件(图片、动图)的文字推文
  • 搜索推文:搜索X,结果数量可自定义
  • 删除推文:程序性删除你的推文
  • 双重认证:支持 OAuth 1.0a 和 OAuth 2.0
  • 媒体上传:使用每种认证方法的相应API版本发布图片
  • 速率限制:内置保护X的API限制
  • 类型安全:完整的TypeScript实现,支持Zod验证

🔄 API 版本处理

该服务器智能地使用基于认证方法和操作的不同 X API 版本:

欧南1.0a

  • 推文操作:使用v2 API端点
  • 媒体上传:使用v1.1端点(upload.twitter.com)
  • 删除备份:v2失败时自动退回v1.1

欧斯2.0

  • 所有操作:仅使用v2 API端点
  • 媒体上传:使用v2端点(api.x.com/2/media/upload)
  • 无v1.1访问:无法退回到v1。

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

X MCP Server - Enhanced Edition

An enhanced Model Context Protocol (MCP) server for X that adds OAuth 2.0 support, v2 API media uploads, and comprehensive rate limiting to the original implementation.

✨ Features

  • Post Tweets: Create text tweets with optional media attachments (images, GIFs)
  • Search Tweets: Search X with customizable result count
  • Delete Tweets: Remove your tweets programmatically
  • Dual Authentication: Support for both OAuth 1.0a and OAuth 2.0
  • Media Upload: Post images using the appropriate API version for each auth method
  • Rate Limiting: Built-in protection for X’s API limits
  • Type Safety: Full TypeScript implementation with Zod validation

🔄 API Version Handling

This server intelligently uses different X API versions based on authentication method and operation:

OAuth 1.0a

  • Tweet operations: Uses v2 API endpoints
  • Media upload: Uses v1.1 endpoint (upload.twitter.com)
  • Delete fallback: Automatically falls back to v1.1 when v2 fails

OAuth 2.0

  • All operations: Uses v2 API endpoints exclusively
  • Media upload: Uses v2 endpoint (api.x.com/2/media/upload)
  • No v1.1 access: Cannot fall back to v1.1 due to authentication restrictions

Why Different Endpoints?

  • v1.1: Legacy API, being phased out but still works with OAuth 1.0a
  • v2: Modern API with better features but some endpoints have issues
  • Media: OAuth 2.0 tokens cannot access v1.1 media endpoints, must use v2
  • Delete: v2 delete endpoint currently has issues (500 errors), v1.1 works as fallback

📋 Prerequisites

Before you begin, you’ll need:

  1. An X Developer Account (sign up at developer.x.com)
  2. An X App created in the Developer Portal
  3. API credentials (detailed setup below)
  4. Node.js 18+ installed

🔐 Authentication Setup

This server supports two authentication methods. Choose based on your needs:

  • OAuth 1.0a: Simpler setup, works with all features including v1.1 fallbacks
  • OAuth 2.0: Modern authentication, required for some newer features

Setting Up Your X App

  1. Create a Developer Account:

    • Go to developer.x.com
    • Sign in with your Twitter account
    • Apply for developer access if you haven’t already
  2. Create a New App:

    • Navigate to the Twitter Developer Portal
    • Click “Projects & Apps” → “New Project”
    • Give your project a name
    • Select your use case
    • Create a new App within the project
  3. Configure App Permissions:

    • In your app settings, go to “User authentication settings”
    • Click “Set up”
    • Enable OAuth 1.0a and/or OAuth 2.0
    • Set App permissions to “Read and write”
    • Add Callback URLs:
      • For OAuth 1.0a: http://localhost:3000/callback
在 GitHub 查看完整 README

安装

npx -y @mbelinky/x-mcp-server
新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "twitter-mcp": { "command": "npx", "args": ["-y", "@mbelinky/x-mcp-server"], "env": { "API_KEY": "your_api_key_here", "API_SECRET_KEY": "your_api_secret_key_here", "ACCESS_TOKEN": "your_access_token_here", "ACCESS_TOKEN_SECRET": "your_access_token_secret_here" } } } }