chaimi-keep-mcp 3.1.45-beta.6 → 3.1.45-beta.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/oauth.js +2 -5
- package/package.json +1 -1
- package/server.js +7 -29
package/oauth.js
CHANGED
|
@@ -312,19 +312,16 @@ class OAuthManager {
|
|
|
312
312
|
const fs = require('fs').promises;
|
|
313
313
|
const path = require('path');
|
|
314
314
|
const stateFile = path.join(require('os').homedir(), '.mcporter', 'auth-state.json');
|
|
315
|
-
|
|
315
|
+
|
|
316
316
|
const dir = path.dirname(stateFile);
|
|
317
317
|
await fs.mkdir(dir, { recursive: true });
|
|
318
|
-
|
|
318
|
+
|
|
319
319
|
await fs.writeFile(
|
|
320
320
|
stateFile,
|
|
321
321
|
JSON.stringify(state, null, 2),
|
|
322
322
|
{ mode: 0o600 }
|
|
323
323
|
);
|
|
324
|
-
console.error('✅ 授权状态已保存');
|
|
325
324
|
} catch (err) {
|
|
326
|
-
console.error('❌ 保存授权状态失败:', err.message);
|
|
327
|
-
throw err;
|
|
328
325
|
}
|
|
329
326
|
}
|
|
330
327
|
|
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -54,26 +54,11 @@ async function fetchConfigFromCloud() {
|
|
|
54
54
|
async function initializeConfig() {
|
|
55
55
|
const fs = require('fs');
|
|
56
56
|
const path = require('path');
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
// XDG 标准配置目录
|
|
60
|
-
// Linux/macOS: ~/.config/chaimi-keep-mcp/
|
|
61
|
-
// Windows: %APPDATA%/chaimi-keep-mcp/ (通过设置 XDG_CONFIG_HOME 环境变量)
|
|
62
|
-
const xdgConfigHome = process.env.XDG_CONFIG_HOME;
|
|
63
|
-
const configDir = xdgConfigHome
|
|
64
|
-
? path.join(xdgConfigHome, 'chaimi-keep-mcp')
|
|
65
|
-
: path.join(os.homedir(), '.config', 'chaimi-keep-mcp');
|
|
66
|
-
|
|
67
|
-
// 确保配置目录存在
|
|
68
|
-
if (!fs.existsSync(configDir)) {
|
|
69
|
-
fs.mkdirSync(configDir, { recursive: true, mode: 0o700 });
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const envPath = path.join(configDir, envFile);
|
|
57
|
+
const envPath = path.join(__dirname, envFile);
|
|
73
58
|
|
|
74
|
-
//
|
|
59
|
+
// 如果配置文件已存在,直接返回
|
|
75
60
|
if (fs.existsSync(envPath)) {
|
|
76
|
-
return
|
|
61
|
+
return;
|
|
77
62
|
}
|
|
78
63
|
|
|
79
64
|
// 首次启动,尝试从云端获取配置
|
|
@@ -117,7 +102,8 @@ JWT_SECRET=${config.JWT_SECRET}
|
|
|
117
102
|
console.error(` 文件位置:${envPath}`);
|
|
118
103
|
console.error('');
|
|
119
104
|
|
|
120
|
-
|
|
105
|
+
// 重新加载环境变量
|
|
106
|
+
require('dotenv').config({ path: envPath });
|
|
121
107
|
}
|
|
122
108
|
|
|
123
109
|
const { Server } = require('@modelcontextprotocol/sdk/server/index.js');
|
|
@@ -736,15 +722,10 @@ async function callMcpPrompt(tool, params, token) {
|
|
|
736
722
|
// 生成请求签名(用于验证请求来自合法 MCP Server)
|
|
737
723
|
function generateSignature(body, timestamp, secret) {
|
|
738
724
|
const payload = JSON.stringify(body) + timestamp;
|
|
739
|
-
|
|
725
|
+
return crypto
|
|
740
726
|
.createHmac('sha256', secret)
|
|
741
727
|
.update(payload)
|
|
742
728
|
.digest('hex');
|
|
743
|
-
// 调试日志(仅在开发环境显示)
|
|
744
|
-
if (process.env.DEBUG_MCP === 'true') {
|
|
745
|
-
console.error('[DEBUG] 生成签名:', { payload: payload.substring(0, 100), timestamp, signature: signature.substring(0, 16) + '...' });
|
|
746
|
-
}
|
|
747
|
-
return signature;
|
|
748
729
|
}
|
|
749
730
|
|
|
750
731
|
// MCP 调用日志记录函数
|
|
@@ -2099,10 +2080,7 @@ let authState = {
|
|
|
2099
2080
|
|
|
2100
2081
|
async function main() {
|
|
2101
2082
|
// 首次启动时自动获取配置
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
// 加载环境变量(无论文件是否存在都需要加载)
|
|
2105
|
-
require('dotenv').config({ path: envPath });
|
|
2083
|
+
await initializeConfig();
|
|
2106
2084
|
|
|
2107
2085
|
// 加载环境变量后赋值
|
|
2108
2086
|
CHAIMI_API_SECRET = process.env.CHAIMI_API_SECRET;
|