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
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.FileHandler = void 0;
40
+ const fs = __importStar(require("fs"));
41
+ const path = __importStar(require("path"));
42
+ const os = __importStar(require("os"));
43
+ const crypto = __importStar(require("crypto"));
44
+ const node_fetch_1 = __importDefault(require("node-fetch"));
45
+ /**
46
+ * File handler for managing file uploads through the native messaging host
47
+ */
48
+ class FileHandler {
49
+ constructor() {
50
+ // Create a temp directory for file operations
51
+ this.tempDir = path.join(os.tmpdir(), 'chrome-mcp-uploads');
52
+ if (!fs.existsSync(this.tempDir)) {
53
+ fs.mkdirSync(this.tempDir, { recursive: true });
54
+ }
55
+ }
56
+ /**
57
+ * Handle file preparation request from the extension
58
+ */
59
+ async handleFileRequest(request) {
60
+ const { action, fileUrl, base64Data, fileName, filePath } = request;
61
+ try {
62
+ switch (action) {
63
+ case 'prepareFile':
64
+ if (fileUrl) {
65
+ return await this.downloadFile(fileUrl, fileName);
66
+ }
67
+ else if (base64Data) {
68
+ return await this.saveBase64File(base64Data, fileName);
69
+ }
70
+ else if (filePath) {
71
+ return await this.verifyFile(filePath);
72
+ }
73
+ break;
74
+ case 'cleanupFile':
75
+ return await this.cleanupFile(filePath);
76
+ default:
77
+ return {
78
+ success: false,
79
+ error: `Unknown file action: ${action}`,
80
+ };
81
+ }
82
+ }
83
+ catch (error) {
84
+ return {
85
+ success: false,
86
+ error: error instanceof Error ? error.message : String(error),
87
+ };
88
+ }
89
+ }
90
+ /**
91
+ * Download a file from URL and save to temp directory
92
+ */
93
+ async downloadFile(fileUrl, fileName) {
94
+ try {
95
+ const response = await (0, node_fetch_1.default)(fileUrl);
96
+ if (!response.ok) {
97
+ throw new Error(`Failed to download file: ${response.statusText}`);
98
+ }
99
+ // Generate filename if not provided
100
+ const finalFileName = fileName || this.generateFileName(fileUrl);
101
+ const filePath = path.join(this.tempDir, finalFileName);
102
+ // Get the file buffer
103
+ const buffer = await response.buffer();
104
+ // Save to file
105
+ fs.writeFileSync(filePath, buffer);
106
+ return {
107
+ success: true,
108
+ filePath: filePath,
109
+ fileName: finalFileName,
110
+ size: buffer.length,
111
+ };
112
+ }
113
+ catch (error) {
114
+ throw new Error(`Failed to download file from URL: ${error}`);
115
+ }
116
+ }
117
+ /**
118
+ * Save base64 data as a file
119
+ */
120
+ async saveBase64File(base64Data, fileName) {
121
+ try {
122
+ // Remove data URL prefix if present
123
+ const base64Content = base64Data.replace(/^data:.*?;base64,/, '');
124
+ // Convert base64 to buffer
125
+ const buffer = Buffer.from(base64Content, 'base64');
126
+ // Generate filename if not provided
127
+ const finalFileName = fileName || `upload-${Date.now()}.bin`;
128
+ const filePath = path.join(this.tempDir, finalFileName);
129
+ // Save to file
130
+ fs.writeFileSync(filePath, buffer);
131
+ return {
132
+ success: true,
133
+ filePath: filePath,
134
+ fileName: finalFileName,
135
+ size: buffer.length,
136
+ };
137
+ }
138
+ catch (error) {
139
+ throw new Error(`Failed to save base64 file: ${error}`);
140
+ }
141
+ }
142
+ /**
143
+ * Verify that a file exists and is accessible
144
+ */
145
+ async verifyFile(filePath) {
146
+ try {
147
+ // Check if file exists
148
+ if (!fs.existsSync(filePath)) {
149
+ throw new Error(`File does not exist: ${filePath}`);
150
+ }
151
+ // Get file stats
152
+ const stats = fs.statSync(filePath);
153
+ // Check if it's actually a file
154
+ if (!stats.isFile()) {
155
+ throw new Error(`Path is not a file: ${filePath}`);
156
+ }
157
+ // Check if file is readable
158
+ fs.accessSync(filePath, fs.constants.R_OK);
159
+ return {
160
+ success: true,
161
+ filePath: filePath,
162
+ fileName: path.basename(filePath),
163
+ size: stats.size,
164
+ };
165
+ }
166
+ catch (error) {
167
+ throw new Error(`Failed to verify file: ${error}`);
168
+ }
169
+ }
170
+ /**
171
+ * Clean up a temporary file
172
+ */
173
+ async cleanupFile(filePath) {
174
+ try {
175
+ // Only allow cleanup of files in our temp directory
176
+ if (!filePath.startsWith(this.tempDir)) {
177
+ return {
178
+ success: false,
179
+ error: 'Can only cleanup files in temp directory',
180
+ };
181
+ }
182
+ if (fs.existsSync(filePath)) {
183
+ fs.unlinkSync(filePath);
184
+ }
185
+ return {
186
+ success: true,
187
+ message: 'File cleaned up successfully',
188
+ };
189
+ }
190
+ catch (error) {
191
+ return {
192
+ success: false,
193
+ error: `Failed to cleanup file: ${error}`,
194
+ };
195
+ }
196
+ }
197
+ /**
198
+ * Generate a filename from URL or create a unique one
199
+ */
200
+ generateFileName(url) {
201
+ if (url) {
202
+ try {
203
+ const urlObj = new URL(url);
204
+ const pathname = urlObj.pathname;
205
+ const basename = path.basename(pathname);
206
+ if (basename && basename !== '/') {
207
+ // Add random suffix to avoid collisions
208
+ const ext = path.extname(basename);
209
+ const name = path.basename(basename, ext);
210
+ const randomSuffix = crypto.randomBytes(4).toString('hex');
211
+ return `${name}-${randomSuffix}${ext}`;
212
+ }
213
+ }
214
+ catch (_a) {
215
+ // Invalid URL, fall through to generate random name
216
+ }
217
+ }
218
+ // Generate random filename
219
+ return `upload-${crypto.randomBytes(8).toString('hex')}.bin`;
220
+ }
221
+ /**
222
+ * Clean up old temporary files (older than 1 hour)
223
+ */
224
+ cleanupOldFiles() {
225
+ try {
226
+ const now = Date.now();
227
+ const oneHour = 60 * 60 * 1000;
228
+ const files = fs.readdirSync(this.tempDir);
229
+ for (const file of files) {
230
+ const filePath = path.join(this.tempDir, file);
231
+ const stats = fs.statSync(filePath);
232
+ if (now - stats.mtimeMs > oneHour) {
233
+ fs.unlinkSync(filePath);
234
+ console.log(`Cleaned up old temp file: ${file}`);
235
+ }
236
+ }
237
+ }
238
+ catch (error) {
239
+ console.error('Error cleaning up old files:', error);
240
+ }
241
+ }
242
+ }
243
+ exports.FileHandler = FileHandler;
244
+ exports.default = new FileHandler();
245
+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AA6B,IAAI,EAAE,CAAC,CAAC;gBACnD,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;CACF;AArND,kCAqNC;AAED,kBAAe,IAAI,WAAW,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
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,141 @@
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 chrome_mcp_shared_1 = require("chrome-mcp-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
+ resources: {},
71
+ prompts: {},
72
+ },
73
+ });
74
+ (0, exports.setupTools)(stdioMcpServer);
75
+ return stdioMcpServer;
76
+ };
77
+ exports.getStdioMcpServer = getStdioMcpServer;
78
+ const ensureMcpClient = async () => {
79
+ try {
80
+ if (mcpClient) {
81
+ const pingResult = await mcpClient.ping();
82
+ if (pingResult) {
83
+ return mcpClient;
84
+ }
85
+ }
86
+ const config = loadConfig();
87
+ mcpClient = new index_js_2.Client({ name: 'Mcp Chrome Proxy', version: '1.0.0' }, { capabilities: {} });
88
+ const transport = new streamableHttp_js_1.StreamableHTTPClientTransport(new URL(config.url), {});
89
+ await mcpClient.connect(transport);
90
+ return mcpClient;
91
+ }
92
+ catch (error) {
93
+ mcpClient === null || mcpClient === void 0 ? void 0 : mcpClient.close();
94
+ mcpClient = null;
95
+ console.error('Failed to connect to MCP server:', error);
96
+ }
97
+ };
98
+ exports.ensureMcpClient = ensureMcpClient;
99
+ const setupTools = (server) => {
100
+ // List tools handler
101
+ server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => ({ tools: chrome_mcp_shared_1.TOOL_SCHEMAS }));
102
+ // Call tool handler
103
+ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => handleToolCall(request.params.name, request.params.arguments || {}));
104
+ // List resources handler - REQUIRED BY MCP PROTOCOL
105
+ server.setRequestHandler(types_js_1.ListResourcesRequestSchema, async () => ({ resources: [] }));
106
+ // List prompts handler - REQUIRED BY MCP PROTOCOL
107
+ server.setRequestHandler(types_js_1.ListPromptsRequestSchema, async () => ({ prompts: [] }));
108
+ };
109
+ exports.setupTools = setupTools;
110
+ const handleToolCall = async (name, args) => {
111
+ try {
112
+ const client = await (0, exports.ensureMcpClient)();
113
+ if (!client) {
114
+ throw new Error('Failed to connect to MCP server');
115
+ }
116
+ const result = await client.callTool({ name, arguments: args }, undefined, {
117
+ timeout: 2 * 6 * 1000, // Default timeout of 2 minute
118
+ });
119
+ return result;
120
+ }
121
+ catch (error) {
122
+ return {
123
+ content: [
124
+ {
125
+ type: 'text',
126
+ text: `Error calling tool: ${error.message}`,
127
+ },
128
+ ],
129
+ isError: true,
130
+ };
131
+ }
132
+ };
133
+ async function main() {
134
+ const transport = new stdio_js_1.StdioServerTransport();
135
+ await (0, exports.getStdioMcpServer)().connect(transport);
136
+ }
137
+ main().catch((error) => {
138
+ console.error('Fatal error Chrome MCP Server main():', error);
139
+ process.exit(1);
140
+ });
141
+ //# sourceMappingURL=mcp-server-stdio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-server-stdio.js","sourceRoot":"","sources":["../../src/mcp/mcp-server-stdio.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,wEAAmE;AACnE,wEAAmE;AACnE,iEAM4C;AAC5C,yDAAiD;AACjD,wEAAiF;AACjF,0FAAmG;AACnG,uCAAyB;AACzB,2CAA6B;AAE7B,IAAI,cAAc,GAAkB,IAAI,CAAC;AACzC,IAAI,SAAS,GAAkB,IAAI,CAAC;AAEpC,4CAA4C;AAC5C,MAAM,UAAU,GAAG,GAAG,EAAE;IACtB,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;QAC7D,MAAM,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QACvD,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAC/E,CAAC;AACH,CAAC,CAAC;AAEK,MAAM,iBAAiB,GAAG,GAAG,EAAE;IACpC,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,cAAc,CAAC;IACxB,CAAC;IACD,cAAc,GAAG,IAAI,iBAAM,CACzB;QACE,IAAI,EAAE,sBAAsB;QAC5B,OAAO,EAAE,OAAO;KACjB,EACD;QACE,YAAY,EAAE;YACZ,KAAK,EAAE,EAAE;YACT,SAAS,EAAE,EAAE;YACb,OAAO,EAAE,EAAE;SACZ;KACF,CACF,CAAC;IAE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AA,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,2 @@
1
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
+ export declare const setupTools: (server: Server) => void;
@@ -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 chrome_mcp_shared_1 = require("chrome-mcp-shared");
10
+ const setupTools = (server) => {
11
+ // List tools handler
12
+ server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => ({ tools: chrome_mcp_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
+ }, chrome_mcp_shared_1.NativeMessageType.CALL_TOOL, 30000);
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,yDAAoE;AAE7D,MAAM,UAAU,GAAG,CAAC,MAAc,EAAE,EAAE;IAC3C,qBAAqB;IACrB,MAAM,CAAC,iBAAiB,CAAC,iCAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,gCAAY,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,IAAI;YACJ,IAAI;SACL,EACD,qCAAiB,CAAC,SAAS,EAC3B,KAAK,CACN,CAAC;QACF,IAAI,QAAQ,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAClC,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,uBAAuB,QAAQ,CAAC,KAAK,EAAE;qBAC9C;iBACF;gBACD,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,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"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "url": "http://127.0.0.1:12306/mcp"
3
+ }
@@ -0,0 +1,42 @@
1
+ import { Server } from './server';
2
+ export declare class NativeMessagingHost {
3
+ private associatedServer;
4
+ private pendingRequests;
5
+ setServer(serverInstance: Server): void;
6
+ start(): void;
7
+ private setupMessageHandling;
8
+ private handleMessage;
9
+ /**
10
+ * Handle file operations from the extension
11
+ */
12
+ private handleFileOperation;
13
+ /**
14
+ * Send request to Chrome and wait for response
15
+ * @param messagePayload Data to send to Chrome
16
+ * @param timeoutMs Timeout for waiting response (milliseconds)
17
+ * @returns Promise, resolves to Chrome's returned payload on success, rejects on failure
18
+ */
19
+ sendRequestToExtensionAndWait(messagePayload: any, messageType?: string, timeoutMs?: number): Promise<any>;
20
+ /**
21
+ * Start Fastify server (now accepts Server instance)
22
+ */
23
+ private startServer;
24
+ /**
25
+ * Stop Fastify server
26
+ */
27
+ private stopServer;
28
+ /**
29
+ * Send message to Chrome extension
30
+ */
31
+ sendMessage(message: any): void;
32
+ /**
33
+ * Send error message to Chrome extension (mainly for sending non-request-response type errors)
34
+ */
35
+ private sendError;
36
+ /**
37
+ * Clean up resources
38
+ */
39
+ private cleanup;
40
+ }
41
+ declare const nativeMessagingHostInstance: NativeMessagingHost;
42
+ export default nativeMessagingHostInstance;