Instagram私信服务器

一个用于发送Instagram私信的模型上下文协议(MCP)服务器,支持通过Claude等工具发送消息、管理聊天和下载媒体内容。

  • by trypeggy
  • Python
  • 本地部署
  • 187 星标
  • 更新于
在 GitHub 查看 trypeggy/instagram_dm_mcp

使用说明

Instagram DM MCP服务器

这是一个用于发送instagram直接消息的模型上下文协议(MCP)服务器。

通过此功能,您可以从您的帐户发送Instagram私信(更多功能即将推出)。

这里有一个例子,说明当它连接到克劳德时你可以做什么。

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

为了获取我们正在进行的此项目和其他项目的更新 在此处输入您的电子邮件


安装

先决条件

  • Python 3.11+
  • 拟人克劳德桌面应用程序(或光标)
  • Pip(Python包管理器),安装 python -m pip install
  • instagram账号

步骤

  1. 克隆此存储库

    git clone https://github.com/trypeggy/instagram_dm_mcp.git
    cd instagram_dm_mcp
    
  2. 安装依赖项

  • 使用紫外线(推荐):
    uv sync
    
  • 使用Pip:
    pip install -r requirements.txt
    
  1. 配置Instagram凭据

    您有两个选项可以提供您的Instagram凭据:

    选项A:环境变量(推荐)

    快速设置(推荐):

    运行辅助脚本:

    python setup_env.py
    

    这将交互式地提示您输入凭据并创建 .env 文件安全。

    手动设置:

    创建一个 .env 项目根目录中的文件:

    cp env.example .env
    

    然后编辑 .env 使用您的实际凭据:

    INSTAGRAM_USERNAME=your_instagram_username
    INSTAGRAM_PASSWORD=your_instagram_password
    

    选项B:命令行参数

    您仍然可以将凭据作为命令行参数传递(安全性较低)。

  2. 连接到MCP服务器

    对于Claude Desktop:

    将此另存为 claude_desktop_config.json 在您的Claude Desktop配置目录中:

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

    对于光标:

    将此另存为 mcp.json 在Cursor配置目录中:

    ~/.cursor/mcp.json
    

    带环境变量的配置(推荐):

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

    带有命令行参数的配置:

    {
      "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. 重新启动克劳德桌面/光标

    打开Claude Desktop,您现在应该看到Instagram DM MCP是一个可用的集成。

    或者重新启动Cursor。


用法

以下是所有可用工具及其功能的列表:

工具名称 描述
send_message 通过用户名向用户发送Instagram私信。
send_photo_message 通过用户名将照片作为Instagram直接消息发送给用户。
send_video_message 通过用户名将视频作为Instagram直接消息发送给用户。
list_chats 使用可选的过滤器/限制从您的帐户获取Instagram直接消息线程(聊天)。
list_messages 按线程ID从特定的Instagram直接消息线程获取消息。现在公开 item_type 并为每条消息共享帖子/卷轴信息。使用此选项确定要使用的下载工具。
download_media_from_message 从DM消息中下载直接上传的照片或视频(不适用于共享帖子/卷轴/剪辑)。
download_shared_post_from_message 从DM消息中的共享帖子、卷轴或剪辑下载媒体(不用于直接上传)。
list_media_messages 在DM线程中列出所有包含直接上传媒体(照片/视频)的消息。
mark_message_seen 在Instagram私信帖子中标记特定消息,如图所示。
list_pending_chats 从您的待处理收件箱中获取Instagram私信帖子。
search_threads 按用户名或关键字搜索Instagram私信帖子。
get_thread_by_participants 按参与者用户ID获取Instagram直接消息线程。
get_thread_details 按线程ID获取特定Instagram直接消息线程的详细信息和消息
get_user_id_from_username 获取给定用户名的Instagram用户ID。
get_username_from_user_id 获取给定用户ID的Instagram用户名
get_user_info 通过用户名获取特定Instagram用户的信息。
search_users 按用户名搜索Instagram用户
get_user_stories 按用户名获取特定Instagram用户的最新故事。
like_media 通过媒体ID与特定媒体帖子相似或不同
get_user_followers 按用户名获取特定Instagram用户的关注者列表。
get_user_following 按用户名获取特定Instagram用户关注的用户列表。
get_user_posts 通过用户名获取特定Instagram用户的最新帖子。

故障排除

Instagram登录挂起: 服务器现在包括自动会话管理,以防止登录挂起。会话文件(例如。, username_session.json)自动创建并重复使用,以在运行之间维护身份验证状态。

有关其他Claude Desktop集成故障排除,请参阅 MCP文件。该文档包括检查日志和解决常见问题的有用提示。


反馈

我们将非常感谢您的反馈。请 告诉我们 您希望接下来看到该列表中的哪些功能或请求全新的功能。


许可证

该项目根据MIT许可证获得许可。