Instagram MCP Server
# Instagram MCP Server
A professional, well-structured MCP (Model Context Protocol) server for managing and posting Instagram content ā PDF to images, carousel batches, auto-posting, and Cloudinary hosting.
## Features
- šø **Content management** ā list, view, delete, archive local images
- āļø **Metadata** ā captions & hashtags per content item
- š± **Post to Instagram** ā single image or carousel posts via Graph API
- š¼ļø **PDF ā Images** ā convert PDF pages to PNGs (poppler)
- š **Carousel batches** ā group images into 2-10 image carousels
- āļø **Cloudinary** ā temporary image hosting + auto-cleanup
- š **Token diagnostics** ā debug token expiry, scopes, and meta error codes
## Project Structure
```
instagram-mcp/
āāā src/instagram_mcp/ # Main package
ā āāā config.py # Env, constants, paths
ā āāā logging_setup.py # Console + file logging
ā āāā errors.py # Meta error parsing + guidance
ā āāā server.py # FastMCP registration (thin)
ā āāā __main__.py # python -m instagram_mcp
ā āāā services/ # External integrations
ā ā āāā instagram.py # Graph API client
ā ā āāā cloudinary.py # Upload/delete/verify
ā ā āāā pdf.py # PDF ā images
ā āāā storage/ # Local data access
ā ā āāā content.py # File resolution
ā ā āāā metadata.py # JSON load/save
ā āāā tools/ # MCP tool implementations
ā āāā content_tools.py
ā āāā metadata_tools.py
ā āāā instagram_tools.py
ā āāā cloudinary_tools.py
ā āāā carousel_tools.py
āāā scripts/ # CLI utilities
ā āāā check_token.py # Validate token + scopes
ā āāā refresh_token.py # Extend long-lived token
āāā tests/ # pytest suite (mocked HTTP)
āāā content/ # Your media files (unchanged)
āāā archive/ # Archived content
āāā logs/ # Log files
āāā server.py # Backward-compatible entry point
āāā pyproject.toml # Package config
```
## Installation
```bash
# Create & activate venv (Windows)
python -m venv .venv
.\.venv\Scripts\Activate.ps1
# Install package (editable)
pip install -e .
```
## Configuration
Copy `.env.example` ā `.env` and fill in:
```bash
# Instagram (required for posting)
INSTAGRAM_ACCESS_TOKEN=your_token_here
INSTAGRAM_BUSINESS_ACCOUNT_ID=your_account_id_here
# Cloudinary (required for publish_image / carousels)
CLOUDINARY_CLOUD_NAME=...
CLOUDINARY_API_KEY=...
CLOUDINARY_API_SECRET=...
# Optional
INSTAGRAM_API_VERSION=v23.0
LOG_LEVEL=INFO
DELETE_LOCAL_AFTER_PUBLISH=false
```
## Running the Server
```bash
# Option 1: Backward-compatible (Claude Desktop config)
python server.py
# Option 2: As a package
python -m instagram_mcp
# Option 3: Console script (after pip install -e .)
instagram-mcp
```
## CLI Utilities
```bash
# Check your token's validity, expiry, and scopes
python scripts/check_token.py
# Info on refreshing a long-lived token (60 days)
python scripts/refresh_token.py
```
## Testing
```bash
pip install -e ".[dev]"
pytest
```
## MCP Tools
| Tool | Purpose |
|------|---------|
| `list_content` | List local images in content dir |
| `get_content` | Get file metadata (mime, size) |
| `manage_content` | list / delete / archive content |
| `manage_metadata` | Update / view / clear captions & hashtags |
| `test_instagram_connection` | Test Graph API connection |
| `debug_instagram_token` | Debug token expiry + scopes |
| `post_to_instagram` | Post single image (direct upload) |
| `test_cloudinary_upload` | Upload to Cloudinary, verify URL |
| `cleanup_cloudinary_asset` | Delete a Cloudinary asset |
| `publish_image` | Publish via Cloudinary HTTPS URL |
| `convert_pdf_to_images` | PDF ā PNG images |
| `create_carousel_batch` | Group images into carousels |
| `post_carousel_to_instagram` | Post a carousel + auto-cleanup |
| `list_carousel_batches` | List carousels + status |
## Resource
- `instagram://content/{filename}` ā access images as base64 blobs for visual analysis.
## Troubleshooting: Daily "API access blocked (code 200)"
Run `test_instagram_connection` and `debug_instagram_token` to diagnose.
Common causes & fixes:
1. **App in Development Mode** ā switch to **Live** in Meta Developer dashboard.
2. **Missing approved permissions** ā submit App Review for `instagram_basic` + `instagram_content_publish`.
3. **Token expired/revoked (60 days)** ā generate a fresh long-lived token.
4. **App flagged by Meta** ā check the app review status / appeal.
Logs are written to `logs/instagram_mcp.log` for diagnosis.TDQS
Scored across 14 tools
Several tools overlap in function: list_content and manage_content's list action both list content, and post_to_instagram and publish_image both post to Instagram via different paths. Descriptions help but the boundaries could still confuse an agent.
All tool names consistently use snake_case with a verb_noun or verb_to_noun pattern, creating a predictable and clear naming convention.
14 tools is well within the ideal 3-15 range for an Instagram content server, covering posting, content management, metadata, diagnostics, and carousel workflows without feeling bloated.
Core posting and content management workflows are covered, but there are notable gaps: no post deletion or status retrieval, and scheduling is mentioned in manage_metadata but not actually implemented as a tool.