by trypeggy
Send Instagram Direct Messages programmatically via an MCP server, enabling seamless interaction with AI assistants such as Claude or Cursor.
Instagram DM MCP provides a Model Context Protocol server that lets you automate sending and managing Instagram Direct Messages from your own account. It integrates with AI tools, allowing conversational agents to perform messaging actions without manual intervention.
uv sync
or pip install -r requirements.txt
).python setup_env.py
to create a secure .env
file with INSTAGRAM_USERNAME
and INSTAGRAM_PASSWORD
, or supply them via command‑line arguments.python src/mcp_server.py
(or use the provided configuration snippets for Claude Desktop or Cursor).claude_desktop_config.json
) or Cursor (mcp.json
) using the example JSON configurations.send_message
, list_chats
, download_media_from_message
, etc., from your AI assistant.Q: Which Python version is required? A: Python 3.11 or newer.
Q: Do I need the Claude Desktop app? A: It’s one supported client; you can also use Cursor or any MCP‑compatible tool.
Q: How are credentials stored securely?
A: Use the interactive setup_env.py
script to create a .env
file that is ignored by Git.
Q: What if login hangs?
A: The server creates and reuses session files (e.g., username_session.json
) to maintain authentication state.
Q: Can I run the server inside a container? A: Yes, as long as the container has Python 3.11+, the required packages, and the environment variables set.
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
python -m pip install
Clone this repository
git clone https://github.com/trypeggy/instagram_dm_mcp.git
cd instagram_dm_mcp
Install dependencies
uv sync
pip install -r requirements.txt
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).
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):
{
"mcpServers": {
"instagram_dms": {
"command": "uv",
"args": [
"run",
"--directory",
"PATH/TO/instagram_dm_mcp",
"python",
"src/mcp_server.py"
]
}
}
}
{
"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}}"
]
}
}
}
Restart Claude Desktop / Cursor
Open Claude Desktop and you should now see the Instagram DM MCP as an available integration.
Or restart Cursor.
Below is a list of all available tools and what they do:
Tool Name | Description |
---|---|
send_message |
Send an Instagram direct message to a user by username. |
send_photo_message |
Send a photo as an Instagram direct message to a user by username. |
send_video_message |
Send a video as an Instagram direct message to a user by username. |
list_chats |
Get Instagram Direct Message threads (chats) from your account, with optional filters/limits. |
list_messages |
Get 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_message |
Download a direct-uploaded photo or video from a DM message (not for shared posts/reels/clips). |
download_shared_post_from_message |
Download media from a shared post, reel, or clip in a DM message (not for direct uploads). |
list_media_messages |
List all messages containing direct-uploaded media (photo/video) in a DM thread. |
mark_message_seen |
Mark a specific message in an Instagram Direct Message thread as seen. |
list_pending_chats |
Get Instagram Direct Message threads from your pending inbox. |
search_threads |
Search Instagram Direct Message threads by username or keyword. |
get_thread_by_participants |
Get an Instagram Direct Message thread by participant user IDs. |
get_thread_details |
Get details and messages for a specific Instagram Direct Message thread by thread ID. |
get_user_id_from_username |
Get the Instagram user ID for a given username. |
get_username_from_user_id |
Get the Instagram username for a given user ID. |
get_user_info |
Get information about a specific Instagram user by username. |
search_users |
Search for Instagram users by username |
get_user_stories |
Get recent stories from a specific Instagram user by username. |
like_media |
Like or unlike a specific media post by media ID. |
get_user_followers |
Get a list of followers for a specific Instagram user by username. |
get_user_following |
Get a list of users that a specific Instagram user is following by username. |
get_user_posts |
Get recent posts from a specific Instagram user by username. |
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.
Your feedback will be massively appreciated. Please tell us which features on that list you like to see next or request entirely new ones.
This project is licensed under the MIT License.
Please log in to share your review and rating for this MCP.
{ "mcpServers": { "instagram_dm": { "command": "python", "args": [ "src/mcp_server.py" ], "env": { "INSTAGRAM_USERNAME": "<YOUR_USERNAME>", "INSTAGRAM_PASSWORD": "<YOUR_PASSWORD>" } } } }
Explore related MCPs that share similar capabilities and solve comparable challenges
by lharries
Enables searching, reading, and sending personal WhatsApp messages and media through a Model Context Protocol (MCP) server, storing all data locally in SQLite and exposing controlled tools for LLMs like Claude.
by iFurySt
Provides authenticated access to XiaoHongShu (RedNote) notes, supporting keyword search, note retrieval by URL, and cookie persistence via a Model Context Protocol server.
by korotovsky
Provides a powerful Model Context Protocol interface for Slack workspaces, enabling message retrieval, search, and optional posting via Stdio or SSE transports without requiring bot permissions.
by ZubeidHendricks
Provides a standardized interface for interacting with YouTube content, enabling video retrieval, transcript access, channel and playlist management, and advanced analytics through the Model Context Protocol.
by InditexTech
Provides Microsoft Teams integration via the Model Context Protocol, enabling reading, creating, replying to messages and mentioning members.
by chigwell
Provides a full‑featured Telegram integration for MCP‑compatible clients, enabling programmatic access to chats, messages, contacts, profile management, and group administration.
by EnesCinr
Interact with Twitter to post tweets and search tweets programmatically via an MCP server.
by chaindead
Manages Telegram dialogs, messages, drafts, and read statuses via the Model Context Protocol, enabling AI assistants to query and interact with Telegram accounts.
by carterlasalle
Securely interfaces with the macOS Messages database via MCP, enabling LLMs to query, analyze, filter, and send iMessage or SMS communications with built‑in phone number validation, attachment handling, and group chat support.