Sandbox
@trypeggy/instagram_dm_mcp

Instagram DM MCP server for Cursor and MCP clients

This repo adds Instagram Direct Messages as an MCP connection your agent can use. It runs a Python server that can send messages, list chats, inspect threads, fetch user info, and work with media.

179 stars38 forksPythonUpdated 1y ago
Who it's for

Builders who want their agent to send and read Instagram DMs from a connected MCP server.

What it delivers

You can manage Instagram conversations from your agent instead of switching into the app.

What it does

Send direct messages

Send text, photo, and video DMs to a username.

Read conversations

List chats, pending chats, thread details, and messages from a DM thread.

Work with media in DMs

Download media from direct uploads or shared posts, reels, and clips.

Inspect accounts and threads

Look up user IDs, usernames, user info, followers, following, posts, and stories.

Control message state

Mark a message as seen and search threads by username, keyword, or participants.

How to get it

  1. 1Clone this repository
    git clone https://github.com/trypeggy/instagram_dm_mcp.git
    cd instagram_dm_mcp
  2. 2Using uv (recommended)
    uv sync
  3. 3Using Pip
    pip install -r requirements.txt
  4. 4Run the helper script
    python setup_env.py
  5. 5Create a .env file in the project root
    cp env.example .env
  6. 6Then edit .env with your actual credentials
    INSTAGRAM_USERNAME=your_instagram_username
    INSTAGRAM_PASSWORD=your_instagram_password

README

Instagram DM MCP server

This is a Model Context Protocol (MCP) server for sending instagram Direct Messages.

With this you can send Instagram Direct Messages from your account (more capabilities coming soon).

Here's an example of what you can do when it's connected to Claude.

https://github.com/user-attachments/assets/9c945f25-4484-4223-8d6b-5bf31243464c

To get updates on this and other projects we work on enter your email here


Installation

Prerequisites

  • Python 3.11+
  • Anthropic Claude Desktop app (or Cursor)
  • Pip (Python package manager), install with python -m pip install
  • An instagram account

Steps

  1. Clone this repository

    git clone https://github.com/trypeggy/instagram_dm_mcp.git
    cd instagram_dm_mcp
    
  2. Install dependencies

  • Using uv (recommended):
    uv sync
    
  • Using Pip:
    pip install -r requirements.txt
    
  1. Configure Instagram credentials

    You have two options for providing your Instagram credentials:

    Option A: Environment Variables (Recommended)

    Quick Setup (Recommended):

    Run the helper script:

    python setup_env.py
    

    This will interactively prompt you for your credentials and create the .env file securely.

    Manual Setup:

    Create a .env file in the project root:

    cp env.example .env
    

    Then edit .env with your actual credentials:

    INSTAGRAM_USERNAME=your_instagram_username
    INSTAGRAM_PASSWORD=your_instagram_password
    

    Option B: Command Line Arguments

    You can still pass credentials as command line arguments (less secure).

  2. Connect to the MCP server

    For Claude Desktop:

    Save this as claude_desktop_config.json in your Claude Desktop configuration directory at:

    ~/Library/Application Support/Claude/claude_desktop_config.json
    

    For Cursor:

    Save this as mcp.json in your Cursor configuration directory at:

    ~/.cursor/mcp.json
    

    Configuration with Environment Variables (Recommended):

    • Using uv
    {
      "mcpServers": {
        "instagram_dms": {
            "command": "uv",
            "args": [
              "run",
              "--directory",
              "PATH/TO/instagram_dm_mcp",
              "python",
              "src/mcp_server.py"
            ]
         }
       }
     }
    
    • Using Python
    {
      "mcpServers": {
        "instagram_dms": {
          "command": "python",
          "args": [
            "{{PATH_TO_SRC}}/instagram_dm_mcp/src/ mcp_server.py"
          ]
        }
      }
    }
    

    Configuration with Command Line Arguments:

    {
      "mcpServers": {
        "instagram_dms": {
          "command": "python",
          "args": [
            "{{PATH_TO_SRC}}/instagram_dm_mcp/src/mcp_server.py",
            "--username",
            "{{YOUR_INSTAGRAM_USERNAME}}",
           "--password",
           "{{YOUR_INSTAGRAM_PASSWORD}}"
          ]
        }
      }
    }
    
  3. Restart Claude Desktop / Cursor

    Open Claude Desktop and you should now see the Instagram DM MCP as an available integration.

    Or restart Cursor.


