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
package/dist/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# axhub-mcp-bridge
|
|
2
|
+
|
|
3
|
+
本程序为Chrome扩展的Native Messaging主机端。
|
|
4
|
+
|
|
5
|
+
## 安装说明
|
|
6
|
+
|
|
7
|
+
1. 确保已安装Node.js
|
|
8
|
+
2. 全局安装本程序:
|
|
9
|
+
```
|
|
10
|
+
npm install -g axhub-mcp-bridge
|
|
11
|
+
```
|
|
12
|
+
3. 注册Native Messaging主机:
|
|
13
|
+
```
|
|
14
|
+
# 用户级别安装(推荐)
|
|
15
|
+
axhub-mcp-bridge register
|
|
16
|
+
|
|
17
|
+
# 如果用户级别安装失败,可以尝试系统级别安装
|
|
18
|
+
axhub-mcp-bridge register --system
|
|
19
|
+
# 或者使用管理员权限
|
|
20
|
+
sudo axhub-mcp-bridge register
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 使用方法
|
|
24
|
+
|
|
25
|
+
此应用程序由Chrome扩展自动启动,无需手动运行。
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
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
|
+
// Import writeNodePath from postinstall
|
|
42
|
+
async function writeNodePath() {
|
|
43
|
+
try {
|
|
44
|
+
const nodePath = process.execPath;
|
|
45
|
+
const nodePathFile = path.join(__dirname, 'node_path.txt');
|
|
46
|
+
console.log((0, utils_1.colorText)(`Writing Node.js path: ${nodePath}`, 'blue'));
|
|
47
|
+
fs.writeFileSync(nodePathFile, nodePath, 'utf8');
|
|
48
|
+
console.log((0, utils_1.colorText)('✓ Node.js path written for run_host scripts', 'green'));
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.warn((0, utils_1.colorText)(`⚠️ Failed to write Node.js path: ${error.message}`, 'yellow'));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
commander_1.program
|
|
55
|
+
.version(require('../package.json').version)
|
|
56
|
+
.description('Mcp Chrome Bridge - Local service for communicating with Chrome extension');
|
|
57
|
+
// Register Native Messaging host
|
|
58
|
+
commander_1.program
|
|
59
|
+
.command('register')
|
|
60
|
+
.description('Register Native Messaging host')
|
|
61
|
+
.option('-f, --force', 'Force re-registration')
|
|
62
|
+
.option('-s, --system', 'Use system-level installation (requires administrator/sudo privileges)')
|
|
63
|
+
.action(async (options) => {
|
|
64
|
+
try {
|
|
65
|
+
// Write Node.js path for run_host scripts
|
|
66
|
+
await writeNodePath();
|
|
67
|
+
// Detect if running with root/administrator privileges
|
|
68
|
+
const isRoot = process.getuid && process.getuid() === 0; // Unix/Linux/Mac
|
|
69
|
+
let isAdmin = false;
|
|
70
|
+
if (process.platform === 'win32') {
|
|
71
|
+
try {
|
|
72
|
+
const mod = await import('is-admin'); // 动态引入 ESM
|
|
73
|
+
isAdmin = await mod.default(); // 调用模块默认导出的方法
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
console.warn((0, utils_1.colorText)('Warning: Unable to detect administrator privileges on Windows', 'yellow'));
|
|
77
|
+
isAdmin = false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const hasElevatedPermissions = isRoot || isAdmin;
|
|
81
|
+
// If --system option is specified or running with root/administrator privileges
|
|
82
|
+
if (options.system || hasElevatedPermissions) {
|
|
83
|
+
await (0, utils_1.registerWithElevatedPermissions)();
|
|
84
|
+
console.log((0, utils_1.colorText)('System-level Native Messaging host registered successfully!', 'green'));
|
|
85
|
+
console.log((0, utils_1.colorText)('You can now use connectNative in Chrome extension to connect to this service.', 'blue'));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// Regular user-level installation
|
|
89
|
+
console.log((0, utils_1.colorText)('Registering user-level Native Messaging host...', 'blue'));
|
|
90
|
+
const success = await (0, utils_1.tryRegisterUserLevelHost)();
|
|
91
|
+
if (success) {
|
|
92
|
+
console.log((0, utils_1.colorText)('Native Messaging host registered successfully!', 'green'));
|
|
93
|
+
console.log((0, utils_1.colorText)('You can now use connectNative in Chrome extension to connect to this service.', 'blue'));
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
console.log((0, utils_1.colorText)('User-level registration failed, please try the following methods:', 'yellow'));
|
|
97
|
+
console.log((0, utils_1.colorText)(' 1. sudo axhub-mcp-bridge register', 'yellow'));
|
|
98
|
+
console.log((0, utils_1.colorText)(' 2. axhub-mcp-bridge register --system', 'yellow'));
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
console.error((0, utils_1.colorText)(`Registration failed: ${error.message}`, 'red'));
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
// Fix execution permissions
|
|
109
|
+
commander_1.program
|
|
110
|
+
.command('fix-permissions')
|
|
111
|
+
.description('Fix execution permissions for native host files')
|
|
112
|
+
.action(async () => {
|
|
113
|
+
try {
|
|
114
|
+
console.log((0, utils_1.colorText)('Fixing execution permissions...', 'blue'));
|
|
115
|
+
await (0, utils_1.ensureExecutionPermissions)();
|
|
116
|
+
console.log((0, utils_1.colorText)('✓ Execution permissions fixed successfully!', 'green'));
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
console.error((0, utils_1.colorText)(`Failed to fix permissions: ${error.message}`, 'red'));
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
// Update port in stdio-config.json
|
|
124
|
+
commander_1.program
|
|
125
|
+
.command('update-port <port>')
|
|
126
|
+
.description('Update the port number in stdio-config.json')
|
|
127
|
+
.action(async (port) => {
|
|
128
|
+
try {
|
|
129
|
+
const portNumber = parseInt(port, 10);
|
|
130
|
+
if (isNaN(portNumber) || portNumber < 1 || portNumber > 65535) {
|
|
131
|
+
console.error((0, utils_1.colorText)('Error: Port must be a valid number between 1 and 65535', 'red'));
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
const configPath = path.join(__dirname, 'mcp', 'stdio-config.json');
|
|
135
|
+
if (!fs.existsSync(configPath)) {
|
|
136
|
+
console.error((0, utils_1.colorText)(`Error: Configuration file not found at ${configPath}`, 'red'));
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
const configData = fs.readFileSync(configPath, 'utf8');
|
|
140
|
+
const config = JSON.parse(configData);
|
|
141
|
+
const currentUrl = new URL(config.url);
|
|
142
|
+
currentUrl.port = portNumber.toString();
|
|
143
|
+
config.url = currentUrl.toString();
|
|
144
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 4));
|
|
145
|
+
console.log((0, utils_1.colorText)(`✓ Port updated successfully to ${portNumber}`, 'green'));
|
|
146
|
+
console.log((0, utils_1.colorText)(`Updated URL: ${config.url}`, 'blue'));
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
console.error((0, utils_1.colorText)(`Failed to update port: ${error.message}`, 'red'));
|
|
150
|
+
process.exit(1);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
commander_1.program.parse(process.argv);
|
|
154
|
+
// If no command provided, show help
|
|
155
|
+
if (!process.argv.slice(2).length) {
|
|
156
|
+
commander_1.program.outputHelp();
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yCAAoC;AACpC,uCAAyB;AACzB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EAAC,gBAAgB,MAAM,CAAC,GAAG,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: 90000;
|
|
13
|
+
readonly EXTENSION_REQUEST_TIMEOUT: 90000;
|
|
14
|
+
readonly PROCESS_DATA_TIMEOUT: 90000;
|
|
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: 90000,
|
|
18
|
+
EXTENSION_REQUEST_TIMEOUT: 90000,
|
|
19
|
+
PROCESS_DATA_TIMEOUT: 90000,
|
|
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"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const server_1 = __importDefault(require("./server"));
|
|
8
|
+
const native_messaging_host_1 = __importDefault(require("./native-messaging-host"));
|
|
9
|
+
try {
|
|
10
|
+
server_1.default.setNativeHost(native_messaging_host_1.default); // Server needs setNativeHost method
|
|
11
|
+
native_messaging_host_1.default.setServer(server_1.default); // NativeHost needs setServer method
|
|
12
|
+
native_messaging_host_1.default.start();
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
process.on('error', (error) => {
|
|
18
|
+
process.exit(1);
|
|
19
|
+
});
|
|
20
|
+
// Handle process signals and uncaught exceptions
|
|
21
|
+
process.on('SIGINT', () => {
|
|
22
|
+
process.exit(0);
|
|
23
|
+
});
|
|
24
|
+
process.on('SIGTERM', () => {
|
|
25
|
+
process.exit(0);
|
|
26
|
+
});
|
|
27
|
+
process.on('exit', (code) => {
|
|
28
|
+
});
|
|
29
|
+
process.on('uncaughtException', (error) => {
|
|
30
|
+
process.exit(1);
|
|
31
|
+
});
|
|
32
|
+
process.on('unhandledRejection', (reason) => {
|
|
33
|
+
// Don't exit immediately, let the program continue running
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AACA,sDAAsC;AACtC,oFAAkE;AAElE,IAAI,CAAC;IACH,gBAAc,CAAC,aAAa,CAAC,+BAA2B,CAAC,CAAC,CAAC,oCAAoC;IAC/F,+BAA2B,CAAC,SAAS,CAAC,gBAAc,CAAC,CAAC,CAAC,oCAAoC;IAC3F,+BAA2B,CAAC,KAAK,EAAE,CAAC;AACtC,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IACf,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;IAC5B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,iDAAiD;AACjD,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;IACxB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;IACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;AAC5B,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,KAAK,EAAE,EAAE;IACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,EAAE;IAC1C,2DAA2D;AAC7D,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
3
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
4
|
+
export declare const getStdioMcpServer: () => Server<{
|
|
5
|
+
method: string;
|
|
6
|
+
params?: {
|
|
7
|
+
[x: string]: unknown;
|
|
8
|
+
_meta?: {
|
|
9
|
+
[x: string]: unknown;
|
|
10
|
+
progressToken?: string | number | undefined;
|
|
11
|
+
} | undefined;
|
|
12
|
+
} | undefined;
|
|
13
|
+
}, {
|
|
14
|
+
method: string;
|
|
15
|
+
params?: {
|
|
16
|
+
[x: string]: unknown;
|
|
17
|
+
_meta?: {
|
|
18
|
+
[x: string]: unknown;
|
|
19
|
+
} | undefined;
|
|
20
|
+
} | undefined;
|
|
21
|
+
}, {
|
|
22
|
+
[x: string]: unknown;
|
|
23
|
+
_meta?: {
|
|
24
|
+
[x: string]: unknown;
|
|
25
|
+
} | undefined;
|
|
26
|
+
}>;
|
|
27
|
+
export declare const ensureMcpClient: () => Promise<Client<{
|
|
28
|
+
method: string;
|
|
29
|
+
params?: {
|
|
30
|
+
[x: string]: unknown;
|
|
31
|
+
_meta?: {
|
|
32
|
+
[x: string]: unknown;
|
|
33
|
+
progressToken?: string | number | undefined;
|
|
34
|
+
} | undefined;
|
|
35
|
+
} | undefined;
|
|
36
|
+
}, {
|
|
37
|
+
method: string;
|
|
38
|
+
params?: {
|
|
39
|
+
[x: string]: unknown;
|
|
40
|
+
_meta?: {
|
|
41
|
+
[x: string]: unknown;
|
|
42
|
+
} | undefined;
|
|
43
|
+
} | undefined;
|
|
44
|
+
}, {
|
|
45
|
+
[x: string]: unknown;
|
|
46
|
+
_meta?: {
|
|
47
|
+
[x: string]: unknown;
|
|
48
|
+
} | undefined;
|
|
49
|
+
}> | undefined>;
|
|
50
|
+
export declare const setupTools: (server: Server) => void;
|
|
@@ -0,0 +1,135 @@
|
|
|
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
|
+
exports.setupTools = exports.ensureMcpClient = exports.getStdioMcpServer = void 0;
|
|
38
|
+
const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
|
|
39
|
+
const index_js_2 = require("@modelcontextprotocol/sdk/client/index.js");
|
|
40
|
+
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
41
|
+
const shared_1 = require("../shared");
|
|
42
|
+
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
43
|
+
const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
44
|
+
const fs = __importStar(require("fs"));
|
|
45
|
+
const path = __importStar(require("path"));
|
|
46
|
+
let stdioMcpServer = null;
|
|
47
|
+
let mcpClient = null;
|
|
48
|
+
// Read configuration from stdio-config.json
|
|
49
|
+
const loadConfig = () => {
|
|
50
|
+
try {
|
|
51
|
+
const configPath = path.join(__dirname, 'stdio-config.json');
|
|
52
|
+
const configData = fs.readFileSync(configPath, 'utf8');
|
|
53
|
+
return JSON.parse(configData);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.error('Failed to load stdio-config.json:', error);
|
|
57
|
+
throw new Error('Configuration file stdio-config.json not found or invalid');
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const getStdioMcpServer = () => {
|
|
61
|
+
if (stdioMcpServer) {
|
|
62
|
+
return stdioMcpServer;
|
|
63
|
+
}
|
|
64
|
+
stdioMcpServer = new index_js_1.Server({
|
|
65
|
+
name: 'StdioChromeMcpServer',
|
|
66
|
+
version: '1.0.0',
|
|
67
|
+
}, {
|
|
68
|
+
capabilities: {
|
|
69
|
+
tools: {},
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
(0, exports.setupTools)(stdioMcpServer);
|
|
73
|
+
return stdioMcpServer;
|
|
74
|
+
};
|
|
75
|
+
exports.getStdioMcpServer = getStdioMcpServer;
|
|
76
|
+
const ensureMcpClient = async () => {
|
|
77
|
+
try {
|
|
78
|
+
if (mcpClient) {
|
|
79
|
+
const pingResult = await mcpClient.ping();
|
|
80
|
+
if (pingResult) {
|
|
81
|
+
return mcpClient;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const config = loadConfig();
|
|
85
|
+
mcpClient = new index_js_2.Client({ name: 'Mcp Chrome Proxy', version: '1.0.0' }, { capabilities: {} });
|
|
86
|
+
const transport = new streamableHttp_js_1.StreamableHTTPClientTransport(new URL(config.url), {});
|
|
87
|
+
await mcpClient.connect(transport);
|
|
88
|
+
return mcpClient;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
mcpClient === null || mcpClient === void 0 ? void 0 : mcpClient.close();
|
|
92
|
+
mcpClient = null;
|
|
93
|
+
console.error('Failed to connect to MCP server:', error);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
exports.ensureMcpClient = ensureMcpClient;
|
|
97
|
+
const setupTools = (server) => {
|
|
98
|
+
// List tools handler
|
|
99
|
+
server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => ({ tools: shared_1.TOOL_SCHEMAS }));
|
|
100
|
+
// Call tool handler
|
|
101
|
+
server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => handleToolCall(request.params.name, request.params.arguments || {}));
|
|
102
|
+
};
|
|
103
|
+
exports.setupTools = setupTools;
|
|
104
|
+
const handleToolCall = async (name, args) => {
|
|
105
|
+
try {
|
|
106
|
+
const client = await (0, exports.ensureMcpClient)();
|
|
107
|
+
if (!client) {
|
|
108
|
+
throw new Error('Failed to connect to MCP server');
|
|
109
|
+
}
|
|
110
|
+
const result = await client.callTool({ name, arguments: args }, undefined, {
|
|
111
|
+
timeout: 2 * 6 * 1000, // Default timeout of 2 minute
|
|
112
|
+
});
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
return {
|
|
117
|
+
content: [
|
|
118
|
+
{
|
|
119
|
+
type: 'text',
|
|
120
|
+
text: `Error calling tool: ${error.message}`,
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
isError: true,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
async function main() {
|
|
128
|
+
const transport = new stdio_js_1.StdioServerTransport();
|
|
129
|
+
await (0, exports.getStdioMcpServer)().connect(transport);
|
|
130
|
+
}
|
|
131
|
+
main().catch((error) => {
|
|
132
|
+
console.error('Fatal error Chrome MCP Server main():', error);
|
|
133
|
+
process.exit(1);
|
|
134
|
+
});
|
|
135
|
+
//# sourceMappingURL=mcp-server-stdio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-server-stdio.js","sourceRoot":"","sources":["../../src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IAAS,EAA2B,EAAE;IAChF,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,IAAA,uBAAe,GAAE,CAAC;QACvC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACrD,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE;YACzE,OAAO,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,8BAA8B;SACtD,CAAC,CAAC;QACH,OAAO,MAAwB,CAAC;IAClC,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,uBAAuB,KAAK,CAAC,OAAO,EAAE;iBAC7C;aACF;YACD,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,KAAK,UAAU,IAAI;IACjB,MAAM,SAAS,GAAG,IAAI,+BAAoB,EAAE,CAAC;IAC7C,MAAM,IAAA,yBAAiB,GAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAC/C,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;IAC9D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
export declare let mcpServer: Server | null;
|
|
3
|
+
export declare const getMcpServer: () => Server<{
|
|
4
|
+
method: string;
|
|
5
|
+
params?: {
|
|
6
|
+
[x: string]: unknown;
|
|
7
|
+
_meta?: {
|
|
8
|
+
[x: string]: unknown;
|
|
9
|
+
progressToken?: string | number | undefined;
|
|
10
|
+
} | undefined;
|
|
11
|
+
} | undefined;
|
|
12
|
+
}, {
|
|
13
|
+
method: string;
|
|
14
|
+
params?: {
|
|
15
|
+
[x: string]: unknown;
|
|
16
|
+
_meta?: {
|
|
17
|
+
[x: string]: unknown;
|
|
18
|
+
} | undefined;
|
|
19
|
+
} | undefined;
|
|
20
|
+
}, {
|
|
21
|
+
[x: string]: unknown;
|
|
22
|
+
_meta?: {
|
|
23
|
+
[x: string]: unknown;
|
|
24
|
+
} | undefined;
|
|
25
|
+
}>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMcpServer = exports.mcpServer = void 0;
|
|
4
|
+
const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
|
|
5
|
+
const register_tools_1 = require("./register-tools");
|
|
6
|
+
exports.mcpServer = null;
|
|
7
|
+
const getMcpServer = () => {
|
|
8
|
+
if (exports.mcpServer) {
|
|
9
|
+
return exports.mcpServer;
|
|
10
|
+
}
|
|
11
|
+
exports.mcpServer = new index_js_1.Server({
|
|
12
|
+
name: 'ChromeMcpServer',
|
|
13
|
+
version: '1.0.0',
|
|
14
|
+
}, {
|
|
15
|
+
capabilities: {
|
|
16
|
+
tools: {},
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
(0, register_tools_1.setupTools)(exports.mcpServer);
|
|
20
|
+
return exports.mcpServer;
|
|
21
|
+
};
|
|
22
|
+
exports.getMcpServer = getMcpServer;
|
|
23
|
+
//# sourceMappingURL=mcp-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../../src/mcp/mcp-server.ts"],"names":[],"mappings":";;;AAAA,wEAAmE;AACnE,qDAA8C;AAEnC,QAAA,SAAS,GAAkB,IAAI,CAAC;AAEpC,MAAM,YAAY,GAAG,GAAG,EAAE;IAC/B,IAAI,iBAAS,EAAE,CAAC;QACd,OAAO,iBAAS,CAAC;IACnB,CAAC;IACD,iBAAS,GAAG,IAAI,iBAAM,CACpB;QACE,IAAI,EAAE,iBAAiB;QACvB,OAAO,EAAE,OAAO;KACjB,EACD;QACE,YAAY,EAAE;YACZ,KAAK,EAAE,EAAE;SACV;KACF,CACF,CAAC;IAEF,IAAA,2BAAU,EAAC,iBAAS,CAAC,CAAC;IACtB,OAAO,iBAAS,CAAC;AACnB,CAAC,CAAC;AAlBW,QAAA,YAAY,gBAkBvB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
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.setupTools = void 0;
|
|
7
|
+
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
8
|
+
const native_messaging_host_1 = __importDefault(require("../native-messaging-host"));
|
|
9
|
+
const shared_1 = require("../shared");
|
|
10
|
+
const setupTools = (server) => {
|
|
11
|
+
// List tools handler
|
|
12
|
+
server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => ({ tools: shared_1.TOOL_SCHEMAS }));
|
|
13
|
+
// Call tool handler
|
|
14
|
+
server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => handleToolCall(request.params.name, request.params.arguments || {}));
|
|
15
|
+
};
|
|
16
|
+
exports.setupTools = setupTools;
|
|
17
|
+
const handleToolCall = async (name, args) => {
|
|
18
|
+
try {
|
|
19
|
+
// 发送请求到Chrome扩展并等待响应
|
|
20
|
+
const response = await native_messaging_host_1.default.sendRequestToExtensionAndWait({
|
|
21
|
+
name,
|
|
22
|
+
args,
|
|
23
|
+
}, shared_1.NativeMessageType.CALL_TOOL, 90000);
|
|
24
|
+
if (response.status === 'success') {
|
|
25
|
+
return response.data;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return {
|
|
29
|
+
content: [
|
|
30
|
+
{
|
|
31
|
+
type: 'text',
|
|
32
|
+
text: `Error calling tool: ${response.error}`,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
isError: true,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
return {
|
|
41
|
+
content: [
|
|
42
|
+
{
|
|
43
|
+
type: 'text',
|
|
44
|
+
text: `Error calling tool: ${error.message}`,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
isError: true,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=register-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-tools.js","sourceRoot":"","sources":["../../src/mcp/register-tools.ts"],"names":[],"mappings":";;;;;;AACA,iEAI4C;AAC5C,qFAAmE;AACnE,sCAA4D;AAErD,MAAM,UAAU,GAAG,CAAC,MAAc,EAAE,EAAE;IAC3C,qBAAqB;IACrB,MAAM,CAAC,iBAAiB,CAAC,iCAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,qBAAY,EAAE,CAAC,CAAC,CAAC;IAExF,oBAAoB;IACpB,MAAM,CAAC,iBAAiB,CAAC,gCAAqB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAChE,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC,CACpE,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,UAAU,cAQrB;AAEF,MAAM,cAAc,GAAG,KAAK,EAAE,IAAY,EAAE,IAAS,EAA2B,EAAE;IAChF,IAAI,CAAC;QACH,qBAAqB;QACrB,MAAM,QAAQ,GAAG,MAAM,+BAA2B,CAAC,6BAA6B,CAC9E;YACE,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