Skip to main content
Glama
README.md
# Instagram MCP

<img src="docs/images/icon.png" alt="Instagram MCP icon" width="96" align="right">

Use Instagram in your own Chrome profile as a Python library, a CLI, a REST
API, or an MCP server. An AI assistant (Claude Code or any MCP client) can
search accounts, read profiles, posts, comments and notifications, list and
read direct messages, send messages, follow accounts, save photos and videos,
receive incoming messages, and answer them through auto-reply profiles.

The work is done by Instagram's own web client, in a tab of your Chrome where
you are logged in yourself. This package never sees your password, and it
stores no Instagram cookie or token. Every command runs one of Instagram's own
operations in that tab.

## Up and running

```bash
git clone https://github.com/alfa-yohannis/instagram-mcp
cd instagram-mcp
./instagram install          # Windows: instagram.cmd install
```

1. In Chrome, open `chrome://extensions`, turn on **Developer mode**, click
   **Load unpacked**, and choose the `instagram_mcp/extension` folder. Its ID
   must be `hfmmgbnmaonoopgcagbbocdeilmkklih`.
2. Run `./instagram open` and log in to instagram.com in the tab that opens, if
   you are not logged in yet.
3. Check with `./instagram status`, which should end with `logged_in as @you`.
4. Read something: `./instagram chats`, then `./instagram user instagram`.
5. Connect Claude Code: `claude mcp add instagram -- "$PWD/instagram" mcp`.
6. Optional auto-reply: open the side panel from the extension's popup, create
   a profile, link chats, and press **Dry run**.

The full walkthrough, with what each status means and how to fix the usual
problems, is in [docs/UP-AND-RUNNING.md](docs/UP-AND-RUNNING.md).

## How it works

```
Claude Code / CLI / REST API / your Python program
        │  InstagramClient: TCP 127.0.0.1 + token from the bridge card
        ▼
native messaging host (instagram_mcp/host.py, started by Chrome)
        │  native messaging (stdio)
        ▼
Instagram MCP Chrome extension (instagram_mcp/extension/)
        │  chrome.scripting, MAIN world
        ▼
bridge.js in https://www.instagram.com/direct/inbox/  →  Instagram's own modules
```

The bridge runs Instagram's own compiled GraphQL operations through the page's
Relay network, with the ids and parameters the page itself loaded. Nothing about
the protocol is reimplemented, and no query ids are hard coded here.

The extension opens a Direct inbox tab in the background when a command needs
one; your other Instagram tabs are not touched. Incoming messages travel the
other way: the page keeps its inbox up to date in memory, the bridge reads that
copy every two seconds (so watching costs no request to Instagram), the
extension forwards new messages to the host, and the host broadcasts them to
subscribed clients (the MCP server, `instagram watch`, `GET /events`, and the
auto-reply service).

An extension is needed because Chrome 136+ ignores DevTools remote debugging on
the default profile directory, and Chrome 137+ ignores `--load-extension`. With
an extension, Instagram MCP works in the same Chrome profile you use every day.

## What works, and how it was checked

| Feature | Checked |
|---|---|
| Accounts: search, profile, posts, one post, comments | the same operations were run live on instagram.com; the code was checked with tests |
| Direct messages: list chats, read a chat, older messages | run live; tests |
| Notifications | the list endpoint answered live; the details of each entry are only tested with sample data |
| Sending text, following and unfollowing, saving photos and videos, incoming messages, the extension and host together in a real Chrome | written and tested with a fake page and a fake extension, not yet tried on a live account |

Sending builds the same request as Instagram's page. If Instagram changes it,
`./instagram capture` shows the names and shapes (never the contents) of what
the page sends while you do the action by hand, so `bridge.js` can follow.
Publishing posts and stories, liking, saving, and message requests are not
part of this version.

## Requirements

