Skip to main content
Glama

Instagram DMs MCP

A Model Context Protocol (MCP) server that lets AI assistants read and send Instagram DMs.

Features

  • πŸ“₯ Get Inbox - List all DM conversations with previews

  • πŸ’¬ Read Messages - Get full message history from any thread

  • βœ‰οΈ Send Messages - Send text messages to existing threads

  • πŸ†• Start Conversations - DM any user by username

  • ❀️ React to Messages - Add emoji reactions

  • πŸ‘€ User Lookup - Search for users by username

Quick Start

1. Get Your Instagram Cookies

Go to instagram.com and log in, then:

  1. Open DevTools (F12 or Cmd+Option+I)

  2. Go to Application tab β†’ Cookies β†’ https://www.instagram.com

  3. Find and copy these cookie values:

Cookie

Required

sessionid

βœ… Yes

ds_user_id

βœ… Yes

csrftoken

βœ… Yes

datr

Optional

ig_did

Optional

mid

Optional

  1. Paste into console to generate JSON (replace with YOUR values):

// Replace the values below with your actual cookie values from the Application tab copy(JSON.stringify({ "sessionid": "YOUR_SESSIONID_HERE", "ds_user_id": "YOUR_DS_USER_ID_HERE", "csrftoken": "YOUR_CSRFTOKEN_HERE", "datr": "YOUR_DATR_HERE", "ig_did": "YOUR_IG_DID_HERE", "mid": "YOUR_MID_HERE" }, null, 2))

This copies the JSON to your clipboard.

Why manual? Instagram marks sessionid as HttpOnly, so JavaScript can't read it directly. You need to copy it from the Application tab.

2. Save Your Cookies

Create the config directory and save your cookies:

mkdir -p ~/.instagram-dms-mcp # Paste the JSON from step 1 into this file: nano ~/.instagram-dms-mcp/cookies.json

Your cookies.json should look like:

{ "sessionid": "your_session_id_here", "ds_user_id": "your_user_id_here", "csrftoken": "your_csrf_token", "ig_did": "...", "mid": "...", "datr": "...", "ig_nrcb": "..." }

3. Build & Run

# Clone the repository git clone https://github.com/anthropics/instagram-dms-mcp.git cd instagram-dms-mcp # Build the gateway (requires Go 1.22+) cd gateway ./build.sh cd .. # Start everything ./start.sh

The MCP server will be available at http://localhost:8000/mcp

Connecting to Poke

  1. Go to poke.com/settings/connections

  2. Add a new MCP integration

  3. Enter your MCP server URL: http://your-server:8000/mcp

Available Tools

Tool

Description

get_account_info

Check connection status and get your username

get_inbox

List all DM conversations

get_messages

Get messages from a specific thread

send_message

Send a message to a thread

send_dm

Send a DM to a user by username

react_to_message

React to a message with an emoji

search_user

Look up a user by username

get_user_info

Get info about a user by ID

mark_as_read

Mark a conversation as read

Example Usage

Once connected to Poke, you can ask things like:

  • "Check my Instagram DMs"

  • "What are my recent Instagram messages?"

  • "Send a message to @username saying hello"

  • "React to that last message with ❀️"

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Poke / AI │────▢│ MCP Server │────▢│ IG Gateway β”‚ β”‚ Assistant β”‚ β”‚ (Python) β”‚ β”‚ (Go) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ :8000 :29391 β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Instagram β”‚ β”‚ Web API β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • MCP Server (Python/FastMCP): Handles the MCP protocol and exposes tools

  • IG Gateway (Go/messagix): Handles Instagram's web API using session cookies

Development

Running Components Separately

Gateway only:

cd gateway ./ig-gateway --cookies ~/.instagram-dms-mcp/cookies.json

MCP Server only:

pip install -r requirements.txt python src/server.py

Environment Variables

Variable

Default

Description

IG_GATEWAY_ADDR

http://127.0.0.1:29391

Gateway address for MCP server

IG_COOKIES_FILE

~/.instagram-dms-mcp/cookies.json

Path to cookies file

PORT

8000

MCP server port

Deployment

Using Render

  1. Fork this repository

  2. Create a new web service on Render

  3. Connect your forked repository

  4. Set the environment variables:

    • IG_COOKIES_FILE: Path to your cookies (you'll need to handle this securely)

  5. Deploy

Note: For production deployments, you'll need to run the Go gateway separately or include it in your build process.

Troubleshooting

"Could not connect to gateway"

  • Make sure the gateway is running: ./gateway/ig-gateway

  • Check that port 29391 is available

"No cookies file found"

  • Create ~/.instagram-dms-mcp/cookies.json with your Instagram cookies

  • Or set the IG_COOKIES_FILE environment variable

"Gateway failed to start"

  • Check if your cookies are valid (try logging into Instagram web again)

  • Instagram session cookies expire periodically - you may need to refresh them

Session expired

If your session expires, simply:

  1. Log into Instagram web again

  2. Run the cookie extraction script

  3. Update your cookies.json

  4. Restart the gateway

Security Notes

⚠️ Important: Your cookies.json contains your Instagram session. Keep it secure:

  • Never commit it to version control

  • Don't share it with anyone

  • Consider the security implications of self-hosting

Credits

This project uses:

  • FastMCP - Python MCP framework

  • messagix - Instagram web client library (from mautrix-meta)

License

MIT

-
security - not tested
F
license - not found
-
quality - not tested

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/braindead-dev/instagram-dms-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server