@purplesquirrel/mega-mcp-server 1.0.0 → 1.0.1

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.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,589 @@
1
+ #!/usr/bin/env node
2
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
5
+ import { exec } from "child_process";
6
+ import { promisify } from "util";
7
+ const execAsync = promisify(exec);
8
+ const MEGA_CMD_PATH = "/Applications/MEGAcmd.app/Contents/MacOS";
9
+ async function runMegaCommand(command, args = []) {
10
+ const escapedArgs = args.map(arg => `'${arg.replace(/'/g, "'\\''")}'`).join(" ");
11
+ const fullCommand = `cd "${MEGA_CMD_PATH}" && ./mega-exec ${command} ${escapedArgs}`;
12
+ try {
13
+ const { stdout, stderr } = await execAsync(fullCommand, { timeout: 60000 });
14
+ // Filter out the shell cwd reset message
15
+ const output = (stdout + stderr)
16
+ .split('\n')
17
+ .filter(line => !line.includes('Shell cwd was reset'))
18
+ .join('\n')
19
+ .trim();
20
+ return output || "Command completed successfully";
21
+ }
22
+ catch (error) {
23
+ if (error.stdout || error.stderr) {
24
+ const output = (error.stdout + error.stderr)
25
+ .split('\n')
26
+ .filter((line) => !line.includes('Shell cwd was reset'))
27
+ .join('\n')
28
+ .trim();
29
+ if (output)
30
+ return output;
31
+ }
32
+ throw new Error(`Command failed: ${error.message}`);
33
+ }
34
+ }
35
+ const server = new Server({
36
+ name: "mega-mcp",
37
+ version: "1.0.0",
38
+ }, {
39
+ capabilities: {
40
+ tools: {},
41
+ },
42
+ });
43
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
44
+ return {
45
+ tools: [
46
+ {
47
+ name: "mega_whoami",
48
+ description: "Get current logged-in MEGA account information",
49
+ inputSchema: {
50
+ type: "object",
51
+ properties: {},
52
+ required: [],
53
+ },
54
+ },
55
+ {
56
+ name: "mega_ls",
57
+ description: "List files and folders in MEGA cloud storage",
58
+ inputSchema: {
59
+ type: "object",
60
+ properties: {
61
+ path: {
62
+ type: "string",
63
+ description: "Remote path to list (default: current directory)",
64
+ default: "/",
65
+ },
66
+ long: {
67
+ type: "boolean",
68
+ description: "Show detailed listing with sizes and dates",
69
+ default: false,
70
+ },
71
+ recursive: {
72
+ type: "boolean",
73
+ description: "List recursively",
74
+ default: false,
75
+ },
76
+ },
77
+ required: [],
78
+ },
79
+ },
80
+ {
81
+ name: "mega_cd",
82
+ description: "Change current working directory in MEGA cloud",
83
+ inputSchema: {
84
+ type: "object",
85
+ properties: {
86
+ path: {
87
+ type: "string",
88
+ description: "Remote path to change to",
89
+ },
90
+ },
91
+ required: ["path"],
92
+ },
93
+ },
94
+ {
95
+ name: "mega_pwd",
96
+ description: "Print current working directory in MEGA cloud",
97
+ inputSchema: {
98
+ type: "object",
99
+ properties: {},
100
+ required: [],
101
+ },
102
+ },
103
+ {
104
+ name: "mega_mkdir",
105
+ description: "Create a directory in MEGA cloud storage",
106
+ inputSchema: {
107
+ type: "object",
108
+ properties: {
109
+ path: {
110
+ type: "string",
111
+ description: "Remote path for new directory",
112
+ },
113
+ parents: {
114
+ type: "boolean",
115
+ description: "Create parent directories as needed",
116
+ default: false,
117
+ },
118
+ },
119
+ required: ["path"],
120
+ },
121
+ },
122
+ {
123
+ name: "mega_rm",
124
+ description: "Remove files or folders from MEGA cloud storage",
125
+ inputSchema: {
126
+ type: "object",
127
+ properties: {
128
+ path: {
129
+ type: "string",
130
+ description: "Remote path to remove",
131
+ },
132
+ recursive: {
133
+ type: "boolean",
134
+ description: "Remove directories recursively",
135
+ default: false,
136
+ },
137
+ force: {
138
+ type: "boolean",
139
+ description: "Force removal without confirmation",
140
+ default: false,
141
+ },
142
+ },
143
+ required: ["path"],
144
+ },
145
+ },
146
+ {
147
+ name: "mega_mv",
148
+ description: "Move or rename files/folders in MEGA cloud storage",
149
+ inputSchema: {
150
+ type: "object",
151
+ properties: {
152
+ source: {
153
+ type: "string",
154
+ description: "Source remote path",
155
+ },
156
+ destination: {
157
+ type: "string",
158
+ description: "Destination remote path",
159
+ },
160
+ },
161
+ required: ["source", "destination"],
162
+ },
163
+ },
164
+ {
165
+ name: "mega_cp",
166
+ description: "Copy files/folders within MEGA cloud storage",
167
+ inputSchema: {
168
+ type: "object",
169
+ properties: {
170
+ source: {
171
+ type: "string",
172
+ description: "Source remote path",
173
+ },
174
+ destination: {
175
+ type: "string",
176
+ description: "Destination remote path",
177
+ },
178
+ },
179
+ required: ["source", "destination"],
180
+ },
181
+ },
182
+ {
183
+ name: "mega_get",
184
+ description: "Download files from MEGA cloud to local filesystem",
185
+ inputSchema: {
186
+ type: "object",
187
+ properties: {
188
+ remote_path: {
189
+ type: "string",
190
+ description: "Remote path in MEGA to download",
191
+ },
192
+ local_path: {
193
+ type: "string",
194
+ description: "Local destination path (default: current directory)",
195
+ },
196
+ },
197
+ required: ["remote_path"],
198
+ },
199
+ },
200
+ {
201
+ name: "mega_put",
202
+ description: "Upload files from local filesystem to MEGA cloud",
203
+ inputSchema: {
204
+ type: "object",
205
+ properties: {
206
+ local_path: {
207
+ type: "string",
208
+ description: "Local file/folder path to upload",
209
+ },
210
+ remote_path: {
211
+ type: "string",
212
+ description: "Remote destination path in MEGA",
213
+ },
214
+ },
215
+ required: ["local_path"],
216
+ },
217
+ },
218
+ {
219
+ name: "mega_df",
220
+ description: "Show MEGA cloud storage space usage",
221
+ inputSchema: {
222
+ type: "object",
223
+ properties: {
224
+ human: {
225
+ type: "boolean",
226
+ description: "Show sizes in human-readable format",
227
+ default: true,
228
+ },
229
+ },
230
+ required: [],
231
+ },
232
+ },
233
+ {
234
+ name: "mega_du",
235
+ description: "Show disk usage of remote path",
236
+ inputSchema: {
237
+ type: "object",
238
+ properties: {
239
+ path: {
240
+ type: "string",
241
+ description: "Remote path to check",
242
+ default: "/",
243
+ },
244
+ human: {
245
+ type: "boolean",
246
+ description: "Show sizes in human-readable format",
247
+ default: true,
248
+ },
249
+ },
250
+ required: [],
251
+ },
252
+ },
253
+ {
254
+ name: "mega_find",
255
+ description: "Search for files/folders in MEGA cloud storage",
256
+ inputSchema: {
257
+ type: "object",
258
+ properties: {
259
+ pattern: {
260
+ type: "string",
261
+ description: "Search pattern (supports wildcards)",
262
+ },
263
+ path: {
264
+ type: "string",
265
+ description: "Path to search in (default: /)",
266
+ default: "/",
267
+ },
268
+ },
269
+ required: ["pattern"],
270
+ },
271
+ },
272
+ {
273
+ name: "mega_export",
274
+ description: "Create a public link for a file/folder",
275
+ inputSchema: {
276
+ type: "object",
277
+ properties: {
278
+ path: {
279
+ type: "string",
280
+ description: "Remote path to export",
281
+ },
282
+ expire: {
283
+ type: "string",
284
+ description: "Expiration time (e.g., '1d', '1w', '1m')",
285
+ },
286
+ password: {
287
+ type: "string",
288
+ description: "Password protect the link",
289
+ },
290
+ },
291
+ required: ["path"],
292
+ },
293
+ },
294
+ {
295
+ name: "mega_share",
296
+ description: "Share a folder with another MEGA user",
297
+ inputSchema: {
298
+ type: "object",
299
+ properties: {
300
+ path: {
301
+ type: "string",
302
+ description: "Remote folder path to share",
303
+ },
304
+ email: {
305
+ type: "string",
306
+ description: "Email of user to share with",
307
+ },
308
+ access_level: {
309
+ type: "string",
310
+ description: "Access level: 'r' (read), 'rw' (read-write), 'full' (full access)",
311
+ enum: ["r", "rw", "full"],
312
+ default: "r",
313
+ },
314
+ },
315
+ required: ["path", "email"],
316
+ },
317
+ },
318
+ {
319
+ name: "mega_transfers",
320
+ description: "Show current transfers (uploads/downloads)",
321
+ inputSchema: {
322
+ type: "object",
323
+ properties: {
324
+ show_completed: {
325
+ type: "boolean",
326
+ description: "Include completed transfers",
327
+ default: false,
328
+ },
329
+ },
330
+ required: [],
331
+ },
332
+ },
333
+ {
334
+ name: "mega_sync",
335
+ description: "Set up sync between local and remote folders",
336
+ inputSchema: {
337
+ type: "object",
338
+ properties: {
339
+ local_path: {
340
+ type: "string",
341
+ description: "Local folder path",
342
+ },
343
+ remote_path: {
344
+ type: "string",
345
+ description: "Remote MEGA folder path",
346
+ },
347
+ list_only: {
348
+ type: "boolean",
349
+ description: "Just list current syncs instead of creating new one",
350
+ default: false,
351
+ },
352
+ },
353
+ required: [],
354
+ },
355
+ },
356
+ {
357
+ name: "mega_tree",
358
+ description: "Show directory tree structure",
359
+ inputSchema: {
360
+ type: "object",
361
+ properties: {
362
+ path: {
363
+ type: "string",
364
+ description: "Remote path to show tree for",
365
+ default: "/",
366
+ },
367
+ },
368
+ required: [],
369
+ },
370
+ },
371
+ {
372
+ name: "mega_cat",
373
+ description: "Display contents of a remote file",
374
+ inputSchema: {
375
+ type: "object",
376
+ properties: {
377
+ path: {
378
+ type: "string",
379
+ description: "Remote file path to display",
380
+ },
381
+ },
382
+ required: ["path"],
383
+ },
384
+ },
385
+ {
386
+ name: "mega_import",
387
+ description: "Import a public MEGA link to your account",
388
+ inputSchema: {
389
+ type: "object",
390
+ properties: {
391
+ link: {
392
+ type: "string",
393
+ description: "MEGA public link to import",
394
+ },
395
+ remote_path: {
396
+ type: "string",
397
+ description: "Destination path in your MEGA",
398
+ default: "/",
399
+ },
400
+ },
401
+ required: ["link"],
402
+ },
403
+ },
404
+ ],
405
+ };
406
+ });
407
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
408
+ const { name, arguments: args } = request.params;
409
+ try {
410
+ let result;
411
+ switch (name) {
412
+ case "mega_whoami":
413
+ result = await runMegaCommand("whoami");
414
+ break;
415
+ case "mega_ls": {
416
+ const cmdArgs = [];
417
+ if (args?.long)
418
+ cmdArgs.push("-l");
419
+ if (args?.recursive)
420
+ cmdArgs.push("-R");
421
+ if (args?.path)
422
+ cmdArgs.push(args.path);
423
+ else
424
+ cmdArgs.push("/");
425
+ result = await runMegaCommand("ls", cmdArgs);
426
+ break;
427
+ }
428
+ case "mega_cd":
429
+ result = await runMegaCommand("cd", [args?.path]);
430
+ break;
431
+ case "mega_pwd":
432
+ result = await runMegaCommand("pwd");
433
+ break;
434
+ case "mega_mkdir": {
435
+ const cmdArgs = [];
436
+ if (args?.parents)
437
+ cmdArgs.push("-p");
438
+ cmdArgs.push(args?.path);
439
+ result = await runMegaCommand("mkdir", cmdArgs);
440
+ break;
441
+ }
442
+ case "mega_rm": {
443
+ const cmdArgs = [];
444
+ if (args?.recursive)
445
+ cmdArgs.push("-r");
446
+ if (args?.force)
447
+ cmdArgs.push("-f");
448
+ cmdArgs.push(args?.path);
449
+ result = await runMegaCommand("rm", cmdArgs);
450
+ break;
451
+ }
452
+ case "mega_mv":
453
+ result = await runMegaCommand("mv", [
454
+ args?.source,
455
+ args?.destination,
456
+ ]);
457
+ break;
458
+ case "mega_cp":
459
+ result = await runMegaCommand("cp", [
460
+ args?.source,
461
+ args?.destination,
462
+ ]);
463
+ break;
464
+ case "mega_get": {
465
+ const cmdArgs = [args?.remote_path];
466
+ if (args?.local_path)
467
+ cmdArgs.push(args.local_path);
468
+ result = await runMegaCommand("get", cmdArgs);
469
+ break;
470
+ }
471
+ case "mega_put": {
472
+ const cmdArgs = [args?.local_path];
473
+ if (args?.remote_path)
474
+ cmdArgs.push(args.remote_path);
475
+ result = await runMegaCommand("put", cmdArgs);
476
+ break;
477
+ }
478
+ case "mega_df": {
479
+ const cmdArgs = [];
480
+ if (args?.human)
481
+ cmdArgs.push("-h");
482
+ result = await runMegaCommand("df", cmdArgs);
483
+ break;
484
+ }
485
+ case "mega_du": {
486
+ const cmdArgs = [];
487
+ if (args?.human)
488
+ cmdArgs.push("-h");
489
+ if (args?.path)
490
+ cmdArgs.push(args.path);
491
+ result = await runMegaCommand("du", cmdArgs);
492
+ break;
493
+ }
494
+ case "mega_find": {
495
+ const cmdArgs = [];
496
+ if (args?.path)
497
+ cmdArgs.push(args.path);
498
+ cmdArgs.push("--pattern=" + args?.pattern);
499
+ result = await runMegaCommand("find", cmdArgs);
500
+ break;
501
+ }
502
+ case "mega_export": {
503
+ const cmdArgs = ["-a", args?.path];
504
+ if (args?.expire)
505
+ cmdArgs.push("--expire=" + args.expire);
506
+ if (args?.password)
507
+ cmdArgs.push("--password=" + args.password);
508
+ result = await runMegaCommand("export", cmdArgs);
509
+ break;
510
+ }
511
+ case "mega_share": {
512
+ const cmdArgs = [
513
+ "-a",
514
+ "--with=" + args?.email,
515
+ "--level=" + (args?.access_level || "r"),
516
+ args?.path,
517
+ ];
518
+ result = await runMegaCommand("share", cmdArgs);
519
+ break;
520
+ }
521
+ case "mega_transfers": {
522
+ const cmdArgs = [];
523
+ if (args?.show_completed)
524
+ cmdArgs.push("-c");
525
+ result = await runMegaCommand("transfers", cmdArgs);
526
+ break;
527
+ }
528
+ case "mega_sync": {
529
+ if (args?.list_only) {
530
+ result = await runMegaCommand("sync");
531
+ }
532
+ else if (args?.local_path && args?.remote_path) {
533
+ result = await runMegaCommand("sync", [
534
+ args.local_path,
535
+ args.remote_path,
536
+ ]);
537
+ }
538
+ else {
539
+ result = await runMegaCommand("sync");
540
+ }
541
+ break;
542
+ }
543
+ case "mega_tree": {
544
+ const cmdArgs = [];
545
+ if (args?.path)
546
+ cmdArgs.push(args.path);
547
+ result = await runMegaCommand("tree", cmdArgs);
548
+ break;
549
+ }
550
+ case "mega_cat":
551
+ result = await runMegaCommand("cat", [args?.path]);
552
+ break;
553
+ case "mega_import": {
554
+ const cmdArgs = [args?.link];
555
+ if (args?.remote_path)
556
+ cmdArgs.push(args.remote_path);
557
+ result = await runMegaCommand("import", cmdArgs);
558
+ break;
559
+ }
560
+ default:
561
+ throw new Error(`Unknown tool: ${name}`);
562
+ }
563
+ return {
564
+ content: [
565
+ {
566
+ type: "text",
567
+ text: result,
568
+ },
569
+ ],
570
+ };
571
+ }
572
+ catch (error) {
573
+ return {
574
+ content: [
575
+ {
576
+ type: "text",
577
+ text: `Error: ${error.message}`,
578
+ },
579
+ ],
580
+ isError: true,
581
+ };
582
+ }
583
+ });
584
+ async function main() {
585
+ const transport = new StdioServerTransport();
586
+ await server.connect(transport);
587
+ console.error("MEGA MCP server running on stdio");
588
+ }
589
+ main().catch(console.error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purplesquirrel/mega-mcp-server",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "MCP server for MEGA cloud storage CLI",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",