feishu-mcp 0.0.6 → 0.0.7

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/README.md CHANGED
@@ -153,13 +153,8 @@ bunx feishu-mcp --feishu-app-id=<你的飞书应用ID> --feishu-app-secret=<你
153
153
  在飞书开发平台测试权限正常(在开放平台调试,失败时会有充足提示信息和指导)
154
154
 
155
155
  ### 文档授权
156
- 如遇到权限问题,请参考[云文档常见问题](https://open.feishu.cn/document/ukTMukTMukTM/uczNzUjL3czM14yN3MTN),特别关注如何为应用或用户开通文档权限。
156
+ 如遇到权限问题,请参考[云文档常见问题](https://open.feishu.cn/document/ukTMukTMukTM/uczNzUjL3czM14yN3MTN)、[知识库常见问题](https://open.feishu.cn/document/server-docs/docs/wiki-v2/wiki-qa),特别关注如何为应用或用户开通文档权限。
157
157
 
158
- ## Cursor最佳实践
159
-
160
- 添加Rules指导模型操作流程
161
-
162
- `在将文档上传至飞书时,请遵循以下操作指南:1. 若未特别指定 folderToken,默认为 FPKvf*********6RnOc。2. 在块创建失败的情况下,通过查询文档中所有的块信息,以确认是否确实发生了失败。3. 若需在现有文档中追加信息,请先获取该文档的所有块信息,并根据返回结果确定要插入的内容及其索引位置。4. 一旦文档内容全部修改完成,请提供文档链接,格式如下: https://vq5iay***bc.feishu.cn/docx/documentId。5.获取文档信息时应优先查询其纯文本内容,如果不满足则通过查询所有块来确定内容`
163
158
  ## 许可证
164
159
 
165
160
  MIT
package/dist/config.js CHANGED
@@ -1,104 +1,26 @@
1
- import { config } from "dotenv";
2
- import yargs from "yargs";
3
- import { hideBin } from "yargs/helpers";
4
- // 确保在任何配置读取前加载.env文件
5
- config();
6
- function maskApiKey(key) {
7
- if (key.length <= 4)
8
- return "****";
9
- return `****${key.slice(-4)}`;
10
- }
1
+ import { Config, ConfigSource } from './utils/config.js';
2
+ /**
3
+ * 为了向后兼容,保留getServerConfig函数
4
+ * 但内部使用Config类
5
+ * @param isStdioMode 是否在stdio模式下
6
+ * @returns 服务器配置
7
+ */
11
8
  export function getServerConfig(isStdioMode) {
12
- // Parse command line arguments
13
- const argv = yargs(hideBin(process.argv))
14
- .options({
15
- port: {
16
- type: "number",
17
- description: "Port to run the server on",
18
- },
19
- "feishu-app-id": {
20
- type: "string",
21
- description: "Feishu App ID",
22
- },
23
- "feishu-app-secret": {
24
- type: "string",
25
- description: "Feishu App Secret",
26
- },
27
- })
28
- .help()
29
- .parseSync();
30
- const config = {
31
- port: 3333,
32
- configSources: {
33
- port: "default",
34
- },
35
- };
36
- // Handle PORT
37
- if (argv.port) {
38
- config.port = argv.port;
39
- config.configSources.port = "cli";
40
- }
41
- else if (process.env.PORT) {
42
- config.port = parseInt(process.env.PORT, 10);
43
- config.configSources.port = "env";
44
- }
45
- // 在加载环境变量之前添加日志
46
- console.log('开始加载环境变量配置...');
47
- console.log('当前环境变量 FEISHU_APP_ID:', process.env.FEISHU_APP_ID);
48
- console.log('当前环境变量 FEISHU_APP_SECRET:', process.env.FEISHU_APP_SECRET);
49
- // Handle Feishu configuration
50
- if (argv["feishu-app-id"]) {
51
- config.feishuAppId = argv["feishu-app-id"];
52
- config.configSources.feishuAppId = "cli";
53
- console.log(`飞书应用 ID 来自命令行参数: ${maskApiKey(config.feishuAppId)}`);
54
- }
55
- else if (process.env.FEISHU_APP_ID) {
56
- config.feishuAppId = process.env.FEISHU_APP_ID;
57
- config.configSources.feishuAppId = "env";
58
- console.log(`飞书应用 ID 来自环境变量: ${maskApiKey(config.feishuAppId)}`);
59
- }
60
- else {
61
- console.log('未提供飞书应用 ID');
62
- }
63
- if (argv["feishu-app-secret"]) {
64
- config.feishuAppSecret = argv["feishu-app-secret"];
65
- config.configSources.feishuAppSecret = "cli";
66
- console.log(`飞书应用密钥来自命令行参数: ${maskApiKey(config.feishuAppSecret)}`);
67
- }
68
- else if (process.env.FEISHU_APP_SECRET) {
69
- config.feishuAppSecret = process.env.FEISHU_APP_SECRET;
70
- config.configSources.feishuAppSecret = "env";
71
- console.log(`飞书应用密钥来自环境变量: ${maskApiKey(config.feishuAppSecret)}`);
72
- }
73
- else {
74
- console.log('未提供飞书应用密钥');
75
- }
76
- // 输出飞书配置状态总结
77
- if (config.feishuAppId && config.feishuAppSecret) {
78
- console.log('飞书配置已完整提供,服务将被初始化');
79
- }
80
- else if (config.feishuAppId || config.feishuAppSecret) {
81
- console.log('飞书配置不完整,服务将不会初始化');
82
- }
83
- else {
84
- console.log('未提供飞书配置,服务将不会初始化');
85
- }
86
- // 验证配置
87
- if (!config.feishuAppId || !config.feishuAppSecret) {
88
- console.error("FEISHU_APP_ID 和 FEISHU_APP_SECRET 是必需的(通过命令行参数 --feishu-app-id 和 --feishu-app-secret 或 .env 文件)");
89
- process.exit(1);
90
- }
91
- // Log configuration sources
9
+ const config = Config.getInstance();
92
10
  if (!isStdioMode) {
93
- console.log("\n配置信息:");
94
- console.log(`- PORT: ${config.port} (来源: ${config.configSources.port})`);
95
- if (config.feishuAppId) {
96
- console.log(`- FEISHU_APP_ID: ${maskApiKey(config.feishuAppId)} (来源: ${config.configSources.feishuAppId})`);
97
- }
98
- if (config.feishuAppSecret) {
99
- console.log(`- FEISHU_APP_SECRET: ${maskApiKey(config.feishuAppSecret)} (来源: ${config.configSources.feishuAppSecret})`);
100
- }
101
- console.log(); // 空行,提高可读性
11
+ config.printConfig(isStdioMode);
102
12
  }
103
- return config;
13
+ // 为了向后兼容,返回旧格式的配置对象
14
+ return {
15
+ port: config.server.port,
16
+ feishuAppId: config.feishu.appId,
17
+ feishuAppSecret: config.feishu.appSecret,
18
+ configSources: {
19
+ port: config.configSources['server.port'].toLowerCase(),
20
+ feishuAppId: config.configSources['feishu.appId']?.toLowerCase(),
21
+ feishuAppSecret: config.configSources['feishu.appSecret']?.toLowerCase()
22
+ }
23
+ };
104
24
  }
25
+ // 导出Config类
26
+ export { Config, ConfigSource };
package/dist/index.js CHANGED
@@ -1,29 +1,30 @@
1
1
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
2
2
  import { FeishuMcpServer } from "./server.js";
3
- import { getServerConfig } from "./config.js";
3
+ import { Config } from "./utils/config.js";
4
4
  import { fileURLToPath } from 'url';
5
5
  import { resolve } from 'path';
6
6
  export async function startServer() {
7
7
  // Check if we're running in stdio mode (e.g., via CLI)
8
8
  const isStdioMode = process.env.NODE_ENV === "cli" || process.argv.includes("--stdio");
9
- const config = getServerConfig(isStdioMode);
10
- // 创建飞书配置对象
11
- const feishuConfig = {
12
- appId: config.feishuAppId,
13
- appSecret: config.feishuAppSecret
14
- };
15
- console.log("Feishu configuration status: Available");
16
- console.log(`Feishu App ID: ${feishuConfig.appId.substring(0, 4)}...${feishuConfig.appId.substring(feishuConfig.appId.length - 4)}`);
17
- console.log(`Feishu App Secret: ${feishuConfig.appSecret.substring(0, 4)}...${feishuConfig.appSecret.substring(feishuConfig.appSecret.length - 4)}`);
18
- const server = new FeishuMcpServer(feishuConfig);
9
+ // 获取配置实例
10
+ const config = Config.getInstance();
11
+ // 打印配置信息
12
+ config.printConfig(isStdioMode);
13
+ // 验证配置
14
+ if (!config.validate()) {
15
+ console.error("配置验证失败,无法启动服务器");
16
+ process.exit(1);
17
+ }
18
+ // 创建MCP服务器
19
+ const server = new FeishuMcpServer();
19
20
  console.log(`isStdioMode:${isStdioMode}`);
20
21
  if (isStdioMode) {
21
22
  const transport = new StdioServerTransport();
22
23
  await server.connect(transport);
23
24
  }
24
25
  else {
25
- console.log(`Initializing Feishu MCP Server in HTTP mode on port ${config.port}...`);
26
- await server.startHttpServer(config.port);
26
+ console.log(`Initializing Feishu MCP Server in HTTP mode on port ${config.server.port}...`);
27
+ await server.startHttpServer(config.server.port);
27
28
  }
28
29
  }
29
30
  // 跨平台兼容的方式检查是否直接运行