feishu-mcp 0.1.9-test.5 → 0.1.9-test.6

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.
@@ -9,6 +9,13 @@ import { TokenCacheManager, UserContextManager, AuthUtils } from '../utils/auth/
9
9
  * 提供通用的HTTP请求处理和认证功能
10
10
  */
11
11
  export class BaseApiService {
12
+ /**
13
+ * 检查是否是 stdio 模式
14
+ * @returns 如果是 stdio 模式返回 true
15
+ */
16
+ isStdioMode() {
17
+ return process.env.NODE_ENV === "cli" || process.argv.includes("--stdio");
18
+ }
12
19
  /**
13
20
  * 处理API错误
14
21
  * @param error 错误对象
@@ -59,9 +66,20 @@ export class BaseApiService {
59
66
  */
60
67
  async request(endpoint, method = 'GET', data, needsAuth = true, additionalHeaders, responseType, retry = false) {
61
68
  // 获取用户上下文
62
- const userContextManager = UserContextManager.getInstance();
63
- const userKey = userContextManager.getUserKey();
64
- const baseUrl = userContextManager.getBaseUrl();
69
+ let userKey;
70
+ let baseUrl;
71
+ if (this.isStdioMode()) {
72
+ // stdio 模式下直接使用默认值
73
+ userKey = 'stdio';
74
+ const config = Config.getInstance();
75
+ baseUrl = `http://localhost:${config.server.port}`;
76
+ }
77
+ else {
78
+ // HTTP 模式下从 UserContextManager 读取
79
+ const userContextManager = UserContextManager.getInstance();
80
+ userKey = userContextManager.getUserKey();
81
+ baseUrl = userContextManager.getBaseUrl();
82
+ }
65
83
  const clientKey = AuthUtils.generateClientKey(userKey);
66
84
  Logger.debug(`[BaseService] Request context - userKey: ${userKey}, baseUrl: ${baseUrl}`);
67
85
  try {
@@ -1,5 +1,4 @@
1
1
  import { AsyncLocalStorage } from 'async_hooks';
2
- import { Config } from '../config.js';
3
2
  /**
4
3
  * 用户上下文管理器
5
4
  * 使用 AsyncLocalStorage 在异步调用链中传递用户信息
@@ -23,13 +22,6 @@ export class UserContextManager {
23
22
  }
24
23
  return UserContextManager.instance;
25
24
  }
26
- /**
27
- * 检查是否是 stdio 模式
28
- * @returns 如果是 stdio 模式返回 true
29
- */
30
- static isStdioMode() {
31
- return process.env.NODE_ENV === "cli" || process.argv.includes("--stdio");
32
- }
33
25
  /**
34
26
  * 在指定上下文中运行回调函数
35
27
  * @param context 用户上下文
@@ -41,31 +33,19 @@ export class UserContextManager {
41
33
  }
42
34
  /**
43
35
  * 获取当前上下文中的用户密钥
44
- * @returns 用户密钥,如果不存在则返回默认值(stdio 模式返回 'stdio',否则返回空字符串)
36
+ * @returns 用户密钥,如果不存在则返回空字符串
45
37
  */
46
38
  getUserKey() {
47
39
  const context = this.asyncLocalStorage.getStore();
48
- if (context?.userKey) {
49
- return context.userKey;
50
- }
51
- // 如果没有上下文,在 stdio 模式下返回默认值 'stdio'
52
- return UserContextManager.isStdioMode() ? 'stdio' : '';
40
+ return context?.userKey || '';
53
41
  }
54
42
  /**
55
43
  * 获取当前上下文中的基础URL
56
- * @returns 基础URL,如果不存在则返回默认值(stdio 模式返回 localhost:port,否则返回空字符串)
44
+ * @returns 基础URL,如果不存在则返回空字符串
57
45
  */
58
46
  getBaseUrl() {
59
47
  const context = this.asyncLocalStorage.getStore();
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 '';
48
+ return context?.baseUrl || '';
69
49
  }
70
50
  /**
71
51
  * 获取当前完整的用户上下文
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feishu-mcp",
3
- "version": "0.1.9-test.5",
3
+ "version": "0.1.9-test.6",
4
4
  "description": "Model Context Protocol server for Feishu integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",