企业微信机器人消息服务器【MCP工具】

一个使用FastMCP通过企业微信机器人发送消息的服务器,支持通过Webhook进行异步通信和消息追踪。

WeCom Bot MCP 服务器

一个符合 Model Context Protocol (MCP) 的 WeCom(企业微信)机器人服务器实现。

功能

  • 支持多种消息类型:
    • 文本消息
    • Markdown 消息
    • 图片消息(base64)
    • 文件消息
  • @提及支持(通过用户ID或电话号码)
  • 消息历史记录追踪
  • 可配置的日志系统
  • 完整的类型注解
  • 基于 Pydantic 的数据验证

要求

  • Python 3.10+
  • WeCom 机器人的 Webhook URL(从 WeCom 群组设置中获取)

安装

有几种方法可以安装 WeCom Bot MCP 服务器:

1. 自动化安装(推荐)

使用 Smithery(适用于 Claude Desktop):
 

npx -y @smithery/cli install wecom-bot-mcp-server --client claude

使用 VSCode 和 Cline 扩展:
  1. 从 VSCode 市场安装 Cline 扩展
  2. 打开命令面板(Ctrl+Shift+P / Cmd+Shift+P)
  3. 搜索 "Cline: Install Package"
  4. 输入 "wecom-bot-mcp-server" 并按 Enter 键

2. 手动安装

从 PyPI 安装:
 

pip install wecom-bot-mcp-server

手动配置 MCP:

创建或更新您的 MCP 配置文件:

// For Windsurf: ~/.windsurf/config.json
{
  "mcpServers": {
    "wecom": {
      "command": "uvx",
      "args": [
        "wecom-bot-mcp-server"
      ],
      "env": {
        "WECOM_WEBHOOK_URL": "your-webhook-url"
      }
    }
  }
}

配置

设置环境变量

 

# Windows PowerShell $env:WECOM_WEBHOOK_URL = "your-webhook-url" # Optional configurations $env:MCP_LOG_LEVEL = "DEBUG" # Log levels: DEBUG, INFO, WARNING, ERROR, CRITICAL $env:MCP_LOG_FILE = "path/to/custom/log/file.log" # Custom log file path

日志管理

日志系统使用 platformdirs.user_log_dir() 进行跨平台日志文件管理:

  • Windows: C:\Users\<username>\AppData\Local\hal\wecom-bot-mcp-server
  • Linux: ~/.local/share/hal/wecom-bot-mcp-server
  • macOS: ~/Library/Application Support/hal/wecom-bot-mcp-server

日志文件名为 mcp_wecom.log,并存储在上述目录中。

使用

启动服务器

 

wecom-bot-mcp-server

使用示例(使用 MCP)

 

# Scenario 1: Send weather information to WeCom USER: "How's the weather in Shenzhen today? Send it to WeCom" ASSISTANT: "I'll check Shenzhen's weather and send it to WeCom" await mcp.send_message( content="Shenzhen Weather:\n- Temperature: 25°C\n- Weather: Sunny\n- Air Quality: Good", msg_type="markdown" ) # Scenario 2: Send meeting reminder and @mention relevant people USER: "Send a reminder for the 3 PM project review meeting, remind Zhang San and Li Si to attend" ASSISTANT: "I'll send the meeting reminder" await mcp.send_message( content="## Project Review Meeting Reminder\n\nTime: Today 3:00 PM\nLocation: Meeting Room A\n\nPlease be on time!", msg_type="markdown", mentioned_list=["zhangsan", "lisi"] ) # Scenario 3: Send a file USER: "Send this weekly report to the WeCom group" ASSISTANT: "I'll send the weekly report" await mcp.send_message( content=Path("weekly_report.docx"), msg_type="file" )

直接使用 API

发送消息
 

from wecom_bot_mcp_server import mcp # Send markdown message await mcp.send_message( content="**Hello World!**", msg_type="markdown" ) # Send text message and mention users await mcp.send_message( content="Hello @user1 @user2", msg_type="text", mentioned_list=["user1", "user2"] )

