axhub-mcp-bridge 1.0.30
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/README.md +25 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +158 -0
- package/dist/cli.js.map +1 -0
- package/dist/constant/index.d.ts +38 -0
- package/dist/constant/index.js +47 -0
- package/dist/constant/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/mcp-server-stdio.d.ts +50 -0
- package/dist/mcp/mcp-server-stdio.js +135 -0
- package/dist/mcp/mcp-server-stdio.js.map +1 -0
- package/dist/mcp/mcp-server.d.ts +25 -0
- package/dist/mcp/mcp-server.js +23 -0
- package/dist/mcp/mcp-server.js.map +1 -0
- package/dist/mcp/register-tools.d.ts +2 -0
- package/dist/mcp/register-tools.js +51 -0
- package/dist/mcp/register-tools.js.map +1 -0
- package/dist/mcp/stdio-config.json +3 -0
- package/dist/native-messaging-host.d.ts +38 -0
- package/dist/native-messaging-host.js +241 -0
- package/dist/native-messaging-host.js.map +1 -0
- package/dist/run_host.bat +95 -0
- package/dist/run_host.sh +141 -0
- package/dist/scripts/build.d.ts +1 -0
- package/dist/scripts/build.js +119 -0
- package/dist/scripts/build.js.map +1 -0
- package/dist/scripts/constant.d.ts +11 -0
- package/dist/scripts/constant.js +45 -0
- package/dist/scripts/constant.js.map +1 -0
- package/dist/scripts/postinstall.d.ts +2 -0
- package/dist/scripts/postinstall.js +231 -0
- package/dist/scripts/postinstall.js.map +1 -0
- package/dist/scripts/register-dev.d.ts +1 -0
- package/dist/scripts/register-dev.js +5 -0
- package/dist/scripts/register-dev.js.map +1 -0
- package/dist/scripts/register.d.ts +2 -0
- package/dist/scripts/register.js +22 -0
- package/dist/scripts/register.js.map +1 -0
- package/dist/scripts/utils.d.ts +36 -0
- package/dist/scripts/utils.js +353 -0
- package/dist/scripts/utils.js.map +1 -0
- package/dist/server/index.d.ts +24 -0
- package/dist/server/index.js +266 -0
- package/dist/server/index.js.map +1 -0
- package/dist/shared.d.ts +62 -0
- package/dist/shared.js +209 -0
- package/dist/shared.js.map +1 -0
- package/dist/util/logger.d.ts +1 -0
- package/dist/util/logger.js +43 -0
- package/dist/util/logger.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.writeFile = exports.mkdir = exports.access = void 0;
|
|
7
|
+
exports.colorText = colorText;
|
|
8
|
+
exports.getUserManifestPath = getUserManifestPath;
|
|
9
|
+
exports.getSystemManifestPath = getSystemManifestPath;
|
|
10
|
+
exports.getMainPath = getMainPath;
|
|
11
|
+
exports.ensureExecutionPermissions = ensureExecutionPermissions;
|
|
12
|
+
exports.createManifestContent = createManifestContent;
|
|
13
|
+
exports.tryRegisterUserLevelHost = tryRegisterUserLevelHost;
|
|
14
|
+
exports.registerWithElevatedPermissions = registerWithElevatedPermissions;
|
|
15
|
+
const fs_1 = __importDefault(require("fs"));
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const os_1 = __importDefault(require("os"));
|
|
18
|
+
const child_process_1 = require("child_process");
|
|
19
|
+
const util_1 = require("util");
|
|
20
|
+
const constant_1 = require("./constant");
|
|
21
|
+
exports.access = (0, util_1.promisify)(fs_1.default.access);
|
|
22
|
+
exports.mkdir = (0, util_1.promisify)(fs_1.default.mkdir);
|
|
23
|
+
exports.writeFile = (0, util_1.promisify)(fs_1.default.writeFile);
|
|
24
|
+
/**
|
|
25
|
+
* 打印彩色文本
|
|
26
|
+
*/
|
|
27
|
+
function colorText(text, color) {
|
|
28
|
+
const colors = {
|
|
29
|
+
red: '\x1b[31m',
|
|
30
|
+
green: '\x1b[32m',
|
|
31
|
+
yellow: '\x1b[33m',
|
|
32
|
+
blue: '\x1b[34m',
|
|
33
|
+
reset: '\x1b[0m',
|
|
34
|
+
};
|
|
35
|
+
return colors[color] + text + colors.reset;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get user-level manifest file path
|
|
39
|
+
*/
|
|
40
|
+
function getUserManifestPath() {
|
|
41
|
+
if (os_1.default.platform() === 'win32') {
|
|
42
|
+
// Windows: %APPDATA%\Google\Chrome\NativeMessagingHosts\
|
|
43
|
+
return path_1.default.join(process.env.APPDATA || path_1.default.join(os_1.default.homedir(), 'AppData', 'Roaming'), 'Google', 'Chrome', 'NativeMessagingHosts', `${constant_1.HOST_NAME}.json`);
|
|
44
|
+
}
|
|
45
|
+
else if (os_1.default.platform() === 'darwin') {
|
|
46
|
+
// macOS: ~/Library/Application Support/Google/Chrome/NativeMessagingHosts/
|
|
47
|
+
return path_1.default.join(os_1.default.homedir(), 'Library', 'Application Support', 'Google', 'Chrome', 'NativeMessagingHosts', `${constant_1.HOST_NAME}.json`);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// Linux: ~/.config/google-chrome/NativeMessagingHosts/
|
|
51
|
+
return path_1.default.join(os_1.default.homedir(), '.config', 'google-chrome', 'NativeMessagingHosts', `${constant_1.HOST_NAME}.json`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get system-level manifest file path
|
|
56
|
+
*/
|
|
57
|
+
function getSystemManifestPath() {
|
|
58
|
+
if (os_1.default.platform() === 'win32') {
|
|
59
|
+
// Windows: %ProgramFiles%\Google\Chrome\NativeMessagingHosts\
|
|
60
|
+
return path_1.default.join(process.env.ProgramFiles || 'C:\\Program Files', 'Google', 'Chrome', 'NativeMessagingHosts', `${constant_1.HOST_NAME}.json`);
|
|
61
|
+
}
|
|
62
|
+
else if (os_1.default.platform() === 'darwin') {
|
|
63
|
+
// macOS: /Library/Google/Chrome/NativeMessagingHosts/
|
|
64
|
+
return path_1.default.join('/Library', 'Google', 'Chrome', 'NativeMessagingHosts', `${constant_1.HOST_NAME}.json`);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// Linux: /etc/opt/chrome/native-messaging-hosts/
|
|
68
|
+
return path_1.default.join('/etc', 'opt', 'chrome', 'native-messaging-hosts', `${constant_1.HOST_NAME}.json`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get native host startup script file path
|
|
73
|
+
*/
|
|
74
|
+
async function getMainPath() {
|
|
75
|
+
try {
|
|
76
|
+
const packageDistDir = path_1.default.join(__dirname, '..');
|
|
77
|
+
const wrapperScriptName = process.platform === 'win32' ? 'run_host.bat' : 'run_host.sh';
|
|
78
|
+
const absoluteWrapperPath = path_1.default.resolve(packageDistDir, wrapperScriptName);
|
|
79
|
+
return absoluteWrapperPath;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
console.log(colorText('Cannot find global package path, using current directory', 'yellow'));
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 确保关键文件具有执行权限
|
|
88
|
+
*/
|
|
89
|
+
async function ensureExecutionPermissions() {
|
|
90
|
+
try {
|
|
91
|
+
const packageDistDir = path_1.default.join(__dirname, '..');
|
|
92
|
+
if (process.platform === 'win32') {
|
|
93
|
+
// Windows 平台处理
|
|
94
|
+
await ensureWindowsFilePermissions(packageDistDir);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
// Unix/Linux 平台处理
|
|
98
|
+
const filesToCheck = [
|
|
99
|
+
path_1.default.join(packageDistDir, 'index.js'),
|
|
100
|
+
path_1.default.join(packageDistDir, 'run_host.sh'),
|
|
101
|
+
path_1.default.join(packageDistDir, 'cli.js'),
|
|
102
|
+
];
|
|
103
|
+
for (const filePath of filesToCheck) {
|
|
104
|
+
if (fs_1.default.existsSync(filePath)) {
|
|
105
|
+
try {
|
|
106
|
+
fs_1.default.chmodSync(filePath, '755');
|
|
107
|
+
console.log(colorText(`✓ Set execution permissions for ${path_1.default.basename(filePath)}`, 'green'));
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
console.warn(colorText(`⚠️ Unable to set execution permissions for ${path_1.default.basename(filePath)}: ${err.message}`, 'yellow'));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
console.warn(colorText(`⚠️ File not found: ${filePath}`, 'yellow'));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
console.warn(colorText(`⚠️ Error ensuring execution permissions: ${error.message}`, 'yellow'));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Windows 平台文件权限处理
|
|
124
|
+
*/
|
|
125
|
+
async function ensureWindowsFilePermissions(packageDistDir) {
|
|
126
|
+
const filesToCheck = [
|
|
127
|
+
path_1.default.join(packageDistDir, 'index.js'),
|
|
128
|
+
path_1.default.join(packageDistDir, 'run_host.bat'),
|
|
129
|
+
path_1.default.join(packageDistDir, 'cli.js'),
|
|
130
|
+
];
|
|
131
|
+
for (const filePath of filesToCheck) {
|
|
132
|
+
if (fs_1.default.existsSync(filePath)) {
|
|
133
|
+
try {
|
|
134
|
+
// 检查文件是否为只读,如果是则移除只读属性
|
|
135
|
+
const stats = fs_1.default.statSync(filePath);
|
|
136
|
+
if (!(stats.mode & parseInt('200', 8))) {
|
|
137
|
+
// 检查写权限
|
|
138
|
+
// 尝试移除只读属性
|
|
139
|
+
fs_1.default.chmodSync(filePath, stats.mode | parseInt('200', 8));
|
|
140
|
+
console.log(colorText(`✓ Removed read-only attribute from ${path_1.default.basename(filePath)}`, 'green'));
|
|
141
|
+
}
|
|
142
|
+
// 验证文件可读性
|
|
143
|
+
fs_1.default.accessSync(filePath, fs_1.default.constants.R_OK);
|
|
144
|
+
console.log(colorText(`✓ Verified file accessibility for ${path_1.default.basename(filePath)}`, 'green'));
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
console.warn(colorText(`⚠️ Unable to verify file permissions for ${path_1.default.basename(filePath)}: ${err.message}`, 'yellow'));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
console.warn(colorText(`⚠️ File not found: ${filePath}`, 'yellow'));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Create Native Messaging host manifest content
|
|
157
|
+
*/
|
|
158
|
+
async function createManifestContent() {
|
|
159
|
+
const mainPath = await getMainPath();
|
|
160
|
+
return {
|
|
161
|
+
name: constant_1.HOST_NAME,
|
|
162
|
+
description: constant_1.DESCRIPTION,
|
|
163
|
+
path: mainPath, // Node.js可执行文件路径
|
|
164
|
+
type: 'stdio',
|
|
165
|
+
allowed_origins: [`chrome-extension://${constant_1.EXTENSION_ID}/`],
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* 验证Windows注册表项是否存在
|
|
170
|
+
*/
|
|
171
|
+
function verifyWindowsRegistryEntry(registryKey, expectedPath) {
|
|
172
|
+
if (os_1.default.platform() !== 'win32') {
|
|
173
|
+
return true; // 非Windows平台跳过验证
|
|
174
|
+
}
|
|
175
|
+
try {
|
|
176
|
+
const result = (0, child_process_1.execSync)(`reg query "${registryKey}" /ve`, { encoding: 'utf8', stdio: 'pipe' });
|
|
177
|
+
const lines = result.split('\n');
|
|
178
|
+
for (const line of lines) {
|
|
179
|
+
if (line.includes('REG_SZ') && line.includes(expectedPath.replace(/\\/g, '\\\\'))) {
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* 尝试注册用户级别的Native Messaging主机
|
|
191
|
+
*/
|
|
192
|
+
async function tryRegisterUserLevelHost() {
|
|
193
|
+
try {
|
|
194
|
+
console.log(colorText('Attempting to register user-level Native Messaging host...', 'blue'));
|
|
195
|
+
// 1. 确保执行权限
|
|
196
|
+
await ensureExecutionPermissions();
|
|
197
|
+
// 2. 确定清单文件路径
|
|
198
|
+
const manifestPath = getUserManifestPath();
|
|
199
|
+
// 3. 确保目录存在
|
|
200
|
+
await (0, exports.mkdir)(path_1.default.dirname(manifestPath), { recursive: true });
|
|
201
|
+
// 4. 创建清单内容
|
|
202
|
+
const manifest = await createManifestContent();
|
|
203
|
+
console.log('manifest path==>', manifest, manifestPath);
|
|
204
|
+
// 5. 写入清单文件
|
|
205
|
+
await (0, exports.writeFile)(manifestPath, JSON.stringify(manifest, null, 2));
|
|
206
|
+
if (os_1.default.platform() === 'win32') {
|
|
207
|
+
const registryKey = `HKCU\\Software\\Google\\Chrome\\NativeMessagingHosts\\${constant_1.HOST_NAME}`;
|
|
208
|
+
try {
|
|
209
|
+
// 确保路径使用正确的转义格式
|
|
210
|
+
const escapedPath = manifestPath.replace(/\\/g, '\\\\');
|
|
211
|
+
const regCommand = `reg add "${registryKey}" /ve /t REG_SZ /d "${escapedPath}" /f`;
|
|
212
|
+
console.log(colorText(`Executing registry command: ${regCommand}`, 'blue'));
|
|
213
|
+
(0, child_process_1.execSync)(regCommand, { stdio: 'pipe' });
|
|
214
|
+
// 验证注册表项是否创建成功
|
|
215
|
+
if (verifyWindowsRegistryEntry(registryKey, manifestPath)) {
|
|
216
|
+
console.log(colorText('✓ Successfully created Windows registry entry', 'green'));
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
console.log(colorText('⚠️ Registry entry created but verification failed', 'yellow'));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
console.log(colorText(`⚠️ Unable to create Windows registry entry: ${error.message}`, 'yellow'));
|
|
224
|
+
console.log(colorText(`Registry key: ${registryKey}`, 'yellow'));
|
|
225
|
+
console.log(colorText(`Manifest path: ${manifestPath}`, 'yellow'));
|
|
226
|
+
return false; // Windows上如果注册表项创建失败,整个注册过程应该视为失败
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
console.log(colorText('Successfully registered user-level Native Messaging host!', 'green'));
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
console.log(colorText(`User-level registration failed: ${error instanceof Error ? error.message : String(error)}`, 'yellow'));
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
// 导入is-admin包(仅在Windows平台使用)
|
|
238
|
+
let isAdmin = async () => false;
|
|
239
|
+
if (process.platform === 'win32') {
|
|
240
|
+
try {
|
|
241
|
+
// 动态导入 ESM 模块
|
|
242
|
+
isAdmin = async () => {
|
|
243
|
+
const mod = await import('is-admin');
|
|
244
|
+
return mod.default();
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
console.warn('缺少is-admin依赖,Windows平台下可能无法正确检测管理员权限');
|
|
249
|
+
console.warn(error);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* 使用提升权限注册系统级清单
|
|
254
|
+
*/
|
|
255
|
+
async function registerWithElevatedPermissions() {
|
|
256
|
+
try {
|
|
257
|
+
console.log(colorText('Attempting to register system-level manifest...', 'blue'));
|
|
258
|
+
// 1. 确保执行权限
|
|
259
|
+
await ensureExecutionPermissions();
|
|
260
|
+
// 2. 准备清单内容
|
|
261
|
+
const manifest = await createManifestContent();
|
|
262
|
+
// 3. 获取系统级清单路径
|
|
263
|
+
const manifestPath = getSystemManifestPath();
|
|
264
|
+
// 4. 创建临时清单文件
|
|
265
|
+
const tempManifestPath = path_1.default.join(os_1.default.tmpdir(), `${constant_1.HOST_NAME}.json`);
|
|
266
|
+
await (0, exports.writeFile)(tempManifestPath, JSON.stringify(manifest, null, 2));
|
|
267
|
+
// 5. 检测是否已经有管理员权限
|
|
268
|
+
const isRoot = process.getuid && process.getuid() === 0; // Unix/Linux/Mac
|
|
269
|
+
const hasAdminRights = process.platform === 'win32' ? isAdmin() : false; // Windows平台检测管理员权限
|
|
270
|
+
const hasElevatedPermissions = isRoot || hasAdminRights;
|
|
271
|
+
// 准备命令
|
|
272
|
+
const command = os_1.default.platform() === 'win32'
|
|
273
|
+
? `if not exist "${path_1.default.dirname(manifestPath)}" mkdir "${path_1.default.dirname(manifestPath)}" && copy "${tempManifestPath}" "${manifestPath}"`
|
|
274
|
+
: `mkdir -p "${path_1.default.dirname(manifestPath)}" && cp "${tempManifestPath}" "${manifestPath}" && chmod 644 "${manifestPath}"`;
|
|
275
|
+
if (hasElevatedPermissions) {
|
|
276
|
+
// 已经有管理员权限,直接执行命令
|
|
277
|
+
try {
|
|
278
|
+
// 创建目录
|
|
279
|
+
if (!fs_1.default.existsSync(path_1.default.dirname(manifestPath))) {
|
|
280
|
+
fs_1.default.mkdirSync(path_1.default.dirname(manifestPath), { recursive: true });
|
|
281
|
+
}
|
|
282
|
+
// 复制文件
|
|
283
|
+
fs_1.default.copyFileSync(tempManifestPath, manifestPath);
|
|
284
|
+
// 设置权限(非Windows平台)
|
|
285
|
+
if (os_1.default.platform() !== 'win32') {
|
|
286
|
+
fs_1.default.chmodSync(manifestPath, '644');
|
|
287
|
+
}
|
|
288
|
+
console.log(colorText('System-level manifest registration successful!', 'green'));
|
|
289
|
+
}
|
|
290
|
+
catch (error) {
|
|
291
|
+
console.error(colorText(`System-level manifest installation failed: ${error.message}`, 'red'));
|
|
292
|
+
throw error;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
// 没有管理员权限,打印手动操作提示
|
|
297
|
+
console.log(colorText('⚠️ Administrator privileges required for system-level installation', 'yellow'));
|
|
298
|
+
console.log(colorText('Please run one of the following commands with administrator privileges:', 'blue'));
|
|
299
|
+
if (os_1.default.platform() === 'win32') {
|
|
300
|
+
console.log(colorText(' 1. Open Command Prompt as Administrator and run:', 'blue'));
|
|
301
|
+
console.log(colorText(` ${command}`, 'cyan'));
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
console.log(colorText(' 1. Run with sudo:', 'blue'));
|
|
305
|
+
console.log(colorText(` sudo ${command}`, 'cyan'));
|
|
306
|
+
}
|
|
307
|
+
console.log(colorText(' 2. Or run the registration command with elevated privileges:', 'blue'));
|
|
308
|
+
console.log(colorText(` sudo ${constant_1.COMMAND_NAME} register --system`, 'cyan'));
|
|
309
|
+
throw new Error('Administrator privileges required for system-level installation');
|
|
310
|
+
}
|
|
311
|
+
// 6. Windows特殊处理 - 设置系统级注册表
|
|
312
|
+
if (os_1.default.platform() === 'win32') {
|
|
313
|
+
const registryKey = `HKLM\\Software\\Google\\Chrome\\NativeMessagingHosts\\${constant_1.HOST_NAME}`;
|
|
314
|
+
// 确保路径使用正确的转义格式
|
|
315
|
+
const escapedPath = manifestPath.replace(/\\/g, '\\\\');
|
|
316
|
+
const regCommand = `reg add "${registryKey}" /ve /t REG_SZ /d "${escapedPath}" /f`;
|
|
317
|
+
console.log(colorText(`Creating system registry entry: ${registryKey}`, 'blue'));
|
|
318
|
+
console.log(colorText(`Manifest path: ${manifestPath}`, 'blue'));
|
|
319
|
+
if (hasElevatedPermissions) {
|
|
320
|
+
// 已经有管理员权限,直接执行注册表命令
|
|
321
|
+
try {
|
|
322
|
+
(0, child_process_1.execSync)(regCommand, { stdio: 'pipe' });
|
|
323
|
+
// 验证注册表项是否创建成功
|
|
324
|
+
if (verifyWindowsRegistryEntry(registryKey, manifestPath)) {
|
|
325
|
+
console.log(colorText('Windows registry entry created successfully!', 'green'));
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
console.log(colorText('⚠️ Registry entry created but verification failed', 'yellow'));
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
console.error(colorText(`Windows registry entry creation failed: ${error.message}`, 'red'));
|
|
333
|
+
console.error(colorText(`Command: ${regCommand}`, 'red'));
|
|
334
|
+
throw error;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
// 没有管理员权限,打印手动操作提示
|
|
339
|
+
console.log(colorText('⚠️ Administrator privileges required for Windows registry modification', 'yellow'));
|
|
340
|
+
console.log(colorText('Please run the following command as Administrator:', 'blue'));
|
|
341
|
+
console.log(colorText(` ${regCommand}`, 'cyan'));
|
|
342
|
+
console.log(colorText('Or run the registration command with elevated privileges:', 'blue'));
|
|
343
|
+
console.log(colorText(` Run Command Prompt as Administrator and execute: ${constant_1.COMMAND_NAME} register --system`, 'cyan'));
|
|
344
|
+
throw new Error('Administrator privileges required for Windows registry modification');
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
catch (error) {
|
|
349
|
+
console.error(colorText(`注册失败: ${error.message}`, 'red'));
|
|
350
|
+
throw error;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/scripts/utils.ts"],"names":[],"mappings":";;;;;;AAcA,8BAUC;AAKD,kDA+BC;AAKD,sDAiBC;AAKD,kCAUC;AAKD,gEAuCC;AAgDD,sDAUC;AA2BD,4DA0DC;AAoBD,0EAoIC;AApbD,4CAAoB;AACpB,gDAAwB;AACxB,4CAAoB;AACpB,iDAAyC;AACzC,+BAAiC;AACjC,yCAAgF;AAEnE,QAAA,MAAM,GAAG,IAAA,gBAAS,EAAC,YAAE,CAAC,MAAM,CAAC,CAAC;AAC9B,QAAA,KAAK,GAAG,IAAA,gBAAS,EAAC,YAAE,CAAC,KAAK,CAAC,CAAC;AAC5B,QAAA,SAAS,GAAG,IAAA,gBAAS,EAAC,YAAE,CAAC,SAAS,CAAC,CAAC;AAEjD;;GAEG;AACH,SAAgB,SAAS,CAAC,IAAY,EAA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Q,CAAC,CAAC,CAAC;oBACxF,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAU,EAAE,CAAC;oBACpB,OAAO,CAAC,KAAK,CACX,SAAS,CAAC,2CAA2C,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAC7E,CAAC;oBACF,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,YAAY,UAAU,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;oBAC1D,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,mBAAmB;gBACnB,OAAO,CAAC,GAAG,CACT,SAAS,CACP,wEAAwE,EACxE,QAAQ,CACT,CACF,CAAC;gBACF,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,oDAAoD,EAAE,MAAM,CAAC,CAAC,CAAC;gBACrF,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,UAAU,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;gBAClD,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,2DAA2D,EAAE,MAAM,CAAC,CAAC,CAAC;gBAC5F,OAAO,CAAC,GAAG,CACT,SAAS,CACP,sDAAsD,uBAAY,oBAAoB,EACtF,MAAM,CACP,CACF,CAAC;gBAEF,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;YACzF,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,SAAS,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;QAC1D,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { FastifyInstance } from 'fastify';
|
|
2
|
+
import { NativeMessagingHost } from '../native-messaging-host';
|
|
3
|
+
export declare class Server {
|
|
4
|
+
private fastify;
|
|
5
|
+
isRunning: boolean;
|
|
6
|
+
private nativeHost;
|
|
7
|
+
private transportsMap;
|
|
8
|
+
constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Initialize Fastify instance with plugins and routes
|
|
11
|
+
*/
|
|
12
|
+
private initializeFastify;
|
|
13
|
+
/**
|
|
14
|
+
* Associate NativeMessagingHost instance
|
|
15
|
+
*/
|
|
16
|
+
setNativeHost(nativeHost: NativeMessagingHost): void;
|
|
17
|
+
private setupPlugins;
|
|
18
|
+
private setupRoutes;
|
|
19
|
+
start(port: number | undefined, nativeHost: NativeMessagingHost): Promise<void>;
|
|
20
|
+
stop(): Promise<void>;
|
|
21
|
+
getInstance(): FastifyInstance;
|
|
22
|
+
}
|
|
23
|
+
declare const serverInstance: Server;
|
|
24
|
+
export default serverInstance;
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Server = void 0;
|
|
7
|
+
const fastify_1 = __importDefault(require("fastify"));
|
|
8
|
+
const cors_1 = __importDefault(require("@fastify/cors"));
|
|
9
|
+
const constant_1 = require("../constant");
|
|
10
|
+
const sse_js_1 = require("@modelcontextprotocol/sdk/server/sse.js");
|
|
11
|
+
const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
12
|
+
const node_crypto_1 = require("node:crypto");
|
|
13
|
+
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
14
|
+
const mcp_server_1 = require("../mcp/mcp-server");
|
|
15
|
+
class Server {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.isRunning = false; // Changed to public or provide a getter
|
|
18
|
+
this.nativeHost = null;
|
|
19
|
+
this.transportsMap = new Map();
|
|
20
|
+
this.fastify = (0, fastify_1.default)({ logger: constant_1.SERVER_CONFIG.LOGGER_ENABLED });
|
|
21
|
+
this.setupPlugins();
|
|
22
|
+
this.setupRoutes();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Initialize Fastify instance with plugins and routes
|
|
26
|
+
*/
|
|
27
|
+
initializeFastify() {
|
|
28
|
+
this.fastify = (0, fastify_1.default)({ logger: constant_1.SERVER_CONFIG.LOGGER_ENABLED });
|
|
29
|
+
this.setupPlugins();
|
|
30
|
+
this.setupRoutes();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Associate NativeMessagingHost instance
|
|
34
|
+
*/
|
|
35
|
+
setNativeHost(nativeHost) {
|
|
36
|
+
this.nativeHost = nativeHost;
|
|
37
|
+
}
|
|
38
|
+
async setupPlugins() {
|
|
39
|
+
await this.fastify.register(cors_1.default, {
|
|
40
|
+
origin: constant_1.SERVER_CONFIG.CORS_ORIGIN,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
setupRoutes() {
|
|
44
|
+
// for ping
|
|
45
|
+
this.fastify.get('/ask-extension', async (request, reply) => {
|
|
46
|
+
if (!this.nativeHost) {
|
|
47
|
+
return reply
|
|
48
|
+
.status(constant_1.HTTP_STATUS.INTERNAL_SERVER_ERROR)
|
|
49
|
+
.send({ error: constant_1.ERROR_MESSAGES.NATIVE_HOST_NOT_AVAILABLE });
|
|
50
|
+
}
|
|
51
|
+
if (!this.isRunning) {
|
|
52
|
+
return reply
|
|
53
|
+
.status(constant_1.HTTP_STATUS.INTERNAL_SERVER_ERROR)
|
|
54
|
+
.send({ error: constant_1.ERROR_MESSAGES.SERVER_NOT_RUNNING });
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
// wait from extension message
|
|
58
|
+
const extensionResponse = await this.nativeHost.sendRequestToExtensionAndWait(request.query, 'process_data', constant_1.TIMEOUTS.EXTENSION_REQUEST_TIMEOUT);
|
|
59
|
+
return reply.status(constant_1.HTTP_STATUS.OK).send({ status: 'success', data: extensionResponse });
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (error.message.includes('timed out')) {
|
|
63
|
+
return reply
|
|
64
|
+
.status(constant_1.HTTP_STATUS.GATEWAY_TIMEOUT)
|
|
65
|
+
.send({ status: 'error', message: constant_1.ERROR_MESSAGES.REQUEST_TIMEOUT });
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return reply.status(constant_1.HTTP_STATUS.INTERNAL_SERVER_ERROR).send({
|
|
69
|
+
status: 'error',
|
|
70
|
+
message: `Failed to get response from extension: ${error.message}`,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
// Compatible with SSE
|
|
76
|
+
this.fastify.get('/sse', async (_, reply) => {
|
|
77
|
+
try {
|
|
78
|
+
// Set SSE headers
|
|
79
|
+
reply.raw.writeHead(constant_1.HTTP_STATUS.OK, {
|
|
80
|
+
'Content-Type': 'text/event-stream',
|
|
81
|
+
'Cache-Control': 'no-cache',
|
|
82
|
+
Connection: 'keep-alive',
|
|
83
|
+
});
|
|
84
|
+
// Create SSE transport
|
|
85
|
+
const transport = new sse_js_1.SSEServerTransport('/messages', reply.raw);
|
|
86
|
+
this.transportsMap.set(transport.sessionId, transport);
|
|
87
|
+
reply.raw.on('close', () => {
|
|
88
|
+
this.transportsMap.delete(transport.sessionId);
|
|
89
|
+
});
|
|
90
|
+
const server = (0, mcp_server_1.getMcpServer)();
|
|
91
|
+
await server.connect(transport);
|
|
92
|
+
// Keep connection open
|
|
93
|
+
reply.raw.write(':\n\n');
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (!reply.sent) {
|
|
97
|
+
reply.code(constant_1.HTTP_STATUS.INTERNAL_SERVER_ERROR).send(constant_1.ERROR_MESSAGES.INTERNAL_SERVER_ERROR);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
// Compatible with SSE
|
|
102
|
+
this.fastify.post('/messages', async (req, reply) => {
|
|
103
|
+
try {
|
|
104
|
+
const { sessionId } = req.query;
|
|
105
|
+
const transport = this.transportsMap.get(sessionId);
|
|
106
|
+
if (!sessionId || !transport) {
|
|
107
|
+
reply.code(constant_1.HTTP_STATUS.BAD_REQUEST).send('No transport found for sessionId');
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
await transport.handlePostMessage(req.raw, reply.raw, req.body);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (!reply.sent) {
|
|
114
|
+
reply.code(constant_1.HTTP_STATUS.INTERNAL_SERVER_ERROR).send(constant_1.ERROR_MESSAGES.INTERNAL_SERVER_ERROR);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
// POST /mcp: Handle client-to-server messages
|
|
119
|
+
this.fastify.post('/mcp', async (request, reply) => {
|
|
120
|
+
const sessionId = request.headers['mcp-session-id'];
|
|
121
|
+
let transport = this.transportsMap.get(sessionId || '');
|
|
122
|
+
if (transport) {
|
|
123
|
+
// transport found, do nothing
|
|
124
|
+
//} else if (!sessionId && isInitializeRequest(request.body)) {
|
|
125
|
+
// 方便测试,临时去掉sessionId的限制
|
|
126
|
+
}
|
|
127
|
+
else if ((0, types_js_1.isInitializeRequest)(request.body)) {
|
|
128
|
+
const newSessionId = (0, node_crypto_1.randomUUID)(); // Generate session ID
|
|
129
|
+
transport = new streamableHttp_js_1.StreamableHTTPServerTransport({
|
|
130
|
+
sessionIdGenerator: () => newSessionId, // Use pre-generated ID
|
|
131
|
+
onsessioninitialized: (initializedSessionId) => {
|
|
132
|
+
// Ensure transport instance exists and session ID matches
|
|
133
|
+
if (transport && initializedSessionId === newSessionId) {
|
|
134
|
+
this.transportsMap.set(initializedSessionId, transport);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
transport.onclose = () => {
|
|
139
|
+
if ((transport === null || transport === void 0 ? void 0 : transport.sessionId) && this.transportsMap.get(transport.sessionId)) {
|
|
140
|
+
this.transportsMap.delete(transport.sessionId);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
await (0, mcp_server_1.getMcpServer)().connect(transport);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
reply.code(constant_1.HTTP_STATUS.BAD_REQUEST).send({ error: constant_1.ERROR_MESSAGES.INVALID_MCP_REQUEST });
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
await transport.handleRequest(request.raw, reply.raw, request.body);
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
if (!reply.sent) {
|
|
154
|
+
reply
|
|
155
|
+
.code(constant_1.HTTP_STATUS.INTERNAL_SERVER_ERROR)
|
|
156
|
+
.send({ error: constant_1.ERROR_MESSAGES.MCP_REQUEST_PROCESSING_ERROR });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
this.fastify.get('/mcp', async (request, reply) => {
|
|
161
|
+
const sessionId = request.headers['mcp-session-id'];
|
|
162
|
+
const transport = sessionId
|
|
163
|
+
? this.transportsMap.get(sessionId)
|
|
164
|
+
: undefined;
|
|
165
|
+
if (!transport) {
|
|
166
|
+
reply.code(constant_1.HTTP_STATUS.BAD_REQUEST).send({ error: constant_1.ERROR_MESSAGES.INVALID_SSE_SESSION });
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
reply.raw.setHeader('Content-Type', 'text/event-stream');
|
|
170
|
+
reply.raw.setHeader('Cache-Control', 'no-cache');
|
|
171
|
+
reply.raw.setHeader('Connection', 'keep-alive');
|
|
172
|
+
reply.raw.flushHeaders(); // Ensure headers are sent immediately
|
|
173
|
+
try {
|
|
174
|
+
// transport.handleRequest will take over the response stream
|
|
175
|
+
await transport.handleRequest(request.raw, reply.raw);
|
|
176
|
+
if (!reply.sent) {
|
|
177
|
+
// If transport didn't send anything (unlikely for SSE initial handshake)
|
|
178
|
+
reply.hijack(); // Prevent Fastify from automatically sending response
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
if (!reply.raw.writableEnded) {
|
|
183
|
+
reply.raw.end();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
request.socket.on('close', () => {
|
|
187
|
+
request.log.info(`SSE client disconnected for session: ${sessionId}`);
|
|
188
|
+
// transport's onclose should handle its own cleanup
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
this.fastify.delete('/mcp', async (request, reply) => {
|
|
192
|
+
const sessionId = request.headers['mcp-session-id'];
|
|
193
|
+
const transport = sessionId
|
|
194
|
+
? this.transportsMap.get(sessionId)
|
|
195
|
+
: undefined;
|
|
196
|
+
if (!transport) {
|
|
197
|
+
reply.code(constant_1.HTTP_STATUS.BAD_REQUEST).send({ error: constant_1.ERROR_MESSAGES.INVALID_SESSION_ID });
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
try {
|
|
201
|
+
await transport.handleRequest(request.raw, reply.raw);
|
|
202
|
+
// Assume transport.handleRequest will send response or transport.onclose will cleanup
|
|
203
|
+
if (!reply.sent) {
|
|
204
|
+
reply.code(constant_1.HTTP_STATUS.NO_CONTENT).send();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
if (!reply.sent) {
|
|
209
|
+
reply
|
|
210
|
+
.code(constant_1.HTTP_STATUS.INTERNAL_SERVER_ERROR)
|
|
211
|
+
.send({ error: constant_1.ERROR_MESSAGES.MCP_SESSION_DELETION_ERROR });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
async start(port = constant_1.NATIVE_SERVER_PORT, nativeHost) {
|
|
217
|
+
if (!this.nativeHost) {
|
|
218
|
+
this.nativeHost = nativeHost; // Ensure nativeHost is set
|
|
219
|
+
}
|
|
220
|
+
else if (this.nativeHost !== nativeHost) {
|
|
221
|
+
this.nativeHost = nativeHost; // Update to the passed instance
|
|
222
|
+
}
|
|
223
|
+
if (this.isRunning) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
try {
|
|
227
|
+
// Ensure Fastify instance is ready before starting
|
|
228
|
+
if (!this.fastify) {
|
|
229
|
+
this.initializeFastify();
|
|
230
|
+
}
|
|
231
|
+
await this.fastify.listen({ port, host: constant_1.SERVER_CONFIG.HOST });
|
|
232
|
+
this.isRunning = true; // Update running status
|
|
233
|
+
// No need to return, Promise resolves void by default
|
|
234
|
+
}
|
|
235
|
+
catch (err) {
|
|
236
|
+
this.isRunning = false; // Startup failed, reset status
|
|
237
|
+
// Throw error instead of exiting directly, let caller (possibly NativeHost) handle
|
|
238
|
+
throw err; // or return Promise.reject(err);
|
|
239
|
+
// process.exit(1); // Not recommended to exit directly here
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
async stop() {
|
|
243
|
+
if (!this.isRunning) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
await this.fastify.close();
|
|
248
|
+
this.isRunning = false; // Update running status
|
|
249
|
+
// Recreate Fastify instance to allow restart
|
|
250
|
+
// This is necessary because Fastify instances cannot be restarted after close()
|
|
251
|
+
this.initializeFastify();
|
|
252
|
+
}
|
|
253
|
+
catch (err) {
|
|
254
|
+
// Even if closing fails, mark as not running, but log the error
|
|
255
|
+
this.isRunning = false;
|
|
256
|
+
throw err; // Throw error
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
getInstance() {
|
|
260
|
+
return this.fastify;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
exports.Server = Server;
|
|
264
|
+
const serverInstance = new Server();
|
|
265
|
+
exports.default = serverInstance;
|
|
266
|
+
//# sourceMappingURL=index.js.map
|