Instagram MCP Server
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.txt2. Configure Environment
cp .env.example .envEdit .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_id3. Run the Server
python server.pyDocker
docker-compose up --buildMCP 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 |
| Get profile information |
| Get account-level analytics |
| List media posts |
| Get detailed post info |
Analytics Tools
Tool | Description |
| Post performance metrics |
| Reel performance metrics |
| Story performance metrics |
| Top-performing content |
| Period-over-period comparison |
Content Tools
Tool | Description |
| Analyze post structure |
| Generate Reel concepts |
| Generate captions with hashtags |
| Generate relevant hashtags |
| Create multi-day calendars |
| Identify content patterns |
Competitor Tools
Tool | Description |
| Analyze competitor profile |
| Compare multiple accounts |
| Find top competitor content |
| Full competitor report |
Comment Tools
Tool | Description |
| Get and classify comments |
| Reply to a comment |
| Moderate with classification |
Publishing Tools
Tool | Description |
| Create publish container |
| Publish to Instagram |
| Check publish status |
Lead Tools
Tool | Description |
| 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_accountsAI 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 |
| Praise, compliments, positive feedback |
| Complaints, criticism, negative sentiment |
| Questions, inquiries |
| Purchase intent, business inquiries |
| Promotional spam, scam content |
| Support requests, issue reports |
| 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.pyRunning Tests
pytest tests/ -vSecurity
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