使用说明
x-mcp
提供对X(Twitter)API v2的只读访问的MCP服务器。
MCP服务器 --适用于Claude Desktop和任何兼容MCP的客户端。
工具
| 工具 | 说明 |
|---|---|
lookup_user |
按用户名查找用户资料 |
get_tweet |
按ID获取一条推文 |
get_tweets |
按ID获取多条推文(最多100条) |
search_tweets |
搜索最近的推文(过去7天) |
get_user_tweets |
获取用户最近的推文 |
get_followers |
获取用户的关注者 |
get_following |
获取用户关注的帐户 |
get_liking_users |
获取喜欢推特的用户 |
get_retweeters |
获取转发推特的用户 |
get_list_tweets |
从X列表获取最近的推文 |
先决条件
设置
git clone https://github.com/brennick/x-mcp.git
cd x-mcp
npm install
npm run build
创建一个 .env file(或直接设置环境变量):
X_BEARER_TOKEN=your_x_api_bearer_token_here
与Claude一起使用
将服务器添加到您的 claude_desktop_config.json:
{
"mcpServers": {
"x-mcp": {
"command": "node",
"args": ["/absolute/path/to/x-mcp/build/index.js"],
"env": {
"X_BEARER_TOKEN": "your_x_api_bearer_token_here"
}
}
}
}
替换 /absolute/path/to/x-mcp 使用克隆仓库的实际路径。
查询示例
连接后,您可以问Claude以下问题:
用户信息
- “查找@elonmusk的个人资料”
- “@anthropic的生物和追随者数量是多少?”
推特
- “获取ID为1234567890的推文”
- “显示@openai的最后20条推文”
搜索
- “搜索最近关于‘大型语言模型’的推文”
- “查找@ycombinator提到人工智能的推文”
社交图谱
- “@github的前50个关注者是谁?”
- “@vercel追随谁?”
参与
- “谁喜欢这条推特?[推特ID]”
- “显示谁转发了这条推文[tweet ID]”
列表
- “从列表1234567890获取最新推文”
可用工具参考
lookup_user
按用户名查找X用户。返回个人资料信息,包括姓名、个人简介、指标等。
- 参数:
username(string,必填)--要查找的X用户名(不带@符号)fields(array,可选)--要返回的用户字段。默认为有用的子集。
- 端点:
GET /2/users/by/username/{username}
get_tweet
按ID获取单个推文。返回推文文本、作者、指标和元数据。
- 参数:
tweet_id(string,必填)——推特的数字IDtweet_fields(数组,可选)--要返回的Tweet字段
- 端点:
GET /2/tweets/{tweet_id}
get_tweets
按ID获取多条推文(最多100条)。返回推文文本、作者、指标和元数据。
- 参数:
tweet_ids(字符串数组,必填)-推特ID数组(1-100)tweet_fields(数组,可选)--要返回的Tweet字段
- 端点:
GET /2/tweets
search_tweets
使用X搜索查询语法搜索最近的推文(过去7天)。支持以下运营商 from:, to:, is:retweet, has:media, lang:等等。
- 参数:
query(字符串,必填)--搜索查询(最多512个字符)max_results(number,可选)--要返回的结果(10-100,默认值10)tweet_fields(数组,可选)--要返回的Tweet字段pagination_token(string,可选)--下一页结果的标记
- 端点:
GET /2/tweets/search/recent
get_user_tweets
获取用户最近的推文。需要用户的数字ID--使用 lookup_user 首先从用户名中获取ID。
- 参数:
user_id(string,必填)--数字用户IDmax_results(数字,可选)--要返回的推文(5-100,默认值10)tweet_fields(数组,可选)--要返回的Tweet字段pagination_token(string,可选)--下一页结果的标记
- 端点:
GET /2/users/{user_id}/tweets
get_followers
获取关注指定用户的用户列表。需要用户的数字ID。
- 参数:
user_id(string,必填)--数字用户IDmax_results(数字,可选)--要返回的关注者(1-1000,默认值100)user_fields(数组,可选)--要返回的用户字段pagination_token(string,可选)--下一页结果的标记
- 端点:
GET /2/users/{user_id}/followers
get_following
获取指定用户正在关注的用户列表。需要用户的数字ID。
- 参数:
user_id(string,必填)--数字用户IDmax_results(数字,可选)--要返回的帐户(1-1000,默认值100)user_fields(数组,可选)--要返回的用户字段pagination_token(string,可选)--下一页结果的标记
- 端点:
GET /2/users/{user_id}/following
get_liking_users
获取喜欢特定推文的用户列表。
- 参数:
tweet_id(string,必填)--数字推特IDmax_results(数字,可选)--要返回的用户(1-100,默认值100)user_fields(数组,可选)--要返回的用户字段pagination_token(string,可选)--下一页结果的标记
- 端点:
GET /2/tweets/{tweet_id}/liking_users
get_retweeters
获取转发特定推文的用户列表。
- 参数:
tweet_id(string,必填)--数字推特IDmax_results(数字,可选)--要返回的用户(1-100,默认值100)user_fields(数组,可选)--要返回的用户字段pagination_token(string,可选)--下一页结果的标记
- 端点:
GET /2/tweets/{tweet_id}/retweeted_by
get_list_tweets
按列表ID从X列表中获取最近的推文。
- 参数:
list_id(string,必填)--数字列表IDmax_results(数字,可选)--要返回的推文(1-100,默认值100)tweet_fields(数组,可选)--要返回的Tweet字段pagination_token(string,可选)--下一页结果的标记
- 端点:
GET /2/lists/{list_id}/tweets
项目结构
src/
├── index.ts # Server entry point — registers all tools
├── api.ts # X API fetch, auth, and error handling
├── fields.ts # Field definitions and defaults for users/tweets
├── format.ts # Text formatting for user and tweet results
└── tools/
├── lookup-user.ts
├── get-tweet.ts
├── get-tweets.ts
├── search-tweets.ts
├── get-user-tweets.ts
├── get-followers.ts
├── get-following.ts
├── get-liking-users.ts
├── get-retweeters.ts
└── get-list-tweets.ts
