WeCom Bot MCP Server

by loonghao
Verified
MIT License
23
  • Linux
  • Apple

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

Integrations

  • Provides a Model Context Protocol (MCP) server implementation for WeCom (WeChat Work) bot, enabling sending of text, markdown, image and file messages to WeCom groups, with support for @mentions and message history tracking.

WeCom Bot MCP サーバー

WeCom (WeChat Work) ボット用のモデル コンテキスト プロトコル (MCP) 準拠のサーバー実装。

英語|中国語

特徴

  • 複数のメッセージ タイプのサポート:
    • テキストメッセージ
    • マークダウンメッセージ
    • 画像メッセージ(base64)
    • ファイルメッセージ
  • @メンションサポート(ユーザーIDまたは電話番号経由)
  • メッセージ履歴の追跡
  • 設定可能なログシステム
  • 完全な型注釈
  • Pydanticベースのデータ検証

要件

  • Python 3.10以上
  • WeCom Bot Webhook URL(WeComグループ設定から取得)

インストール

WeCom Bot MCP サーバーをインストールするには、いくつかの方法があります。

1. 自動インストール(推奨)

Smithery の使用 (Claude デスクトップの場合):

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

Cline 拡張機能で VSCode を使用する:

  1. VSCodeマーケットプレイスからCline拡張機能をインストールする
  2. コマンドパレットを開く (Ctrl+Shift+P / Cmd+Shift+P)
  3. 「Cline: パッケージのインストール」を検索
  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

ライセンス

このプロジェクトは MIT ライセンスに基づいてライセンスされています - 詳細についてはLICENSEファイルを参照してください。

接触

-
security - not tested
A
license - permissive license
-
quality - not tested

FastMCP を使用して WeCom ボット経由でメッセージを送信するためのサーバー。非同期通信と、Webhook を介したメッセージ追跡をサポートします。

  1. Features
    1. Requirements
      1. Installation
        1. 1. Automated Installation (Recommended)
        2. 2. Manual Installation
      2. Configuration
        1. Setting Environment Variables
        2. Log Management
      3. Usage
        1. Starting the Server
        2. Usage Examples (With MCP)
        3. Direct API Usage
      4. Development
        1. Setup Development Environment
        2. Testing
        3. Code Style
        4. Building and Publishing
      5. Project Structure
        1. License
          1. Contact
            ID: amr2j23lbk