Meta Graph API MCP服务器

一个用于Meta Graph API的模型上下文协议(MCP)服务器,支持Facebook页面、Instagram商业账户的内容管理和分析。

  • by jordanburke
  • TypeScript
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 jordanburke/meta-graph-api-mcp-server

使用说明

Meta Graph API MCP服务器

用于Meta Graph API的模型上下文协议(MCP)服务器-Facebook页面、Instagram业务、内容管理和分析。

特性

  • Facebook页面:列出页面,创建/管理帖子,适度评论
  • Instagram商业:管理连接的Instagram帐户,创建帖子,查看见解
  • 分析:页面洞察、帖子参与度指标、Instagram统计数据
  • 媒体上传:将照片上传到Facebook和Instagram
  • OAuth 2.0:自动代币交换和长期代币管理

快速开始

1.创建元开发者应用程序

  1. 首选 面向开发人员的Meta
  2. 点击 创建应用程序 并选择 商业 应用程序类型
  3. 添加 脸书登录 产品
  4. 配置OAuth重定向类型: http://localhost:3000/oauth/callback
  5. 注意你的 应用程序ID 和 应用程序密钥

2.配置权限

在应用程序的应用程序审查部分,请求这些权限(所有权限都可以通过标准访问获得):

页:

  • pages_show_list -列出托管页面
  • pages_read_engagement -阅读帖子、关注者、元数据
  • pages_manage_posts -创建/编辑/删除帖子
  • pages_read_user_content -阅读页面上的用户评论
  • pages_manage_engagement -回复/删除评论
  • read_insights -页面和帖子分析

Instagram:

  • instagram_basic -阅读Instagram个人资料和媒体
  • instagram_content_publish -创建有机帖子
  • instagram_manage_comments -管理评论
  • instagram_manage_insights -获取Instagram见解

3.安装和配置

# Clone the repository
git clone https://github.com/jordanburke/meta-graph-api-mcp-server.git
cd meta-graph-api-mcp-server

# Install dependencies
pnpm install

# Copy environment template
cp .env.example .env

# Edit .env with your credentials

4.环境变量

# Required
FACEBOOK_APP_ID=your_app_id
FACEBOOK_APP_SECRET=your_app_secret

# Server Configuration
TRANSPORT_TYPE=http    # "http" for web/remote, "stdio" for Claude Desktop
PORT=3000
HOST=localhost
BASE_URL=http://localhost:3000

5.运行服务器

# Development (hot reload)
pnpm serve:dev

# Production
pnpm start

MCP工具(共20个)

连接和页面

工具 说明
test_connection 测试服务器连接
get_my_pages 列出所有管理的Facebook页面
get_page 获取详细的页面信息

帖子

工具 说明
create_page_post 创建帖子(文本、链接或带照片)
get_page_posts 列出页面中的最新帖子
get_post 获得一个有参与度的帖子
delete_post 删除帖子

评论

工具 说明
get_post_comments 列出帖子的评论
reply_to_comment 对评论的回复
delete_comment 删除评论

媒体

工具 说明
upload_photo 通过URL上传照片

分析

工具 说明
get_page_insights 页面级分析(印象、参与度、粉丝)
get_post_insights 参与后指标

Instagram商业

工具 说明
get_instagram_account 获取Instagram商业账号链接
get_instagram_media 列出Instagram帖子
create_instagram_post 创建Instagram帖子(图片+标题)
get_instagram_comments 在Instagram媒体上列出评论
reply_to_instagram_comment 回复Instagram评论
get_instagram_insights Instagram帐户分析

克劳德桌面/Claude代码配置

选项1:npx(推荐)

无需安装-直接从npm运行:

克劳德桌面版 (~/Library/Application Support/Claude/claude_desktop_config.json 在macOS上):

{
  "mcpServers": {
    "meta-graph-api": {
      "command": "npx",
      "args": ["-y", "meta-graph-api-mcp-server"],
      "env": {
        "FACEBOOK_APP_ID": "your_app_id",
        "FACEBOOK_APP_SECRET": "your_app_secret",
        "TRANSPORT_TYPE": "stdio"
      }
    }
  }
}

克劳德代码 (.mcp.json 在您的项目中):

{
  "mcpServers": {
    "meta-graph": {
      "command": "npx",
      "args": ["-y", "meta-graph-api-mcp-server"],
      "env": {
        "FACEBOOK_APP_ID": "your_app_id",
        "FACEBOOK_APP_SECRET": "your_app_secret",
        "TRANSPORT_TYPE": "stdio"
      }
    }
  }
}

选项2:HTTP模式(用于开发)

单独运行服务器并通过HTTP连接。在开发或调试时很有用:

  1. 启动服务器:
FACEBOOK_APP_ID=xxx FACEBOOK_APP_SECRET=yyy pnpm serve:dev
  1. 配置MCP以连接:
{
  "mcpServers": {
    "meta-graph": {
      "type": "http",
      "url": "http://localhost:3000/mcp"
    }
  }
}

选项3:本地安装

如果您更喜欢本地安装:

{
  "mcpServers": {
    "meta-graph-api": {
      "command": "node",
      "args": ["/path/to/meta-graph-api-mcp-server/dist/bin.cjs"],
      "env": {
        "FACEBOOK_APP_ID": "your_app_id",
        "FACEBOOK_APP_SECRET": "your_app_secret",
        "TRANSPORT_TYPE": "stdio"
      }
    }
  }
}

身份验证流程

服务器实现了完整的OAuth 2.0流程:

  1. 授权:用户访问 /oauth/authorize 并通过Facebook进行身份验证
  2. 代码交换:服务器为短期令牌交换授权码
  3. 令牌扩展:短期代币兑换长期代币(60天)
  4. 页面令牌:服务器通过以下方式获取页面访问令牌 /me/accounts
  5. 会话管理:FastMCP发行映射到Facebook代币的JWT

开发命令

# Pre-checkin (format, lint, test, build)
pnpm validate

# Individual commands
pnpm format        # Format code
pnpm lint          # Fix lint issues
pnpm test          # Run tests
pnpm build         # Production build
pnpm dev           # Watch mode

# Server
pnpm start         # Build and run
pnpm serve         # Run built server
pnpm serve:dev     # Hot reload development
pnpm inspect       # MCP inspector for debugging

项目结构

src/
├── index.ts                    # MCP server with OAuth proxy
├── bin.ts                      # CLI entry point
├── types.ts                    # Type definitions
├── client/
│   └── meta-graph-client.ts    # Meta Graph API client
└── utils/
    └── formatters.ts           # Markdown formatters
test/
└── formatters.spec.ts          # Formatter tests

API 参考

图形API版本

服务器使用Meta Graph API v21.0.

速率限制

  • 标准访问:因端点而异
  • 页面洞察:每小时200个电话
  • 帖子创建:基于应用层

错误处理

所有错误都会返回描述性消息:

Meta API Error [190]: Invalid OAuth access token
Meta API Error [100]: (#100) Pages Public Content Access requires...

故障排除

“OAuth访问令牌无效”

  • 令牌可能已过期(长期令牌持续60天)
  • 通过OAuth流重新进行身份验证

“页面公共内容访问需要…”

  • 您的应用需要app Review才能访问公共页面
  • 对于测试,将自己添加为应用程序上的测试人员/管理员

未找到Instagram帐户

  • 确保Facebook页面有一个连接的Instagram商业帐户
  • Instagram必须是商业或创作者帐户(非个人帐户)

许可证

麻省理工学院

相关项目