企业微信机器人消息服务器云托管添加福利群:解决AI开发者的「MCP实战痛点」
符合模型上下文协议(MCP)的企业微信(WeChat Work)机器人服务端实现。
有多种方式安装企业微信机器人MCP服务端:
npx -y @smithery/cli install wecom-bot-mcp-server --client claude
将服务端添加到您的MCP客户端配置文件中:
// macOS上的Claude桌面版: ~/Library/Application Support/Claude/claude_desktop_config.json
// Windows上的Claude桌面版: %APPDATA%\Claude\claude_desktop_config.json
// Windsurf: ~/.windsurf/config.json
// VSCode中的Cline: VSCode设置 > Cline > MCP设置
{
"mcpServers": {
"wecom": {
"command": "uvx",
"args": [
"wecom-bot-mcp-server"
],
"env": {
"WECOM_WEBHOOK_URL": "您的webhook地址"
}
}
}
}

# Windows PowerShell
$env:WECOM_WEBHOOK_URL = "您的webhook地址"
# 可选配置
$env:MCP_LOG_LEVEL = "DEBUG" # 日志级别: DEBUG, INFO, WARNING, ERROR, CRITICAL
$env:MCP_LOG_FILE = "自定义日志文件路径.log" # 自定义日志文件路径

日志系统使用platformdirs.user_log_dir()实现跨平台日志文件管理:
C:\Users\<用户名>\AppData\Local\hal\wecom-bot-mcp-server\Logs~/.local/state/hal/wecom-bot-mcp-server/log~/Library/Logs/hal/wecom-bot-mcp-server日志文件名为mcp_wecom.log,存储在以上目录中。
可通过环境变量自定义日志级别和文件路径:
MCP_LOG_LEVEL: 设置为DEBUG, INFO, WARNING, ERROR或CRITICALMCP_LOG_FILE: 设置为自定义日志文件路径配置完成后,MCP服务端会在您的MCP客户端启动时自动运行。您可以通过AI助手的自然语言交互来使用它。
场景1:发送天气信息到企业微信
用户: "今天深圳天气怎么样?发送到企业微信" 助手: "我将查询深圳天气并发送到企业微信" [助手会使用send_message工具发送天气信息]
场景2:发送会议提醒并@相关人员
用户: "发送下午3点项目评审会议提醒,提醒张三和李四参加" 助手: "我将发送会议提醒" [助手会使用send_message工具并设置mentioned_list参数]
场景3:发送文件
用户: "把这份周报发送到企业微信群" 助手: "我将发送周报" [助手会使用send_file工具]
场景4:发送图片
用户: "把这个图表图片发送到企业微信" 助手: "我将发送图片" [助手会使用send_image工具]
服务端提供以下工具供AI助手使用:
send_message - 发送文本或markdown消息
content, msg_type (text/markdown), mentioned_list, mentioned_mobile_listsend_file - 向企业微信发送文件
file_pathsend_image - 向企业微信发送图片
image_path (本地路径或URL)如果您想在Python代码中直接使用此包(不作为MCP服务端):
from wecom_bot_mcp_server import send_message, send_wecom_file, send_wecom_image
# 发送markdown消息
await send_message(
content="**Hello World!**",
msg_type="markdown"
)
# 发送文本消息并@用户
await send_message(
content="Hello @user1 @user2",
msg_type="text",
mentioned_list=["user1", "user2"]
)
# 发送文件
await send_wecom_file("/path/to/file.txt")
# 发送图片
await send_wecom_image("/path/to/image.png")

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

# 使用uv(推荐)
pip install uv
uv venv
uv pip install -e ".[dev]"
# 或使用传统方法
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -e ".[dev]"

# 运行所有测试(含覆盖率)
uvx nox -s pytest
# 仅运行导入测试
uvx nox -s test_imports
# 运行特定测试文件
uvx nox -s pytest -- tests/test_message.py
# 详细模式运行测试
uvx nox -s pytest -- -v

# 代码检查
uvx nox -s lint
# 自动修复代码风格问题
uvx nox -s lint_fix

# 构建包
uvx nox -s build
# 发布到PyPI(需要认证)
uvx nox -s publish

项目使用GitHub Actions进行CI/CD:
所有依赖项在CI过程中都会自动测试,以便及早发现问题。
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
本项目采用MIT许可证 - 详见LICENSE文件。