Skip to main content
Glama
Dishant27

X (Twitter) MCP Server

by Dishant27

X(Twitter)MCP 服务器

该 MCP 服务器允许客户端与 X(以前称为 Twitter)进行交互,从而实现包括发布推文、搜索内容、管理帐户和组织列表在内的综合平台操作。

快速入门

  1. 创建 X 开发者帐户并从X 开发者门户获取 API 密钥

  2. 在环境变量中设置所有必需的 API 密钥

  3. 克隆此存储库: git clone https://github.com/Dishant27/twitter-mcp.git

  4. 安装依赖项: npm install

  5. 运行服务器:

  • 使用环境变量:

TWITTER_API_KEY=your_api_key \
TWITTER_API_SECRET=your_api_secret \
TWITTER_ACCESS_TOKEN=your_access_token \
TWITTER_ACCESS_TOKEN_SECRET=your_access_token_secret \
npm start
  • 使用.env文件:

# Create a .env file with your X API keys
echo "TWITTER_API_KEY=your_api_key
TWITTER_API_SECRET=your_api_secret
TWITTER_ACCESS_TOKEN=your_access_token
TWITTER_ACCESS_TOKEN_SECRET=your_access_token_secret" > .env

# Start the server
npm start
  1. 与 MCP 客户端(例如 Claude)一起使用。

Related MCP server: Twitter MCP Server

克劳德配置

要将此服务器与 Claude 一起使用,您需要设置 MCP 配置。以下是配置结构的示例:

{
  "name": "x",
  "display_name": "X",
  "description": "X MCP allows Claude to interact with X (formerly Twitter)",
  "path": "path/to/twitter-mcp/dist/index.js",
  "startup": {
    "env": {
      "TWITTER_API_KEY": "your_api_key",
      "TWITTER_API_SECRET": "your_api_secret",
      "TWITTER_ACCESS_TOKEN": "your_access_token",
      "TWITTER_ACCESS_TOKEN_SECRET": "your_access_token_secret"
    }
  },
  "transport": "stdio"
}

将此配置保存在您的 Claude MCP 配置目录中,通常位于:

  • Windows: %APPDATA%\AnthropicClaude\mcp-servers

  • macOS: ~/Library/Application Support/AnthropicClaude/mcp-servers

  • Linux: ~/.config/AnthropicClaude/mcp-servers

特征

后期操作

  • 帖子内容(最多 280 个字符)

  • 按查询搜索帖子,可自定义结果计数

账户管理

  • 获取任何用户或经过身份验证的帐户的个人资料信息

  • 更新个人资料详细信息(姓名、简历、位置、网站网址)

  • 关注和取消关注用户

  • 列出任何用户或经过身份验证的帐户的关注者

  • 列出用户关注的帐户

列表管理

  • 创建新列表(公共或私人)

  • 获取有关特定列表的信息

  • 检索经过身份验证的用户拥有的所有列表

可用的 MCP 工具

工具名称

描述

post_tweet

将新内容发布到 X

search_tweets

在 X 上搜索内容

get_profile

获取用户或经过身份验证的帐户的个人资料信息

update_profile

更新已验证用户的个人资料

follow_user

关注用户

unfollow_user

取消关注用户

list_followers

列出用户或已验证帐户的关注者

list_following

列出用户或经过身份验证的帐户正在关注的帐户

create_list

创建新列表

get_list_info

获取有关列表的信息

get_user_lists

获取已验证用户拥有的所有列表

要求

  • Node.js 18.x 或更高版本

  • X 带有 API 密钥的开发者帐户

  • API v1 和 v2 访问

环境变量

多变的

描述

TWITTER_API_KEY

您的 API 密钥

TWITTER_API_SECRET

您的 API 秘密

TWITTER_ACCESS_TOKEN

您的访问令牌

TWITTER_ACCESS_TOKEN_SECRET

您的访问令牌秘密

存储库结构

twitter-mcp/
├── .github/
│   └── workflows/
│       ├── publish.yml
│       └── release.yml
├── code/
│   ├── account_management.py  # Sample Python code for account management
│   ├── post_tweet.py          # Sample Python code for posting content
│   └── retrieve_tweets.py     # Sample Python code for retrieving content
├── src/
│   ├── index.ts        # Main entry point
│   ├── twitter-api.ts  # X API client
│   ├── formatter.ts    # Response formatter
│   └── types.ts        # Type definitions
├── .env.example
├── .gitignore
├── Dockerfile
├── LICENSE
├── package.json
├── README.md
└── tsconfig.json

执照

麻省理工学院

Related MCP Connectors

Related MCP Servers

  • F
    license
    B
    quality
    D
    maintenance
    Enables users to interact with X (Twitter) through the X API. Supports posting tweets, retrieving user timelines, searching tweets, and replying to tweets with comprehensive error handling.
    3
    9 npm
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables LLM agents to interact with Twitter (X) for searching tweets, posting content with images, analyzing engagement, and extracting topics using the Twitter API.
    -
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables interaction with X (Twitter) to post tweets, threads, and replies while retrieving tweet metrics and account information. It supports core management tasks like deleting tweets and verifying authentication through the Twitter API.
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables AI assistants to interact with X (Twitter) API v2 for posting tweets, searching, liking, retweeting, and more through natural language.
    29 PyPI
    MIT