mcp-chrome-bridger 1.0.0

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.
Files changed (57) hide show
  1. package/README.md +183 -0
  2. package/dist/README.md +25 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +185 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/constant/index.d.ts +38 -0
  7. package/dist/constant/index.js +47 -0
  8. package/dist/constant/index.js.map +1 -0
  9. package/dist/file-handler.d.ts +37 -0
  10. package/dist/file-handler.js +245 -0
  11. package/dist/file-handler.js.map +1 -0
  12. package/dist/index.d.ts +2 -0
  13. package/dist/index.js +35 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/mcp/mcp-server-stdio.d.ts +50 -0
  16. package/dist/mcp/mcp-server-stdio.js +141 -0
  17. package/dist/mcp/mcp-server-stdio.js.map +1 -0
  18. package/dist/mcp/mcp-server.d.ts +25 -0
  19. package/dist/mcp/mcp-server.js +23 -0
  20. package/dist/mcp/mcp-server.js.map +1 -0
  21. package/dist/mcp/register-tools.d.ts +2 -0
  22. package/dist/mcp/register-tools.js +51 -0
  23. package/dist/mcp/register-tools.js.map +1 -0
  24. package/dist/mcp/stdio-config.json +3 -0
  25. package/dist/native-messaging-host.d.ts +42 -0
  26. package/dist/native-messaging-host.js +287 -0
  27. package/dist/native-messaging-host.js.map +1 -0
  28. package/dist/run_host.bat +95 -0
  29. package/dist/run_host.sh +141 -0
  30. package/dist/scripts/browser-config.d.ts +28 -0
  31. package/dist/scripts/browser-config.js +229 -0
  32. package/dist/scripts/browser-config.js.map +1 -0
  33. package/dist/scripts/build.d.ts +1 -0
  34. package/dist/scripts/build.js +119 -0
  35. package/dist/scripts/build.js.map +1 -0
  36. package/dist/scripts/constant.d.ts +5 -0
  37. package/dist/scripts/constant.js +9 -0
  38. package/dist/scripts/constant.js.map +1 -0
  39. package/dist/scripts/postinstall.d.ts +2 -0
  40. package/dist/scripts/postinstall.js +231 -0
  41. package/dist/scripts/postinstall.js.map +1 -0
  42. package/dist/scripts/register-dev.d.ts +1 -0
  43. package/dist/scripts/register-dev.js +5 -0
  44. package/dist/scripts/register-dev.js.map +1 -0
  45. package/dist/scripts/register.d.ts +2 -0
  46. package/dist/scripts/register.js +22 -0
  47. package/dist/scripts/register.js.map +1 -0
  48. package/dist/scripts/utils.d.ts +37 -0
  49. package/dist/scripts/utils.js +380 -0
  50. package/dist/scripts/utils.js.map +1 -0
  51. package/dist/server/index.d.ts +20 -0
  52. package/dist/server/index.js +250 -0
  53. package/dist/server/index.js.map +1 -0
  54. package/dist/util/logger.d.ts +1 -0
  55. package/dist/util/logger.js +43 -0
  56. package/dist/util/logger.js.map +1 -0
  57. package/package.json +80 -0