Usage

Below is a list of all available tools and what they do:

Tool NameDescription
send_messageSend an Instagram direct message to a user by username.
send_photo_messageSend a photo as an Instagram direct message to a user by username.
send_video_messageSend a video as an Instagram direct message to a user by username.
list_chatsGet Instagram Direct Message threads (chats) from your account, with optional filters/limits.
list_messagesGet messages from a specific Instagram Direct Message thread by thread ID. Now exposes item_type and shared post/reel info for each message. Use this to determine which download tool to use.
download_media_from_messageDownload a direct-uploaded photo or video from a DM message (not for shared posts/reels/clips).
download_shared_post_from_messageDownload media from a shared post, reel, or clip in a DM message (not for direct uploads).
list_media_messagesList all messages containing direct-uploaded media (photo/video) in a DM thread.
mark_message_seenMark a specific message in an Instagram Direct Message thread as seen.
list_pending_chatsGet Instagram Direct Message threads from your pending inbox.
search_threadsSearch Instagram Direct Message threads by username or keyword.
get_thread_by_participantsGet an Instagram Direct Message thread by participant user IDs.
get_thread_detailsGet details and messages for a specific Instagram Direct Message thread by thread ID.
get_user_id_from_usernameGet the Instagram user ID for a given username.
get_username_from_user_idGet the Instagram username for a given user ID.
get_user_infoGet information about a specific Instagram user by username.
search_usersSearch for Instagram users by username
get_user_storiesGet recent stories from a specific Instagram user by username.
like_mediaLike or unlike a specific media post by media ID.
get_user_followersGet a list of followers for a specific Instagram user by username.
get_user_followingGet a list of users that a specific Instagram user is following by username.
get_user_postsGet recent posts from a specific Instagram user by username.

Troubleshooting

Instagram Login Hanging: The server now includes automatic session management to prevent login hangs. Session files (e.g., username_session.json) are automatically created and reused to maintain authentication state between runs.

For additional Claude Desktop integration troubleshooting, see the MCP documentation. The documentation includes helpful tips for checking logs and resolving common issues.


Feedback

Your feedback will be massively appreciated. Please tell us which features on that list you like to see next or request entirely new ones.


License

This project is licensed under the MIT License.

License Python

Files in the repo

Repository payload10 top-level entries
  • src
  • .gitignore
  • .python-version
  • env.example
  • LICENSE
  • pyproject.toml
  • readme.md
  • requirements.txt
  • setup_env.py
  • uv.lock

Discussion (0)

Ask about usage, or say what you built with it

Sign in to join the discussion.

No comments yet. Be the first to say what this is good for.

More connectors

Real-time global intelligence dashboard. AI-powered news aggregation, geopolitical monitoring, and infrastructure tracking in a unified situational awareness interface

86k

High-performance code intelligence MCP server. Indexes codebases into a persistent knowledge graph — average repo in milliseconds. 158 languages, sub-ms queries, 99% fewer tokens. Single static binary, zero dependencies.

43k

Universal provider proxy for OpenAI Codex & Claude Code — use any LLM (Claude, Gemini, Grok, DeepSeek, Ollama…) with Codex CLI, App, SDK, and Claude Code

14k
okf-memory/
okf-agent-memory

Git-native persistent memory for AI coding agents. Implements Google OKF v0.2 with sub-300µs in-memory BM25 search, embedded MCP server, and progressive disclosure. Slashes token bloat by 80% with zero external databases or dependencies. Built in pure Go.

547
tirth8205/
code-review-graph

Local-first code intelligence graph for MCP and CLI. Builds a persistent map of your codebase so AI coding tools read only what matters, with benchmarked context reductions on reviews and large-repo workflows.

31k
2akouwu/
reverify

Stop your AI from making things up — it proposes, deterministic tools decide, every claim checked against ground truth with evidence. Grounded facts and context survive resets. Reverse engineering is the proving ground. MCP server + CLI.

1.1k