Skip to main content
Glama
index.ts2.66 kB
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import { z } from "zod"; import { DingtalkBot } from "./dingtalk_custom_robot.js"; // Create server instance const server = new McpServer({ name: "dingding-bot", version: "1.0.0", description: "A tool for sending messages to Dingding groups via a custom robot", }); const DINGTALK_BOT_ACCESS_TOKEN = process.env.DINGTALK_BOT_ACCESS_TOKEN; const DINGTALK_BOT_SECRET = process.env.DINGTALK_BOT_SECRET; if (!DINGTALK_BOT_ACCESS_TOKEN) { console.error("DINGTALK_BOT_ACCESS_TOKEN environment variable is not set"); process.exit(1); } const dingtalkBot = new DingtalkBot(DINGTALK_BOT_ACCESS_TOKEN, DINGTALK_BOT_SECRET); server.tool( 'send_text_message', 'Send a plain text message', { text: z.string().describe("The text content to send"), atMobiles: z.array(z.string()).optional().describe("The mobile numbers of users to @mention (ping) individually in the group chat"), atAll: z.boolean().optional().describe("Whether to @all the users in the group"), }, async ({ text, atMobiles, atAll }) => { const response = await dingtalkBot.sendText(text, atMobiles, atAll); if (response.errcode !== 0) { return { content: [{ type: "text", text: `Failed to send message, code: ${response.errcode}, message: ${response.errmsg}` }], }; } return { content: [{ type: "text", text: "Message sent successfully" }], }; } ); server.tool( 'send_markdown_message', 'Send a markdown message', { title: z.string().describe("The title of the message"), text: z.string().describe("The text content to send"), atMobiles: z.array(z.string()).optional().describe("The mobile numbers of users to @mention (ping) individually in the group chat"), atAll: z.boolean().optional().describe("Whether to @all the users in the group"), }, async ({ title, text, atMobiles, atAll }) => { const response = await dingtalkBot.sendMarkdown(title, text, atMobiles, atAll); if (response.errcode !== 0) { return { content: [{ type: "text", text: `Failed to send message, code: ${response.errcode}, message: ${response.errmsg}` }], }; } return { content: [{ type: "text", text: "Message sent successfully" }], }; } ); async function main() { const transport = new StdioServerTransport(); await server.connect(transport); console.error("Dingding group robot MCP Server running on stdio"); } main().catch((error) => { console.error("Fatal error in main()", error); process.exit(1); });

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/Shawyeok/mcp-dingding-bot'

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