feishu-mcp 0.3.0 → 0.3.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/dist/cli/commands/auth.js +12 -4
- package/dist/cli/dispatcher.js +17 -2
- package/package.json +1 -1
|
@@ -3,6 +3,8 @@ import { createServer as createNetServer } from 'net';
|
|
|
3
3
|
import express from 'express';
|
|
4
4
|
import { Config } from '../../utils/config.js';
|
|
5
5
|
import { AuthUtils, TokenCacheManager } from '../../utils/auth/index.js';
|
|
6
|
+
import { getRequiredScopes } from '../../services/constants/feishuScopes.js';
|
|
7
|
+
import { ModuleRegistry } from '../../modules/index.js';
|
|
6
8
|
// callbackService 需延迟导入,避免其模块级 Config.getInstance() 在 CLI 启动时提前触发 yargs
|
|
7
9
|
const AUTH_TIMEOUT_MS = 5 * 60 * 1000; // 5 分钟
|
|
8
10
|
const POLL_INTERVAL_MS = 1000;
|
|
@@ -87,13 +89,19 @@ export async function handleAuthRequired(userKey) {
|
|
|
87
89
|
// 1. 寻找可用端口(从配置端口开始)
|
|
88
90
|
const port = await findAvailablePort(config.server.port);
|
|
89
91
|
const redirectUri = `http://localhost:${port}/callback`;
|
|
90
|
-
// 2. 计算 clientKey 和 state
|
|
92
|
+
// 2. 计算 clientKey、scope 和 state
|
|
91
93
|
const clientKey = AuthUtils.generateClientKey(userKey);
|
|
94
|
+
const authType = config.feishu.authType;
|
|
95
|
+
const enabledIds = config.features.enabledModules;
|
|
96
|
+
const effectiveModules = ModuleRegistry.getEnabledModules(enabledIds, authType).map(m => m.id);
|
|
97
|
+
const scopeList = getRequiredScopes(effectiveModules, authType);
|
|
98
|
+
const scope = encodeURIComponent(scopeList.join(' '));
|
|
92
99
|
const state = AuthUtils.encodeState(appId, appSecret, clientKey, redirectUri);
|
|
93
|
-
// 3. 构造飞书 OAuth 授权 URL
|
|
94
|
-
const authUrl = `https://
|
|
95
|
-
`?
|
|
100
|
+
// 3. 构造飞书 OAuth 授权 URL(与 baseService.generateUserAuthUrl 保持一致)
|
|
101
|
+
const authUrl = `https://accounts.feishu.cn/open-apis/authen/v1/authorize` +
|
|
102
|
+
`?client_id=${encodeURIComponent(appId)}` +
|
|
96
103
|
`&redirect_uri=${encodeURIComponent(redirectUri)}` +
|
|
104
|
+
`&scope=${scope}` +
|
|
97
105
|
`&state=${encodeURIComponent(state)}`;
|
|
98
106
|
// 4. 启动临时 callback 服务器
|
|
99
107
|
let server;
|
package/dist/cli/dispatcher.js
CHANGED
|
@@ -8,6 +8,21 @@ import { createDocument, getDocumentInfo, getDocumentBlocks, searchDocuments, ba
|
|
|
8
8
|
import { createTasks, listTasks, updateTask, deleteTasks } from '../modules/task/toolApi/index.js';
|
|
9
9
|
// Member toolApis
|
|
10
10
|
import { getUsers } from '../modules/member/toolApi/index.js';
|
|
11
|
+
/** 将 getImageResource 返回的 Buffer 转为 base64 字符串输出 */
|
|
12
|
+
async function getImageResourceAsBase64(mediaId, extra, svc) {
|
|
13
|
+
const result = await getImageResource(mediaId, extra, svc);
|
|
14
|
+
const buf = result instanceof Buffer ? result : Buffer.from(result.data);
|
|
15
|
+
return { base64: buf.toString('base64') };
|
|
16
|
+
}
|
|
17
|
+
/** 将 getWhiteboardContent 返回的 Buffer 缩略图转为 base64 字符串输出 */
|
|
18
|
+
async function getWhiteboardContentSafe(whiteboardId, svc) {
|
|
19
|
+
const result = await getWhiteboardContent(whiteboardId, svc);
|
|
20
|
+
if (result.type === 'thumbnail') {
|
|
21
|
+
const buf = result.buffer instanceof Buffer ? result.buffer : Buffer.from(result.buffer.data);
|
|
22
|
+
return { type: 'thumbnail', base64: buf.toString('base64') };
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
11
26
|
/**
|
|
12
27
|
* 按模块组织的工具注册表,与 src/modules 目录划分保持一致
|
|
13
28
|
*/
|
|
@@ -22,10 +37,10 @@ const MODULE_REGISTRY = {
|
|
|
22
37
|
batch_update_feishu_block_text: (p, s) => batchUpdateBlockText(p, s),
|
|
23
38
|
batch_create_feishu_blocks: (p, s) => batchCreateBlocks(p, s),
|
|
24
39
|
delete_feishu_document_blocks: (p, s) => deleteDocumentBlocks(p, s),
|
|
25
|
-
get_feishu_image_resource: (p, s) =>
|
|
40
|
+
get_feishu_image_resource: (p, s) => getImageResourceAsBase64(p.mediaId, p.extra ?? '', s),
|
|
26
41
|
upload_and_bind_image_to_block: (p, s) => uploadAndBindImageToBlock(p, s),
|
|
27
42
|
create_feishu_table: (p, s) => createTable(p, s),
|
|
28
|
-
get_feishu_whiteboard_content: (p, s) =>
|
|
43
|
+
get_feishu_whiteboard_content: (p, s) => getWhiteboardContentSafe(p.whiteboardId, s),
|
|
29
44
|
fill_whiteboard_with_plantuml: (p, s) => fillWhiteboardWithPlantuml(p, s),
|
|
30
45
|
get_feishu_root_folder_info: (_p, s) => getRootFolderInfo(s),
|
|
31
46
|
get_feishu_folder_files: (p, s) => getFolderFiles(p, s),
|