@purplesquirrel/mega-mcp-server 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.
- package/.github/dependabot.yml +21 -0
- package/.github/workflows/ci.yml +36 -0
- package/LICENSE +21 -0
- package/README.md +205 -0
- package/package.json +23 -0
- package/src/index.ts +605 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
- package-ecosystem: "npm"
|
|
4
|
+
directory: "/"
|
|
5
|
+
schedule:
|
|
6
|
+
interval: "weekly"
|
|
7
|
+
open-pull-requests-limit: 10
|
|
8
|
+
labels:
|
|
9
|
+
- "dependencies"
|
|
10
|
+
commit-message:
|
|
11
|
+
prefix: "chore(deps)"
|
|
12
|
+
|
|
13
|
+
- package-ecosystem: "github-actions"
|
|
14
|
+
directory: "/"
|
|
15
|
+
schedule:
|
|
16
|
+
interval: "weekly"
|
|
17
|
+
labels:
|
|
18
|
+
- "dependencies"
|
|
19
|
+
- "github-actions"
|
|
20
|
+
commit-message:
|
|
21
|
+
prefix: "chore(ci)"
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
strategy:
|
|
14
|
+
matrix:
|
|
15
|
+
node-version: [18.x, 20.x]
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
21
|
+
uses: actions/setup-node@v4
|
|
22
|
+
with:
|
|
23
|
+
node-version: ${{ matrix.node-version }}
|
|
24
|
+
cache: 'npm'
|
|
25
|
+
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: npm ci
|
|
28
|
+
|
|
29
|
+
- name: Run linter
|
|
30
|
+
run: npm run lint --if-present
|
|
31
|
+
|
|
32
|
+
- name: Run tests
|
|
33
|
+
run: npm test --if-present
|
|
34
|
+
|
|
35
|
+
- name: Build
|
|
36
|
+
run: npm run build --if-present
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Purple Squirrel Media
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
[](https://opensource.org/licenses/MIT)
|
|
2
|
+
[](https://modelcontextprotocol.io)
|
|
3
|
+
[](https://mega.io)
|
|
4
|
+
[](https://github.com/PurpleSquirrelMedia/mega-mcp-server/actions/workflows/ci.yml)
|
|
5
|
+
|
|
6
|
+
# MEGA Cloud Storage MCP Server
|
|
7
|
+
|
|
8
|
+
MCP server for MEGA cloud storage integration with Claude Code. Provides comprehensive file management, synchronization, and sharing capabilities using MEGAcmd.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **File Management** - List, copy, move, delete files and folders
|
|
13
|
+
- **Upload/Download** - Transfer files between local and cloud
|
|
14
|
+
- **Sharing** - Create public links and share with other users
|
|
15
|
+
- **Sync** - Set up folder synchronization
|
|
16
|
+
- **Storage Info** - View usage and quotas
|
|
17
|
+
|
|
18
|
+
## Available Tools (18 total)
|
|
19
|
+
|
|
20
|
+
### Account & Navigation
|
|
21
|
+
| Tool | Description |
|
|
22
|
+
|------|-------------|
|
|
23
|
+
| `mega_whoami` | Get current logged-in account info |
|
|
24
|
+
| `mega_pwd` | Print current working directory |
|
|
25
|
+
| `mega_cd` | Change current directory |
|
|
26
|
+
| `mega_df` | Show storage space usage |
|
|
27
|
+
| `mega_du` | Show disk usage of remote path |
|
|
28
|
+
|
|
29
|
+
### File Operations
|
|
30
|
+
| Tool | Description |
|
|
31
|
+
|------|-------------|
|
|
32
|
+
| `mega_ls` | List files and folders |
|
|
33
|
+
| `mega_mkdir` | Create a directory |
|
|
34
|
+
| `mega_rm` | Remove files or folders |
|
|
35
|
+
| `mega_mv` | Move or rename files/folders |
|
|
36
|
+
| `mega_cp` | Copy files/folders |
|
|
37
|
+
| `mega_cat` | Display contents of a remote file |
|
|
38
|
+
| `mega_tree` | Show directory tree structure |
|
|
39
|
+
| `mega_find` | Search for files/folders |
|
|
40
|
+
|
|
41
|
+
### Transfer
|
|
42
|
+
| Tool | Description |
|
|
43
|
+
|------|-------------|
|
|
44
|
+
| `mega_get` | Download files to local filesystem |
|
|
45
|
+
| `mega_put` | Upload files to MEGA cloud |
|
|
46
|
+
| `mega_transfers` | Show current transfers |
|
|
47
|
+
| `mega_sync` | Set up folder synchronization |
|
|
48
|
+
|
|
49
|
+
### Sharing
|
|
50
|
+
| Tool | Description |
|
|
51
|
+
|------|-------------|
|
|
52
|
+
| `mega_export` | Create a public link |
|
|
53
|
+
| `mega_share` | Share folder with another user |
|
|
54
|
+
| `mega_import` | Import a public MEGA link |
|
|
55
|
+
|
|
56
|
+
## Setup
|
|
57
|
+
|
|
58
|
+
### 1. Prerequisites
|
|
59
|
+
|
|
60
|
+
Install MEGAcmd from https://mega.io/cmd
|
|
61
|
+
|
|
62
|
+
On macOS:
|
|
63
|
+
```bash
|
|
64
|
+
brew install --cask megacmd
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Login to your MEGA account:
|
|
68
|
+
```bash
|
|
69
|
+
mega-login your@email.com password
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 2. Install Dependencies
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
cd ~/mcp-servers/mega-mcp
|
|
76
|
+
npm install
|
|
77
|
+
npm run build
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 3. Add to Claude Code
|
|
81
|
+
|
|
82
|
+
Add to `~/.claude.json`:
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"mcpServers": {
|
|
87
|
+
"mega": {
|
|
88
|
+
"type": "stdio",
|
|
89
|
+
"command": "node",
|
|
90
|
+
"args": ["/Users/matthewkarsten/mcp-servers/mega-mcp/dist/index.js"]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Architecture
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
Claude Code (Opus 4.5)
|
|
100
|
+
│
|
|
101
|
+
└──▶ MEGA MCP Server
|
|
102
|
+
│
|
|
103
|
+
└──▶ MEGAcmd CLI
|
|
104
|
+
│
|
|
105
|
+
└──▶ MEGA Cloud Storage
|
|
106
|
+
│
|
|
107
|
+
├── 20 GB Free Storage
|
|
108
|
+
├── End-to-End Encryption
|
|
109
|
+
├── File Versioning
|
|
110
|
+
└── Sharing & Sync
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## MEGA Features
|
|
114
|
+
|
|
115
|
+
- **End-to-End Encryption** - All files encrypted client-side
|
|
116
|
+
- **20 GB Free Storage** - Free tier included
|
|
117
|
+
- **File Versioning** - Automatic version history
|
|
118
|
+
- **Cross-Platform Sync** - Desktop and mobile apps
|
|
119
|
+
- **Public Links** - Share files with anyone
|
|
120
|
+
- **Folder Sharing** - Collaborate with other MEGA users
|
|
121
|
+
|
|
122
|
+
## Usage Examples
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
User: Show my MEGA storage usage
|
|
126
|
+
|
|
127
|
+
Claude: [Uses mega_df tool]
|
|
128
|
+
Result:
|
|
129
|
+
Account: purplesquirrelmedia@icloud.com
|
|
130
|
+
Used: 2.3 GB of 20 GB (11.5%)
|
|
131
|
+
Available: 17.7 GB
|
|
132
|
+
|
|
133
|
+
User: List files in my Documents folder
|
|
134
|
+
|
|
135
|
+
Claude: [Uses mega_ls tool with path=/Documents]
|
|
136
|
+
Result:
|
|
137
|
+
- project-files/
|
|
138
|
+
- presentations/
|
|
139
|
+
- backup.zip (156 MB)
|
|
140
|
+
- notes.txt (2.3 KB)
|
|
141
|
+
|
|
142
|
+
User: Create a public link for backup.zip
|
|
143
|
+
|
|
144
|
+
Claude: [Uses mega_export tool]
|
|
145
|
+
Result: https://mega.nz/file/xxxxx#yyyyy
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Transfer Features
|
|
149
|
+
|
|
150
|
+
### Upload
|
|
151
|
+
```
|
|
152
|
+
User: Upload ~/reports/ to MEGA
|
|
153
|
+
|
|
154
|
+
Claude: [Uses mega_put tool]
|
|
155
|
+
Uploading 15 files...
|
|
156
|
+
Completed: ~/reports/ -> /reports/
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Download
|
|
160
|
+
```
|
|
161
|
+
User: Download /Documents/backup.zip
|
|
162
|
+
|
|
163
|
+
Claude: [Uses mega_get tool]
|
|
164
|
+
Downloaded: /Documents/backup.zip -> ~/Downloads/backup.zip
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Sync
|
|
168
|
+
```
|
|
169
|
+
User: Set up sync between ~/Projects and /Projects
|
|
170
|
+
|
|
171
|
+
Claude: [Uses mega_sync tool]
|
|
172
|
+
Sync established: ~/Projects <-> /Projects
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Files
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
mega-mcp/
|
|
179
|
+
├── src/
|
|
180
|
+
│ └── index.ts # MCP server implementation
|
|
181
|
+
├── dist/ # Compiled JavaScript
|
|
182
|
+
├── package.json
|
|
183
|
+
├── tsconfig.json
|
|
184
|
+
└── README.md
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Dependencies
|
|
188
|
+
|
|
189
|
+
- `@modelcontextprotocol/sdk` - MCP SDK
|
|
190
|
+
- MEGAcmd - MEGA command-line client
|
|
191
|
+
|
|
192
|
+
## Security
|
|
193
|
+
|
|
194
|
+
- All data encrypted with your account key
|
|
195
|
+
- Zero-knowledge encryption (MEGA can't read your files)
|
|
196
|
+
- Two-factor authentication supported
|
|
197
|
+
- Session-based authentication via MEGAcmd
|
|
198
|
+
|
|
199
|
+
## Author
|
|
200
|
+
|
|
201
|
+
Matthew Karsten
|
|
202
|
+
|
|
203
|
+
## License
|
|
204
|
+
|
|
205
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@purplesquirrel/mega-mcp-server",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "MCP server for MEGA cloud storage CLI",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"mega-mcp": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"start": "node dist/index.js",
|
|
13
|
+
"dev": "tsx src/index.ts"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^20.10.0",
|
|
20
|
+
"tsx": "^4.7.0",
|
|
21
|
+
"typescript": "^5.3.0"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
4
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
|
+
import {
|
|
6
|
+
CallToolRequestSchema,
|
|
7
|
+
ListToolsRequestSchema,
|
|
8
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
9
|
+
import { exec } from "child_process";
|
|
10
|
+
import { promisify } from "util";
|
|
11
|
+
|
|
12
|
+
const execAsync = promisify(exec);
|
|
13
|
+
|
|
14
|
+
const MEGA_CMD_PATH = "/Applications/MEGAcmd.app/Contents/MacOS";
|
|
15
|
+
|
|
16
|
+
async function runMegaCommand(command: string, args: string[] = []): Promise<string> {
|
|
17
|
+
const escapedArgs = args.map(arg => `'${arg.replace(/'/g, "'\\''")}'`).join(" ");
|
|
18
|
+
const fullCommand = `cd "${MEGA_CMD_PATH}" && ./mega-exec ${command} ${escapedArgs}`;
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
const { stdout, stderr } = await execAsync(fullCommand, { timeout: 60000 });
|
|
22
|
+
// Filter out the shell cwd reset message
|
|
23
|
+
const output = (stdout + stderr)
|
|
24
|
+
.split('\n')
|
|
25
|
+
.filter(line => !line.includes('Shell cwd was reset'))
|
|
26
|
+
.join('\n')
|
|
27
|
+
.trim();
|
|
28
|
+
return output || "Command completed successfully";
|
|
29
|
+
} catch (error: any) {
|
|
30
|
+
if (error.stdout || error.stderr) {
|
|
31
|
+
const output = (error.stdout + error.stderr)
|
|
32
|
+
.split('\n')
|
|
33
|
+
.filter((line: string) => !line.includes('Shell cwd was reset'))
|
|
34
|
+
.join('\n')
|
|
35
|
+
.trim();
|
|
36
|
+
if (output) return output;
|
|
37
|
+
}
|
|
38
|
+
throw new Error(`Command failed: ${error.message}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const server = new Server(
|
|
43
|
+
{
|
|
44
|
+
name: "mega-mcp",
|
|
45
|
+
version: "1.0.0",
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
capabilities: {
|
|
49
|
+
tools: {},
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
55
|
+
return {
|
|
56
|
+
tools: [
|
|
57
|
+
{
|
|
58
|
+
name: "mega_whoami",
|
|
59
|
+
description: "Get current logged-in MEGA account information",
|
|
60
|
+
inputSchema: {
|
|
61
|
+
type: "object",
|
|
62
|
+
properties: {},
|
|
63
|
+
required: [],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: "mega_ls",
|
|
68
|
+
description: "List files and folders in MEGA cloud storage",
|
|
69
|
+
inputSchema: {
|
|
70
|
+
type: "object",
|
|
71
|
+
properties: {
|
|
72
|
+
path: {
|
|
73
|
+
type: "string",
|
|
74
|
+
description: "Remote path to list (default: current directory)",
|
|
75
|
+
default: "/",
|
|
76
|
+
},
|
|
77
|
+
long: {
|
|
78
|
+
type: "boolean",
|
|
79
|
+
description: "Show detailed listing with sizes and dates",
|
|
80
|
+
default: false,
|
|
81
|
+
},
|
|
82
|
+
recursive: {
|
|
83
|
+
type: "boolean",
|
|
84
|
+
description: "List recursively",
|
|
85
|
+
default: false,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
required: [],
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: "mega_cd",
|
|
93
|
+
description: "Change current working directory in MEGA cloud",
|
|
94
|
+
inputSchema: {
|
|
95
|
+
type: "object",
|
|
96
|
+
properties: {
|
|
97
|
+
path: {
|
|
98
|
+
type: "string",
|
|
99
|
+
description: "Remote path to change to",
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
required: ["path"],
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: "mega_pwd",
|
|
107
|
+
description: "Print current working directory in MEGA cloud",
|
|
108
|
+
inputSchema: {
|
|
109
|
+
type: "object",
|
|
110
|
+
properties: {},
|
|
111
|
+
required: [],
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: "mega_mkdir",
|
|
116
|
+
description: "Create a directory in MEGA cloud storage",
|
|
117
|
+
inputSchema: {
|
|
118
|
+
type: "object",
|
|
119
|
+
properties: {
|
|
120
|
+
path: {
|
|
121
|
+
type: "string",
|
|
122
|
+
description: "Remote path for new directory",
|
|
123
|
+
},
|
|
124
|
+
parents: {
|
|
125
|
+
type: "boolean",
|
|
126
|
+
description: "Create parent directories as needed",
|
|
127
|
+
default: false,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
required: ["path"],
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: "mega_rm",
|
|
135
|
+
description: "Remove files or folders from MEGA cloud storage",
|
|
136
|
+
inputSchema: {
|
|
137
|
+
type: "object",
|
|
138
|
+
properties: {
|
|
139
|
+
path: {
|
|
140
|
+
type: "string",
|
|
141
|
+
description: "Remote path to remove",
|
|
142
|
+
},
|
|
143
|
+
recursive: {
|
|
144
|
+
type: "boolean",
|
|
145
|
+
description: "Remove directories recursively",
|
|
146
|
+
default: false,
|
|
147
|
+
},
|
|
148
|
+
force: {
|
|
149
|
+
type: "boolean",
|
|
150
|
+
description: "Force removal without confirmation",
|
|
151
|
+
default: false,
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
required: ["path"],
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: "mega_mv",
|
|
159
|
+
description: "Move or rename files/folders in MEGA cloud storage",
|
|
160
|
+
inputSchema: {
|
|
161
|
+
type: "object",
|
|
162
|
+
properties: {
|
|
163
|
+
source: {
|
|
164
|
+
type: "string",
|
|
165
|
+
description: "Source remote path",
|
|
166
|
+
},
|
|
167
|
+
destination: {
|
|
168
|
+
type: "string",
|
|
169
|
+
description: "Destination remote path",
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
required: ["source", "destination"],
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
name: "mega_cp",
|
|
177
|
+
description: "Copy files/folders within MEGA cloud storage",
|
|
178
|
+
inputSchema: {
|
|
179
|
+
type: "object",
|
|
180
|
+
properties: {
|
|
181
|
+
source: {
|
|
182
|
+
type: "string",
|
|
183
|
+
description: "Source remote path",
|
|
184
|
+
},
|
|
185
|
+
destination: {
|
|
186
|
+
type: "string",
|
|
187
|
+
description: "Destination remote path",
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
required: ["source", "destination"],
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
name: "mega_get",
|
|
195
|
+
description: "Download files from MEGA cloud to local filesystem",
|
|
196
|
+
inputSchema: {
|
|
197
|
+
type: "object",
|
|
198
|
+
properties: {
|
|
199
|
+
remote_path: {
|
|
200
|
+
type: "string",
|
|
201
|
+
description: "Remote path in MEGA to download",
|
|
202
|
+
},
|
|
203
|
+
local_path: {
|
|
204
|
+
type: "string",
|
|
205
|
+
description: "Local destination path (default: current directory)",
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
required: ["remote_path"],
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
name: "mega_put",
|
|
213
|
+
description: "Upload files from local filesystem to MEGA cloud",
|
|
214
|
+
inputSchema: {
|
|
215
|
+
type: "object",
|
|
216
|
+
properties: {
|
|
217
|
+
local_path: {
|
|
218
|
+
type: "string",
|
|
219
|
+
description: "Local file/folder path to upload",
|
|
220
|
+
},
|
|
221
|
+
remote_path: {
|
|
222
|
+
type: "string",
|
|
223
|
+
description: "Remote destination path in MEGA",
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
required: ["local_path"],
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
name: "mega_df",
|
|
231
|
+
description: "Show MEGA cloud storage space usage",
|
|
232
|
+
inputSchema: {
|
|
233
|
+
type: "object",
|
|
234
|
+
properties: {
|
|
235
|
+
human: {
|
|
236
|
+
type: "boolean",
|
|
237
|
+
description: "Show sizes in human-readable format",
|
|
238
|
+
default: true,
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
required: [],
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
name: "mega_du",
|
|
246
|
+
description: "Show disk usage of remote path",
|
|
247
|
+
inputSchema: {
|
|
248
|
+
type: "object",
|
|
249
|
+
properties: {
|
|
250
|
+
path: {
|
|
251
|
+
type: "string",
|
|
252
|
+
description: "Remote path to check",
|
|
253
|
+
default: "/",
|
|
254
|
+
},
|
|
255
|
+
human: {
|
|
256
|
+
type: "boolean",
|
|
257
|
+
description: "Show sizes in human-readable format",
|
|
258
|
+
default: true,
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
required: [],
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
name: "mega_find",
|
|
266
|
+
description: "Search for files/folders in MEGA cloud storage",
|
|
267
|
+
inputSchema: {
|
|
268
|
+
type: "object",
|
|
269
|
+
properties: {
|
|
270
|
+
pattern: {
|
|
271
|
+
type: "string",
|
|
272
|
+
description: "Search pattern (supports wildcards)",
|
|
273
|
+
},
|
|
274
|
+
path: {
|
|
275
|
+
type: "string",
|
|
276
|
+
description: "Path to search in (default: /)",
|
|
277
|
+
default: "/",
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
required: ["pattern"],
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
name: "mega_export",
|
|
285
|
+
description: "Create a public link for a file/folder",
|
|
286
|
+
inputSchema: {
|
|
287
|
+
type: "object",
|
|
288
|
+
properties: {
|
|
289
|
+
path: {
|
|
290
|
+
type: "string",
|
|
291
|
+
description: "Remote path to export",
|
|
292
|
+
},
|
|
293
|
+
expire: {
|
|
294
|
+
type: "string",
|
|
295
|
+
description: "Expiration time (e.g., '1d', '1w', '1m')",
|
|
296
|
+
},
|
|
297
|
+
password: {
|
|
298
|
+
type: "string",
|
|
299
|
+
description: "Password protect the link",
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
required: ["path"],
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
name: "mega_share",
|
|
307
|
+
description: "Share a folder with another MEGA user",
|
|
308
|
+
inputSchema: {
|
|
309
|
+
type: "object",
|
|
310
|
+
properties: {
|
|
311
|
+
path: {
|
|
312
|
+
type: "string",
|
|
313
|
+
description: "Remote folder path to share",
|
|
314
|
+
},
|
|
315
|
+
email: {
|
|
316
|
+
type: "string",
|
|
317
|
+
description: "Email of user to share with",
|
|
318
|
+
},
|
|
319
|
+
access_level: {
|
|
320
|
+
type: "string",
|
|
321
|
+
description: "Access level: 'r' (read), 'rw' (read-write), 'full' (full access)",
|
|
322
|
+
enum: ["r", "rw", "full"],
|
|
323
|
+
default: "r",
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
required: ["path", "email"],
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
name: "mega_transfers",
|
|
331
|
+
description: "Show current transfers (uploads/downloads)",
|
|
332
|
+
inputSchema: {
|
|
333
|
+
type: "object",
|
|
334
|
+
properties: {
|
|
335
|
+
show_completed: {
|
|
336
|
+
type: "boolean",
|
|
337
|
+
description: "Include completed transfers",
|
|
338
|
+
default: false,
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
required: [],
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
name: "mega_sync",
|
|
346
|
+
description: "Set up sync between local and remote folders",
|
|
347
|
+
inputSchema: {
|
|
348
|
+
type: "object",
|
|
349
|
+
properties: {
|
|
350
|
+
local_path: {
|
|
351
|
+
type: "string",
|
|
352
|
+
description: "Local folder path",
|
|
353
|
+
},
|
|
354
|
+
remote_path: {
|
|
355
|
+
type: "string",
|
|
356
|
+
description: "Remote MEGA folder path",
|
|
357
|
+
},
|
|
358
|
+
list_only: {
|
|
359
|
+
type: "boolean",
|
|
360
|
+
description: "Just list current syncs instead of creating new one",
|
|
361
|
+
default: false,
|
|
362
|
+
},
|
|
363
|
+
},
|
|
364
|
+
required: [],
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
name: "mega_tree",
|
|
369
|
+
description: "Show directory tree structure",
|
|
370
|
+
inputSchema: {
|
|
371
|
+
type: "object",
|
|
372
|
+
properties: {
|
|
373
|
+
path: {
|
|
374
|
+
type: "string",
|
|
375
|
+
description: "Remote path to show tree for",
|
|
376
|
+
default: "/",
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
required: [],
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
name: "mega_cat",
|
|
384
|
+
description: "Display contents of a remote file",
|
|
385
|
+
inputSchema: {
|
|
386
|
+
type: "object",
|
|
387
|
+
properties: {
|
|
388
|
+
path: {
|
|
389
|
+
type: "string",
|
|
390
|
+
description: "Remote file path to display",
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
required: ["path"],
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
name: "mega_import",
|
|
398
|
+
description: "Import a public MEGA link to your account",
|
|
399
|
+
inputSchema: {
|
|
400
|
+
type: "object",
|
|
401
|
+
properties: {
|
|
402
|
+
link: {
|
|
403
|
+
type: "string",
|
|
404
|
+
description: "MEGA public link to import",
|
|
405
|
+
},
|
|
406
|
+
remote_path: {
|
|
407
|
+
type: "string",
|
|
408
|
+
description: "Destination path in your MEGA",
|
|
409
|
+
default: "/",
|
|
410
|
+
},
|
|
411
|
+
},
|
|
412
|
+
required: ["link"],
|
|
413
|
+
},
|
|
414
|
+
},
|
|
415
|
+
],
|
|
416
|
+
};
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
420
|
+
const { name, arguments: args } = request.params;
|
|
421
|
+
|
|
422
|
+
try {
|
|
423
|
+
let result: string;
|
|
424
|
+
|
|
425
|
+
switch (name) {
|
|
426
|
+
case "mega_whoami":
|
|
427
|
+
result = await runMegaCommand("whoami");
|
|
428
|
+
break;
|
|
429
|
+
|
|
430
|
+
case "mega_ls": {
|
|
431
|
+
const cmdArgs: string[] = [];
|
|
432
|
+
if (args?.long) cmdArgs.push("-l");
|
|
433
|
+
if (args?.recursive) cmdArgs.push("-R");
|
|
434
|
+
if (args?.path) cmdArgs.push(args.path as string);
|
|
435
|
+
else cmdArgs.push("/");
|
|
436
|
+
result = await runMegaCommand("ls", cmdArgs);
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
case "mega_cd":
|
|
441
|
+
result = await runMegaCommand("cd", [args?.path as string]);
|
|
442
|
+
break;
|
|
443
|
+
|
|
444
|
+
case "mega_pwd":
|
|
445
|
+
result = await runMegaCommand("pwd");
|
|
446
|
+
break;
|
|
447
|
+
|
|
448
|
+
case "mega_mkdir": {
|
|
449
|
+
const cmdArgs: string[] = [];
|
|
450
|
+
if (args?.parents) cmdArgs.push("-p");
|
|
451
|
+
cmdArgs.push(args?.path as string);
|
|
452
|
+
result = await runMegaCommand("mkdir", cmdArgs);
|
|
453
|
+
break;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
case "mega_rm": {
|
|
457
|
+
const cmdArgs: string[] = [];
|
|
458
|
+
if (args?.recursive) cmdArgs.push("-r");
|
|
459
|
+
if (args?.force) cmdArgs.push("-f");
|
|
460
|
+
cmdArgs.push(args?.path as string);
|
|
461
|
+
result = await runMegaCommand("rm", cmdArgs);
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
case "mega_mv":
|
|
466
|
+
result = await runMegaCommand("mv", [
|
|
467
|
+
args?.source as string,
|
|
468
|
+
args?.destination as string,
|
|
469
|
+
]);
|
|
470
|
+
break;
|
|
471
|
+
|
|
472
|
+
case "mega_cp":
|
|
473
|
+
result = await runMegaCommand("cp", [
|
|
474
|
+
args?.source as string,
|
|
475
|
+
args?.destination as string,
|
|
476
|
+
]);
|
|
477
|
+
break;
|
|
478
|
+
|
|
479
|
+
case "mega_get": {
|
|
480
|
+
const cmdArgs: string[] = [args?.remote_path as string];
|
|
481
|
+
if (args?.local_path) cmdArgs.push(args.local_path as string);
|
|
482
|
+
result = await runMegaCommand("get", cmdArgs);
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
case "mega_put": {
|
|
487
|
+
const cmdArgs: string[] = [args?.local_path as string];
|
|
488
|
+
if (args?.remote_path) cmdArgs.push(args.remote_path as string);
|
|
489
|
+
result = await runMegaCommand("put", cmdArgs);
|
|
490
|
+
break;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
case "mega_df": {
|
|
494
|
+
const cmdArgs: string[] = [];
|
|
495
|
+
if (args?.human) cmdArgs.push("-h");
|
|
496
|
+
result = await runMegaCommand("df", cmdArgs);
|
|
497
|
+
break;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
case "mega_du": {
|
|
501
|
+
const cmdArgs: string[] = [];
|
|
502
|
+
if (args?.human) cmdArgs.push("-h");
|
|
503
|
+
if (args?.path) cmdArgs.push(args.path as string);
|
|
504
|
+
result = await runMegaCommand("du", cmdArgs);
|
|
505
|
+
break;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
case "mega_find": {
|
|
509
|
+
const cmdArgs: string[] = [];
|
|
510
|
+
if (args?.path) cmdArgs.push(args.path as string);
|
|
511
|
+
cmdArgs.push("--pattern=" + (args?.pattern as string));
|
|
512
|
+
result = await runMegaCommand("find", cmdArgs);
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
case "mega_export": {
|
|
517
|
+
const cmdArgs: string[] = ["-a", args?.path as string];
|
|
518
|
+
if (args?.expire) cmdArgs.push("--expire=" + args.expire);
|
|
519
|
+
if (args?.password) cmdArgs.push("--password=" + args.password);
|
|
520
|
+
result = await runMegaCommand("export", cmdArgs);
|
|
521
|
+
break;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
case "mega_share": {
|
|
525
|
+
const cmdArgs: string[] = [
|
|
526
|
+
"-a",
|
|
527
|
+
"--with=" + (args?.email as string),
|
|
528
|
+
"--level=" + ((args?.access_level as string) || "r"),
|
|
529
|
+
args?.path as string,
|
|
530
|
+
];
|
|
531
|
+
result = await runMegaCommand("share", cmdArgs);
|
|
532
|
+
break;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
case "mega_transfers": {
|
|
536
|
+
const cmdArgs: string[] = [];
|
|
537
|
+
if (args?.show_completed) cmdArgs.push("-c");
|
|
538
|
+
result = await runMegaCommand("transfers", cmdArgs);
|
|
539
|
+
break;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
case "mega_sync": {
|
|
543
|
+
if (args?.list_only) {
|
|
544
|
+
result = await runMegaCommand("sync");
|
|
545
|
+
} else if (args?.local_path && args?.remote_path) {
|
|
546
|
+
result = await runMegaCommand("sync", [
|
|
547
|
+
args.local_path as string,
|
|
548
|
+
args.remote_path as string,
|
|
549
|
+
]);
|
|
550
|
+
} else {
|
|
551
|
+
result = await runMegaCommand("sync");
|
|
552
|
+
}
|
|
553
|
+
break;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
case "mega_tree": {
|
|
557
|
+
const cmdArgs: string[] = [];
|
|
558
|
+
if (args?.path) cmdArgs.push(args.path as string);
|
|
559
|
+
result = await runMegaCommand("tree", cmdArgs);
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
case "mega_cat":
|
|
564
|
+
result = await runMegaCommand("cat", [args?.path as string]);
|
|
565
|
+
break;
|
|
566
|
+
|
|
567
|
+
case "mega_import": {
|
|
568
|
+
const cmdArgs: string[] = [args?.link as string];
|
|
569
|
+
if (args?.remote_path) cmdArgs.push(args.remote_path as string);
|
|
570
|
+
result = await runMegaCommand("import", cmdArgs);
|
|
571
|
+
break;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
default:
|
|
575
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
return {
|
|
579
|
+
content: [
|
|
580
|
+
{
|
|
581
|
+
type: "text",
|
|
582
|
+
text: result,
|
|
583
|
+
},
|
|
584
|
+
],
|
|
585
|
+
};
|
|
586
|
+
} catch (error: any) {
|
|
587
|
+
return {
|
|
588
|
+
content: [
|
|
589
|
+
{
|
|
590
|
+
type: "text",
|
|
591
|
+
text: `Error: ${error.message}`,
|
|
592
|
+
},
|
|
593
|
+
],
|
|
594
|
+
isError: true,
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
async function main() {
|
|
600
|
+
const transport = new StdioServerTransport();
|
|
601
|
+
await server.connect(transport);
|
|
602
|
+
console.error("MEGA MCP server running on stdio");
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
main().catch(console.error);
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"rootDir": "./src",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"declaration": true
|
|
13
|
+
},
|
|
14
|
+
"include": ["src/**/*"],
|
|
15
|
+
"exclude": ["node_modules", "dist"]
|
|
16
|
+
}
|