- Python 3.10 or newer
- Google Chrome (Linux, Windows, or macOS)
- An Instagram account, logged in on instagram.com in Chrome
- For draft and auto replies: the [Claude Code](https://code.claude.com) CLI (`claude`)

## Installation

The `./instagram` launcher installs the package and its dependencies on first
run: into `$INSTAGRAM_VENV` when set, into `~/venv` when it exists, or into
`.venv` in this directory. `install` registers the native messaging host with
Chrome (a manifest file on Linux and macOS, an HKCU registry key on Windows)
and prints how to load the extension. Loading it is a one-time step in the
Chrome profile where you are logged in to Instagram, described in
[docs/UP-AND-RUNNING.md](docs/UP-AND-RUNNING.md).

## Chrome and its profiles

When Chrome is not running, `./instagram open` (the `open_instagram` tool)
starts it and opens Instagram's Direct inbox. The profile used is:

1. the one requested (`--profile "Profile 3"` or its display name), or
   `INSTAGRAM_CHROME_PROFILE` in `.env`;
2. otherwise the most recently used profile, preferring profiles that already
   have the Instagram MCP extension.

`./instagram profiles` lists every profile with a masked email, when it was
last active, and which one will be picked.

## Using it

### MCP (Claude Code)

```bash
claude mcp add instagram -- /path/to/instagram-mcp/instagram mcp
```

To get incoming messages pushed into a Claude Code session as channel
notifications, add the server to your project's `.mcp.json` and start:

```bash
claude --dangerously-load-development-channels server:instagram
```

Claude Code channels are a research preview. Without them, incoming messages
are still available through the `incoming_messages` tool. By default only
messages from accounts you follow are pushed (`INSTAGRAM_NOTIFY_FROM`). Every
tool is listed in [docs/MCP.md](docs/MCP.md).

### CLI

```bash
./instagram users "coffee shop"
./instagram user instagram
./instagram posts instagram --limit 6
./instagram comments https://www.instagram.com/p/SHORTCODE/
./instagram chats --unread
./instagram messages someone --limit 20
./instagram send someone --text "Hello" --text "Are you free today?"      # dry run
./instagram send someone --text "Hello" --send                            # for real
./instagram watch                                                         # incoming messages
```

Every command is in [docs/CLI.md](docs/CLI.md).

### REST API

```bash
./instagram api           # http://127.0.0.1:8000, interactive docs at /docs
```

Endpoints are in [docs/API.md](docs/API.md).

### Python library

```python
from instagram_mcp import InstagramClient, list_chats, send_message, user_info

client = InstagramClient()
print(user_info(client, "instagram")["followers"])
plan = send_message(client, "someone", ["Hello"])               # dry run
send_message(client, "someone", ["Hello"], send=True)           # for real
```

## Auto-reply

Reply profiles decide how incoming direct messages are answered. A profile can
be linked to a chat (including a group) or to an account, and a chat or account
can carry several profiles; the highest priority wins. Each profile has a mode:

| Mode | What happens |
|---|---|
| `template` | fixed text with `{name}`, `{chat_name}`, `{time}`, `{date}`, `{day}`; sent right away |
| `draft` | the Claude CLI writes a reply from the profile's instructions; it waits for your approval |
| `auto` | the Claude CLI writes the reply and it is sent right away |

A profile also has a scope (only linked chats and accounts, accounts you
follow, or everyone), active hours and days, a per-chat cooldown, and a switch
for groups (off by default). A global limit caps replies per hour.

Manage profiles in the extension's side panel (toolbar icon > Auto-reply
profiles), with `./instagram replies ...`, the MCP tools, or the REST API.
Then run the service:

```bash
./instagram service --dry-run      # try your profiles: every reply becomes a draft
./instagram service                # answer for real
```

The service can also run inside the extension's native messaging host, with
Run, Dry run, and Stop in the side panel or `./instagram service start|stop|status`.
Only one service can run at a time.

Incoming messages are untrusted text. The reply writer runs
`claude -p --tools "" --strict-mcp-config`, so it has no tools and no MCP
servers: it can only return text, and that text only goes to the chat the
message came from. Using `draft` or `auto` sends the message and the recent
conversation to the Claude CLI. Drafts wait in the side panel,
`./instagram replies drafts`, or the `list_replies` tool until you approve or
reject them.

## Writing is always a dry run first

Everything that writes to Instagram (`send_message`, `follow_user`,
`approve_draft`) is a dry run by default. What comes back is a summary: the
account or chat that was found and the content. Acting only happens with
`send=True` (CLI: `--send`), on the target that the dry run resolved. A name
that matches several chats is rejected with the list of choices.

If a command went out but its answer was lost, the result is `UncertainResult`
(MCP: `sent=true, ok=false`) and it is never retried automatically, so a
message is not sent twice.

## Settings

Copy `.env.example` to `.env` and fill in only what you need. Settings that are
safe to share can also go in `instagram.yaml` (see `instagram.yaml.example`).
Precedence: `configure()` in code, the environment, `.env`, `instagram.yaml`,
then the default.

