im-connector 1.0.0 → 1.0.1

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
@@ -1,182 +1,86 @@
1
- # IM Connector(可扩展的多 IM 透传插件)
1
+ # im-connector
2
2
 
3
- 一个可在 npm 上分发的统一 IM 连接器:通过**一个 MCP 工具 `mcp__im__run`**,按 `provider` 路由到各平台的命令行客户端,返回其 JSON 输出。当前接入**钉钉**(dws)与**企业微信**(wecom-cli),并预留了飞书、Discord 等平台的扩展位。
3
+ 让 AI Agent 通过 MCP 调用**钉钉(dws)**和**企业微信(wecom-cli)**的 CLI,在渠道里干活:发消息、写日志/日报、建待办、查日程、处理审批。
4
4
 
5
- ```
6
- DSH Agent ── mcp__im__run { provider, args } ──▶ dist/mcp/server.js
7
- ├─ provider=dingtalk ──▶ dws ──▶ 钉钉
8
- └─ provider=wecom ──▶ wecom-cli ──▶ 企业微信
9
- ```
10
-
11
- ## 定位:Agent 侧集成(让机器人在渠道里干活)
12
-
13
- 本连接器只负责**「Agent → 渠道」方向**:Agent 通过 MCP 工具调用 dws / wecom-cli,让机器人在钉钉/企微里完成实际工作——发消息、写日志/日报、建待办、查日程、处理审批等。
14
-
15
- **渠道 → Agent 方向**(在群里/私聊里跟机器人对话)由独立的 `dsh-im` 插件负责,不在本连接器的范围内。
16
-
17
- ## 典型用法(让机器人在渠道里干活)
18
-
19
- ```json
20
- // 发消息到群 / 私聊
21
- { "provider": "dingtalk", "args": ["chat", "+messages-send", "--group", "<openConversationId>", "--markdown", "今天 18:00 前提交周报", "--yes"] }
22
- { "provider": "dingtalk", "args": ["chat", "+messages-send", "--user", "<userId>", "--markdown", "私聊通知", "--yes"] }
23
-
24
- // 写/提交日志(日报周报)
25
- { "provider": "dingtalk", "args": ["report", "+create", "--template", "日报", "--content", "...", "--yes"] }
26
- { "provider": "dingtalk", "args": ["report", "+my", "--type", "日报"] }
27
-
28
- // 待办
29
- { "provider": "dingtalk", "args": ["todo", "+create", "--title", "整理今日测试报告", "--due", "2026-10-23 18:00"] }
30
- { "provider": "dingtalk", "args": ["todo", "+get-my-tasks"] }
31
-
32
- // 日程 / 审批 / 通讯录
33
- { "provider": "dingtalk", "args": ["calendar", "+today"] }
34
- { "provider": "dingtalk", "args": ["oa", "approval", "list-pending"] }
35
- { "provider": "dingtalk", "args": ["contact", "+me"] }
36
-
37
- // 企业微信
38
- { "provider": "wecom", "args": ["contact", "users", "search", "--keywords", "张三"] }
39
- { "provider": "wecom", "args": ["message", "send", "--chat-id", "<id>", "--msg-type", "text", "--text", "{\"content\":\"通知内容\"}"] }
40
- ```
41
-
42
- 写操作需用户明确意图;不确定时先用 `--dry-run` 预览(两平台都支持)。
43
-
44
- ## 设计核心:Provider 注册表
5
+ > 本包只负责「Agent → 渠道」方向。在群里/私聊里与机器人对话(渠道 → Agent)请用 dsh-im 插件。
45
6
 
46
- 每个 IM 平台只是 `src/providers/*.ts` 里的一条规格(`ImProviderSpec`),描述:
47
-
48
- - 该平台的 CLI 命令名、npm 包名与 bin 脚本路径(用于自动解析 npm 全局安装、规避 Windows shim)
49
- - 请求 JSON 输出的 flag(dws 用 `--format json`;wecom 默认 JSON 则留空)
50
- - 覆盖 bin 的环境变量名、示例命令
7
+ ## 前置条件
51
8
 
52
- **新增一个平台(飞书 / Discord / …)只需**:
53
- 1. 新建 `src/providers/feishu.ts`,导出一个 `ImProviderSpec`;
54
- 2. 在 `src/providers/registry.ts` 的 `providers` 数组里追加它。
9
+ - Node.js >= 18
10
+ - **钉钉**:`npm i -g dingtalk-workspace-cli`,然后 `dws auth login --recommend`
11
+ - **企业微信**:`npm i -g @wecom/cli`,然后 `wecom-cli auth init --noninteractive` 扫码授权
55
12
 
56
- MCP 工具的 `provider` 枚举与描述会**自动**从注册表生成,无需改其它代码。
13
+ 连接器不保存任何凭据,直接用两个 CLI 自己的登录态。
57
14
 
58
- ## 快速开始(npm)
15
+ ## 安装
59
16
 
