@danyow/lark-mcp 0.5.4 → 0.5.5

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.
Files changed (26) hide show
  1. package/dist/mcp-server/shared/types.d.ts +2 -2
  2. package/dist/mcp-tool/tools/en/builtin-tools/drive/builtin.js +79 -52
  3. package/dist/mcp-tool/tools/en/gen-tools/zod/aily_v1.d.ts +16 -16
  4. package/dist/mcp-tool/tools/en/gen-tools/zod/attendance_v1.d.ts +84 -84
  5. package/dist/mcp-tool/tools/en/gen-tools/zod/baike_v1.d.ts +72 -72
  6. package/dist/mcp-tool/tools/en/gen-tools/zod/docx_v1.d.ts +697 -697
  7. package/dist/mcp-tool/tools/en/gen-tools/zod/hire_v1.d.ts +32 -32
  8. package/dist/mcp-tool/tools/en/gen-tools/zod/lingo_v1.d.ts +72 -72
  9. package/dist/mcp-tool/tools/en/gen-tools/zod/okr_v1.d.ts +24 -24
  10. package/dist/mcp-tool/tools/en/gen-tools/zod/task_v1.d.ts +20 -20
  11. package/dist/mcp-tool/tools/en/gen-tools/zod/task_v2.d.ts +18 -18
  12. package/dist/mcp-tool/tools/en/gen-tools/zod/vc_v1.d.ts +64 -64
  13. package/dist/mcp-tool/tools/en/gen-tools/zod/wiki_v2.d.ts +4 -4
  14. package/dist/mcp-tool/tools/zh/builtin-tools/drive/builtin.js +79 -52
  15. package/dist/mcp-tool/tools/zh/gen-tools/zod/aily_v1.d.ts +16 -16
  16. package/dist/mcp-tool/tools/zh/gen-tools/zod/attendance_v1.d.ts +84 -84
  17. package/dist/mcp-tool/tools/zh/gen-tools/zod/baike_v1.d.ts +72 -72
  18. package/dist/mcp-tool/tools/zh/gen-tools/zod/docx_v1.d.ts +716 -716
  19. package/dist/mcp-tool/tools/zh/gen-tools/zod/hire_v1.d.ts +32 -32
  20. package/dist/mcp-tool/tools/zh/gen-tools/zod/lingo_v1.d.ts +72 -72
  21. package/dist/mcp-tool/tools/zh/gen-tools/zod/okr_v1.d.ts +24 -24
  22. package/dist/mcp-tool/tools/zh/gen-tools/zod/task_v1.d.ts +20 -20
  23. package/dist/mcp-tool/tools/zh/gen-tools/zod/task_v2.d.ts +18 -18
  24. package/dist/mcp-tool/tools/zh/gen-tools/zod/vc_v1.d.ts +64 -64
  25. package/dist/mcp-tool/tools/zh/gen-tools/zod/wiki_v2.d.ts +4 -4
  26. package/package.json +1 -1
@@ -10,14 +10,14 @@ export declare const mcpServerOptionSchema: z.ZodObject<{
10
10
  toolNameCase: z.ZodOptional<z.ZodEnum<["snake", "camel"]>>;
11
11
  tokenMode: z.ZodOptional<z.ZodEnum<["auto", "user_access_token", "tenant_access_token"]>>;
12
12
  }, "strip", z.ZodTypeAny, {
13
- language?: "en" | "zh" | undefined;
14
13
  tokenMode?: "auto" | "user_access_token" | "tenant_access_token" | undefined;
15
14
  tools?: string | string[] | undefined;
15
+ language?: "en" | "zh" | undefined;
16
16
  toolNameCase?: "snake" | "camel" | undefined;
17
17
  }, {
18
- language?: "en" | "zh" | undefined;
19
18
  tokenMode?: "auto" | "user_access_token" | "tenant_access_token" | undefined;
20
19
  tools?: string | string[] | undefined;
20
+ language?: "en" | "zh" | undefined;
21
21
  toolNameCase?: "snake" | "camel" | undefined;
22
22
  }>;
