feishu-mcp 0.1.9-test.4 → 0.1.9-test.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.
|
@@ -309,11 +309,8 @@ export class BaseApiService {
|
|
|
309
309
|
*/
|
|
310
310
|
generateUserAuthUrl(baseUrl, userKey) {
|
|
311
311
|
const { appId, appSecret } = Config.getInstance().feishu;
|
|
312
|
-
const config = Config.getInstance();
|
|
313
312
|
const clientKey = AuthUtils.generateClientKey(userKey);
|
|
314
|
-
|
|
315
|
-
const finalBaseUrl = baseUrl || `http://localhost:${config.server.port}`;
|
|
316
|
-
const redirect_uri = `${finalBaseUrl}/callback`;
|
|
313
|
+
const redirect_uri = `${baseUrl}/callback`;
|
|
317
314
|
const scope = encodeURIComponent('base:app:read bitable:app bitable:app:readonly board:whiteboard:node:read board:whiteboard:node:create contact:user.employee_id:readonly docs:document.content:read docx:document docx:document.block:convert docx:document:create docx:document:readonly drive:drive drive:drive:readonly drive:file drive:file:upload sheets:spreadsheet sheets:spreadsheet:readonly space:document:retrieve space:folder:create wiki:space:read wiki:space:retrieve wiki:wiki wiki:wiki:readonly offline_access');
|
|
318
315
|
const state = AuthUtils.encodeState(appId, appSecret, clientKey, redirect_uri);
|
|
319
316
|
return `https://accounts.feishu.cn/open-apis/authen/v1/authorize?client_id=${appId}&redirect_uri=${encodeURIComponent(redirect_uri)}&scope=${scope}&state=${state}`;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
|
+
import { Config } from '../config.js';
|
|
2
3
|
/**
|
|
3
4
|
* 用户上下文管理器
|
|
4
5
|
* 使用 AsyncLocalStorage 在异步调用链中传递用户信息
|
|
@@ -22,6 +23,13 @@ export class UserContextManager {
|
|
|
22
23
|
}
|
|
23
24
|
return UserContextManager.instance;
|
|
24
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* 检查是否是 stdio 模式
|
|
28
|
+
* @returns 如果是 stdio 模式返回 true
|
|
29
|
+
*/
|
|
30
|
+
static isStdioMode() {
|
|
31
|
+
return process.env.NODE_ENV === "cli" || process.argv.includes("--stdio");
|
|
32
|
+
}
|
|
25
33
|
/**
|
|
26
34
|
* 在指定上下文中运行回调函数
|
|
27
35
|
* @param context 用户上下文
|
|
@@ -33,19 +41,31 @@ export class UserContextManager {
|
|
|
33
41
|
}
|
|
34
42
|
/**
|
|
35
43
|
* 获取当前上下文中的用户密钥
|
|
36
|
-
* @returns
|
|
44
|
+
* @returns 用户密钥,如果不存在则返回默认值(stdio 模式返回 'stdio',否则返回空字符串)
|
|
37
45
|
*/
|
|
38
46
|
getUserKey() {
|
|
39
47
|
const context = this.asyncLocalStorage.getStore();
|
|
40
|
-
|
|
48
|
+
if (context?.userKey) {
|
|
49
|
+
return context.userKey;
|
|
50
|
+
}
|
|
51
|
+
// 如果没有上下文,在 stdio 模式下返回默认值 'stdio'
|
|
52
|
+
return UserContextManager.isStdioMode() ? 'stdio' : '';
|
|
41
53
|
}
|
|
42
54
|
/**
|
|
43
55
|
* 获取当前上下文中的基础URL
|
|
44
|
-
* @returns 基础URL
|
|
56
|
+
* @returns 基础URL,如果不存在则返回默认值(stdio 模式返回 localhost:port,否则返回空字符串)
|
|
45
57
|
*/
|
|
46
58
|
getBaseUrl() {
|
|
47
59
|
const context = this.asyncLocalStorage.getStore();
|
|
48
|
-
|
|
60
|
+
if (context?.baseUrl) {
|
|
61
|
+
return context.baseUrl;
|
|
62
|
+
}
|
|
63
|
+
// 如果没有上下文,在 stdio 模式下返回默认值
|
|
64
|
+
if (UserContextManager.isStdioMode()) {
|
|
65
|
+
const config = Config.getInstance();
|
|
66
|
+
return `http://localhost:${config.server.port}`;
|
|
67
|
+
}
|
|
68
|
+
return '';
|
|
49
69
|
}
|
|
50
70
|
/**
|
|
51
71
|
* 获取当前完整的用户上下文
|