60
17
  ```bash
61
- npm i -g im-connector # 全局安装(提供 im-connector 命令)
62
- # 或直接用 npx(无需安装):
63
- npx -y im-connector
18
+ npx -y im-connector # 直接用,无需安装
19
+ npm i -g im-connector # 或全局安装
64
20
  ```
65
21
 
66
- `im-connector` 是一个 **stdio MCP server**:任何 MCP 客户端(DSH / Claude Desktop / 其它 Agent)都可以把它注册成 MCP 连接。配置示例:
22
+ ## 配置 MCP 客户端
23
+
24
+ 通用 MCP 客户端(如 Claude Desktop):
67
25
 
68
26
  ```json
69
27
  {
70
28
  "mcpServers": {
71
- "im": {
72
- "command": "npx",
73
- "args": ["-y", "im-connector"],
74
- "env": {
75
- "DINGTALK_DWS_BIN": "<npm root -g>/dingtalk-workspace-cli/bin/dws.js",
76
- "WECOM_CLI_BIN": "<npm root -g>/@wecom/cli/bin/wecom.js"
77
- }
78
- }
29
+ "im": { "command": "npx", "args": ["-y", "im-connector"] }
79
30
  }
80
31
  }
81
32
  ```
82
33
 
83
- > `env` 可选:不填时连接器会自动通过 `npm root -g` 解析两个 CLI;填了更稳(规避 Windows shim)。
84
-
85
- DSH 用户:本包**同时是 DSH 的 MCP 连接 bundle**(`package.json` 里声明了 `dsh.bundle.patch`),一条命令完成"装包 + 注册 MCP 连接":
34
+ **DSH 用户**一条命令即可(装包 + 注册 MCP 连接):
86
35
 
87
36
  ```
88
37
  plugin_manager install_bundle target: im-connector
89
38
  ```
90
39
 
91
- 安装后工具名为 `mcp__im__run`。细节与手工安装方式见 `mcp-bundle/README.md`。
92
-
93
- ## 前置条件
94
-
95
- ```bash
96
- # 钉钉
97
- npm install -g dingtalk-workspace-cli
98
- dws auth login --recommend --format json
99
-
100
- # 企业微信
101
- npm install -g @wecom/cli
102
- wecom-cli auth show --status # 未授权时:wecom-cli auth init --noninteractive 扫码
103
- ```
104
-
105
- 连接器不保存任何凭据,认证复用各 CLI 的本地登录态。
106
-
107
- ## 构建与验证
108
-
109
- ```bash
110
- pnpm install
111
- pnpm verify # typecheck + 测试 + build + MCP 冒烟
112
- ```
113
-
114
- ## 接入 DSH(官方推荐路径)
115
-
116
- 按 DSH 官方 `references/mcp-bundle.md` 的做法:**配置型 bundle**(只插入一条 `@deepseek-ai/dsh-mcp-client` 行,无 Host/Client 入口文件),display 元数据用 `locale/*.json` + `icon.svg`,patch 用官方 stdio 形式:
117
-
118
- ```yaml
119
- - insert:
120
- - id: im-connector-mcp
121
- name: '@deepseek-ai/dsh-mcp-client'
122
- config:
123
- serverName: im
124
- transport: stdio
125
- command: npx
126
- args: ['-y', 'im-connector']
127
- failOnStartupError: true
128
- ```
129
-
130
- - 推荐安装:`plugin_manager install_bundle target: im-connector`(包内已声明 `dsh.bundle.patch`,一步完成)
131
- - 手工安装:把 `mcp-bundle/` 复制到任意目录后 `install_bundle` 指向该目录
132
- - 不需要写死路径或凭据(`npx` 跨平台;凭据保持在两个 CLI 自己的登录态里,env 覆盖用 Loader `!!js`)
40
+ 安装后工具名为 `mcp__im__run`。
133
41
 
134
42
  ## 使用
135
43
 
136
- 调用 `mcp__im__run`,`provider` 选平台,`args` 是该平台 CLI 的命令数组:
44
+ Agent 调用 `mcp__im__run`,参数是 `{ provider, args }`,`args` 就是对应 CLI 的原生命令参数:
137
45
 
