dingtalk-mcp 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,6 +11,7 @@
11
11
  - 钉钉签到
12
12
  - 钉钉工作通知
13
13
  - 钉钉应用管理
14
+ - 钉钉服务窗
14
15
 
15
16
  ## 如何使用
16
17
  ```json
@@ -36,17 +37,19 @@
36
37
  2. DINGTALK_Client_Secret
37
38
  3. ACTIVE_PROFILES,激活哪些钉钉MCP服务,逗号风格,如果是ALL则激活全部。可选集合
38
39
 
39
- | ProfileId | Description | Permission |
40
- |-----------------------------|--------------------|----------------------------------------------|
41
- | dingtalk-contacts | 钉钉通讯录,默认激活 |
42
- | dingtalk-department | 钉钉部门管理 |
43
- | dingtalk-robot-send-message | 钉钉机器人发消息/DING,默认激活 |企业内机器人发送消息权限
44
- | dingtalk-honor | 钉钉企业文化荣誉 |
45
- | dingtalk-tasks | 钉钉待办 | Todo.Todo.Write<br>Todo.Todo.Read |
46
- | dingtalk-calendar | 钉钉日程 |
47
- | dingtalk-checkin | 钉钉签到 |
48
- | dingtalk-notice | 钉钉工作通知 |
49
- | dingtalk-app-manage | 钉钉应用管理 | qyapi_microapp_manage<br>qyapi_get_microapp_list
40
+ | ProfileId | Description | Permission |
41
+ |--------------------------|--------------------|-------------------------------------------------|
42
+ | dingtalk-contacts | 钉钉通讯录,默认激活 |
43
+ | dingtalk-department | 钉钉部门管理 |
44
+ | dingtalk-robot-send-message | 钉钉机器人发消息/DING,默认激活 | 需要企业内机器人发送消息权限 |
45
+ | dingtalk-honor | 钉钉企业文化荣誉 |
46
+ | dingtalk-tasks | 钉钉待办 | Todo.Todo.Write<br>Todo.Todo.Read |
47
+ | dingtalk-calendar | 钉钉日程 |
48
+ | dingtalk-checkin | 钉钉签到 |
49
+ | dingtalk-notice | 钉钉工作通知 |
50
+ | dingtalk-app-manage | 钉钉应用管理 | qyapi_microapp_manage<br>qyapi_get_microapp_list |
51
+ | dingtalk-service-window | 钉钉服务窗 | |
52
+
50
53
  4. ROBOT_CODE,用于发消息/DING的机器人Code
51
54
  5. ROBOT_ACCESS_TOKEN,群自定义机器人ACCESS_TOKEN,用于自定义机器人发消息
52
55
  6. DINGTALK_AGENT_ID 用于发送工作通知
@@ -0,0 +1,146 @@
1
+ server:
2
+ name: dingtalk-service-window
3
+ version: 1.0.0
4
+ description: DingTalk ServiceWindow MCP Server with Message Builder
5
+ securitySchemes:
6
+ - id: DingTalkAuth
7
+ type: apiKey
8
+ in: header
9
+ name: x-acs-dingtalk-access-token
10
+
11
+ # 注意:当前版本的工具定义在代码中,此配置文件为预留扩展
12
+ tools:
13
+
14
+ - name: sendServiceWindowMessage
15
+ description: "发送服务窗单人消息"
16
+ requestTemplate:
17
+ method: POST
18
+ url: "https://api.dingtalk.com/v1.0/crm/officialAccounts/oToMessages/send"
19
+ security:
20
+ id: DingTalkAuth
21
+ args:
22
+ - name: userId
23
+ description: 用户userId
24
+ type: string
25
+ required: true
26
+ position: body
27
+ - name: accountId
28
+ description: 服务窗帐号ID
29
+ type: string
30
+ required: true
31
+ position: body
32
+ - name: messageTitle
33
+ description: 消息标题
34
+ type: string
35
+ required: true
36
+ position: body
37
+ - name: messageContent
38
+ description: markdown格式的消息内容
39
+ type: string
40
+ required: true
41
+ position: body
42
+
43
+
44
+
45
+ - name: batchSendServiceWindowMessage
46
+ description: "批量发送服务窗消息"
47
+ requestTemplate:
48
+ method: POST
49
+ url: "https://api.dingtalk.com/v1.0/crm/officialAccounts/oToMessages/batchSend"
50
+ security:
51
+ id: DingTalkAuth
52
+ args:
53
+ - name: userIdList
54
+ description: 用户userId
55
+ type: array
56
+ required: false
57
+ position: body
58
+ items:
59
+ type: string
60
+ - name: accountId
61
+ description: 服务窗帐号ID
62
+ type: string
63
+ required: true
64
+ position: body
65
+ - name: messageTitle
66
+ description: 消息标题
67
+ type: string
68
+ required: true
69
+ position: body
70
+ - name: messageContent
71
+ description: markdown格式的消息内容
72
+ type: string
73
+ required: true
74
+ position: body
75
+
76
+ - name: getServiceWindowFollowerInfo
77
+ description: "获取关注服务窗的单个用户信息"
78
+ requestTemplate:
79
+ method: GET
80
+ url: "https://api.dingtalk.com/v1.0/link/followers/infos?userId={String}&accountId={String}"
81
+ security:
82
+ id: DingTalkAuth
83
+ args:
84
+ - name: accountId
85
+ description: 服务窗帐号ID
86
+ type: string
87
+ required: true
88
+ position: query
89
+ - name: userId
90
+ description: 关注服务窗用户的userId
91
+ type: string
92
+ required: true
93
+ position: query
94
+
95
+ - name: listServiceWindowFollowersInfo
96
+ description: "批量获取关注服务窗用户的信息"
97
+ requestTemplate:
98
+ method: GET
99
+ url: "https://api.dingtalk.com/v1.0/link/followers?accountId={String}&nextToken={String}&maxResults={String}"
100
+ security:
101
+ id: DingTalkAuth
102
+ args:
103
+ - name: accountId
104
+ description: 服务窗帐号ID
105
+ type: string
106
+ required: true
107
+ position: query
108
+ - name: nextToken
109
+ description: 分页游标
110
+ type: string
111
+ required: false
112
+ position: query
113
+ - name: maxResults
114
+ description: 每页最大条目数,最大值100
115
+ type: string
116
+ required: false
117
+ position: query
118
+
119
+
120
+ - name: getUserFollowStatus
121
+ description: "获取用户的服务窗关注状态"
122
+ requestTemplate:
123
+ method: GET
124
+ url: "https://api.dingtalk.com/v1.0/link/followers/statuses?accountId={String}&userId={String}"
125
+ security:
126
+ id: DingTalkAuth
127
+ args:
128
+ - name: accountId
129
+ description: 服务窗帐号ID
130
+ type: string
131
+ required: true
132
+ position: query
133
+ - name: userId
134
+ description: 关注服务窗用户的userId
135
+ type: string
136
+ required: true
137
+ position: query
138
+
139
+
140
+ - name: listServiceWindows
141
+ description: "获取企业下的服务窗列表,以获取服务窗帐号IDaccountId"
142
+ requestTemplate:
143
+ method: GET
144
+ url: "https://api.dingtalk.com/v1.0/link/accounts"
145
+ security:
146
+ id: DingTalkAuth
@@ -96,16 +96,7 @@ tools:
96
96
  position: body
97
97
  items:
98
98
  type: string
99
- - name: detailUrl.appUrl
100
- description: 移动端待办详情页URL
101
- type: string
102
- position: body
103
- required: true
104
- - name: detailUrl.pcUrl
105
- description: PC端待办详情页URL
106
- type: string
107
- position: body
108
- required: true
99
+
109
100
  requestTemplate:
110
101
  url: https://api.dingtalk.com/v1.0/todo/users/{unionId}/tasks
111
102
  method: POST
@@ -1,11 +1,14 @@
1
1
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
2
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
3
3
  import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
4
+ import { ServiceWindowMessageBuilder } from './utils/messageBuilder.js'
4
5
  import axios from 'axios';
5
6
  import * as yaml from 'js-yaml';
6
7
  import fs from 'fs';
7
8
  import path from 'path';
8
9
  import { fileURLToPath } from 'url';
10
+ import {ifError} from "node:assert";
11
+ import {resolveObjectURL} from "node:buffer";
9
12
  const __filename = fileURLToPath(import.meta.url);
10
13
  const __dirname = path.dirname(__filename);
11
14
  export class DingTalkMCPServer {
@@ -429,6 +432,14 @@ export class DingTalkMCPServer {
429
432
  if (tool.requestTemplate.method === 'GET' || tool.requestTemplate.method === 'DELETE') {
430
433
  return undefined;
431
434
  }
435
+
436
+ if (tool.name === 'sendServiceWindowMessage'){
437
+ return ServiceWindowMessageBuilder.buildSendServiceWindowMarkdownBody(args);
438
+ }else if (tool.name === 'batchSendServiceWindowMessage'){
439
+ return ServiceWindowMessageBuilder.buildBatchSendServiceWindowMarkdownBody(args);
440
+ }
441
+
442
+
432
443
  const body = {};
433
444
  (tool.args || []).forEach(arg => {
434
445
  if (arg.position === 'body') {
@@ -0,0 +1,54 @@
1
+ /**
2
+ * ServiceWindow Message Builder - 核心特色功能
3
+ * 简化复杂的服务窗消息格式构建
4
+ */
5
+ export class ServiceWindowMessageBuilder {
6
+ /**
7
+ * 构建服务窗消息体
8
+ * @param message 用户友好的消息参数
9
+ * @returns 钉钉API标准格式的消息体
10
+ */
11
+ static buildSendServiceWindowMarkdownBody(message) {
12
+ return {
13
+ detail: {
14
+ msgType: "markdown",
15
+ uuid: this.generateMessageUuid(),
16
+ userId: message.userId,
17
+ messageBody: {
18
+ markdown: {
19
+ title: message.messageTitle,
20
+ text: message.messageContent
21
+ }
22
+ }
23
+ },
24
+ accountId: message.accountId
25
+ }
26
+ }
27
+
28
+ static buildBatchSendServiceWindowMarkdownBody(message) {
29
+ return {
30
+ detail: {
31
+ msgType: "markdown",
32
+ uuid: this.generateMessageUuid(),
33
+ userIdList: message.userIdList,
34
+ messageBody: {
35
+ markdown: {
36
+ title: message.messageTitle,
37
+ text: message.messageContent
38
+ }
39
+ }
40
+ },
41
+ accountId: message.accountId
42
+ }
43
+ }
44
+
45
+
46
+ /**
47
+ * 生成唯一的消息ID
48
+ */
49
+ static generateMessageUuid() {
50
+ const UUID = crypto.randomUUID();
51
+ return UUID.toString();
52
+ // return `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
53
+ }
54
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dingtalk-mcp",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "DingTalk MCP Server - A TypeScript-based MCP server for DingTalk integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -12,7 +12,7 @@
12
12
  "dist/**/*",
13
13
  "*.yaml",
14
14
  "!dist/test.js",
15
- "!dist/utils"
15
+ "dist/utils"
16
16
  ],
17
17
  "scripts": {
18
18
  "build": "tsc",