Skip to main content
Glama
instagram-mcp

instagram-mcp

README.md
# instagram-mcp

A **streamable-HTTP MCP server** (endpoint `/mcp`, port 8000) that gives any
MCP-compatible AI agent **full control over an Instagram account** — post
photos/albums/reels, stories, DMs, comments, likes, follows, search, highlights,
profile edits, and more (**68+ tools**).

Built on [`instagrapi`](https://github.com/subzeroid/instagrapi) (curl_cffi
anti-detection) and the official
[Model Context Protocol Python SDK](https://github.com/modelcontextprotocol/python-sdk).

Owner: Aidan Cohen.

---

## What it does

| Area | Tools (examples) |
|------|------------------|
| Auth | `instagram_login_with_credentials`, `instagram_login_with_sessionid`, `instagram_complete_2fa`, `instagram_complete_challenge`, `instagram_get_login_status`, `instagram_logout` |
| Posts | `instagram_post_photo`, `instagram_post_album`, `instagram_edit_caption`, `instagram_disable_comments`, `instagram_archive_media`, `instagram_pin_media` |
| Stories / Reels | `instagram_upload_story_photo`, `instagram_upload_story_video`, `instagram_upload_reel`, `instagram_upload_video` |
| Engagement | `instagram_like_media`, `instagram_unlike_media`, `instagram_comment`, `instagram_delete_comment`, `instagram_follow`, `instagram_unfollow` |
| DMs | `instagram_send_direct_message`, `instagram_get_direct_threads`, `instagram_get_direct_messages` |
| Discovery | `instagram_search_users`, `instagram_search_hashtags`, `instagram_get_profile`, `instagram_get_user_media`, `instagram_get_hashtag_media` |

Ask the server for `tools/list` to see the full surface.

## Architecture

- **Transport:** streamable-HTTP MCP, stateless (`stateless_http=True`), served
  at `http://<host>:8000/mcp`. A `/healthz` GET returns `{"ok": true, ...}`.
- **Logging:** every `except` in the codebase logs (level + message + traceback)
  to a log file **and** stdout — there are no silent `except: pass` paths.
  Logs are written to `/var/log/instagram-mcp/{app,errors,access}.log` and a
  sidecar container tails them, so `kubectl logs <pod> -c logs` streams live
  output.
- **Credentials:** read only from the environment `IG_USERNAME` / `IG_PASSWORD`
  (injected from a Kubernetes Secret). Never hardcoded, never committed.
- **Session persistence:** the instagrapi session file lives on a PVC mounted at
  `/data/instagram_session.json`, so a login survives pod restarts.
- **Safe startup:** login (from env creds, if present) runs in a background
  thread. A login failure / 2FA / challenge never stops the MCP endpoint from
  serving — the failure is logged and the server stays up.

## Run it (Docker)

```bash
docker build -t instagram-mcp:latest .
docker run --rm -p 8000:8000 \
  -e IG_USERNAME=your_handle \
  -e IG_PASSWORD=your_password \
  instagram-mcp:latest
```

Then hit `http://localhost:8000/mcp` with an MCP client, or check
`http://localhost:8000/healthz`.

## Deploy on Kubernetes (k3s)

The manifest (`deploy.yaml`) creates, in the `default` namespace:

1. A `Secret` (`instagram-mcp-secret`) — **placeholder, empty values**; create
   the real one out-of-band:
   ```bash
   kubectl create secret generic instagram-mcp-secret \
     --from-literal=IG_USERNAME=<handle> --from-literal=IG_PASSWORD=<password>
   ```
2. A `PVC` (`instagram-mcp-session`) for session persistence.
3. A `Deployment` (`instagram-mcp`) — main container + logging sidecar, sharing
   an `emptyDir` at `/var/log/instagram-mcp`.
4. A `ClusterIP` `Service` (`instagram-mcp`) mapping `8000 -> 8000`.

Build + import + apply (the image is local, not pushed to a registry):

```bash
docker build -t instagram-mcp:latest .
docker save instagram-mcp:latest | sudo k3s ctr images import -
sudo k3s ctr images label docker.io/library/instagram-mcp:latest io.cri-containerd.pinned=pinned

kubectl create secret generic instagram-mcp-secret \
  --from-literal=IG_USERNAME=<handle> --from-literal=IG_PASSWORD=<password>

kubectl apply -f deploy.yaml
kubectl rollout status deploy/instagram-mcp --timeout=120s
```

> The image is **arm64**. The pod is pinned to `kubernetes.io/arch: arm64`; the
> liqo virtual nodes are amd64, so build on an arm64 node (the lima-ubuntu
> control-plane in this fleet).

### Verify

```bash
kubectl get pods,svc
kubectl logs deploy/instagram-mcp -c instagram-mcp   # main container stdout
kubectl logs deploy/instagram-mcp -c logs            # live tail of app/errors/access logs
```

Run the smoke test (from any host that can reach the cluster, via port-forward):

```bash
kubectl port-forward svc/instagram-mcp 8000:8000 &
python3 smoke.py http://127.0.0.1:8000/mcp
```

`smoke.py` performs a real MCP `initialize` → `notifications/initialized` →
`tools/list` handshake over streamable HTTP.

## Rebuild from scratch (what a cold clone does)

```bash
git clone https://github.com/salmonhealer772/instagram-mcp.git
cd instagram-mcp
# (the steps under "Deploy on Kubernetes" above)
```

## License

MIT — see [LICENSE](LICENSE). Forked from
[official-Arvind/instagram-mcp](https://github.com/official-Arvind/instagram-mcp).