138
46
  ```json
139
- // 钉钉(dws)
140
- { "provider": "dingtalk", "args": ["contact", "+me"] }
47
+ // 发消息
48
+ { "provider": "dingtalk", "args": ["chat", "+messages-send", "--group", "<群ID>", "--markdown", "内容", "--yes"] }
49
+
50
+ // 待办
51
+ { "provider": "dingtalk", "args": ["todo", "+create", "--title", "整理今日测试报告", "--due", "2026-10-23 18:00"] }
141
52
  { "provider": "dingtalk", "args": ["todo", "+get-my-tasks"] }
53
+
54
+ // 日志 / 日报周报
55
+ { "provider": "dingtalk", "args": ["report", "+create", "--template", "日报", "--content", "..."] }
56
+
57
+ // 日程 / 审批 / 通讯录
58
+ { "provider": "dingtalk", "args": ["calendar", "+today"] }
142
59
  { "provider": "dingtalk", "args": ["oa", "approval", "list-pending"] }
143
- { "provider": "dingtalk", "args": ["chat", "+chat-messages", "--group", "研发群", "--limit", "20"] }
144
- { "provider": "dingtalk", "args": ["chat", "+messages-send", "--group", "<cid>", "--markdown", "内容", "--title", "标题", "--yes"] }
60
+ { "provider": "dingtalk", "args": ["contact", "+me"] }
145
61
 
146
- // 企业微信(wecom-cli)
62
+ // 企业微信
147
63
  { "provider": "wecom", "args": ["contact", "users", "search", "--keywords", "张三"] }
148
- { "provider": "wecom", "args": ["chat", "messages", "list", "--chat-id", "<id>", "--begin-time", "2026-10-01 00:00:00", "--end-time", "2026-10-21 00:00:00"] }
149
- { "provider": "wecom", "args": ["auth", "show", "--status"] }
150
64
  ```
151
65
 
152
- 写操作(发消息/提交/审批等)需用户明确意图,必要时加 `--yes`(钉钉)或先用 `--dry-run` 预览(两平台都支持 `--dry-run`)。
153
-
154
- ## 发布(维护者)
66
+ 完整命令见各 CLI 的 `--help`(如 `dws chat --help`、`wecom-cli message --help`)。
155
67
 
156
- ```bash
157
- npm login # 首次发布前登录(已登录则跳过)
158
- pnpm verify # typecheck + 测试 + build + MCP 冒烟(prepublishOnly 也会跑)
159
- npm publish # 发布到 npm(publishConfig.access=public)
160
- ```
68
+ ## 说明
161
69
 
162
- 发布内容(`files`):`dist/`(编译产物 + shebang 入口)、`mcp-bundle/`(DSH 连接 bundle)、`README.md`、`LICENSE`。
70
+ - **写操作**(发消息、提交审批等)请先让 Agent 确认意图;不确定时用 `--dry-run` 预览(两平台都支持)
71
+ - 参数会原样透传给 CLI,返回其 JSON 输出
72
+ - 支持的 provider:`dingtalk`、`wecom`
163
73
 
164
- 发布前可用 `npm pack --dry-run` 查看实际打包清单。
74
+ ## 开发
165
75
 
166
- ## 目录结构
167
-
168
- ```
169
- src/
170
- cli/runner.ts CliRunner:通用 CLI 透传(npm 全局解析、JSON 解析、错误信封映射)
171
- cli/errors.ts CliError + stderr 错误信封解析
172
- providers/ ImProviderSpec + registry(dingtalk / wecom,可扩展)
173
- mcp/server.ts MCP stdio server,暴露单一 `run { provider, args }` 工具
174
- index.ts 包入口
175
- tests/ fake-cli.mjs + cli/mcp 测试
176
- mcp-bundle/ DSH MCP 连接 bundle
177
- scripts/ mcp-smoke.mjs / duty-reminder.mjs(钉钉值班提醒,独立任务)
76
+ ```bash
77
+ pnpm install
78
+ pnpm verify # typecheck + 测试 + 构建 + MCP 冒烟
178
79
  ```
179
80
 
180
- ## 值班提醒(独立任务)
81
+ 发布(维护者):
181
82
 
182
- `scripts/duty-reminder.mjs` 由 DSH 周提醒触发,用 `spawnSync` 直接调 `dws`,与本连接器解耦,不受影响。
83
+ ```bash
84
+ npm version patch
85
+ npm publish --registry=https://registry.npmjs.org/
86
+ ```
@@ -34,6 +34,16 @@ plugin_manager install_bundle target: im-connector
34
34
  - `failOnStartupError: true`:连接失败时让该行激活失败,便于发现问题(官方模板同款)。
35
35
  - 对照官方 `templates/mcp/`:manifest 只需 name/version/`dsh.bundle.patch`(配置型 bundle 无 Host/Client 入口文件),display 元数据走 `locale/*.json` + `icon.svg`。
36
36
 
37
+ > ⚠️ 个别 Windows 环境下 `npx` 转发 stdio 到本包 server 不稳定(`npx --version` 与其它包正常,但管道下 MCP 握手被关闭)。遇到这种情况改用 node + 绝对路径:
38
+
39
+ ```yaml
40
+ config:
41
+ serverName: im
42
+ transport: stdio
43
+ command: node
44
+ args: ['<npm root -g>/im-connector/dist/mcp/server.js']
45
+ ```
46
+
37
47
  ## 验证
38
48
 
39
49
  安装后在会话里调用 `mcp__im__run`(例如 `{ provider: "dingtalk", args: ["contact", "+me"] }`)确认连接可用。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "im-connector",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "MCP server that lets agents drive DingTalk (dws) and WeCom (wecom-cli) CLIs: send messages, write reports, create todos, query calendars and approvals. Extensible provider registry for more IM platforms.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",