钉钉群机器人-发送文本消息
ding_send_textSends text or Markdown messages to DingTalk group robots using a bot access token. Supports custom message types and titles.
Instructions
钉钉群机器人发送文本或Markdown消息
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | 消息内容 | |
| title | No | 消息标题 | |
| msgtype | No | 内容类型,仅支持: text/markdown | markdown |
| bot_key | No | 钉钉群机器人access_token,默认从环境变量获取 |
Implementation Reference
- mcp_notify/other.py:40-64 (registration)The tool 'ding_send_text' is registered via @mcp.tool decorator on the function ding_send_text within add_tools(), which is called from __init__.py
@mcp.tool( title="钉钉群机器人-发送文本消息", description="钉钉群机器人发送文本或Markdown消息", ) def ding_send_text( text: str = Field(description="消息内容"), title: str = Field("", description="消息标题"), msgtype: str = Field("markdown", description="内容类型,仅支持: text/markdown"), bot_key: str = Field("", description="钉钉群机器人access_token,默认从环境变量获取"), ): """ https://open.dingtalk.com/document/development/custom-robots-send-group-messages """ if msgtype == "markdown": body = {"title": title, "text": text} else: body = {"content": f'{title}\n{text}'.strip()} if not bot_key: bot_key = os.getenv("DINGTALK_BOT_KEY", "") base = os.getenv("DINGTALK_BASE_URL") or "https://oapi.dingtalk.com" res = requests.post( f"{base}/robot/send?access_token={bot_key}", json={"msgtype": msgtype, msgtype: body}, ) return res.json() - mcp_notify/other.py:44-64 (handler)Handler function for ding_send_text: sends text/markdown messages to DingTalk group robot via HTTP POST to DingTalk Open API
def ding_send_text( text: str = Field(description="消息内容"), title: str = Field("", description="消息标题"), msgtype: str = Field("markdown", description="内容类型,仅支持: text/markdown"), bot_key: str = Field("", description="钉钉群机器人access_token,默认从环境变量获取"), ): """ https://open.dingtalk.com/document/development/custom-robots-send-group-messages """ if msgtype == "markdown": body = {"title": title, "text": text} else: body = {"content": f'{title}\n{text}'.strip()} if not bot_key: bot_key = os.getenv("DINGTALK_BOT_KEY", "") base = os.getenv("DINGTALK_BASE_URL") or "https://oapi.dingtalk.com" res = requests.post( f"{base}/robot/send?access_token={bot_key}", json={"msgtype": msgtype, msgtype: body}, ) return res.json() - mcp_notify/other.py:44-49 (schema)Schema/input definition for ding_send_text: accepts text (required), title, msgtype, and bot_key parameters using pydantic Field descriptors
def ding_send_text( text: str = Field(description="消息内容"), title: str = Field("", description="消息标题"), msgtype: str = Field("markdown", description="内容类型,仅支持: text/markdown"), bot_key: str = Field("", description="钉钉群机器人access_token,默认从环境变量获取"), ): - mcp_notify/__init__.py:21-21 (registration)Registration call: other.add_tools(mcp) is invoked in __init__.py to register all tools from other.py, including ding_send_text
other.add_tools(mcp)