| Setting | Default | Purpose |
|---|---|---|
| `INSTAGRAM_CHROME_PROFILE` | most recently used | Chrome profile to open |
| `INSTAGRAM_CHROME` | found automatically | path of the Chrome program |
| `INSTAGRAM_CHROME_USER_DATA_DIR` | OS default | Chrome user data directory |
| `INSTAGRAM_API_TOKEN` | empty | REST API bearer token |
| `INSTAGRAM_NOTIFY_FROM` | `following` | `following`, `all`, or `none` |
| `INSTAGRAM_DESKTOP_NOTIFICATIONS` | `no` | desktop notifications from the MCP server |
| `INSTAGRAM_SEND_DELAY_SECONDS` | `3` | pause between messages in one send |
| `INSTAGRAM_MAX_DOWNLOAD_MB` | `200` | largest file a download may save |
| `INSTAGRAM_TIMEOUT_SECONDS` | `60` | how long to wait for Instagram to answer |
| `INSTAGRAM_TIMEZONE` | `Asia/Jakarta` | time zone of dates in the output |
| `INSTAGRAM_CLAUDE` | `claude` | Claude CLI used by draft and auto profiles |
| `INSTAGRAM_REPLY_MODEL` | `haiku` | model the Claude CLI uses for replies |
| `INSTAGRAM_LLM_TIMEOUT_SECONDS` | `120` | how long to wait for the Claude CLI |
| `INSTAGRAM_MAX_REPLIES_PER_HOUR` | `20` | auto-reply limit across all chats |
| `INSTAGRAM_REPLY_DB` | in the state directory | reply database location |

## Security and limits

- Bridge cards (host port and token), the host log, and the reply database live
  in the user's state directory (mode 0600 for cards): `~/.local/state/instagram-mcp`
  (Linux), `~/Library/Application Support/instagram-mcp` (macOS),
  `%LOCALAPPDATA%\instagram-mcp` (Windows).
- The host only listens on 127.0.0.1. Without `INSTAGRAM_API_TOKEN` the REST API
  only serves requests from this computer, and only when the Host header names
  this computer (so a web page that points its own domain at 127.0.0.1 is refused).
- Media is downloaded only from Instagram's own hosts over HTTPS, without cookies.
- Reading messages through this package does not mark them as seen. Opening a
  chat by hand in Instagram does.
- Message, comment, notification, and profile content is written by other
  people. The assistant is told to treat it as data, never as instructions.
- Instagram's terms restrict automated use, and it limits accounts that make
  many requests. This package paces its own requests, keeps lists short, and
  stops with `rate_limited` when Instagram says so. Keep volumes low, never
  follow or message in bulk, and expect an occasional check from Instagram.
- Instagram changes its web client often. If an operation is renamed, the error
  is `not_loaded`; fix `instagram_mcp/extension/bridge.js` and run
  `./instagram reload`.

## Layout

```
instagram                  Linux/macOS launcher
instagram.cmd              Windows launcher
instagram_mcp/
  extension/               Chrome extension (manifest, background.js, bridge.js, relay.js, popup, side panel, icons)
  host.py                  native messaging host
  instagram_client.py      InstagramClient and errors
  chrome.py                the Chrome program, its profiles, and launching it
  install.py               host registration for Chrome
  status.py                check_login and open_instagram
  users.py, posts.py       accounts, posts, comments
  chat.py, messages.py     chats and direct messages
  notifications.py, media.py, actions.py
  autoreply.py             reply profiles, links, drafts, the engine, and the service
  writes.py                WriteResult (dry run and send)
  cli.py, api.py, mcp_server.py
docs/                      UP-AND-RUNNING.md, MCP.md, CLI.md, API.md
examples/                  ready-to-run examples
tests/                     unit tests (./instagram test)
```

## License

MIT

TDQS

B3.1/5.0

Scored across 28 tools

Disambiguation4/5

Tools are mostly distinct, and descriptions clarify boundaries such as check_login/open_instagram/chrome_profiles for status, launch, and profile listing. There is minor overlap around new_chat, chat_info, and send_message with users, but the intended differences are documented.

Naming Consistency3/5

The set consistently uses snake_case, but it mixes verb-led action names like list_chats, send_message, and start_auto_reply with noun-only retrieval/state names like user_info, post_comments, notifications, and auto_reply_status. It remains readable, but there is no single predictable verb_noun convention.

Tool Count2/5

With 28 tools, the surface is above the 25-tool threshold and is heavy for an agent to navigate. Most tools are individually meaningful, but the combination of browsing, messaging, downloads, and auto-reply management creates a large selection burden.

Completeness3/5

Coverage is strong for browsing, DMs, downloads, and the auto-reply lifecycle. However, common Instagram post interactions such as like, comment, save, and create-post are absent, and DM coverage lacks some lifecycle operations, leaving notable gaps.