23
23
  export interface McpServerOptions {
@@ -34,11 +34,11 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.driveBuiltinTools = exports.larkDriveExportTaskDownloadTool = void 0;
37
- const lark = __importStar(require("@larksuiteoapi/node-sdk"));
38
37
  const zod_1 = require("zod");
39
38
  const fs = __importStar(require("fs"));
40
39
  const path = __importStar(require("path"));
41
40
  const os = __importStar(require("os"));
41
+ const http_instance_1 = require("../../../../../utils/http-instance");
42
42
  exports.larkDriveExportTaskDownloadTool = {
43
43
  project: 'drive',
44
44
  name: 'drive.v1.exportTask.download',
@@ -67,7 +67,7 @@ exports.larkDriveExportTaskDownloadTool = {
67
67
  useUAT: zod_1.z.boolean().describe('Use user access token, otherwise use tenant access token').optional(),
68
68
  },
69
69
  customHandler: async (client, params, options) => {
70
- var _a, _b, _c, _d;
70
+ var _a, _b, _c, _d, _e, _f;
71
71
  try {
72
72
  const { userAccessToken } = options || {};
73
73
  const fileToken = (_a = params === null || params === void 0 ? void 0 : params.path) === null || _a === void 0 ? void 0 : _a.file_token;
@@ -85,80 +85,73 @@ exports.larkDriveExportTaskDownloadTool = {
85
85
  fs.mkdirSync(outputDir, { recursive: true });
86
86
  }
87
87
  const filePath = path.join(outputDir, fileName);
88
- // Use SDK's built-in download method which returns writeFile/getReadableStream
89
- let response;
90
88
  const debug = [];
91
89
  debug.push(`fileToken: ${fileToken}`);
92
90
  debug.push(`useUAT: ${params === null || params === void 0 ? void 0 : params.useUAT}, hasUserAccessToken: ${!!userAccessToken}`);
91
+ // Get access token from SDK client
92
+ let accessToken;
93
93
  if (userAccessToken && (params === null || params === void 0 ? void 0 : params.useUAT)) {
94
- response = await client.drive.exportTask.download({ path: { file_token: fileToken } }, lark.withUserAccessToken(userAccessToken));
94
+ accessToken = userAccessToken;
95
+ debug.push('using user access token');
95
96
  }
96
97
  else {
97
- response = await client.drive.exportTask.download({ path: { file_token: fileToken } });
98
+ // Get tenant access token from client
99
+ try {
100
+ const tokenRes = await ((_d = client.tokenManager) === null || _d === void 0 ? void 0 : _d.getTenantAccessToken());
101
+ accessToken = tokenRes;
102
+ debug.push('using tenant access token');
103
+ }
104
+ catch (tokenError) {
105
+ debug.push(`failed to get tenant token: ${tokenError === null || tokenError === void 0 ? void 0 : tokenError.message}`);
106
+ }
98
107
  }
99
- debug.push(`response type: ${typeof response}`);
100
- debug.push(`response keys: ${response ? Object.keys(response).join(', ') : 'null/undefined'}`);
101
- debug.push(`response.code: ${response === null || response === void 0 ? void 0 : response.code}`);
102
- debug.push(`response.msg: ${response === null || response === void 0 ? void 0 : response.msg}`);
103
- debug.push(`has writeFile: ${typeof (response === null || response === void 0 ? void 0 : response.writeFile)}`);
104
- debug.push(`has getReadableStream: ${typeof (response === null || response === void 0 ? void 0 : response.getReadableStream)}`);
105
- // Check if response contains an API error
106
- if ((response === null || response === void 0 ? void 0 : response.code) && response.code !== 0) {
108
+ if (!accessToken) {
107
109
  return {
108
110
  isError: true,
109
111
  content: [{ type: 'text', text: JSON.stringify({
110
- msg: 'API error',
111
- code: response.code,
112
- error: response.msg || 'Unknown error',
113
- hint: 'The file_token may be invalid or expired. Export files are deleted 10 minutes after the export task completes.',
112
+ msg: 'Failed to get access token',
114
113
  debug
115
114
  }) }],
116
115
  };
117
116
  }
118
- // Use the SDK's writeFile method to save the file
119
- if (response === null || response === void 0 ? void 0 : response.writeFile) {
120
- debug.push('using writeFile method');
121
- await response.writeFile(filePath);
122
- debug.push('writeFile completed');
123
- }
124
- else if (response === null || response === void 0 ? void 0 : response.getReadableStream) {
125
- debug.push('using getReadableStream method');
126
- // Fallback to stream if writeFile is not available
127
- const readableStream = response.getReadableStream();
128
- debug.push(`readableStream: ${readableStream ? 'exists' : 'undefined'}`);
129
- if (!readableStream) {
130
- return {
131
- isError: true,
132
- content: [{ type: 'text', text: JSON.stringify({
133
- msg: 'Failed to download file: getReadableStream returned undefined',
134
- hint: 'The file_token may be invalid or expired. Export files are deleted 10 minutes after the export task completes.',
135
- debug
136
- }) }],
137
- };
138
- }
139
- const writableStream = fs.createWriteStream(filePath);
140
- await new Promise((resolve, reject) => {
141
- readableStream.pipe(writableStream);
142
- writableStream.on('finish', resolve);
143
- writableStream.on('error', reject);
144
- readableStream.on('error', reject);
145
- });
146
- debug.push('stream completed');
147
- }
148
- else {
117
+ // Use commonHttpInstance directly (with proxy support) instead of SDK's download method
118
+ const domain = client.domain || 'https://open.feishu.cn';
119
+ const downloadUrl = `${domain}/open-apis/drive/v1/export_tasks/file/${fileToken}/download`;
120
+ debug.push(`downloadUrl: ${downloadUrl}`);
121
+ const response = await http_instance_1.commonHttpInstance.request({
122
+ url: downloadUrl,
123
+ method: 'GET',
124
+ headers: {
125
+ 'Authorization': `Bearer ${accessToken}`,
126
+ },
127
+ responseType: 'stream',
128
+ timeout: 60000, // 60 seconds timeout for download
129
+ });
130
+ debug.push(`response status: ${response.status}`);
131
+ // Check if we got a valid stream response
132
+ if (!response.data) {
149
133
  return {
150
134
  isError: true,
151
135
  content: [{ type: 'text', text: JSON.stringify({
152
- msg: 'Failed to download file: SDK response does not contain writeFile or getReadableStream',
136
+ msg: 'Failed to download file: empty response',
153
137
  debug
154
138
  }) }],
155
139
  };
156
140
  }
141
+ // Write stream to file
142
+ const writableStream = fs.createWriteStream(filePath);
143
+ await new Promise((resolve, reject) => {
144
+ response.data.pipe(writableStream);
145
+ writableStream.on('finish', resolve);
146
+ writableStream.on('error', reject);
147
+ response.data.on('error', reject);
148
+ });
149
+ debug.push('stream completed');
157
150
  // Check if file was created and get stats
158
151
  if (!fs.existsSync(filePath)) {
159
152
  return {
160
153
  isError: true,
161
- content: [{ type: 'text', text: JSON.stringify({ msg: 'Failed to download file: file was not created' }) }],
154
+ content: [{ type: 'text', text: JSON.stringify({ msg: 'Failed to download file: file was not created', debug }) }],
162
155
  };
163
156
  }
164
157
  const stats = fs.statSync(filePath);
@@ -178,6 +171,40 @@ exports.larkDriveExportTaskDownloadTool = {
178
171
  };
179
172
  }
180
173
  catch (error) {
174
+ // Handle API error responses
175
+ if ((_e = error === null || error === void 0 ? void 0 : error.response) === null || _e === void 0 ? void 0 : _e.data) {
176
+ // For stream responses, we need to read the error from the stream
177
+ const errorData = error.response.data;
178
+ if (typeof errorData.pipe === 'function') {
179
+ // It's a stream, try to read it
180
+ const chunks = [];
181
+ for await (const chunk of errorData) {
182
+ chunks.push(chunk);
183
+ }
184
+ const errorText = Buffer.concat(chunks).toString('utf-8');
185
+ try {
186
+ const errorJson = JSON.parse(errorText);
187
+ return {
188
+ isError: true,
189
+ content: [{ type: 'text', text: JSON.stringify({
190
+ msg: 'API error',
191
+ code: errorJson.code,
192
+ error: errorJson.msg || 'Unknown error',
193
+ hint: 'The file_token may be invalid or expired. Export files are deleted 10 minutes after the export task completes.',
194
+ }) }],
195
+ };
196
+ }
197
+ catch (_g) {
198
+ return {
199
+ isError: true,
200
+ content: [{ type: 'text', text: JSON.stringify({
201
+ msg: 'Failed to download export file',
202
+ error: errorText,
203
+ }) }],
204
+ };
205
+ }
206
+ }
207
+ }
181
208
  return {
182
209
  isError: true,
183
210
  content: [
@@ -185,7 +212,7 @@ exports.larkDriveExportTaskDownloadTool = {
185
212
  type: 'text',
186
213
  text: JSON.stringify({
187
214
  msg: 'Failed to download export file',
188
- error: ((_d = error === null || error === void 0 ? void 0 : error.response) === null || _d === void 0 ? void 0 : _d.data) || (error === null || error === void 0 ? void 0 : error.message) || String(error),
215
+ error: ((_f = error === null || error === void 0 ? void 0 : error.response) === null || _f === void 0 ? void 0 : _f.data) || (error === null || error === void 0 ? void 0 : error.message) || String(error),
189
216
  }),
190
217
  },
191
218
  ],
@@ -22,16 +22,16 @@ export declare const ailyV1AilySessionAilyMessageCreate: {
22
22
  name: z.ZodOptional<z.ZodString>;
23
23
  aily_id: z.ZodOptional<z.ZodString>;
24
24
  }, "strip", z.ZodTypeAny, {
25
+ key?: string | undefined;
25
26
  name?: string | undefined;
26
27
  entity_id?: string | undefined;
27
28
  identity_provider?: "AILY" | "FEISHU" | undefined;
28
- key?: string | undefined;
29
29
  aily_id?: string | undefined;
30
30
  }, {
31
+ key?: string | undefined;
31
32
  name?: string | undefined;
32
33
  entity_id?: string | undefined;
33
34
  identity_provider?: "AILY" | "FEISHU" | undefined;
34
- key?: string | undefined;
35
35
  aily_id?: string | undefined;
36
36
  }>, "many">>;
37
37
  }, "strip", z.ZodTypeAny, {
@@ -41,10 +41,10 @@ export declare const ailyV1AilySessionAilyMessageCreate: {
41
41
  file_ids?: string[] | undefined;
42
42
  quote_message_id?: string | undefined;
43
43
  mentions?: {
44
+ key?: string | undefined;
44
45
  name?: string | undefined;
45
46
  entity_id?: string | undefined;
46
47
  identity_provider?: "AILY" | "FEISHU" | undefined;
47
- key?: string | undefined;
48
48
  aily_id?: string | undefined;
49
49
  }[] | undefined;
50
50
  }, {
@@ -54,10 +54,10 @@ export declare const ailyV1AilySessionAilyMessageCreate: {
54
54
  file_ids?: string[] | undefined;
55
55
  quote_message_id?: string | undefined;
56
56
  mentions?: {
57
+ key?: string | undefined;
57
58
  name?: string | undefined;
58
59
  entity_id?: string | undefined;
59
60
  identity_provider?: "AILY" | "FEISHU" | undefined;
60
- key?: string | undefined;
61
61
  aily_id?: string | undefined;
62
62
  }[] | undefined;
63
63
  }>;
@@ -397,16 +397,16 @@ export declare const ailyV1AppDataAssetCreate: {
397
397
  url: z.ZodOptional<z.ZodString>;
398
398
  }, "strip", z.ZodTypeAny, {
399
399
  content?: string | undefined;
400
+ url?: string | undefined;
400
401
  title?: string | undefined;
401
402
  token?: string | undefined;
402
403
  mime_type?: string | undefined;
403
- url?: string | undefined;
404
404
  }, {
405
405
  content?: string | undefined;
406
+ url?: string | undefined;
406
407
  title?: string | undefined;
407
408
  token?: string | undefined;
408
409
  mime_type?: string | undefined;
409
- url?: string | undefined;
410
410
  }>>;
411
411
  lark_doc: z.ZodOptional<z.ZodObject<{
412
412
  type: z.ZodEnum<["doc", "file", "wiki", "docx", "folder"]>;
@@ -464,10 +464,10 @@ export declare const ailyV1AppDataAssetCreate: {
464
464
  }, "strip", z.ZodTypeAny, {
465
465
  file?: {
466
466
  content?: string | undefined;
467
+ url?: string | undefined;
467
468
  title?: string | undefined;
468
469
  token?: string | undefined;
469
470
  mime_type?: string | undefined;
470
- url?: string | undefined;
471
471
  } | undefined;
472
472
  lark_wiki_space?: {
473
473
  space_id: string;
@@ -495,10 +495,10 @@ export declare const ailyV1AppDataAssetCreate: {
495
495
  }, {
496
496
  file?: {
497
497
  content?: string | undefined;
498
+ url?: string | undefined;
498
499
  title?: string | undefined;
499
500
  token?: string | undefined;
500
501
  mime_type?: string | undefined;
501
- url?: string | undefined;
502
502
  } | undefined;
503
503
  lark_wiki_space?: {
504
504
  space_id: string;
@@ -531,10 +531,10 @@ export declare const ailyV1AppDataAssetCreate: {
531
531
  import_knowledge_setting?: {
532
532
  file?: {
533
533
  content?: string | undefined;
534
+ url?: string | undefined;
534
535
  title?: string | undefined;
535
536
  token?: string | undefined;
536
537
  mime_type?: string | undefined;
537
- url?: string | undefined;
538
538
  } | undefined;
539
539
  lark_wiki_space?: {
540
540
  space_id: string;
@@ -567,10 +567,10 @@ export declare const ailyV1AppDataAssetCreate: {
567
567
  import_knowledge_setting?: {
568
568
  file?: {
569
569
  content?: string | undefined;
570
+ url?: string | undefined;
570
571
  title?: string | undefined;
571
572
  token?: string | undefined;
572
573
  mime_type?: string | undefined;
573
- url?: string | undefined;
574
574
  } | undefined;
575
575
  lark_wiki_space?: {
576
576
  space_id: string;
@@ -916,16 +916,16 @@ export declare const ailyV1Tools: ({
916
916
  url: z.ZodOptional<z.ZodString>;
917
917
  }, "strip", z.ZodTypeAny, {
918
918
  content?: string | undefined;
919
+ url?: string | undefined;
919
920
  title?: string | undefined;
920
921
  token?: string | undefined;
921
922
  mime_type?: string | undefined;
922
- url?: string | undefined;
923
923
  }, {
924
924
  content?: string | undefined;
925
+ url?: string | undefined;
925
926
  title?: string | undefined;
926
927
  token?: string | undefined;
927
928
  mime_type?: string | undefined;
928
- url?: string | undefined;
929
929
  }>>;
930
930
  lark_doc: z.ZodOptional<z.ZodObject<{
931
931
  type: z.ZodEnum<["doc", "file", "wiki", "docx", "folder"]>;
@@ -983,10 +983,10 @@ export declare const ailyV1Tools: ({
983
983
  }, "strip", z.ZodTypeAny, {
984
984
  file?: {
985
985
  content?: string | undefined;
986
+ url?: string | undefined;
986
987
  title?: string | undefined;
987
988
  token?: string | undefined;
988
989
  mime_type?: string | undefined;
989
- url?: string | undefined;
990
990
  } | undefined;
991
991
  lark_wiki_space?: {
992
992
  space_id: string;
@@ -1014,10 +1014,10 @@ export declare const ailyV1Tools: ({
1014
1014
  }, {
1015
1015
  file?: {
1016
1016
  content?: string | undefined;
1017
+ url?: string | undefined;
1017
1018
  title?: string | undefined;
1018
1019
  token?: string | undefined;
1019
1020
  mime_type?: string | undefined;
1020
- url?: string | undefined;
1021
1021
  } | undefined;
1022
1022
  lark_wiki_space?: {
1023
1023
  space_id: string;
@@ -1050,10 +1050,10 @@ export declare const ailyV1Tools: ({
1050
1050
  import_knowledge_setting?: {
1051
1051
  file?: {
1052
1052
  content?: string | undefined;
1053
+ url?: string | undefined;
1053
1054
  title?: string | undefined;
1054
1055
  token?: string | undefined;
1055
1056
  mime_type?: string | undefined;
1056
- url?: string | undefined;
1057
1057
  } | undefined;
1058
1058
  lark_wiki_space?: {
1059
1059
  space_id: string;
@@ -1086,10 +1086,10 @@ export declare const ailyV1Tools: ({
1086
1086
  import_knowledge_setting?: {
1087
1087
  file?: {
1088
1088
  content?: string | undefined;
1089
+ url?: string | undefined;
1089
1090
  title?: string | undefined;
1090
1091
  token?: string | undefined;
1091
1092
  mime_type?: string | undefined;
1092
- url?: string | undefined;
1093
1093
  } | undefined;
1094
1094
  lark_wiki_space?: {
1095
1095
  space_id: string;