Skip to main content
Glama
sfyyy

Claude Code DingTalk MCP Server

by sfyyy

dingtalk_send_text

Send text messages to DingTalk groups from Claude Code for task alerts and notifications, with optional @all mentions.

Instructions

Send a text message to DingTalk group

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYesText content to send
atAllNoWhether to @all members

Implementation Reference

  • MCP tool handler function that prepares the message by appending the git username and calls DingTalkClient.sendText to send the text message to DingTalk.
    private async handleSendText(args: { content: string; atAll?: boolean }) {
      if (!this.dingTalkClient) {
        throw new Error('DingTalk client not configured. Use dingtalk_configure first or set environment variables (DINGTALK_WEBHOOK, DINGTALK_SECRET).');
      }
    
      const gitUsername = this.getGitUsername();
      const contentWithUser = `${args.content}\n\n---\nπŸ‘€ 发送者: ${gitUsername}`;
    
      const success = await this.dingTalkClient.sendText(contentWithUser, args.atAll);
      return {
        content: [
          {
            type: 'text',
            text: success 
              ? 'βœ… Text message sent successfully' 
              : '❌ Failed to send text message',
          },
        ],
      };
    }
  • Input schema definition for the dingtalk_send_text tool, specifying content as required string and optional atAll boolean.
    inputSchema: {
      type: 'object',
      properties: {
        content: {
          type: 'string',
          description: 'Text content to send',
        },
        atAll: {
          type: 'boolean',
          description: 'Whether to @all members',
          default: false,
        },
      },
      required: ['content'],
    },
  • src/index.ts:85-103 (registration)
    Tool registration in the listTools response, including name, description, and input schema.
    {
      name: 'dingtalk_send_text',
      description: 'Send a text message to DingTalk group',
      inputSchema: {
        type: 'object',
        properties: {
          content: {
            type: 'string',
            description: 'Text content to send',
          },
          atAll: {
            type: 'boolean',
            description: 'Whether to @all members',
            default: false,
          },
        },
        required: ['content'],
      },
    },
  • Helper method in DingTalkClient that constructs the text message payload and delegates to sendMessage.
    async sendText(content: string, atAll = false): Promise<boolean> {
      return this.sendMessage({
        msgtype: 'text',
        text: { content },
        at: { isAtAll: atAll }
      });
    }
  • Core helper function that handles HTTP POST to DingTalk webhook, including optional signature generation for security.
    async sendMessage(message: DingTalkMessage): Promise<boolean> {
      try {
        const signParams = this.generateSign();
        const url = signParams 
          ? `${this.config.webhook}&${signParams}`
          : this.config.webhook;
    
        const response = await fetch(url, {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
          },
          body: JSON.stringify(message),
        });
    
        const result = await response.json();
        return result.errcode === 0;
      } catch (error) {
        console.error('DingTalk notification failed:', error);
        return false;
      }
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sfyyy/claude-code-dingtalk-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server