feishu-mcp 0.1.9-test.3 → 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.
package/dist/server.js CHANGED
@@ -8,7 +8,6 @@ import { SSEConnectionManager } from './manager/sseConnectionManager.js';
8
8
  import { FeishuMcp } from './mcp/feishuMcp.js';
9
9
  import { callback } from './services/callbackService.js';
10
10
  import { UserAuthManager, UserContextManager, getBaseUrl, TokenCacheManager, TokenRefreshManager } from './utils/auth/index.js';
11
- import { Config } from './utils/config.js';
12
11
  export class FeishuMcpServer {
13
12
  constructor() {
14
13
  Object.defineProperty(this, "connectionManager", {
@@ -47,15 +46,7 @@ export class FeishuMcpServer {
47
46
  }
48
47
  async connect(transport) {
49
48
  const server = new FeishuMcp();
50
- // stdio模式只能本地运行,使用localhost + 配置的端口
51
- const config = Config.getInstance();
52
- const baseUrl = `http://localhost:${config.server.port}`;
53
- await this.userContextManager.run({
54
- userKey: 'stdio',
55
- baseUrl: baseUrl
56
- }, async () => {
57
- await server.connect(transport);
58
- });
49
+ await server.connect(transport);
59
50
  // 监听 transport 关闭事件,清理 callback 服务器
60
51
  // 对于 stdio 模式,监听 stdin 关闭事件
61
52
  if (process.stdin && typeof process.stdin.on === 'function') {
@@ -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
- // 如果 baseUrl 为空,使用默认值(stdio 模式)
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
- return context?.userKey || '';
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
- return context?.baseUrl || '';
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
  * 获取当前完整的用户上下文
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feishu-mcp",
3
- "version": "0.1.9-test.3",
3
+ "version": "0.1.9-test.5",
4
4
  "description": "Model Context Protocol server for Feishu integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",