Multi-Bot Configuration
Detailed guide for configuring multiple WeCom bots.
Configuration Methods
Method 1: WECOM_BOTS JSON (Recommended)
The most flexible way to configure multiple bots:
json
{
"bot_id": {
"name": "Display Name",
"webhook_url": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx",
"description": "Optional description for AI context"
}
}Full Example:
bash
export WECOM_BOTS='{
"default": {
"name": "General Bot",
"webhook_url": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=general",
"description": "For general announcements"
},
"alert": {
"name": "Alert Bot",
"webhook_url": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=alert",
"description": "For system alerts and critical notifications"
},
"ci": {
"name": "CI/CD Bot",
"webhook_url": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=ci",
"description": "For build, test, and deployment notifications"
},
"team-frontend": {
"name": "Frontend Team",
"webhook_url": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=frontend",
"description": "Frontend team group"
},
"team-backend": {
"name": "Backend Team",
"webhook_url": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=backend",
"description": "Backend team group"
}
}'powershell
$env:WECOM_BOTS = '{"default": {"name": "General Bot", "webhook_url": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=general"}, "alert": {"name": "Alert Bot", "webhook_url": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=alert"}, "ci": {"name": "CI/CD Bot", "webhook_url": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=ci"}}'Method 2: Individual Environment Variables
For simpler setups or when you can't use JSON:
bash
# Each variable creates a bot with the ID from the variable name
export WECOM_BOT_ALERT_URL="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=alert"
export WECOM_BOT_CI_URL="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=ci"
export WECOM_BOT_DEVOPS_URL="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=devops"Naming Rules:
- Pattern:
WECOM_BOT_{NAME}_URL {NAME}becomes the bot ID (converted to lowercase)- Example:
WECOM_BOT_MY_TEAM_URL→ bot ID:my_team
Method 3: Combined Configuration
Mix WECOM_WEBHOOK_URL with other methods:
bash
# This becomes the "default" bot
export WECOM_WEBHOOK_URL="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=default"
# Additional bots
export WECOM_BOT_ALERT_URL="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=alert"
export WECOM_BOTS='{"ci": {"name": "CI Bot", "webhook_url": "https://..."}}'MCP Client Configuration
Claude Desktop
json
{
"mcpServers": {
"wecom": {
"command": "uvx",
"args": ["wecom-bot-mcp-server"],
"env": {
"WECOM_BOTS": "{\"alert\": {\"name\": \"Alert Bot\", \"webhook_url\": \"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=alert\", \"description\": \"For alerts\"}, \"ci\": {\"name\": \"CI Bot\", \"webhook_url\": \"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=ci\", \"description\": \"For CI/CD\"}}"
}
}
}
}JSON Escaping
In JSON config files, you need to escape the inner JSON string. Use \" for quotes inside the WECOM_BOTS value.
Bot ID Guidelines
- Use lowercase: Bot IDs are case-insensitive and stored as lowercase
- Use descriptive names:
alert,ci,team-frontendare better thanbot1,bot2 - Avoid special characters: Stick to letters, numbers, hyphens, and underscores
- Reserve "default": The
defaultbot is used when nobot_idis specified
Descriptions for AI Context
The description field helps AI assistants choose the right bot:
json
{
"alert": {
"name": "Alert Bot",
"webhook_url": "https://...",
"description": "Use for system alerts, errors, and critical notifications"
},
"ci": {
"name": "CI Bot",
"webhook_url": "https://...",
"description": "Use for build results, test reports, and deployment status"
}
}When you ask the AI "send a build notification", it will intelligently choose the CI bot.
Loading Priority
When the same bot ID is defined multiple times:
- WECOM_WEBHOOK_URL →
defaultbot (loaded first) - WECOM_BOTS → Can override
defaultand add more - WECOM_BOT_{NAME}_URL → Only adds if not already defined
Verification
List All Bots
Ask your AI assistant:
What WeCom bots are available?Or use Python:
python
from wecom_bot_mcp_server.bot_config import list_available_bots
print(list_available_bots())Check Specific Bot
python
from wecom_bot_mcp_server.bot_config import get_bot_registry
registry = get_bot_registry()
if registry.has_bot("alert"):
print("Alert bot is configured")
print(f"URL: {registry.get_webhook_url('alert')}")Troubleshooting
Bot Not Found
Error: Bot 'xxx' not found. Available bots: default, alert, ciSolutions:
- Check the bot ID spelling (case-insensitive)
- Verify the environment variable is set
- Restart the MCP client
Invalid JSON
Warning: Invalid JSON in WECOM_BOTSSolutions:
- Validate your JSON with a JSON validator
- Check for proper escaping in config files
- Use single quotes around the JSON value in shell
Empty Webhook URL
Error: Bot 'xxx' has empty webhook_urlSolutions:
- Check the webhook URL is not empty
- Verify the URL format is correct
- Ensure no extra whitespace in the URL