package/README.md ADDED
@@ -0,0 +1,183 @@
1
+ # Fastify Chrome Native Messaging服务
2
+
3
+ 这是一个基于Fastify的TypeScript项目,用于与Chrome扩展进行原生通信。
4
+
5
+ ## 功能特性
6
+
7
+ - 通过Chrome Native Messaging协议与Chrome扩展进行双向通信
8
+ - **支持多浏览器**: Chrome 和 Chromium (包括 Linux、macOS 和 Windows)
9
+ - 提供RESTful API服务
10
+ - 完全使用TypeScript开发
11
+ - 包含完整的测试套件
12
+ - 遵循代码质量最佳实践
13
+
14
+ ## 开发环境设置
15
+
16
+ ### 前置条件
17
+
18
+ - Node.js 14+
19
+ - npm 6+
20
+
21
+ ### 安装
22
+
23
+ ```bash
24
+ git clone https://github.com/your-username/fastify-chrome-native.git
25
+ cd fastify-chrome-native
26
+ npm install
27
+ ```
28
+
29
+ ### 开发
30
+
31
+ 1. 本地构建注册native server
32
+
33
+ ```bash
34
+ cd app/native-server
35
+ npm run dev
36
+ ```
37
+
38
+ 2. 启动chrome extension
39
+
40
+ ```bash
41
+ cd app/chrome-extension
42
+ npm run dev
43
+ ```
44
+
45
+ ### 构建
46
+
47
+ ```bash
48
+ npm run build
49
+ ```
50
+
51
+ ### 注册Native Messaging主机
52
+
53
+ #### 自动检测并注册所有已安装的浏览器
54
+
55
+ ```bash
56
+ mcp-chrome-bridge register --detect
57
+ ```
58
+
59
+ #### 注册特定浏览器
60
+
61
+ ```bash
62
+ # 仅注册 Chrome
63
+ mcp-chrome-bridge register --browser chrome
64
+
65
+ # 仅注册 Chromium
66
+ mcp-chrome-bridge register --browser chromium
67
+
68
+ # 注册所有支持的浏览器
69
+ mcp-chrome-bridge register --browser all
70
+ ```
71
+
72
+ #### 全局安装(会自动注册检测到的浏览器)
73
+
74
+ ```bash
75
+ npm i -g mcp-chrome-bridge
76
+ ```
77
+
78
+ #### 浏览器支持
79
+
80
+ | 浏览器 | Linux | macOS | Windows |
81
+ | ------------- | ----- | ----- | ------- |
82
+ | Google Chrome | ✓ | ✓ | ✓ |
83
+ | Chromium | ✓ | ✓ | ✓ |
84
+
85
+ 注册位置:
86
+
87
+ - **Linux**: `~/.config/[browser-name]/NativeMessagingHosts/`
88
+ - **macOS**: `~/Library/Application Support/[Browser]/NativeMessagingHosts/`
89
+ - **Windows**: `%APPDATA%\[Browser]\NativeMessagingHosts\`
90
+
91
+ ### 与Chrome扩展集成
92
+
93
+ 以下是Chrome扩展中如何使用此服务的简单示例:
94
+
95
+ ```javascript
96
+ // background.js
97
+ let nativePort = null;
98
+ let serverRunning = false;
99
+
100
+ // 启动Native Messaging服务
101
+ function startServer() {
102
+ if (nativePort) {
103
+ console.log('已连接到Native Messaging主机');
104
+ return;
105
+ }
106
+
107
+ try {
108
+ nativePort = chrome.runtime.connectNative('com.yourcompany.fastify_native_host');
109
+
110
+ nativePort.onMessage.addListener((message) => {
111
+ console.log('收到Native消息:', message);
112
+
113
+ if (message.type === 'started') {
114
+ serverRunning = true;
115
+ console.log(`服务已启动,端口: ${message.payload.port}`);
116
+ } else if (message.type === 'stopped') {
117
+ serverRunning = false;
118
+ console.log('服务已停止');
119
+ } else if (message.type === 'error') {
120
+ console.error('Native错误:', message.payload.message);
121
+ }
122
+ });
123
+
124
+ nativePort.onDisconnect.addListener(() => {
125
+ console.log('Native连接断开:', chrome.runtime.lastError);
126
+ nativePort = null;
127
+ serverRunning = false;
128
+ });
129
+
130
+ // 启动服务器
131
+ nativePort.postMessage({ type: 'start', payload: { port: 3000 } });
132
+ } catch (error) {
133
+ console.error('启动Native Messaging时出错:', error);
134
+ }
135
+ }
136
+
137
+ // 停止服务器
138
+ function stopServer() {
139
+ if (nativePort && serverRunning) {
140
+ nativePort.postMessage({ type: 'stop' });
141
+ }
142
+ }
143
+
144
+ // 测试与服务器的通信
145
+ async function testPing() {
146
+ try {
147
+ const response = await fetch('http://localhost:3000/ping');
148
+ const data = await response.json();
149
+ console.log('Ping响应:', data);
150
+ return data;
151
+ } catch (error) {
152
+ console.error('Ping失败:', error);
153
+ return null;
154
+ }
155
+ }
156
+
157
+ // 在扩展启动时连接Native主机
158
+ chrome.runtime.onStartup.addListener(startServer);
159
+
160
+ // 导出供popup或内容脚本使用的API
161
+ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
162
+ if (message.action === 'startServer') {
163
+ startServer();
164
+ sendResponse({ success: true });
165
+ } else if (message.action === 'stopServer') {
166
+ stopServer();
167
+ sendResponse({ success: true });
168
+ } else if (message.action === 'testPing') {
169
+ testPing().then(sendResponse);
170
+ return true; // 指示我们将异步发送响应
171
+ }
172
+ });
173
+ ```
174
+
175
+ ### 测试
176
+
177
+ ```bash
178
+ npm run test
179
+ ```
180
+
181
+ ### 许可证
182
+
183
+ MIT
package/dist/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # mcp-chrome-bridger
2
+
3
+ 本程序为Chrome扩展的Native Messaging主机端。
4
+
5
+ ## 安装说明
6
+
7
+ 1. 确保已安装Node.js
8
+ 2. 全局安装本程序:
9
+ ```
10
+ npm install -g mcp-chrome-bridger
11
+ ```
12
+ 3. 注册Native Messaging主机:
13
+ ```
14
+ # 用户级别安装(推荐)
15
+ mcp-chrome-bridger register
16
+
17
+ # 如果用户级别安装失败,可以尝试系统级别安装
18
+ mcp-chrome-bridger register --system
19
+ # 或者使用管理员权限
20
+ sudo mcp-chrome-bridger register
21
+ ```
22
+
23
+ ## 使用方法
24
+
25
+ 此应用程序由Chrome扩展自动启动,无需手动运行。
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ const commander_1 = require("commander");
38
+ const fs = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ const utils_1 = require("./scripts/utils");
41
+ const browser_config_1 = require("./scripts/browser-config");
42
+ // Import writeNodePath from postinstall
43
+ async function writeNodePath() {
44
+ try {
45
+ const nodePath = process.execPath;
46
+ const nodePathFile = path.join(__dirname, 'node_path.txt');
47
+ console.log((0, utils_1.colorText)(`Writing Node.js path: ${nodePath}`, 'blue'));
48
+ fs.writeFileSync(nodePathFile, nodePath, 'utf8');
49
+ console.log((0, utils_1.colorText)('✓ Node.js path written for run_host scripts', 'green'));
50
+ }
51
+ catch (error) {
52
+ console.warn((0, utils_1.colorText)(`⚠️ Failed to write Node.js path: ${error.message}`, 'yellow'));
53
+ }
54
+ }
55
+ commander_1.program
56
+ .version(require('../package.json').version)
57
+ .description('Mcp Chrome Bridge - Local service for communicating with Chrome extension');
58
+ // Register Native Messaging host
59
+ commander_1.program
60
+ .command('register')
61
+ .description('Register Native Messaging host')
62
+ .option('-f, --force', 'Force re-registration')
63
+ .option('-s, --system', 'Use system-level installation (requires administrator/sudo privileges)')
64
+ .option('-b, --browser <browser>', 'Register for specific browser (chrome, chromium, or all)')
65
+ .option('-d, --detect', 'Auto-detect installed browsers')
66
+ .action(async (options) => {
67
+ try {
68
+ // Write Node.js path for run_host scripts
69
+ await writeNodePath();
70
+ // Determine which browsers to register
71
+ let targetBrowsers;
72
+ if (options.browser) {
73
+ if (options.browser.toLowerCase() === 'all') {
74
+ targetBrowsers = [browser_config_1.BrowserType.CHROME, browser_config_1.BrowserType.CHROMIUM];
75
+ console.log((0, utils_1.colorText)('Registering for all supported browsers...', 'blue'));
76
+ }
77
+ else {
78
+ const browserType = (0, browser_config_1.parseBrowserType)(options.browser);
79
+ if (!browserType) {
80
+ console.error((0, utils_1.colorText)(`Invalid browser: ${options.browser}. Use 'chrome', 'chromium', or 'all'`, 'red'));
81
+ process.exit(1);
82
+ }
83
+ targetBrowsers = [browserType];
84
+ }
85
+ }
86
+ else if (options.detect) {
87
+ targetBrowsers = (0, browser_config_1.detectInstalledBrowsers)();
88
+ if (targetBrowsers.length === 0) {
89
+ console.log((0, utils_1.colorText)('No supported browsers detected, will register for Chrome and Chromium', 'yellow'));
90
+ targetBrowsers = undefined; // Will use default behavior
91
+ }
92
+ }
93
+ // If neither option specified, tryRegisterUserLevelHost will detect browsers
94
+ // Detect if running with root/administrator privileges
95
+ const isRoot = process.getuid && process.getuid() === 0; // Unix/Linux/Mac
96
+ let isAdmin = false;
97
+ if (process.platform === 'win32') {
98
+ try {
99
+ isAdmin = require('is-admin')(); // Windows requires additional package
100
+ }
101
+ catch (error) {
102
+ console.warn((0, utils_1.colorText)('Warning: Unable to detect administrator privileges on Windows', 'yellow'));
103
+ isAdmin = false;
104
+ }
105
+ }
106
+ const hasElevatedPermissions = isRoot || isAdmin;
107
+ // If --system option is specified or running with root/administrator privileges
108
+ if (options.system || hasElevatedPermissions) {
109
+ // TODO: Update registerWithElevatedPermissions to support multiple browsers
110
+ await (0, utils_1.registerWithElevatedPermissions)();
111
+ console.log((0, utils_1.colorText)('System-level Native Messaging host registered successfully!', 'green'));
112
+ console.log((0, utils_1.colorText)('You can now use connectNative in Chrome extension to connect to this service.', 'blue'));
113
+ }
114
+ else {
115
+ // Regular user-level installation
116
+ console.log((0, utils_1.colorText)('Registering user-level Native Messaging host...', 'blue'));
117
+ const success = await (0, utils_1.tryRegisterUserLevelHost)(targetBrowsers);
118
+ if (success) {
119
+ console.log((0, utils_1.colorText)('Native Messaging host registered successfully!', 'green'));
120
+ console.log((0, utils_1.colorText)('You can now use connectNative in Chrome extension to connect to this service.', 'blue'));
121
+ }
122
+ else {
123
+ console.log((0, utils_1.colorText)('User-level registration failed, please try the following methods:', 'yellow'));
124
+ console.log((0, utils_1.colorText)(' 1. sudo mcp-chrome-bridge register', 'yellow'));
125
+ console.log((0, utils_1.colorText)(' 2. mcp-chrome-bridge register --system', 'yellow'));
126
+ process.exit(1);
127
+ }
128
+ }
129
+ }
130
+ catch (error) {
131
+ console.error((0, utils_1.colorText)(`Registration failed: ${error.message}`, 'red'));
132
+ process.exit(1);
133
+ }
134
+ });
135
+ // Fix execution permissions
136
+ commander_1.program
137
+ .command('fix-permissions')
138
+ .description('Fix execution permissions for native host files')
139
+ .action(async () => {
140
+ try {
141
+ console.log((0, utils_1.colorText)('Fixing execution permissions...', 'blue'));
142
+ await (0, utils_1.ensureExecutionPermissions)();
143
+ console.log((0, utils_1.colorText)('✓ Execution permissions fixed successfully!', 'green'));
144
+ }
145
+ catch (error) {
146
+ console.error((0, utils_1.colorText)(`Failed to fix permissions: ${error.message}`, 'red'));
147
+ process.exit(1);
148
+ }
149
+ });
150
+ // Update port in stdio-config.json
151
+ commander_1.program
152
+ .command('update-port <port>')
153
+ .description('Update the port number in stdio-config.json')
154
+ .action(async (port) => {
155
+ try {
156
+ const portNumber = parseInt(port, 10);
157
+ if (isNaN(portNumber) || portNumber < 1 || portNumber > 65535) {
158
+ console.error((0, utils_1.colorText)('Error: Port must be a valid number between 1 and 65535', 'red'));
159
+ process.exit(1);
160
+ }
161
+ const configPath = path.join(__dirname, 'mcp', 'stdio-config.json');
162
+ if (!fs.existsSync(configPath)) {
163
+ console.error((0, utils_1.colorText)(`Error: Configuration file not found at ${configPath}`, 'red'));
164
+ process.exit(1);
165
+ }
166
+ const configData = fs.readFileSync(configPath, 'utf8');
167
+ const config = JSON.parse(configData);
168
+ const currentUrl = new URL(config.url);
169
+ currentUrl.port = portNumber.toString();
170
+ config.url = currentUrl.toString();
171
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 4));
172
+ console.log((0, utils_1.colorText)(`✓ Port updated successfully to ${portNumber}`, 'green'));
173
+ console.log((0, utils_1.colorText)(`Updated URL: ${config.url}`, 'blue'));
174
+ }
175
+ catch (error) {
176
+ console.error((0, utils_1.colorText)(`Failed to update port: ${error.message}`, 'red'));
177
+ process.exit(1);
178
+ }
179
+ });
180
+ commander_1.program.parse(process.argv);
181
+ // If no command provided, show help
182
+ if (!process.argv.slice(2).length) {
183
+ commander_1.program.outputHelp();
184
+ }
185
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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G,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IAC/D,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,CAAC,IAAA,iBAAS,EAAC,0BAA0B,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;QAC3E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,mBAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5B,oCAAoC;AACpC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAClC,mBAAO,CAAC,UAAU,EAAE,CAAC;AACvB,CAAC"}
@@ -0,0 +1,38 @@
1
+ export declare enum NATIVE_MESSAGE_TYPE {
2
+ START = "start",
3
+ STARTED = "started",
4
+ STOP = "stop",
5
+ STOPPED = "stopped",
6
+ PING = "ping",
7
+ PONG = "pong",
8
+ ERROR = "error"
9
+ }
10
+ export declare const NATIVE_SERVER_PORT = 56889;
11
+ export declare const TIMEOUTS: {
12
+ readonly DEFAULT_REQUEST_TIMEOUT: 15000;
13
+ readonly EXTENSION_REQUEST_TIMEOUT: 20000;
14
+ readonly PROCESS_DATA_TIMEOUT: 20000;
15
+ };
16
+ export declare const SERVER_CONFIG: {
17
+ readonly HOST: "127.0.0.1";
18
+ readonly CORS_ORIGIN: true;
19
+ readonly LOGGER_ENABLED: false;
20
+ };
21
+ export declare const HTTP_STATUS: {
22
+ readonly OK: 200;
23
+ readonly NO_CONTENT: 204;
24
+ readonly BAD_REQUEST: 400;
25
+ readonly INTERNAL_SERVER_ERROR: 500;
26
+ readonly GATEWAY_TIMEOUT: 504;
27
+ };
28
+ export declare const ERROR_MESSAGES: {
29
+ readonly NATIVE_HOST_NOT_AVAILABLE: "Native host connection not established.";
30
+ readonly SERVER_NOT_RUNNING: "Server is not actively running.";
31
+ readonly REQUEST_TIMEOUT: "Request to extension timed out.";
32
+ readonly INVALID_MCP_REQUEST: "Invalid MCP request or session.";
33
+ readonly INVALID_SESSION_ID: "Invalid or missing MCP session ID.";
34
+ readonly INTERNAL_SERVER_ERROR: "Internal Server Error";
35
+ readonly MCP_SESSION_DELETION_ERROR: "Internal server error during MCP session deletion.";
36
+ readonly MCP_REQUEST_PROCESSING_ERROR: "Internal server error during MCP request processing.";
37
+ readonly INVALID_SSE_SESSION: "Invalid or missing MCP session ID for SSE.";
38
+ };
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ERROR_MESSAGES = exports.HTTP_STATUS = exports.SERVER_CONFIG = exports.TIMEOUTS = exports.NATIVE_SERVER_PORT = exports.NATIVE_MESSAGE_TYPE = void 0;
4
+ var NATIVE_MESSAGE_TYPE;
5
+ (function (NATIVE_MESSAGE_TYPE) {
6
+ NATIVE_MESSAGE_TYPE["START"] = "start";
7
+ NATIVE_MESSAGE_TYPE["STARTED"] = "started";
8
+ NATIVE_MESSAGE_TYPE["STOP"] = "stop";
9
+ NATIVE_MESSAGE_TYPE["STOPPED"] = "stopped";
10
+ NATIVE_MESSAGE_TYPE["PING"] = "ping";
11
+ NATIVE_MESSAGE_TYPE["PONG"] = "pong";
12
+ NATIVE_MESSAGE_TYPE["ERROR"] = "error";
13
+ })(NATIVE_MESSAGE_TYPE || (exports.NATIVE_MESSAGE_TYPE = NATIVE_MESSAGE_TYPE = {}));
14
+ exports.NATIVE_SERVER_PORT = 56889;
15
+ // Timeout constants (in milliseconds)
16
+ exports.TIMEOUTS = {
17
+ DEFAULT_REQUEST_TIMEOUT: 15000,
18
+ EXTENSION_REQUEST_TIMEOUT: 20000,
19
+ PROCESS_DATA_TIMEOUT: 20000,
20
+ };
21
+ // Server configuration
22
+ exports.SERVER_CONFIG = {
23
+ HOST: '127.0.0.1',
24
+ CORS_ORIGIN: true,
25
+ LOGGER_ENABLED: false,
26
+ };
27
+ // HTTP Status codes
28
+ exports.HTTP_STATUS = {
29
+ OK: 200,
30
+ NO_CONTENT: 204,
31
+ BAD_REQUEST: 400,
32
+ INTERNAL_SERVER_ERROR: 500,
33
+ GATEWAY_TIMEOUT: 504,
34
+ };
35
+ // Error messages
36
+ exports.ERROR_MESSAGES = {
37
+ NATIVE_HOST_NOT_AVAILABLE: 'Native host connection not established.',
38
+ SERVER_NOT_RUNNING: 'Server is not actively running.',
39
+ REQUEST_TIMEOUT: 'Request to extension timed out.',
40
+ INVALID_MCP_REQUEST: 'Invalid MCP request or session.',
41
+ INVALID_SESSION_ID: 'Invalid or missing MCP session ID.',
42
+ INTERNAL_SERVER_ERROR: 'Internal Server Error',
43
+ MCP_SESSION_DELETION_ERROR: 'Internal server error during MCP session deletion.',
44
+ MCP_REQUEST_PROCESSING_ERROR: 'Internal server error during MCP request processing.',
45
+ INVALID_SSE_SESSION: 'Invalid or missing MCP session ID for SSE.',
46
+ };
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constant/index.ts"],"names":[],"mappings":";;;AAAA,IAAY,mBAQX;AARD,WAAY,mBAAmB;IAC7B,sCAAe,CAAA;IACf,0CAAmB,CAAA;IACnB,oCAAa,CAAA;IACb,0CAAmB,CAAA;IACnB,oCAAa,CAAA;IACb,oCAAa,CAAA;IACb,sCAAe,CAAA;AACjB,CAAC,EARW,mBAAmB,mCAAnB,mBAAmB,QAQ9B;AAEY,QAAA,kBAAkB,GAAG,KAAK,CAAC;AAExC,sCAAsC;AACzB,QAAA,QAAQ,GAAG;IACtB,uBAAuB,EAAE,KAAK;IAC9B,yBAAyB,EAAE,KAAK;IAChC,oBAAoB,EAAE,KAAK;CACnB,CAAC;AAEX,uBAAuB;AACV,QAAA,aAAa,GAAG;IAC3B,IAAI,EAAE,WAAW;IACjB,WAAW,EAAE,IAAI;IACjB,cAAc,EAAE,KAAK;CACb,CAAC;AAEX,oBAAoB;AACP,QAAA,WAAW,GAAG;IACzB,EAAE,EAAE,GAAG;IACP,UAAU,EAAE,GAAG;IACf,WAAW,EAAE,GAAG;IAChB,qBAAqB,EAAE,GAAG;IAC1B,eAAe,EAAE,GAAG;CACZ,CAAC;AAEX,iBAAiB;AACJ,QAAA,cAAc,GAAG;IAC5B,yBAAyB,EAAE,yCAAyC;IACpE,kBAAkB,EAAE,iCAAiC;IACrD,eAAe,EAAE,iCAAiC;IAClD,mBAAmB,EAAE,iCAAiC;IACtD,kBAAkB,EAAE,oCAAoC;IACxD,qBAAqB,EAAE,uBAAuB;IAC9C,0BAA0B,EAAE,oDAAoD;IAChF,4BAA4B,EAAE,sDAAsD;IACpF,mBAAmB,EAAE,4CAA4C;CACzD,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * File handler for managing file uploads through the native messaging host
3
+ */
4
+ export declare class FileHandler {
5
+ private tempDir;
6
+ constructor();
7
+ /**
8
+ * Handle file preparation request from the extension
9
+ */
10
+ handleFileRequest(request: any): Promise<any>;
11
+ /**
12
+ * Download a file from URL and save to temp directory
13
+ */
14
+ private downloadFile;
15
+ /**
16
+ * Save base64 data as a file
17
+ */
18
+ private saveBase64File;
19
+ /**
20
+ * Verify that a file exists and is accessible
21
+ */
22
+ private verifyFile;
23
+ /**
24
+ * Clean up a temporary file
25
+ */
26
+ private cleanupFile;
27
+ /**
28
+ * Generate a filename from URL or create a unique one
29
+ */
30
+ private generateFileName;
31
+ /**
32
+ * Clean up old temporary files (older than 1 hour)
33
+ */
34
+ cleanupOldFiles(): void;
35
+ }
36
+ declare const _default: FileHandler;
37
+ export default _default;