Twitter智能分析平台

一个基于Node.js/TypeScript的Twitter智能分析与监控平台,提供14种高级工具,包括用户分析、推文搜索和实时监控等功能,适用于AI助手集成和社交媒体分析。

  • by icaruschan
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 icaruschan/Twitter-MCP

使用说明

🚀 代理式Twitter智能平台

这个仓库包含一个强大且“智能”的 模型上下文协议(MCP) 用于高级Twitter分析和监控的服务器。它旨在作为AI助手(如Claude)的工具,提供一个自然语言界面,以访问一系列强大的Twitter情报和自动化功能。

该服务器使用Node.js/TypeScript构建,打包在Docker容器中,并与有状态服务集成 n8n 用于持续、全天候监控的自动化后端系统。


🏛️ 系统架构

该项目采用了一种现代、解耦且基于代理的架构,以实现最大的稳健性和可扩展性。

  • Twitter MCP 服务器(此仓库): 无状态的、基于Docker的前端,为AI助手提供丰富的工具集。
  • n8n 自动化引擎: 一个具有状态的、持久化的后端,包含两个主要部分:
    1. 人工智能代理路由器: 一个单一的工作流,接收来自MCP(管理控制平面)的命令,使用大型语言模型(LLM)来理解意图,并调用相应的子工作流来管理监控列表。
    2. 监控引擎: 两个独立的、定时运行的工作流,它们会轮询Twitter API以获取被监控用户和关键词的新推文,从而避免重复通知。
  • Supabase(PostgreSQL)数据库: “单一真实来源”用于存储监控列表以及用于状态管理的最后一条推文ID。

📖 工具清单与功能概述

MCP总共暴露了 14个高级工具这些分为两类:一类是用于管理n8n监控引擎的控制面板,另一类是一套按需分析工具。

🤖 统一监控控制面板(3种工具)

这些工具充当n8n监控引擎的自然语言遥控器。

1. `add_monitor`
Adds a new target (either a user account or a keyword/query) to the 24/7 monitoring list. The n8n AI Agent is smart enough to differentiate between the target types.

Parameters: `target` (string, required) - The user account (e.g., "@nasa") or keyword/query (e.g., "#AI") to start monitoring.
2. `remove_monitor`
Removes a target from the monitoring list.

Parameters: `target` (string, required) - The user account or keyword/query to stop monitoring.
3. `list_monitors`
Lists all currently monitored user accounts and keywords from the n8n engine.

Parameters: None.

🔬 按需分析与情报工具(11款工具)

这些工具能够实时获取和处理数据,以即时提供洞察。

4. `analyze_account`
Provides a comprehensive intelligence report on a single Twitter user.

Underlying Sub-Tasks: `getUserInfo`, `getUserTweets`, `calculateTweetStats`, `getUserFollowers`, `getUserFollowings`.

Parameters: `userName` (string, required), `includeFollowers` (boolean), `includeFollowings` (boolean), `includeTweets` (boolean).
5. `search_tweets`
Performs a powerful, one-time search for tweets using full Twitter Advanced Search syntax.

Underlying Sub-Tasks: `advancedSearch`.

Parameters: `query` (string, required), `maxResults` (number).
6. `track_engagement`
Provides a detailed breakdown of the engagement for a single, specific tweet.

Underlying Sub-Tasks: `getTweetsByIds`, `getTweetReplies`, `getTweetQuotes`, `getTweetRetweeters`.

Parameters: `tweetId` (string, required).
7. `get_verified_followers`
Gets a list of a user's followers who are verified (have a blue check).

Underlying Sub-Tasks: `getVerifiedFollowers`.

Parameters: `userId` (string, required), `cursor` (string).
8. `get_list_members`
Gets the members of a specific Twitter List.

Underlying Sub-Tasks: `getListMembers`.

Parameters: `listId` (string, required), `cursor` (string).
9. `get_list_followers`
Gets the followers of a specific Twitter List.

Underlying Sub-Tasks: `getListFollowers`.

Parameters: `listId` (string, required), `cursor` (string).
10. `check_relationships`
Checks the mutual follow status between multiple Twitter accounts.

Underlying Sub-Tasks: `checkFollowRelationship`.

Parameters: `accounts` (array of strings, required).
11. `get_mentions`
Retrieves recent tweets that @mention a specific user.

Underlying Sub-Tasks: `getUserMentions`.

Parameters: `userName` (string, required), `sinceHours` (number).
12. `get_trends`
Gets the current list of trending topics on Twitter for a specific location.

Underlying Sub-Tasks: `getTrends`.

Parameters: `location` (string).
13. `batch_analyze`
Efficiently retrieves profile information for a list of multiple users in a single API call.

Underlying Sub-Tasks: `getBatchUserInfo`.

Parameters: `userNames` (array of strings, required).
14. `get_article`
Retrieves the content of a long-form tweet (article).

Underlying Sub-Tasks: `getArticle`.

Parameters: `tweetId` (string, required).

🛠️ 开始使用

先决条件

安装与本地设置

  1. 克隆仓库

    git clone https://github.com/icaruschan/Twitter-MCP.git
    cd Twitter-MCP
    
  2. 配置环境变量

    • 创建一个 .env 项目根目录下的文件。
    • 添加您的Twitter API密钥:
    TWITTER_API_KEY=your_secret_api_key_here
    
  3. 设置n8n和Supabase

    • 完整的n8n后端,包括所有监控和代理工作流,作为一个可导入的JSON模板集,可在单独的存储库中获取。
    • 点击此处获取n8n工作流模板
    • 按照该存储库中的说明设置您的Supabase表,并将工作流导入到您的n8n实例中。
    • 一旦您的“统一AI代理”工作流在n8n中激活,请复制其唯一的 生产环境Webhook URL.
    • 在这个项目中 src/index.ts 文件,将那个URL粘贴到 N8N_UNIFIED_AGENT_WEBHOOK 常数。
  4. 构建并运行Docker容器

    # Build the container image
    docker-compose build
    
    # Run the container in the background
    docker-compose up -d
    

🔌 正在连接至AI助手

要将此服务器连接到如Claude Desktop等AI助手以进行本地开发:

  1. 导航至您的人工智能助手的开发者/工具设置。
  2. 添加一个具有以下配置的新本地MCP服务器:
    "twitter-mcp-server": {
      "command": "docker",
      "args": [
        "exec",
        "-i",
        "twitter-mcp-server",
        "node",
        "dist/index.js"
      ]
    }