lunisphere-mcp 0.0.0-stage → 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/README.md +19 -2
- package/bin/cli.js +68 -0
- package/lib/poller.js +110 -0
- package/lib/tools.js +346 -0
- package/package.json +33 -4
package/README.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# lunisphere-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Local PC agent for [Lunisphere MCP Relay](https://mcp.lunisphere.com). Connects your local workspace to remote MCP clients (Gemini, Claude, Cursor) via outbound HTTPS long-polling with zero tunnel or port-forwarding setup.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Run directly with `npx`:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx lunisphere-mcp --server="https://mcp.lunisphere.com" --key="YOUR_DEVICE_KEY" --dir="."
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or install globally:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g lunisphere-mcp
|
|
17
|
+
lunisphere-mcp --server="https://mcp.lunisphere.com" --key="YOUR_DEVICE_KEY" --dir="."
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Add `--allow-shell` to enable `cmd_execute` and `bg_*` background job tools.
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { LocalToolkit } = require('../lib/tools');
|
|
6
|
+
const { RelayPoller } = require('../lib/poller');
|
|
7
|
+
|
|
8
|
+
function parseArgs(argv) {
|
|
9
|
+
const args = {};
|
|
10
|
+
for (let i = 0; i < argv.length; i++) {
|
|
11
|
+
const token = argv[i];
|
|
12
|
+
if (token.startsWith('--')) {
|
|
13
|
+
const eq = token.indexOf('=');
|
|
14
|
+
if (eq !== -1) {
|
|
15
|
+
args[token.slice(2, eq)] = token.slice(eq + 1);
|
|
16
|
+
} else {
|
|
17
|
+
const key = token.slice(2);
|
|
18
|
+
const next = argv[i + 1];
|
|
19
|
+
if (next && !next.startsWith('--')) {
|
|
20
|
+
args[key] = next;
|
|
21
|
+
i++;
|
|
22
|
+
} else {
|
|
23
|
+
args[key] = true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return args;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const args = parseArgs(process.argv.slice(2));
|
|
32
|
+
|
|
33
|
+
if (args.help || !args.key) {
|
|
34
|
+
console.log(`
|
|
35
|
+
Lunisphere MCP PC Client
|
|
36
|
+
Usage:
|
|
37
|
+
lunisphere-mcp --server="https://mcp.lunisphere.com" --key="dk_..." --dir="." [--allow-shell]
|
|
38
|
+
|
|
39
|
+
Options:
|
|
40
|
+
--server Relay server base URL (default: https://mcp.lunisphere.com)
|
|
41
|
+
--key Device Key copied from your dashboard (required)
|
|
42
|
+
--dir Workspace directory to expose (default: current directory)
|
|
43
|
+
--allow-shell Enable cmd_execute and bg_* background job tools (off by default)
|
|
44
|
+
`);
|
|
45
|
+
process.exit(args.help ? 0 : 1);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const serverUrl = args.server || 'https://mcp.lunisphere.com';
|
|
49
|
+
const rootDir = path.resolve(args.dir || process.cwd());
|
|
50
|
+
const allowShell = Boolean(args['allow-shell']);
|
|
51
|
+
|
|
52
|
+
console.log('===============================================');
|
|
53
|
+
console.log(' Lunisphere MCP PC Client');
|
|
54
|
+
console.log(` Server: ${serverUrl}`);
|
|
55
|
+
console.log(` Workspace: ${rootDir}`);
|
|
56
|
+
console.log(` Shell: ${allowShell ? 'ENABLED' : 'DISABLED (read/write sandbox only)'}`);
|
|
57
|
+
console.log('===============================================');
|
|
58
|
+
|
|
59
|
+
const toolkit = new LocalToolkit({ rootDir, allowShell });
|
|
60
|
+
const poller = new RelayPoller({ serverUrl, deviceKey: args.key, toolkit });
|
|
61
|
+
|
|
62
|
+
process.on('SIGINT', () => {
|
|
63
|
+
console.log('\n[STOP] Shutting down Lunisphere MCP Client...');
|
|
64
|
+
poller.stop();
|
|
65
|
+
process.exit(0);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
poller.start();
|
package/lib/poller.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const os = require('os');
|
|
4
|
+
|
|
5
|
+
class RelayPoller {
|
|
6
|
+
constructor({ serverUrl, deviceKey, toolkit }) {
|
|
7
|
+
this.serverUrl = serverUrl.replace(/\/+$/, '');
|
|
8
|
+
this.deviceKey = deviceKey;
|
|
9
|
+
this.toolkit = toolkit;
|
|
10
|
+
this.running = false;
|
|
11
|
+
this.backoffMs = 2000;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
_headers() {
|
|
15
|
+
return {
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
'X-Device-Key': this.deviceKey
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async register() {
|
|
22
|
+
const res = await fetch(`${this.serverUrl}/relay/register`, {
|
|
23
|
+
method: 'POST',
|
|
24
|
+
headers: this._headers(),
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
tools: this.toolkit.getToolSchemas(),
|
|
27
|
+
meta: {
|
|
28
|
+
hostname: os.hostname(),
|
|
29
|
+
platform: os.platform(),
|
|
30
|
+
rootDir: this.toolkit.rootDir,
|
|
31
|
+
allowShell: this.toolkit.allowShell
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
});
|
|
35
|
+
const data = await res.json().catch(() => ({}));
|
|
36
|
+
if (!res.ok) {
|
|
37
|
+
throw new Error(data.error || `Register failed (${res.status})`);
|
|
38
|
+
}
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async _executeAndReport(job) {
|
|
43
|
+
console.log(`[JOB] ${job.jobId} -> ${job.toolName}`);
|
|
44
|
+
const result = await this.toolkit.execute(job.toolName, job.arguments || {});
|
|
45
|
+
try {
|
|
46
|
+
await fetch(`${this.serverUrl}/relay/result`, {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: this._headers(),
|
|
49
|
+
body: JSON.stringify({ jobId: job.jobId, result })
|
|
50
|
+
});
|
|
51
|
+
} catch (err) {
|
|
52
|
+
console.error(`[ERROR] Failed to post result for ${job.jobId}:`, err.message);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async start() {
|
|
57
|
+
this.running = true;
|
|
58
|
+
while (this.running) {
|
|
59
|
+
try {
|
|
60
|
+
const reg = await this.register();
|
|
61
|
+
console.log(`[ONLINE] Connected as "${reg.deviceName}" (${reg.deviceId}) | Tools: ${this.toolkit.getToolSchemas().length}`);
|
|
62
|
+
this.backoffMs = 2000;
|
|
63
|
+
|
|
64
|
+
while (this.running) {
|
|
65
|
+
const controller = new AbortController();
|
|
66
|
+
const timeout = setTimeout(() => controller.abort(), 30000);
|
|
67
|
+
try {
|
|
68
|
+
const res = await fetch(`${this.serverUrl}/relay/poll`, {
|
|
69
|
+
method: 'GET',
|
|
70
|
+
headers: this._headers(),
|
|
71
|
+
signal: controller.signal
|
|
72
|
+
});
|
|
73
|
+
clearTimeout(timeout);
|
|
74
|
+
|
|
75
|
+
if (res.status === 401 || res.status === 403) {
|
|
76
|
+
const errData = await res.json().catch(() => ({}));
|
|
77
|
+
console.error(`[AUTH] ${errData.error || 'Key rejected'}. Stopping client.`);
|
|
78
|
+
this.running = false;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (!res.ok) {
|
|
82
|
+
throw new Error(`Poll HTTP ${res.status}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const payload = await res.json();
|
|
86
|
+
if (Array.isArray(payload.jobs) && payload.jobs.length > 0) {
|
|
87
|
+
for (const job of payload.jobs) {
|
|
88
|
+
this._executeAndReport(job);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
} catch (pollErr) {
|
|
92
|
+
clearTimeout(timeout);
|
|
93
|
+
throw pollErr;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} catch (err) {
|
|
97
|
+
if (!this.running) break;
|
|
98
|
+
console.error(`[RECONNECT] ${err.message} — retrying in ${this.backoffMs / 1000}s...`);
|
|
99
|
+
await new Promise((r) => setTimeout(r, this.backoffMs));
|
|
100
|
+
this.backoffMs = Math.min(15000, this.backoffMs * 2);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
stop() {
|
|
106
|
+
this.running = false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
module.exports = { RelayPoller };
|
package/lib/tools.js
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const crypto = require('crypto');
|
|
7
|
+
const { exec, spawn } = require('child_process');
|
|
8
|
+
|
|
9
|
+
class LocalToolkit {
|
|
10
|
+
constructor({ rootDir, allowShell = false }) {
|
|
11
|
+
this.rootDir = path.resolve(rootDir || process.cwd());
|
|
12
|
+
this.allowShell = Boolean(allowShell);
|
|
13
|
+
this.bgJobs = new Map();
|
|
14
|
+
this.bgLogDir = path.join(os.tmpdir(), 'lunisphere-mcp-jobs');
|
|
15
|
+
if (!fs.existsSync(this.bgLogDir)) fs.mkdirSync(this.bgLogDir, { recursive: true });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
_resolveSafe(targetPath) {
|
|
19
|
+
const resolved = path.resolve(this.rootDir, targetPath || '.');
|
|
20
|
+
const normRoot = this.rootDir.toLowerCase();
|
|
21
|
+
const normTarget = resolved.toLowerCase();
|
|
22
|
+
if (normTarget !== normRoot && !normTarget.startsWith(normRoot + path.sep)) {
|
|
23
|
+
throw new Error(`Access denied: path escapes sandbox root (${this.rootDir})`);
|
|
24
|
+
}
|
|
25
|
+
return resolved;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getToolSchemas() {
|
|
29
|
+
const tools = [
|
|
30
|
+
{
|
|
31
|
+
name: 'fs_read_file',
|
|
32
|
+
description: 'Reads full content or specified line range of a file inside the workspace.',
|
|
33
|
+
inputSchema: {
|
|
34
|
+
type: 'object',
|
|
35
|
+
properties: {
|
|
36
|
+
path: { type: 'string', description: 'Relative or absolute path inside workspace.' },
|
|
37
|
+
start_line: { type: 'integer', description: 'Optional 1-based start line.' },
|
|
38
|
+
end_line: { type: 'integer', description: 'Optional 1-based end line.' }
|
|
39
|
+
},
|
|
40
|
+
required: ['path']
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'fs_write_file',
|
|
45
|
+
description: 'Writes or appends content to a file inside the workspace.',
|
|
46
|
+
inputSchema: {
|
|
47
|
+
type: 'object',
|
|
48
|
+
properties: {
|
|
49
|
+
path: { type: 'string' },
|
|
50
|
+
content: { type: 'string' },
|
|
51
|
+
append: { type: 'boolean', default: false }
|
|
52
|
+
},
|
|
53
|
+
required: ['path', 'content']
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'fs_list_directory',
|
|
58
|
+
description: 'Lists files and folders inside the workspace (max depth 2 recommended).',
|
|
59
|
+
inputSchema: {
|
|
60
|
+
type: 'object',
|
|
61
|
+
properties: {
|
|
62
|
+
path: { type: 'string', default: '.' },
|
|
63
|
+
depth: { type: 'integer', default: 1 }
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: 'fs_search_files',
|
|
69
|
+
description: 'Searches filenames and optional text content inside a subfolder.',
|
|
70
|
+
inputSchema: {
|
|
71
|
+
type: 'object',
|
|
72
|
+
properties: {
|
|
73
|
+
path: { type: 'string', default: '.' },
|
|
74
|
+
pattern: { type: 'string', default: '' },
|
|
75
|
+
content_search: { type: 'string', default: '' }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: 'fs_delete_file_or_dir',
|
|
81
|
+
description: 'Deletes a file or directory inside the workspace.',
|
|
82
|
+
inputSchema: {
|
|
83
|
+
type: 'object',
|
|
84
|
+
properties: {
|
|
85
|
+
path: { type: 'string' },
|
|
86
|
+
recursive: { type: 'boolean', default: false }
|
|
87
|
+
},
|
|
88
|
+
required: ['path']
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: 'fs_create_directory',
|
|
93
|
+
description: 'Creates a directory recursively inside the workspace.',
|
|
94
|
+
inputSchema: {
|
|
95
|
+
type: 'object',
|
|
96
|
+
properties: { path: { type: 'string' } },
|
|
97
|
+
required: ['path']
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
];
|
|
101
|
+
|
|
102
|
+
if (this.allowShell) {
|
|
103
|
+
tools.push(
|
|
104
|
+
{
|
|
105
|
+
name: 'cmd_execute',
|
|
106
|
+
description: 'Executes a quick shell command (<35s) in the workspace.',
|
|
107
|
+
inputSchema: {
|
|
108
|
+
type: 'object',
|
|
109
|
+
properties: {
|
|
110
|
+
command: { type: 'string' },
|
|
111
|
+
cwd: { type: 'string', default: '.' },
|
|
112
|
+
timeout_seconds: { type: 'integer', default: 35 }
|
|
113
|
+
},
|
|
114
|
+
required: ['command']
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: 'bg_start_job',
|
|
119
|
+
description: 'Starts a long-running command in the background and returns job_id immediately.',
|
|
120
|
+
inputSchema: {
|
|
121
|
+
type: 'object',
|
|
122
|
+
properties: {
|
|
123
|
+
command: { type: 'string' },
|
|
124
|
+
cwd: { type: 'string', default: '.' },
|
|
125
|
+
name: { type: 'string' }
|
|
126
|
+
},
|
|
127
|
+
required: ['command']
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'bg_check_job',
|
|
132
|
+
description: 'Checks status and recent log lines of a background job.',
|
|
133
|
+
inputSchema: {
|
|
134
|
+
type: 'object',
|
|
135
|
+
properties: {
|
|
136
|
+
job_id: { type: 'string' },
|
|
137
|
+
tail_lines: { type: 'integer', default: 40 }
|
|
138
|
+
},
|
|
139
|
+
required: ['job_id']
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: 'bg_list_jobs',
|
|
144
|
+
description: 'Lists recent background jobs.',
|
|
145
|
+
inputSchema: { type: 'object', properties: {} }
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
name: 'bg_stop_job',
|
|
149
|
+
description: 'Stops a running background job.',
|
|
150
|
+
inputSchema: {
|
|
151
|
+
type: 'object',
|
|
152
|
+
properties: { job_id: { type: 'string' } },
|
|
153
|
+
required: ['job_id']
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return tools;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async execute(toolName, args = {}) {
|
|
163
|
+
try {
|
|
164
|
+
const text = await this._runTool(toolName, args);
|
|
165
|
+
return { content: [{ type: 'text', text: typeof text === 'string' ? text : JSON.stringify(text, null, 2) }] };
|
|
166
|
+
} catch (err) {
|
|
167
|
+
return { isError: true, content: [{ type: 'text', text: `Error: ${err.message}` }] };
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async _runTool(name, args) {
|
|
172
|
+
if (name === 'fs_read_file') {
|
|
173
|
+
const p = this._resolveSafe(args.path);
|
|
174
|
+
const raw = fs.readFileSync(p, 'utf8');
|
|
175
|
+
if (args.start_line || args.end_line) {
|
|
176
|
+
const lines = raw.split(/\r?\n/);
|
|
177
|
+
const start = Math.max(1, parseInt(args.start_line || 1, 10)) - 1;
|
|
178
|
+
const end = args.end_line ? parseInt(args.end_line, 10) : lines.length;
|
|
179
|
+
return lines.slice(start, end).join('\n');
|
|
180
|
+
}
|
|
181
|
+
return raw.slice(0, 200000);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (name === 'fs_write_file') {
|
|
185
|
+
const p = this._resolveSafe(args.path);
|
|
186
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
187
|
+
if (args.append) {
|
|
188
|
+
fs.appendFileSync(p, args.content, 'utf8');
|
|
189
|
+
} else {
|
|
190
|
+
fs.writeFileSync(p, args.content, 'utf8');
|
|
191
|
+
}
|
|
192
|
+
return `Wrote ${args.content.length} chars to ${path.relative(this.rootDir, p) || '.'}`;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (name === 'fs_list_directory') {
|
|
196
|
+
const p = this._resolveSafe(args.path || '.');
|
|
197
|
+
const maxDepth = Math.min(3, Math.max(1, parseInt(args.depth || 1, 10)));
|
|
198
|
+
const results = [];
|
|
199
|
+
const ignore = new Set(['node_modules', '.git', '.next', 'dist', 'build', 'vendor', '__pycache__']);
|
|
200
|
+
|
|
201
|
+
const walk = (dir, curDepth, prefix) => {
|
|
202
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
203
|
+
for (const e of entries) {
|
|
204
|
+
if (results.length >= 400) return;
|
|
205
|
+
if (ignore.has(e.name)) continue;
|
|
206
|
+
const rel = prefix ? `${prefix}/${e.name}` : e.name;
|
|
207
|
+
results.push({ name: e.isDirectory() ? `${rel}/` : rel, type: e.isDirectory() ? 'directory' : 'file' });
|
|
208
|
+
if (e.isDirectory() && curDepth < maxDepth) {
|
|
209
|
+
walk(path.join(dir, e.name), curDepth + 1, rel);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
walk(p, 1, '');
|
|
214
|
+
return { directory: p, entries: results };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (name === 'fs_search_files') {
|
|
218
|
+
const p = this._resolveSafe(args.path || '.');
|
|
219
|
+
const pattern = String(args.pattern || '').toLowerCase();
|
|
220
|
+
const needle = String(args.content_search || '');
|
|
221
|
+
const matches = [];
|
|
222
|
+
const ignore = new Set(['node_modules', '.git', '.next', 'dist', 'build', 'vendor', '__pycache__']);
|
|
223
|
+
|
|
224
|
+
const walk = (dir, depth) => {
|
|
225
|
+
if (depth > 5 || matches.length >= 100) return;
|
|
226
|
+
let entries;
|
|
227
|
+
try { entries = fs.readdirSync(dir, { withFileTypes: true }); } catch (_) { return; }
|
|
228
|
+
for (const e of entries) {
|
|
229
|
+
if (matches.length >= 100) return;
|
|
230
|
+
if (ignore.has(e.name)) continue;
|
|
231
|
+
const full = path.join(dir, e.name);
|
|
232
|
+
if (e.isDirectory()) {
|
|
233
|
+
walk(full, depth + 1);
|
|
234
|
+
} else {
|
|
235
|
+
const rel = path.relative(this.rootDir, full);
|
|
236
|
+
if (pattern && !e.name.toLowerCase().includes(pattern.replace(/\*/g, ''))) continue;
|
|
237
|
+
if (needle) {
|
|
238
|
+
try {
|
|
239
|
+
const stat = fs.statSync(full);
|
|
240
|
+
if (stat.size > 512 * 1024) continue;
|
|
241
|
+
const txt = fs.readFileSync(full, 'utf8');
|
|
242
|
+
if (txt.includes(needle)) matches.push(rel);
|
|
243
|
+
} catch (_) {}
|
|
244
|
+
} else {
|
|
245
|
+
matches.push(rel);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
walk(p, 0);
|
|
251
|
+
return { matches };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (name === 'fs_create_directory') {
|
|
255
|
+
const p = this._resolveSafe(args.path);
|
|
256
|
+
fs.mkdirSync(p, { recursive: true });
|
|
257
|
+
return `Created directory: ${p}`;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (name === 'fs_delete_file_or_dir') {
|
|
261
|
+
const p = this._resolveSafe(args.path);
|
|
262
|
+
if (p === this.rootDir) throw new Error('Cannot delete workspace root.');
|
|
263
|
+
fs.rmSync(p, { recursive: Boolean(args.recursive), force: true });
|
|
264
|
+
return `Deleted: ${p}`;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (!this.allowShell) {
|
|
268
|
+
throw new Error(`Tool '${name}' requires --allow-shell flag on PC client.`);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (name === 'cmd_execute') {
|
|
272
|
+
const cwd = this._resolveSafe(args.cwd || '.');
|
|
273
|
+
const timeoutMs = Math.min(38000, Math.max(1000, (parseInt(args.timeout_seconds || 35, 10)) * 1000));
|
|
274
|
+
return await new Promise((resolve) => {
|
|
275
|
+
exec(args.command, { cwd, timeout: timeoutMs, maxBuffer: 2 * 1024 * 1024 }, (err, stdout, stderr) => {
|
|
276
|
+
resolve({
|
|
277
|
+
exit_code: err ? (err.code || 1) : 0,
|
|
278
|
+
stdout: String(stdout || '').slice(0, 60000),
|
|
279
|
+
stderr: String(stderr || '').slice(0, 20000)
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (name === 'bg_start_job') {
|
|
286
|
+
const cwd = this._resolveSafe(args.cwd || '.');
|
|
287
|
+
const jobId = `bg_${crypto.randomBytes(4).toString('hex')}`;
|
|
288
|
+
const logFile = path.join(this.bgLogDir, `${jobId}.log`);
|
|
289
|
+
const outFd = fs.openSync(logFile, 'w');
|
|
290
|
+
const child = spawn(args.command, {
|
|
291
|
+
cwd,
|
|
292
|
+
shell: true,
|
|
293
|
+
detached: true,
|
|
294
|
+
stdio: ['ignore', outFd, outFd]
|
|
295
|
+
});
|
|
296
|
+
const job = {
|
|
297
|
+
jobId,
|
|
298
|
+
name: args.name || args.command.slice(0, 40),
|
|
299
|
+
command: args.command,
|
|
300
|
+
pid: child.pid,
|
|
301
|
+
logFile,
|
|
302
|
+
status: 'running',
|
|
303
|
+
startedAt: new Date().toISOString(),
|
|
304
|
+
exitCode: null
|
|
305
|
+
};
|
|
306
|
+
child.on('exit', (code) => {
|
|
307
|
+
job.status = 'finished';
|
|
308
|
+
job.exitCode = code;
|
|
309
|
+
try { fs.closeSync(outFd); } catch (_) {}
|
|
310
|
+
});
|
|
311
|
+
child.unref();
|
|
312
|
+
this.bgJobs.set(jobId, job);
|
|
313
|
+
return { job_id: jobId, pid: child.pid, status: 'running' };
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (name === 'bg_check_job') {
|
|
317
|
+
const job = this.bgJobs.get(args.job_id);
|
|
318
|
+
if (!job) throw new Error(`Job not found: ${args.job_id}`);
|
|
319
|
+
const tail = Math.max(5, parseInt(args.tail_lines || 40, 10));
|
|
320
|
+
let logs = '';
|
|
321
|
+
if (fs.existsSync(job.logFile)) {
|
|
322
|
+
const lines = fs.readFileSync(job.logFile, 'utf8').split(/\r?\n/);
|
|
323
|
+
logs = lines.slice(-tail).join('\n');
|
|
324
|
+
}
|
|
325
|
+
return { ...job, logs };
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (name === 'bg_list_jobs') {
|
|
329
|
+
return Array.from(this.bgJobs.values());
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (name === 'bg_stop_job') {
|
|
333
|
+
const job = this.bgJobs.get(args.job_id);
|
|
334
|
+
if (!job) throw new Error(`Job not found: ${args.job_id}`);
|
|
335
|
+
try {
|
|
336
|
+
process.kill(job.pid);
|
|
337
|
+
job.status = 'stopped';
|
|
338
|
+
} catch (_) {}
|
|
339
|
+
return { job_id: job.jobId, status: job.status };
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
module.exports = { LocalToolkit };
|
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lunisphere-mcp",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Local PC agent for Lunisphere MCP Relay — connect your local workspace to Gemini, Claude, or Cursor with zero tunnel setup.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"lunisphere-mcp": "bin/cli.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"bin/",
|
|
10
|
+
"lib/",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/mrahatcreations/lunisphere-mcp-relay.git",
|
|
16
|
+
"directory": "client"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://mcp.lunisphere.com",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/mrahatcreations/lunisphere-mcp-relay/issues"
|
|
21
|
+
},
|
|
22
|
+
"author": "Lunisphere",
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18.0.0"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"mcp",
|
|
28
|
+
"gemini",
|
|
29
|
+
"claude",
|
|
30
|
+
"cursor",
|
|
31
|
+
"relay",
|
|
32
|
+
"lunisphere"
|
|
33
|
+
],
|
|
34
|
+
"license": "MIT"
|
|
35
|
+
}
|