io.github.mcpware/instagram-mcp — MCP Server for Instagram Graph API
Instagram MCP (@mcpware/instagram-mcp) is a Model Context Protocol (MCP) server that provides 23 tools for the Instagram Graph API, covering posts, DMs, stories, reels, and analytics. The package is distributed as an npm package and described with topics including instagram, graph-api, and model-context-protocol.
🛠️ Key Features
23 tools for Instagram Graph API
Supports: posts, DMs, stories, reels, analytics
Identified as an MCP server (model-context-protocol)
npm package: @mcpware/instagram-mcp
🚀 Use Cases
Automate interactions with Instagram content (posts, stories, reels)
Integrate Instagram direct messaging (DMs)
Retrieve Instagram analytics data
Build Instagram-related agents using MCP tools
⚡ Developer Benefits
Tool-based access to Instagram Graph API via MCP
Developer-focused distribution through Node.js/TypeScript ecosystem (topics include nodejs, npm-package, typescript)
Common metadata for discovery: instagram-api, instagram-automation, instagram-bot
⚠️ Limitations
Scope is limited to Instagram Graph API capabilities listed in the description (posts, DMs, stories, reels, analytics)
A Model Context Protocol (MCP) server that provides seamless integration with Instagram's Graph API, enabling AI applications to interact with Instagram Business accounts programmatically.
Features
🔧 Tools (Model-controlled)
Get Profile Info: Retrieve Instagram business profile details
Get Media Posts: Fetch recent posts from an Instagram account
Get Media Insights: Retrieve engagement metrics for specific posts
Publish Media: Upload and publish images/videos to Instagram
Get Account Pages: List Facebook pages connected to the account
Get Conversations: List Instagram DM conversations (requires Advanced Access)
Get Conversation Messages: Read messages from specific conversations (requires Advanced Access)
Send DM: Reply to Instagram direct messages (requires Advanced Access)
📊 Resources (Application-controlled)
Profile Data: Access to profile information including follower counts, bio, etc.
Media Feed: Recent posts with engagement metrics
Insights Data: Detailed analytics for posts and account performance
💬 Prompts (User-controlled)
Analyze Engagement: Pre-built prompt for analyzing post performance
Content Strategy: Template for generating content recommendations
Hashtag Analysis: Prompt for hashtag performance evaluation
Prerequisites
Instagram Business Account: Must be connected to a Facebook Page
Facebook Developer Account: Required for API access
Access Token: Long-lived access token with appropriate permissions
Python 3.10+: For running the MCP server (required by MCP dependencies)
Required Instagram API Permissions
Standard Access (available immediately):
instagram_basic
instagram_content_publish
instagram_manage_insights
instagram_manage_comments
pages_show_list
pages_read_engagement
pages_manage_metadata
pages_read_user_content
business_management
Advanced Access (requires Meta App Review):
instagram_manage_messages - Required for Direct Messaging features
⚠️ Instagram DM Features: Reading and sending Instagram direct messages requires Advanced Access approval from Meta. See INSTAGRAM_DM_SETUP.md for the App Review process.
In the explorer, make a GET request to: /me/accounts
Find your Facebook Page in the response
Copy the access_token for your page
Get Instagram Business Account ID:
Use the page access token to make a GET request to: /{page-id}?fields=instagram_business_account
Copy the Instagram Business Account ID from the response
Option B: Using Facebook Login Flow (Recommended for Production)
Set Up Facebook Login:
In your app dashboard, add "Facebook Login" product
Configure Valid OAuth Redirect URIs
Implement OAuth Flow:
python
# Example OAuth URL
oauth_url = f"https://www.facebook.com/v19.0/dialog/oauth?client_id={app_id}&redirect_uri={redirect_uri}&scope=pages_show_list,instagram_basic,instagram_content_publish,instagram_manage_insights"
Exchange Code for Token:
python
# Exchange authorization code for access token
token_url = f"https://graph.facebook.com/v19.0/oauth/access_token?client_id={app_id}&redirect_uri={redirect_uri}&client_secret={app_secret}&code={auth_code}"
Step 6: Get Long-Lived Access Token
Short-lived tokens expire in 1 hour. Convert to long-lived token (60 days):
bash
curl -X GET "https://graph.facebook.com/v19.0/oauth/access_token?grant_type=fb_exchange_token&client_id={app_id}&client_secret={app_secret}&fb_exchange_token={short_lived_token}"
Step 7: Set Up Environment Variables
Create a .env file in your project root:
env
# Facebook App Credentials
FACEBOOK_APP_ID=your_app_id_here
FACEBOOK_APP_SECRET=your_app_secret_here
# Instagram Access Token (long-lived)
INSTAGRAM_ACCESS_TOKEN=your_long_lived_access_token_here
# Instagram Business Account ID
INSTAGRAM_BUSINESS_ACCOUNT_ID=your_instagram_business_account_id_here
# Optional: API Configuration
INSTAGRAM_API_VERSION=v19.0
RATE_LIMIT_REQUESTS_PER_HOUR=200
CACHE_ENABLED=true
LOG_LEVEL=INFO
Step 8: Test Your Setup
Run the validation script to test your credentials:
bash
python scripts/setup.py
Or test manually:
python
import os
import requests
# Test access token
access_token = os.getenv('INSTAGRAM_ACCESS_TOKEN')
response = requests.get(f'https://graph.facebook.com/v19.0/me?access_token={access_token}')
print(response.json())
🚨 Important Security Notes
Never commit credentials to version control
Use environment variables or secure secret management
Regularly rotate access tokens
Monitor token expiration dates
Use HTTPS only in production
Implement proper error handling for expired tokens
🔄 Token Refresh Strategy
Long-lived tokens expire after 60 days. Implement automatic refresh:
Show me my last 5 Instagram posts and their engagement metrics
Publish Content:
code
Upload this image to my Instagram account with the caption "Beautiful sunset! #photography #nature"
Using with Python MCP Client
python
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
# Connect to the Instagram MCP server
server_params = StdioServerParameters(
command="python",
args=["src/instagram_mcp_server.py"]
)
asyncwith stdio_client(server_params) as (read, write):
asyncwith ClientSession(read, write) as session:
await session.initialize()
# Get profile information
result = await session.call_tool("get_profile_info", {})
print(result)
API Endpoints Covered
Profile Management
Get business profile information
Update profile details (future feature)
Media Management
Retrieve recent posts
Get specific media details
Upload and publish new content
Delete media (future feature)
Analytics & Insights
Post engagement metrics (likes, comments, shares)
Account insights (reach, impressions)
Hashtag performance analysis
Account Management
List connected Facebook pages
Switch between business accounts
Rate Limiting & Best Practices
The server implements intelligent rate limiting to comply with Instagram's API limits:
Profile requests: 200 calls per hour
Media requests: 200 calls per hour
Publishing: 25 posts per day
Insights: 200 calls per hour
Best Practices
Cache frequently accessed data
Use batch requests when possible
Implement exponential backoff for retries
Monitor rate limit headers
Error Handling
The server provides comprehensive error handling for common scenarios:
Authentication errors: Invalid or expired tokens
Permission errors: Missing required permissions
Rate limiting: Automatic retry with backoff
Network errors: Connection timeouts and retries
API errors: Instagram-specific error responses
Security Considerations
Token Security: Store access tokens securely
Environment Variables: Never commit tokens to version control
# Run all tests
python -m pytest tests/
# Run with coverage
python -m pytest tests/ --cov=src/
# Run specific test file
python -m pytest tests/test_instagram_client.py
Contributing
Fork the repository
Create a feature branch (git checkout -b feature/amazing-feature)
Commit your changes (git commit -m 'Add amazing feature')
Push to the branch (git push origin feature/amazing-feature)
Open a Pull Request
Troubleshooting
Common Issues
"Invalid Access Token"
Verify token is not expired
Check token permissions
Regenerate long-lived token
"Rate Limit Exceeded"
Wait for rate limit reset
Implement request queuing
Use batch requests
"Permission Denied"
Verify Instagram Business account setup
Check Facebook page connection
Review API permissions
Debug Mode
Enable debug logging by setting:
env
LOG_LEVEL=DEBUG
Troubleshooting
Problem
Cause
Fix
me/accounts returns empty []
IG not connected to a Facebook Page, or you're not Page admin
Do Step 1
Graph API Explorer says "No configuration available"
Permissions not added to app
Do Step 3
"Generate Access Token" is disabled
Need to select "Get User Access Token" first
Click "Get Token" dropdown
App name rejected (contains "IG", "Insta", etc.)
Meta blocks trademarked words
Use a generic name
Token expired
Short-lived tokens last 1 hour
Do Step 6 for 60-day token
(#10) To use Instagram Graph API...
IG account is Personal, not Business
Switch to Business/Creator in IG settings
Environment Variables
Variable
Required
Default
Description
INSTAGRAM_ACCESS_TOKEN
Yes
—
Meta long-lived access token
INSTAGRAM_ACCOUNT_ID
Yes
—
Instagram business account ID
INSTAGRAM_API_VERSION
No
v19.0
Graph API version
Tools (23)
Profile & Account
Tool
Description
get_profile_info
Get profile info (bio, followers, media count)
get_account_pages
List connected Facebook pages
get_account_insights
Account-level analytics (reach, profile views)
validate_access_token
Check if token is valid
Media & Publishing
Tool
Description
get_media_posts
Get recent posts with engagement metrics
get_media_insights
Detailed analytics for a specific post
publish_media
Publish image or video
publish_carousel
Publish carousel (2-10 images/videos)
publish_reel
Publish a Reel
get_content_publishing_limit
Check daily publishing quota
Comments
Tool
Description
get_comments
Get comments on a post
post_comment
Post a comment
reply_to_comment
Reply to a comment
delete_comment
Delete a comment
hide_comment
Hide/unhide a comment
Direct Messages
Tool
Description
get_conversations
List DM conversations
get_conversation_messages
Read messages in a conversation
send_dm
Send a direct message
Discovery & Content
Tool
Description
search_hashtag
Search for a hashtag ID
get_hashtag_media
Get top/recent media for a hashtag
get_stories
Get current active stories
get_mentions
Get posts you're tagged in
business_discovery
Look up another business account
Limitations
These are Instagram Graph API limitations, not this tool's:
Business/Creator accounts only — personal accounts are not supported
Long-lived tokens expire after 60 days — refresh before expiry
200 API calls per hour rate limit
25 posts per day publishing limit
DMs require Advanced Access — Meta app review required