Threads API服务器

一个为Meta Threads API设计的Model Context Protocol服务器,提供完整的读写访问功能,包括发布分析、内容发布、线程链式管理、Webhook事件和双账户管理。

  • by SvetimFM
  • TypeScript
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 SvetimFM/threads-mcp-server

使用说明

线程MCP服务器

A. 模型上下文协议 服务器 元线程API。为Claude(或任何MCP客户端)提供对Threads的完全读/写访问权限——后分析、内容发布、线程链、webhook事件和双帐户管理。

专为配合使用而设计 理念 作为一个跨平台的内容策略工具,但可以与任何兼容MCP的客户端独立工作。

特性

  • 15个MCP工具 覆盖整个螺纹API表面
  • 双账户支持 --从一台服务器管理主帐户和镜像/品牌帐户
  • 线程链接 --使用单个工具调用发布多帖子线程
  • Webhook事件 --通过ngrok实时提及、回复和发布通知
  • 轮询 --检测自上次检查跨帐户工作流以来的新帖子
  • 每日摘要 --在一次通话中汇总两个客户的见解
  • 批量洞察 --您最近发布的帖子中的参与度指标

工具

工具 说明
threads_list_accounts 列出已配置的帐户
threads_get_profile 个人资料信息(用户名、个人简介、验证)
threads_get_posts 最近发布的包含文本、媒体、时间戳的帖子
threads_get_post_insights 单帖指标:浏览量、点赞、回复、转发、引用
threads_batch_insights N个最近帖子的批量参与度指标
threads_get_account_insights 日/周/28天的账户级别指标
threads_get_replies 对特定帖子的回复
threads_get_my_replies 您对其他帖子的回复
threads_create_post 发布文本、图像或视频帖子
threads_create_thread 从文本数组中发布回复链(线程)
threads_publishing_limit 检查剩余发布配额(250/24h)
threads_get_events 读取webhook事件(提及、回复)
threads_setup_webhooks 使用Meta注册webhook订阅
threads_poll_account 仅获取自上次投票以来的新帖子
threads_daily_digest 完整摘要:见解、热门帖子、活动、配额

所有与帐户交互的工具都接受可选 account 参数("primary" 或 "mirror",默认为 "primary").

快速开始

1.先决条件

2.安装

git clone https://github.com/svetimfm/threads-mcp-server.git
cd threads-mcp-server
npm install

3.配置

cp .env.example .env

编辑 .env 使用您的Meta应用凭据:

THREADS_APP_ID=your_app_id
THREADS_APP_SECRET=your_app_secret
THREADS_REDIRECT_URI=https://your-domain.ngrok-free.app/callback

4.身份验证

开始ngrok指向端口3001:

ngrok http 3001 --domain=your-domain.ngrok-free.app

然后验证您的主帐户:

npm run auth:primary

这将打开您的OAuth浏览器,交换一个长期令牌(60天),并将其保存到 .env.

对于第二个帐户:

npm run auth:mirror

5.建造

npm run build

6.联系克劳德

克劳德代码 --添加到 ~/.claude.json:

{
  "mcpServers": {
    "threads": {
      "command": "node",
      "args": ["/path/to/threads-mcp-server/dist/index.js"]
    }
  }
}

克劳德桌面/协作 --添加到 ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "threads": {
      "command": "node",
      "args": ["/path/to/threads-mcp-server/dist/index.js"]
    }
  }
}

7.Webhooks(可选)

对于实时事件监控,将ngrok指向端口3002:

ngrok http 3002 --domain=your-domain.ngrok-free.app

然后使用 threads_setup_webhooks Claude提供的向Meta注册的工具。

建筑

src/
├── index.ts            # MCP server — 15 tool registrations, stdio transport
├── threads-api.ts      # Threads API client (all HTTP calls)
├── accounts.ts         # Dual account config loader + API factory
├── auth.ts             # OAuth flow (short-lived → long-lived token)
├── state.ts            # Persistent state (~/.threads-mcp-state.json)
└── webhook-server.ts   # HTTP server for Meta webhook events (port 3002)

服务器同时运行两个传输:

  • 标准 用于MCP与Claude的通信
  • 端口3002上的HTTP 用于Meta webhook传递(如果端口繁忙,则优雅地跳过)

范围

OAuth流请求以下线程API作用域:

  • threads_basic --配置文件访问
  • threads_content_publish --岗位创建
  • threads_manage_insights --分析学
  • threads_read_replies --阅读回复
  • threads_manage_replies --管理回复
  • threads_manage_mentions --提及监控
  • threads_keyword_search --关键字搜索

用例

  • 内容策略 --提取参与度数据,确定执行内容,计划内容
  • 双账户工作流程 --主要帖子,镜像帐户反应/放大
  • 预定摘要 --通过Cowork的日程表或cron进行每日总结
  • 线程发布 --在对话中起草多部分线程,在一次调用中发布
  • 参与度监控 --用于实时提及/回复警报的webhooks

ideAI集成

此服务器旨在与 理念 MCP连接器。当两者都连接到Claude时,您可以将您的Threads参与度与您的个人知识图、笔记和行为数据进行交叉引用,以构建基于您实际思维的数据驱动内容策略。

许可证

麻省理工学院