企业微信应用号-发送文本消息
wework_app_send_textSend text or Markdown messages through WeChat Work app to specific users or all members, with support for @all and individual IDs.
Instructions
通过企业微信应用号发送文本或Markdown消息
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | 消息内容,最长不超过2048个字节 | |
| msgtype | No | 内容类型,仅支持: text/markdown | text |
| touser | No | 接收消息的成员ID,多个用`|`分隔,为`@all`时向该企业应用全部成员发送,默认从环境变量获取 |
Implementation Reference
- mcp_notify/wework.py:106-122 (handler)The `wework_app_send_text` function is the handler for sending text/markdown messages via WeWork app (应用号). It POSTs to the WeChat Work API with the message content, type, and recipient.
def wework_app_send_text( text: str = Field(description="消息内容,最长不超过2048个字节"), msgtype: str = Field("text", description="内容类型,仅支持: text/markdown"), touser: str = FIELD_TO_USER, ): res = requests.post( f"{WEWORK_BASE_URL}/cgi-bin/message/send?access_token={get_access_token()}", json={ "touser": touser or WEWORK_APP_TOUSER, "agentid": WEWORK_APP_AGENTID, "msgtype": msgtype, msgtype: {"content": text}, "enable_duplicate_check": 1, "duplicate_check_interval": 60, }, ) return res.json() or {} - mcp_notify/wework.py:107-109 (schema)Input schema for `wework_app_send_text`: `text` (message content), `msgtype` (text/markdown), `touser` (recipient user IDs).
text: str = Field(description="消息内容,最长不超过2048个字节"), msgtype: str = Field("text", description="内容类型,仅支持: text/markdown"), touser: str = FIELD_TO_USER, - mcp_notify/wework.py:102-105 (registration)The @mcp.tool decorator registers the tool with FastMCP, providing title and description metadata.
@mcp.tool( title="企业微信应用号-发送文本消息", description="通过企业微信应用号发送文本或Markdown消息", ) - mcp_notify/__init__.py:18-23 (registration)The top-level MCP server is created and `wework.add_tools(mcp)` is called to register all WeWork tools including `wework_app_send_text`.
mcp = FastMCP(name="mcp-notify", version="0.1.11") wework.add_tools(mcp) tgbot.add_tools(mcp) other.add_tools(mcp) hass.add_tools(mcp) util.add_tools(mcp) - mcp_notify/wework.py:92-99 (helper)The `get_access_token` helper function (cached) fetches an OAuth access token required for the WeWork App API call.
@cached(TTLCache(maxsize=1, ttl=3600)) def get_access_token(): res = requests.get( f"{WEWORK_BASE_URL}/cgi-bin/gettoken", params={"corpid": WEWORK_APP_CORPID, "corpsecret": WEWORK_APP_SECRET}, timeout=60, ) return res.json().get("access_token")