Skip to main content
Glama
Instagram MCP Server

Instagram MCP Server

Instagram MCP Server

一个可用于生产的 Model Context Protocol(MCP)服务器,用于与 Instagram/Meta API 交互。使 AI 代理能够通过结构化的 MCP 工具管理内容、分析表现、研究竞争对手,并处理发布工作流。

功能特性

  • 账户管理:个人资料获取、账户洞察、媒体列表

  • 内容分析:帖子、Reel 和 Story 的洞察及互动指标

  • 内容生成:Reel 创意、文案、话题标签、内容日历

  • 竞争对手研究:个人资料分析、内容对比、竞争对手报告

  • 评论管理:分类、审核、自动回复工作流

  • 发布工作流:容器创建、媒体发布、状态跟踪

  • 潜在客户评分:带评分分层的商业潜在客户分析

  • 审计日志:包含执行指标的全量请求/响应日志

Related MCP server: Instagram Control MCP Server

前提条件

  • Python 3.10+

  • 具有 Instagram Graph API 访问权限的 Meta 开发者应用

  • 已连接到 Meta 应用的 Instagram 商业账户

快速开始

1. 克隆并安装

git clone <repository-url>
cd instagram-mcp
pip install -r requirements.txt

2. 配置环境

cp .env.example .env

使用你的凭据编辑 .env:

META_APP_ID=your_meta_app_id
META_APP_SECRET=your_meta_app_secret
INSTAGRAM_ACCESS_TOKEN=your_instagram_access_token
INSTAGRAM_BUSINESS_ACCOUNT_ID=your_instagram_business_account_id

3. 运行服务器

python server.py

Docker

docker-compose up --build

MCP 客户端配置

添加到你的 MCP 客户端配置中(例如 Claude Desktop、Cursor):

{
  "mcpServers": {
    "instagram": {
      "command": "python",
      "args": ["server.py"],
      "cwd": "/path/to/instagram-mcp"
    }
  }
}

可用工具

账户工具

工具

描述

instagram_get_profile

获取个人资料信息

instagram_get_account_insights

获取账户级分析数据

instagram_get_media

列出媒体帖子

instagram_get_media_details

获取帖子详细信息

分析工具

工具

描述

instagram_get_post_insights

帖子表现指标

instagram_get_reel_insights

Reel 表现指标

instagram_get_story_insights

Story 表现指标

instagram_get_top_content

表现最佳的内容

instagram_compare_content

周期对比分析

内容工具

工具

描述

instagram_analyze_content

分析帖子结构

instagram_generate_reel_ideas

生成 Reel 创意

instagram_generate_caption

生成带话题标签的文案

instagram_generate_hashtags

生成相关话题标签

instagram_generate_content_calendar

创建多日内容日历

instagram_find_content_patterns

识别内容模式

竞争对手工具

工具

描述

instagram_analyze_competitor

分析竞争对手资料

instagram_compare_accounts

对比多个账户

instagram_find_competitor_content

查找竞争对手的顶级内容

instagram_competitor_report

完整的竞争对手报告

评论工具

工具

描述

instagram_get_comments

获取并分类评论

instagram_reply_comment

回复评论

instagram_moderate_comments

带分类的评论审核

发布工具

工具

描述

instagram_create_media_container

创建发布容器

instagram_publish_media

发布到 Instagram

instagram_get_publish_status

检查发布状态

潜在客户工具

工具

描述

instagram_analyze_leads

对潜在客户进行评分和分析

自然语言命令示例

"What were my best performing Reels last month?"
→ instagram_get_reel_insights (multiple calls) → sort → analyze → top results

"Generate a 30-day content calendar for an AI automation agency"
→ instagram_generate_content_calendar

"Analyze my competitor @examplebrand"
→ instagram_analyze_competitor → instagram_find_competitor_content

"What comments need moderation on my latest post?"
→ instagram_get_comments → classify → filter

"Compare my engagement with @competitor1 and @competitor2"
→ instagram_compare_accounts

AI 决策层

服务器实现了一个内部决策流水线:

  1. 用户请求 — 自然语言输入

  2. 意图检测 — 确定所需操作

  3. 权限检查 — 验证 API 访问权限

  4. 工具选择 — 映射到相应的 MCP 工具

  5. Instagram API — 执行已授权的 API 调用

  6. 数据验证 — 验证响应数据

  7. 分析与推理 — 处理和分析结果

  8. 结构化响应 — 返回格式化 JSON

评论分类

分类

描述

positive

赞美、好评、积极反馈

negative

投诉、批评、负面情绪

question

问题、咨询

lead

购买意向、商业咨询

spam

促销垃圾信息、诈骗内容

support

支持请求、问题报告

other

未分类的评论

潜在客户评分

分数区间

等级

81-100

非常高

61-80

高

31-60

中等

0-30

低

评分因素:粉丝数量、发布频率、业务类别、需求识别、网站存在情况。

错误处理

所有工具均返回结构化的错误响应:

{
  "success": false,
  "error": {
    "code": "RATE_LIMIT",
    "message": "Instagram API rate limit reached.",
    "retryable": true
  }
}

错误代码:UNAUTHORIZED、FORBIDDEN、NOT_FOUND、RATE_LIMIT、SERVER_ERROR、NETWORK_ERROR、INVALID_MEDIA、PERMISSION_MISSING

项目结构

instagram-mcp/
├── server.py              # Main MCP server with tool definitions
├── config.py              # Configuration management
├── requirements.txt       # Python dependencies
├── .env.example           # Environment template
├── Dockerfile             # Container configuration
├── docker-compose.yml     # Docker Compose setup
├── mcp/
│   ├── tools/             # MCP tool implementations
│   │   ├── account.py     # Account tools
│   │   ├── analytics.py   # Analytics tools
│   │   ├── content.py     # Content generation tools
│   │   ├── comments.py    # Comment management tools
│   │   ├── publishing.py  # Publishing workflow tools
│   │   └── competitors.py # Competitor research tools
│   └── schemas/           # Pydantic data models
│       ├── account.py
│       ├── content.py
│       └── analytics.py
├── services/              # Business logic layer
│   ├── instagram_api.py   # Instagram Graph API client
│   ├── analytics.py       # Analytics calculations
│   ├── content_ai.py      # Content generation engine
│   └── lead_scoring.py    # Lead analysis and scoring
├── database/              # Data persistence
│   ├── models.py          # SQLAlchemy models
│   └── repository.py      # Database operations
└── tests/                 # Unit tests
    ├── test_account.py
    ├── test_analytics.py
    ├── test_publishing.py
    └── test_errors.py

运行测试

pytest tests/ -v

安全性

  • 使用 OAuth 2.0 认证

  • 访问令牌存储在环境变量中

  • 不使用硬编码凭据

  • 操作前进行权限验证

  • 处理速率限制并带重试逻辑

  • 对所有工具执行进行审计日志记录

  • 绝不暴露令牌或密钥

许可证

MIT

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    An MCP server that integrates with Instagram's Graph API to enable AI-driven management of Instagram Business accounts. It provides tools for fetching profile data, publishing media, analyzing engagement metrics, and managing direct messages.
    203
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A production-ready Remote MCP Server that gives Claude direct, tool-based access to your Instagram Business account through the Meta Graph API — profile data, posts, comments, publishing, insights, analytics, hashtags, messaging, and real-time webhooks.
    11 npm
    MIT