|
|
8 luni în urmă | |
|---|---|---|
| .. | ||
| README.cn.md | 8 luni în urmă | |
| README.md | 8 luni în urmă | |
| init.go | 8 luni în urmă | |
一个符合模型上下文协议 (MCP) 的企业微信机器人服务器实现。
有多种方式安装 WeCom Bot MCP 服务器:
npx -y @smithery/cli install wecom-bot-mcp-server --client claude
pip install wecom-bot-mcp-server
创建或更新您的 MCP 配置文件:
// 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"
# 可选配置
$env:MCP_LOG_LEVEL = "DEBUG" # 日志级别: DEBUG, INFO, WARNING, ERROR, CRITICAL
$env:MCP_LOG_FILE = "path/to/custom/log/file.log" # 自定义日志文件路径
日志系统使用 platformdirs.user_log_dir() 进行跨平台日志文件管理:
C:\Users\<username>\AppData\Local\hal\wecom-bot-mcp-server~/.local/share/hal/wecom-bot-mcp-server~/Library/Application Support/hal/wecom-bot-mcp-server日志文件名为 mcp_wecom.log,存储在上述目录中。
wecom-bot-mcp-server
# 场景 1: 发送天气信息到企业微信
用户: "深圳今天天气怎么样?发送到企业微信"
助手: "我来查看深圳的天气并发送到企业微信"
await mcp.send_message(
content="深圳天气:\n- 温度: 25°C\n- 天气: 晴天\n- 空气质量: 良好",
msg_type="markdown"
)
# 场景 2: 发送会议提醒并@相关人员
用户: "发送下午3点项目评审会议提醒,提醒张三和李四参加"
助手: "我来发送会议提醒"
await mcp.send_message(
content="## 项目评审会议提醒\n\n时间: 今天下午3:00\n地点: 会议室A\n\n请准时参加!",
msg_type="markdown",
mentioned_list=["zhangsan", "lisi"]
)
# 场景 3: 发送文件
用户: "把这个周报发送到企业微信群"
助手: "我来发送周报"
await mcp.send_message(
content=Path("weekly_report.docx"),
msg_type="file"
)
from wecom_bot_mcp_server import mcp
# 发送 markdown 消息
await mcp.send_message(
content="**你好世界!**",
msg_type="markdown"
)
# 发送文本消息并@用户
await mcp.send_message(
content="你好 @user1 @user2",
msg_type="text",
mentioned_list=["user1", "user2"]
)
from wecom_bot_mcp_server import send_wecom_file
# 发送文件
await send_wecom_file("/path/to/file.txt")
from wecom_bot_mcp_server import send_wecom_image
# 发送本地图片
await send_wecom_image("/path/to/image.png")
# 发送网络图片
await send_wecom_image("https://example.com/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]"
# 使用 uv(推荐)
uvx nox -s pytest
# 或使用传统方法
nox -s pytest
# 检查代码
uvx nox -s lint
# 自动修复代码风格问题
uvx nox -s lint_fix
# 构建包
uv build
# 构建并发布到 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
本项目采用 MIT 许可证 - 详情请见 LICENSE 文件。