### Setup Script Source: https://github.com/mcpware/instagram-mcp/blob/main/AUTHENTICATION_GUIDE.md Command to run the setup script for the project. ```bash python scripts/setup.py ``` -------------------------------- ### Use Case Description for App Review Source: https://github.com/mcpware/instagram-mcp/blob/main/INSTAGRAM_DM_SETUP.md Example use case description for the `instagram_manage_messages` permission. ```text Use Case: AI-Powered Instagram Customer Support Assistant Our application uses the Instagram Messaging API to provide AI-powered customer support through Instagram DMs. The AI assistant helps businesses: 1. Read incoming customer inquiries (get_conversations, get_conversation_messages) 2. Send automated responses within the 24-hour messaging window (send_dm) 3. Provide context-aware replies using AI language models DM features are essential for our core functionality as a customer support automation tool. Without message access, our application cannot fulfill its primary purpose. ``` -------------------------------- ### Example of failing DM API calls Source: https://github.com/mcpware/instagram-mcp/blob/main/INSTAGRAM_DM_SETUP.md These are examples of API calls that will fail with a '#2 Service temporarily unavailable' error. ```python client.get_conversations(page_id) client.get_conversation_messages(conversation_id) client.send_dm(request) ``` -------------------------------- ### Standard Access Permissions Source: https://github.com/mcpware/instagram-mcp/blob/main/INSTAGRAM_DM_SETUP.md These permissions work immediately after OAuth connection. ```text ✅ instagram_basic - Profile and media access ✅ instagram_content_publish - Post images/videos ✅ instagram_manage_insights - Analytics data ✅ instagram_manage_comments - Comment management ✅ pages_show_list - List Facebook pages ✅ pages_read_engagement - Page engagement metrics ✅ pages_manage_metadata - Page metadata ✅ pages_read_user_content - User-generated content ✅ business_management - Business account management ``` -------------------------------- ### Environment Variables for Instagram API Source: https://github.com/mcpware/instagram-mcp/blob/main/AUTHENTICATION_GUIDE.md Example .env file configuration for storing Instagram API credentials and settings. ```env FACEBOOK_APP_ID=your_app_id_here FACEBOOK_APP_SECRET=your_app_secret_here INSTAGRAM_ACCESS_TOKEN=your_access_token_here INSTAGRAM_BUSINESS_ACCOUNT_ID=your_instagram_account_id_here INSTAGRAM_API_VERSION=v19.0 RATE_LIMIT_REQUESTS_PER_HOUR=200 CACHE_ENABLED=true LOG_LEVEL=INFO ``` -------------------------------- ### Install Dependencies Source: https://github.com/mcpware/instagram-mcp/blob/main/TESTING_SUMMARY.md Command to install project dependencies. ```bash pip install -r requirements.txt ``` -------------------------------- ### Environment Variables Setup Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Example of a .env file for storing Facebook App credentials, Instagram access token, and business account ID. ```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 ``` -------------------------------- ### Set up environment variables Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Copies the example environment file and instructs to edit it with Instagram API credentials. ```bash cp .env.example .env # Edit .env with your Instagram API credentials ``` -------------------------------- ### Advanced Access Permissions Source: https://github.com/mcpware/instagram-mcp/blob/main/INSTAGRAM_DM_SETUP.md These permissions require Meta's approval. ```text ⏳ instagram_manage_messages - **Required for all DM features** ``` -------------------------------- ### Working Standard Access Features Source: https://github.com/mcpware/instagram-mcp/blob/main/INSTAGRAM_DM_SETUP.md These features work immediately after OAuth connection and do not require Advanced Access. ```python # ✅ These work immediately client.get_profile_info() client.get_media_posts() client.get_media_insights(media_id) client.publish_media(request) client.get_account_insights() client.get_account_pages() ``` -------------------------------- ### Environment Variables (.env) Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Example content for the .env file, showing required Instagram and Facebook API credentials. ```env INSTAGRAM_ACCESS_TOKEN=your_long_lived_access_token FACEBOOK_APP_ID=your_facebook_app_id FACEBOOK_APP_SECRET=your_facebook_app_secret INSTAGRAM_BUSINESS_ACCOUNT_ID=your_instagram_business_account_id ``` -------------------------------- ### OAuth URL Example Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Example of an OAuth URL for initiating the Facebook Login flow to obtain authorization. ```python 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" ``` -------------------------------- ### Error handling for Instagram API errors Source: https://github.com/mcpware/instagram-mcp/blob/main/INSTAGRAM_DM_SETUP.md Python code demonstrating how to catch and handle specific Instagram API errors, particularly the '#2 Service temporarily unavailable' error. ```python try: conversations = await client.get_conversations() except InstagramAPIError as e: if "#2" in str(e) or "unavailable" in str(e).lower(): print( "Instagram Direct Messaging is not yet available. " "This feature requires Advanced Access approval from Meta. " "Please see INSTAGRAM_DM_SETUP.md for details." ) else: print(f"Error: {e}") ``` -------------------------------- ### Get Profile Information (Claude Desktop) Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Example prompt for Claude Desktop to retrieve Instagram profile information. ```text Can you get my Instagram profile information? ``` -------------------------------- ### Error Message Source: https://github.com/mcpware/instagram-mcp/blob/main/INSTAGRAM_DM_SETUP.md This error indicates that the `instagram_manage_messages` permission is not yet approved for Advanced Access. ```text Error: (#2) Service temporarily unavailable ``` -------------------------------- ### Test API Connection with Python Source: https://github.com/mcpware/instagram-mcp/blob/main/AUTHENTICATION_GUIDE.md A Python script using the requests library to test the Instagram API connection by fetching user data. ```python import requests import os # Test API connection access_token = "YOUR_ACCESS_TOKEN" response = requests.get(f'https://graph.facebook.com/v19.0/me?access_token={access_token}') print(response.json()) ``` -------------------------------- ### Publish Content (Claude Desktop) Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Example prompt for Claude Desktop to upload an image to Instagram with a caption. ```text Upload this image to my Instagram account with the caption "Beautiful sunset! #photography #nature" ``` -------------------------------- ### Analyze Recent Posts (Claude Desktop) Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Example prompt for Claude Desktop to analyze recent Instagram posts and their engagement metrics. ```text Show me my last 5 Instagram posts and their engagement metrics ``` -------------------------------- ### Python MCP Client - Connect and Get Profile Info Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Python code snippet demonstrating how to connect to the Instagram MCP server using the Python MCP Client and retrieve profile information. ```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"] ) async with stdio_client(server_params) as (read, write): async with ClientSession(read, write) as session: await session.initialize() # Get profile information result = await session.call_tool("get_profile_info", {{}}) print(result) ``` -------------------------------- ### Generate Long-Lived Access Token Source: https://github.com/mcpware/instagram-mcp/blob/main/AUTHENTICATION_GUIDE.md Bash command to exchange a short-lived access token for a long-lived one (60 days). ```bash curl "https://graph.facebook.com/v19.0/oauth/access_token?grant_type=fb_exchange_token&client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&fb_exchange_token=YOUR_SHORT_TOKEN" ``` -------------------------------- ### Get Long-Lived Access Token Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Bash command to exchange a short-lived access token for a long-lived one (60 days) using the Facebook Graph API. ```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}" ``` -------------------------------- ### Refresh Instagram Access Token Source: https://github.com/mcpware/instagram-mcp/blob/main/AUTHENTICATION_GUIDE.md Python function to refresh an Instagram access token using the Facebook Graph API. ```python def refresh_token(current_token, app_id, app_secret): url = "https://graph.facebook.com/v19.0/oauth/access_token" params = { 'grant_type': 'fb_exchange_token', 'client_id': app_id, 'client_secret': app_secret, 'fb_exchange_token': current_token } response = requests.get(url, params=params) return response.json().get('access_token') ``` -------------------------------- ### Run Server Source: https://github.com/mcpware/instagram-mcp/blob/main/TESTING_SUMMARY.md Command to run the Instagram MCP Server. ```bash python src/instagram_mcp_server.py ``` -------------------------------- ### Run all tests Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Command to execute all tests in the project. ```bash python -m pytest tests/ ``` -------------------------------- ### Run tests with coverage Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Command to run tests and generate a code coverage report. ```bash python -m pytest tests/ --cov=src/ ``` -------------------------------- ### Run specific test file Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Command to execute tests from a specific test file. ```bash python -m pytest tests/test_instagram_client.py ``` -------------------------------- ### Enable Debug Mode Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Enable debug logging by setting the LOG_LEVEL environment variable to DEBUG. ```env LOG_LEVEL=DEBUG ``` -------------------------------- ### Clone the repository Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Clones the Instagram MCP repository and navigates into the project directory. ```bash git clone cd ig-mcp ``` -------------------------------- ### Configure the MCP server Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Instructs to edit the config.json file with specific settings. ```bash # Edit config.json with your specific settings ``` -------------------------------- ### Contributing - Commit your changes Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Git command to commit staged changes with a descriptive message. ```bash git commit -m 'Add amazing feature' ``` -------------------------------- ### Contributing - Create a feature branch Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Git command to create a new branch for feature development. ```bash git checkout -b feature/amazing-feature ``` -------------------------------- ### MCP Client Configuration Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md JSON configuration for an MCP client (e.g., Claude Desktop) to connect to the Instagram MCP server. ```json { "mcpServers": { "instagram": { "command": "python", "args": ["/path/to/ig-mcp/src/instagram_mcp_server.py"], "env": { "INSTAGRAM_ACCESS_TOKEN": "your_access_token" } } } } ``` -------------------------------- ### Contributing - Push to the branch Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Git command to push the local feature branch to the remote repository. ```bash git push origin feature/amazing-feature ``` -------------------------------- ### Project Structure Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Directory structure of the ig-mcp project. ```tree ig-mcp/ ├── src/ │ ├── instagram_mcp_server.py # Main MCP server │ ├── instagram_client.py # Instagram API client │ ├── models/ # Data models │ ├── tools/ # MCP tools implementation │ ├── resources/ # MCP resources implementation │ └── prompts/ # MCP prompts implementation ├── tests/ # Unit and integration tests ├── config/ # Configuration files ├── requirements.txt # Python dependencies ├── .env.example # Environment variables template └── README.md # This file ``` -------------------------------- ### Manual Access Token Test Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Python code to test the Instagram access token by making a request to the Facebook Graph API. ```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()) ``` -------------------------------- ### Exchange Code for Token Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Python code snippet to exchange an authorization code for an access token using the Facebook Graph API. ```python 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}" ``` -------------------------------- ### Token Refresh Strategy - Refresh Token Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Python function to refresh a long-lived Instagram access token before it expires. ```python # Refresh token before expiration def refresh_long_lived_token(access_token, app_id, app_secret): url = f"https://graph.facebook.com/v19.0/oauth/access_token" params = { 'grant_type': 'fb_exchange_token', 'client_id': app_id, 'client_secret': app_secret, 'fb_exchange_token': access_token } response = requests.get(url, params=params) return response.json().get('access_token') ``` -------------------------------- ### Token Refresh Strategy - Check Validity Source: https://github.com/mcpware/instagram-mcp/blob/main/README.md Python function to check if an Instagram access token is still valid by making a request to the Facebook Graph API. ```python # Check token validity def check_token_validity(access_token): url = f"https://graph.facebook.com/v19.0/me?access_token={access_token}" response = requests.get(url) return response.status_code == 200 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.