返回市场
微信MCP服务器

微信MCP服务器

作者:panxingfeng63 星标更新:2025-10-24

项目介绍

MCP Server WeChat

基于MCP技术的微信聊天记录获取及消息发送服务器,使用了pywechat工具,实现了对微信的自动化操作。

功能特性

此服务器提供以下主要功能:

  • 获取指定日期的微信聊天记录
  • 向单个好友发送一条消息
  • 向单个好友发送多条消息
  • 向多个好友发送消息

可用工具

  • wechat_get_chat_history - 获取特定日期的微信聊天记录

    • 必需参数:
      • to_user(字符串):好友或群聊备注或昵称
      • target_date(字符串):目标日期,格式为YY/M/D,例如25/3/22
  • wechat_send_message - 向单个微信好友发送一条消息

    • 必需参数:
      • to_user(字符串):好友或群聊备注或昵称
      • message(字符串):要发送的消息
  • wechat_send_multiple_messages - 向单个微信联系人发送多条消息

    • 必需参数:
      • to_user(字符串):好友或群聊备注或昵称
      • messages(数组):要发送的消息列表(以英文逗号分隔的字符串)
  • wechat_send_to_multiple_friends - 向多个微信联系人发送一条或多条消息

    • 必需参数:
      • to_user(数组):好友或群聊备注或昵称列表(以英文逗号分隔的字符串)
      • message(字符串/数组):要发送的消息(向所有好友发送一条消息;当多条消息以英文逗号分隔且数量与好友数量匹配时,分别发送给对应的好友)

安装方法

stdio版本

pip install mcp_server_wechat

获取最新版本
pip install --upgrade mcp_server_wechat

sse版本 / Streamable_HTTP版本

python -m venv venv  # 创建虚拟环境
venv/scripts/activate # 激活环境
pip install -r requirements.txt

使用示例

配置为MCP服务

添加到您的MCP配置中:

stdio版本

{
    "mcpServers": {
        "wechat": {
            "command": "python",
            "args": ["-m", "mcp_server_wechat","--folder-path=存放历史记录的目录"]
        }
    }
}

SSE版

启动命令

python -m mcp_server_wechat_sse --folder-path=x:\xxxxx #默认文件夹可以在代码中修改
{
    "mcpServers": {
        "wechat": {
            "url": "http://localhost:3000/sse"
        }
    }
}

Streamable_HTTP版

启动命令

python -m mcp_server_wechat_Streamable_HTTP --folder-path=x:\xxxxx #默认文件夹可以在代码中修改
{
    "mcpServers": {
        "wechat": {
            "url": "http://localhost:3000/mcp"
        }
    }
}

调用示例

  1. 获取聊天历史:
{
  "name": "wechat_get_chat_history",
  "arguments": {
    "to_user": "张三",
    "target_date": "25/3/22"
  }
}
  1. 发送一条消息:
{
  "name": "wechat_send_message",
  "arguments": {
    "to_user": "张三",
    "message": "你好,这是一条测试消息"
  }
}
  1. 发送多条消息:
{
  "name": "wechat_send_multiple_messages",
  "arguments": {
    "to_user": "张三",
    "messages": "你好","这是第一条消息","这是第二条消息"
  }
}
  1. 发送给多个好友(单条消息):
{
  "name": "wechat_send_to_multiple_friends",
  "arguments": {
    "to_user": ["张三", "李四", "王五"],
    "message": "大家好,这是一条群发消息"或者"你好,张三","你好,李四","你好,王五"
  }
}

调试

您可以使用MCP inspector来调试服务器:

npx @modelcontextprotocol/inspector python -m mcp_server_wechat

实际效果演示

<table> <tr> <td align="center" width="33%"> <img src="https://gips2.baidu.com/it/u=1481444006,942581177&fm=3081&app=3081&f=PNG?w=1797&h=1756" width="330" /><br> <em>inspector的测试</em> </td> <td align="center" width="33%"> <img src="https://raw.githubusercontent.com/panxingfeng/mcp_server_wechat/main/多工具测试.gif" width="330" /><br> <em>基于我自己UI(仿Cherry Studio)</a>的测试</em> </td> <td align="center" width="34%"> <img src="https://gips2.baidu.com/it/u=3220808249,2531733869&fm=3081&app=3081&f=PNG?w=1165&h=745" width="330" /><br> <em>基于 Cherry Studio 的Streamable_HTTP</a>的测试</em> </td> </tr> </table>

注意事项

  • 使用此工具前,必须保持微信桌面版登录状态
  • 获取聊天历史和发送消息时,需要确保微信窗口可以正常操作
  • 使用过程中,请勿手动操作微信窗口,以免干扰自动化过程
  • 不得使用此工具进行任何违反微信服务协议的行为

许可证

mcp_server_wechat采用MIT许可证。这意味着您可以在遵守MIT许可证条款和条件的前提下自由使用、修改和分发本软件。详情请参阅项目仓库中的LICENSE文件。