发送文件
 

from wecom_bot_mcp_server import send_wecom_file # Send file await send_wecom_file("/path/to/file.txt")

发送图片
 

from wecom_bot_mcp_server import send_wecom_image # Send local image await send_wecom_image("/path/to/image.png") # Send URL image await send_wecom_image("https://example.com/image.png")

开发

设置开发环境

  1. 克隆仓库:
 

git clone https://github.com/loonghao/wecom-bot-mcp-server.git cd wecom-bot-mcp-server

  1. 创建虚拟环境并安装依赖项:
 

# Using uv (recommended) pip install uv uv venv uv pip install -e ".[dev]" # Or using traditional method python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -e ".[dev]"

测试

 

# Using uv (recommended) uvx nox -s pytest # Or using traditional method nox -s pytest

代码风格

 

# Check code uvx nox -s lint # Automatically fix code style issues uvx nox -s lint_fix

构建和发布

 

# Build the package uv build # Build and publish to PyPI uv build && twine upload dist/*

项目结构

wecom-bot-mcp-server/
├── src/
│   └── wecom_bot_mcp_server/
│       ├── __init__.py
│       ├── server.py
│       ├── message.py
│       ├── file.py
│       ├── image.py
│       ├── utils.py
│       └── errors.py
├── tests/
│   ├── test_server.py
│   ├── test_message.py
│   ├── test_file.py
│   └── test_image.py
├── docs/
├── pyproject.toml
├── noxfile.py
└── README.md
微信支付 MCP(Model Context Protocol)功能是一种通过标准化接口将模型与外部服务集成的方案。该功能允许开发者在不编写大量代码的前提下,快速接入如支付、地图等第三方能力,从而提升开发效率和系统扩展性。微信支付 MCP 通常通过配置化的方式,在客户端(如 Cursor.app 或其他支持 MCP 的编辑器)中连接到特定的服务端实现。 ### 微信支付 MCP 功能特点 1. **快速集成**:通过简单的 JSON 配置即可完成对微信支付功能的调用[^2]。 2. **无需编写代码**:可以在前端工具或编辑器中直接使用,降低了开发门槛。 3. **标准化协议**:基于 Model Context Protocol (MCP),确保了不同服务之间的兼容性和互操作性。 4. **可扩展性强**:除了支付功能,MCP 还可以用于集成更多服务,例如物流跟踪、用户身份验证等。 ### 使用场景 - 在 AI 模型中嵌入支付功能以支持交易行为。 - 开发智能助手时需要提供支付选项。 - 快速构建原型应用并测试支付流程。 ### 接入方法 要使用微信支付 MCP 功能,需按照如下步骤进行: 1. **获取必要的密钥和凭证**:包括商户私钥、API 密钥以及证书信息。 2. **部署 MCP Server**:选择合适的 MCP Server 实现,例如 `@wechat/mcp-server-wechatpay` 并安装运行。 3. **配置客户端**:在支持 MCP 的客户端中添加相应的服务器配置。 以下是一个示例配置片段,展示了如何在 MCP 客户端中设置微信支付服务器: ```json { "mcpServers": { "mcp-server-wechatpay": { "command": "npx", "args": ["-y", "@wechat/mcp-server-wechatpay"], "env": { "WX_APP_ID": "your_app_id", "WX_MCH_ID": "your_merchant_id", "WX_API_KEY": "your_api_key", "WX_CERT_PATH": "/path/to/your/cert.pem", "WX_KEY_PATH": "/path/to/your/key.pem", "WX_NOTIFY_URL": "https://your-own-server.com/notify" } } } } ``` ### 最新文档资源 对于最新的官方文档和更新,请访问相关 GitHub 仓库或者官方网站查询详细内容。一般而言,这些资源会包含详细的 API 描述、错误码解释以及常见问题解答。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值