Instagram MCP Server
A production-ready MCP server for interacting with Instagram/Meta APIs, enabling AI agents to manage content, analyze performance, research competitors, and handle publishing workflows.
README
Instagram MCP Server
A production-ready Model Context Protocol (MCP) server for interacting with Instagram/Meta APIs. Enables AI agents to manage content, analyze performance, research competitors, and handle publishing workflows through structured MCP tools.
Features
- Account Management: Profile retrieval, account insights, media listing
- Content Analytics: Post, Reel, and Story insights with engagement metrics
- Content Generation: Reel ideas, captions, hashtags, content calendars
- Competitor Research: Profile analysis, content comparison, competitor reports
- Comment Management: Classification, moderation, auto-reply workflows
- Publishing Workflow: Container creation, media publishing, status tracking
- Lead Scoring: Business lead analysis with scoring tiers
- Audit Logging: Full request/response logging with execution metrics
Prerequisites
- Python 3.10+
- Meta Developer App with Instagram Graph API access
- Instagram Business Account connected to your Meta App
Quick Start
1. Clone and Install
git clone <repository-url>
cd instagram-mcp
pip install -r requirements.txt
2. Configure Environment
cp .env.example .env
Edit .env with your credentials:
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. Run the Server
python server.py
Docker
docker-compose up --build
MCP Client Configuration
Add to your MCP client configuration (e.g., Claude Desktop, Cursor):
{
"mcpServers": {
"instagram": {
"command": "python",
"args": ["server.py"],
"cwd": "/path/to/instagram-mcp"
}
}
}
Available Tools
Account Tools
| Tool | Description |
|---|---|
instagram_get_profile |
Get profile information |
instagram_get_account_insights |
Get account-level analytics |
instagram_get_media |
List media posts |
instagram_get_media_details |
Get detailed post info |
Analytics Tools
| Tool | Description |
|---|---|
instagram_get_post_insights |
Post performance metrics |
instagram_get_reel_insights |
Reel performance metrics |
instagram_get_story_insights |
Story performance metrics |
instagram_get_top_content |
Top-performing content |
instagram_compare_content |
Period-over-period comparison |
Content Tools
| Tool | Description |
|---|---|
instagram_analyze_content |
Analyze post structure |
instagram_generate_reel_ideas |
Generate Reel concepts |
instagram_generate_caption |
Generate captions with hashtags |
instagram_generate_hashtags |
Generate relevant hashtags |
instagram_generate_content_calendar |
Create multi-day calendars |
instagram_find_content_patterns |
Identify content patterns |
Competitor Tools
| Tool | Description |
|---|---|
instagram_analyze_competitor |
Analyze competitor profile |
instagram_compare_accounts |
Compare multiple accounts |
instagram_find_competitor_content |
Find top competitor content |
instagram_competitor_report |
Full competitor report |
Comment Tools
| Tool | Description |
|---|---|
instagram_get_comments |
Get and classify comments |
instagram_reply_comment |
Reply to a comment |
instagram_moderate_comments |
Moderate with classification |
Publishing Tools
| Tool | Description |
|---|---|
instagram_create_media_container |
Create publish container |
instagram_publish_media |
Publish to Instagram |
instagram_get_publish_status |
Check publish status |
Lead Tools
| Tool | Description |
|---|---|
instagram_analyze_leads |
Score and analyze leads |
Example Natural Language Commands
"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 Decision Layer
The server implements an internal decision pipeline:
- User Request - Natural language input
- Intent Detection - Determine required operation
- Permission Check - Validate API access
- Tool Selection - Map to appropriate MCP tool
- Instagram API - Execute authorized API call
- Data Validation - Validate response data
- Analytics/Reasoning - Process and analyze results
- Structured Response - Return formatted JSON
Comment Classification
Comments are automatically classified into:
| Category | Description |
|---|---|
positive |
Praise, compliments, positive feedback |
negative |
Complaints, criticism, negative sentiment |
question |
Questions, inquiries |
lead |
Purchase intent, business inquiries |
spam |
Promotional spam, scam content |
support |
Support requests, issue reports |
other |
Unclassified comments |
Lead Scoring
| Score Range | Tier |
|---|---|
| 81-100 | Very High |
| 61-80 | High |
| 31-60 | Medium |
| 0-30 | Low |
Scoring factors: follower count, posting frequency, business category, identified needs, website presence.
Error Handling
All tools return structured error responses:
{
"success": false,
"error": {
"code": "RATE_LIMIT",
"message": "Instagram API rate limit reached.",
"retryable": true
}
}
Error codes: UNAUTHORIZED, FORBIDDEN, NOT_FOUND, RATE_LIMIT, SERVER_ERROR, NETWORK_ERROR, INVALID_MEDIA, PERMISSION_MISSING
Project Structure
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
Running Tests
pytest tests/ -v
Security
- OAuth 2.0 authentication via Meta Graph API
- Access tokens stored in environment variables
- No credential scraping or session extraction
- Permission validation before operations
- Rate-limit handling with retry logic
- Audit logging for all tool executions
- Never exposes tokens or secrets in responses
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。