mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-09-11 12:17:45 +02:00
[shawn] feat: make Instagram MCP account-agnostic — setup script + portable paths
This commit is contained in:
+35
-27
@@ -163,44 +163,52 @@ Your agents can now use Google Calendar, Gmail, Drive, etc. through MCP tools.
|
||||
|
||||
---
|
||||
|
||||
## Instagram (`instagram-mcp-buddy`) from this repo (optional)
|
||||
## Instagram (`instagram_dm_mcp` via local install) (optional)
|
||||
|
||||
The published npm package is meant to ship a **maintainer-injected** Meta app so end users need no `.env`. A **git checkout** uses placeholders until you either set env vars or inject at build time.
|
||||
OpenSwarm uses [ShawnMadadha/instagram_dm_mcp](https://github.com/ShawnMadadha/instagram_dm_mcp), a rate-limited fork of trypeggy/instagram_dm_mcp. 25 tools for DMs, user/follower lookup, post engagement, and story reads, powered by `instagrapi` (pure HTTP, no browser). The server enforces per-category rate limits on sends, likes, searches, lookups, and modifications to protect the connected account from being flagged for automation.
|
||||
|
||||
1. [Create a Meta developer app](https://developers.facebook.com/) with Instagram API (Instagram Login), and note the app id and secret.
|
||||
2. Open a terminal and `cd` to your **clone of this repository** (the folder that contains `backend/`, `frontend/`, and **`instagram-mcp/`**).
|
||||
It is **not** `~/instagram-mcp` unless you created that yourself. Example:
|
||||
### Prerequisites
|
||||
|
||||
`git` and `python3` on `PATH`.
|
||||
|
||||
### One-time install
|
||||
|
||||
From the repo root:
|
||||
|
||||
```bash
|
||||
cd /path/to/your/openswarm # e.g. ~/OpenSwarmShawn/openswarm
|
||||
cd instagram-mcp
|
||||
bash scripts/setup-instagram-mcp.sh
|
||||
```
|
||||
|
||||
If `cd instagram-mcp` says **no such file**, you are in the wrong directory — go up to the repo root first.
|
||||
This clones the server into `~/.openswarm/instagram-mcp/`, creates a venv, and pip-installs `instagrapi` + the rest of the dependencies. Re-running upgrades to the latest fork commit.
|
||||
|
||||
3. Configure and build (run every command **from `instagram-mcp/`**):
|
||||
### Connect from the UI
|
||||
|
||||
1. Open the **Tools** page in the sidebar.
|
||||
2. Find the **Instagram** tile and click **Connect Instagram**.
|
||||
3. Enter the username and password of the Instagram account the agent should use.
|
||||
4. Tile flips to **Connected**.
|
||||
|
||||
Session state is cached at `~/.instagram_dm_mcp/sessions/<username>_session.json` (per OS user, isolated from any project checkout) so future restarts skip the password prompt.
|
||||
|
||||
### Rate limits (built into the server)
|
||||
|
||||
| Category | Tools | per_min | per_hour | per_day |
|
||||
|---|---|---:|---:|---:|
|
||||
| `dm_send` | `send_message`, `send_photo_message`, `send_video_message` | 2 | 20 | 80 |
|
||||
| `like` | `like_media` | 6 | 30 | 200 |
|
||||
| `search` | `search_users`, `search_threads` | 30 | 200 | 1000 |
|
||||
| `lookup` | 16 read tools | 30 | 300 | 2000 |
|
||||
| `modify` | `mark_message_seen`, `mute_conversation`, `delete_message` | 10 | 100 | 500 |
|
||||
|
||||
Plus randomized jitter (1.5–4s before DMs, 0.5–2s before likes, smaller elsewhere) so action timing isn't bot-perfect.
|
||||
|
||||
Overridable per env var, e.g.:
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
export IG_RATE_LIMIT_DM_SEND_PER_DAY=40
|
||||
```
|
||||
|
||||
Edit `.env` and set `INSTAGRAM_MCP_APP_ID` and `INSTAGRAM_MCP_APP_SECRET` on the **uncommented** `KEY=value` lines (lines starting with `#` are ignored by the loader).
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npm run build
|
||||
node dist/index.js connect
|
||||
```
|
||||
|
||||
The CLI **loads `instagram-mcp/.env` automatically** (no need to `export` in your shell). Alternatively, bake credentials into `dist/oauth-config.js` once (still from **`instagram-mcp/`**):
|
||||
|
||||
```bash
|
||||
npm run build:inject
|
||||
```
|
||||
|
||||
(`inject-credentials.mjs` also reads `.env` if the variables are not already in the environment.)
|
||||
|
||||
To skip `npx` delegation entirely when testing: set `INSTAGRAM_MCP_NO_NPX_FALLBACK=1` in `.env`.
|
||||
Rate-limit state persists at `~/.instagram-mcp-rate-limits.json` so a server restart doesn't reset the daily budget. When a cap is hit, the tool returns a structured `{ok: false, rate_limited: true, retry_after_seconds: ...}` response the agent can surface as *"hit DM cap, retry in 4h"* instead of failing opaquely.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -148,16 +148,16 @@ const INTEGRATIONS: Integration[] = [
|
||||
id: 'instagram',
|
||||
name: 'Instagram',
|
||||
description:
|
||||
'Instagram DM outreach plus user/follower lookup, post engagement, and story reads. 25 tools from trypeggy/instagram_dm_mcp. Sign in with your Instagram username and password (personal accounts supported). NOTE: mass-DMing from personal accounts triggers Instagram anti-abuse detection; use sparingly on established accounts.',
|
||||
'Instagram DM outreach plus user/follower lookup, post engagement, and story reads. 25 tools from ShawnMadadha/instagram_dm_mcp (a rate-limited fork of trypeggy/instagram_dm_mcp). Sign in with your Instagram username and password. First-time setup: run scripts/setup-instagram-mcp.sh. NOTE: mass-DMing from personal accounts triggers Instagram anti-abuse detection; per-tool rate limits are enforced by the server to protect your account.',
|
||||
mcp_config: {
|
||||
type: 'stdio',
|
||||
command: '/usr/local/bin/python3.11',
|
||||
args: ['/Users/shawnmadadha/dev/instagram_dm_mcp/src/mcp_server.py'],
|
||||
command: 'bash',
|
||||
args: ['-c', 'exec "$HOME/.openswarm/instagram-mcp/.venv/bin/python" "$HOME/.openswarm/instagram-mcp/src/mcp_server.py"'],
|
||||
},
|
||||
color: '#E4405F',
|
||||
website: 'https://github.com/trypeggy/instagram_dm_mcp',
|
||||
website: 'https://github.com/ShawnMadadha/instagram_dm_mcp',
|
||||
connectLabel: 'Connect Instagram',
|
||||
connectInstructions: 'Sign in with the username and password of the Instagram account you want the agent to use. Credentials are stored locally in OpenSwarm and passed as env vars to the MCP server on launch. Instagram session is cached on disk after first successful login so you do not need to re-enter on every restart.',
|
||||
connectInstructions: 'First-time on this machine: run `bash scripts/setup-instagram-mcp.sh` in a terminal. It installs the MCP server into ~/.openswarm/instagram-mcp/. Then sign in below with the Instagram username and password the agent should use. Credentials are stored locally in OpenSwarm; session files live in ~/.instagram_dm_mcp/sessions/ and are reused on every restart.',
|
||||
credentialFields: [
|
||||
{ key: 'INSTAGRAM_USERNAME', label: 'Instagram Username', placeholder: 'your_handle (no @)', type: 'text' },
|
||||
{ key: 'INSTAGRAM_PASSWORD', label: 'Instagram Password', placeholder: '••••••••', type: 'password' },
|
||||
|
||||
Executable
+47
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
# One-time setup for the Instagram MCP server. Each OpenSwarm user runs this
|
||||
# once on their machine; it installs the ShawnMadadha/instagram_dm_mcp fork
|
||||
# (carries the per-tool rate limiter that protects accounts from anti-abuse
|
||||
# bans) into ~/.openswarm/instagram-mcp/ and pip-installs its dependencies
|
||||
# into a local venv. Re-running upgrades to the latest version.
|
||||
#
|
||||
# Why a fork: trypeggy/instagram_dm_mcp upstream does not have the rate
|
||||
# limiter yet. PR is open at trypeggy/instagram_dm_mcp#12.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
DEST="$HOME/.openswarm/instagram-mcp"
|
||||
REPO_URL="https://github.com/ShawnMadadha/instagram_dm_mcp.git"
|
||||
|
||||
if ! command -v git >/dev/null 2>&1; then
|
||||
echo "error: git not found on PATH." >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! command -v python3 >/dev/null 2>&1; then
|
||||
echo "error: python3 not found on PATH." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -d "$DEST/.git" ]; then
|
||||
echo "Updating existing checkout at $DEST..."
|
||||
git -C "$DEST" fetch --quiet
|
||||
git -C "$DEST" reset --hard origin/main --quiet
|
||||
else
|
||||
echo "Cloning $REPO_URL into $DEST..."
|
||||
mkdir -p "$(dirname "$DEST")"
|
||||
git clone --depth=1 --quiet "$REPO_URL" "$DEST"
|
||||
fi
|
||||
|
||||
VENV="$DEST/.venv"
|
||||
if [ ! -d "$VENV" ]; then
|
||||
echo "Creating venv at $VENV..."
|
||||
python3 -m venv "$VENV"
|
||||
fi
|
||||
|
||||
echo "Installing requirements into venv..."
|
||||
"$VENV/bin/python" -m pip install --quiet --upgrade pip
|
||||
"$VENV/bin/python" -m pip install --quiet -r "$DEST/requirements.txt"
|
||||
|
||||
echo "Installed: $DEST"
|
||||
"$VENV/bin/python" -c "from pathlib import Path; print(' python:', Path('$VENV/bin/python').resolve()); print(' server:', '$DEST/src/mcp_server.py')"
|
||||
echo "Done. Connect Instagram from the OpenSwarm Tools page next."
|
||||
Reference in New Issue
Block a user