@prmichaelsen/acp-mcp 0.7.1 → 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/CHANGELOG.md +57 -0
- package/README.md +121 -41
- package/agent/progress.yaml +29 -5
- package/dist/server-factory.js +2 -496
- package/dist/server-factory.js.map +4 -4
- package/dist/server.js +2 -496
- package/dist/server.js.map +4 -4
- package/dist/utils/ssh-connection.d.ts +0 -40
- package/package.json +1 -1
- package/src/server-factory.ts +2 -12
- package/src/server.ts +2 -11
- package/src/utils/ssh-connection.ts +1 -304
- package/dist/tools/acp-remote-list-files.d.ts +0 -16
- package/dist/tools/acp-remote-read-file.d.ts +0 -16
- package/dist/tools/acp-remote-write-file.d.ts +0 -16
- package/dist/types/file-entry.d.ts +0 -88
- package/src/tools/acp-remote-list-files.ts +0 -100
- package/src/tools/acp-remote-read-file.ts +0 -94
- package/src/tools/acp-remote-write-file.ts +0 -107
- package/src/types/file-entry.ts +0 -123
package/dist/server-factory.js
CHANGED
|
@@ -5,70 +5,6 @@ import {
|
|
|
5
5
|
ListToolsRequestSchema
|
|
6
6
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
7
7
|
|
|
8
|
-
// src/tools/acp-remote-list-files.ts
|
|
9
|
-
var acpRemoteListFilesTool = {
|
|
10
|
-
name: "acp_remote_list_files",
|
|
11
|
-
description: "List files and directories in a specified path on the remote machine via SSH. Returns comprehensive metadata including permissions, timestamps, size, and ownership. Includes hidden files by default.",
|
|
12
|
-
inputSchema: {
|
|
13
|
-
type: "object",
|
|
14
|
-
properties: {
|
|
15
|
-
path: {
|
|
16
|
-
type: "string",
|
|
17
|
-
description: "The directory path to list files from"
|
|
18
|
-
},
|
|
19
|
-
recursive: {
|
|
20
|
-
type: "boolean",
|
|
21
|
-
description: "Whether to list files recursively",
|
|
22
|
-
default: false
|
|
23
|
-
},
|
|
24
|
-
includeHidden: {
|
|
25
|
-
type: "boolean",
|
|
26
|
-
description: "Whether to include hidden files (starting with .)",
|
|
27
|
-
default: true
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
required: ["path"]
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
async function handleAcpRemoteListFiles(args, sshConnection) {
|
|
34
|
-
const { path, recursive = false, includeHidden = true } = args;
|
|
35
|
-
try {
|
|
36
|
-
const entries = await listRemoteFiles(sshConnection, path, recursive, includeHidden);
|
|
37
|
-
const output = JSON.stringify(entries, null, 2);
|
|
38
|
-
return {
|
|
39
|
-
content: [
|
|
40
|
-
{
|
|
41
|
-
type: "text",
|
|
42
|
-
text: output
|
|
43
|
-
}
|
|
44
|
-
]
|
|
45
|
-
};
|
|
46
|
-
} catch (error) {
|
|
47
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
48
|
-
return {
|
|
49
|
-
content: [
|
|
50
|
-
{
|
|
51
|
-
type: "text",
|
|
52
|
-
text: `Error listing remote files: ${errorMessage}`
|
|
53
|
-
}
|
|
54
|
-
]
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
async function listRemoteFiles(ssh, dirPath, recursive, includeHidden) {
|
|
59
|
-
const entries = await ssh.listFiles(dirPath, includeHidden);
|
|
60
|
-
const allEntries = [...entries];
|
|
61
|
-
if (recursive) {
|
|
62
|
-
for (const entry of entries) {
|
|
63
|
-
if (entry.type === "directory") {
|
|
64
|
-
const subEntries = await listRemoteFiles(ssh, entry.path, recursive, includeHidden);
|
|
65
|
-
allEntries.push(...subEntries);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return allEntries;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
8
|
// src/utils/logger.ts
|
|
73
9
|
var LOG_LEVELS = {
|
|
74
10
|
error: 0,
|
|
@@ -318,195 +254,8 @@ async function executeWithProgress(command, cwd, sshConnection, progressToken, s
|
|
|
318
254
|
};
|
|
319
255
|
}
|
|
320
256
|
|
|
321
|
-
// src/tools/acp-remote-read-file.ts
|
|
322
|
-
var acpRemoteReadFileTool = {
|
|
323
|
-
name: "acp_remote_read_file",
|
|
324
|
-
description: "Read file contents from the remote machine via SSH",
|
|
325
|
-
inputSchema: {
|
|
326
|
-
type: "object",
|
|
327
|
-
properties: {
|
|
328
|
-
path: {
|
|
329
|
-
type: "string",
|
|
330
|
-
description: "Absolute path to file"
|
|
331
|
-
},
|
|
332
|
-
encoding: {
|
|
333
|
-
type: "string",
|
|
334
|
-
description: "File encoding (default: utf-8)",
|
|
335
|
-
default: "utf-8",
|
|
336
|
-
enum: ["utf-8", "ascii", "base64"]
|
|
337
|
-
},
|
|
338
|
-
maxSize: {
|
|
339
|
-
type: "number",
|
|
340
|
-
description: "Max file size in bytes (default: 1MB)",
|
|
341
|
-
default: 1048576
|
|
342
|
-
}
|
|
343
|
-
},
|
|
344
|
-
required: ["path"]
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
async function handleAcpRemoteReadFile(args, sshConnection) {
|
|
348
|
-
const { path, encoding = "utf-8", maxSize = 1048576 } = args;
|
|
349
|
-
logger.debug("Reading remote file", { path, encoding, maxSize });
|
|
350
|
-
try {
|
|
351
|
-
const result = await sshConnection.readFile(path, encoding, maxSize);
|
|
352
|
-
logger.debug("File read successful", { path, size: result.size });
|
|
353
|
-
const output = {
|
|
354
|
-
content: result.content,
|
|
355
|
-
size: result.size,
|
|
356
|
-
encoding: result.encoding
|
|
357
|
-
};
|
|
358
|
-
return {
|
|
359
|
-
content: [
|
|
360
|
-
{
|
|
361
|
-
type: "text",
|
|
362
|
-
text: JSON.stringify(output, null, 2)
|
|
363
|
-
}
|
|
364
|
-
]
|
|
365
|
-
};
|
|
366
|
-
} catch (error) {
|
|
367
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
368
|
-
logger.error("File read error", { path, error: errorMessage });
|
|
369
|
-
return {
|
|
370
|
-
content: [
|
|
371
|
-
{
|
|
372
|
-
type: "text",
|
|
373
|
-
text: JSON.stringify({
|
|
374
|
-
error: errorMessage,
|
|
375
|
-
content: "",
|
|
376
|
-
size: 0,
|
|
377
|
-
encoding
|
|
378
|
-
}, null, 2)
|
|
379
|
-
}
|
|
380
|
-
]
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// src/tools/acp-remote-write-file.ts
|
|
386
|
-
var acpRemoteWriteFileTool = {
|
|
387
|
-
name: "acp_remote_write_file",
|
|
388
|
-
description: "Write file contents to the remote machine via SSH",
|
|
389
|
-
inputSchema: {
|
|
390
|
-
type: "object",
|
|
391
|
-
properties: {
|
|
392
|
-
path: {
|
|
393
|
-
type: "string",
|
|
394
|
-
description: "Absolute path to file"
|
|
395
|
-
},
|
|
396
|
-
content: {
|
|
397
|
-
type: "string",
|
|
398
|
-
description: "File contents to write"
|
|
399
|
-
},
|
|
400
|
-
encoding: {
|
|
401
|
-
type: "string",
|
|
402
|
-
description: "File encoding (default: utf-8)",
|
|
403
|
-
default: "utf-8"
|
|
404
|
-
},
|
|
405
|
-
createDirs: {
|
|
406
|
-
type: "boolean",
|
|
407
|
-
description: "Create parent directories if they don't exist (default: false)",
|
|
408
|
-
default: false
|
|
409
|
-
},
|
|
410
|
-
backup: {
|
|
411
|
-
type: "boolean",
|
|
412
|
-
description: "Backup existing file before overwriting (default: false)",
|
|
413
|
-
default: false
|
|
414
|
-
}
|
|
415
|
-
},
|
|
416
|
-
required: ["path", "content"]
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
async function handleAcpRemoteWriteFile(args, sshConnection) {
|
|
420
|
-
const { path, content, encoding = "utf-8", createDirs = false, backup = false } = args;
|
|
421
|
-
logger.debug("Writing remote file", { path, contentSize: content.length, encoding, createDirs, backup });
|
|
422
|
-
try {
|
|
423
|
-
const result = await sshConnection.writeFile(path, content, {
|
|
424
|
-
encoding,
|
|
425
|
-
createDirs,
|
|
426
|
-
backup
|
|
427
|
-
});
|
|
428
|
-
logger.debug("File write successful", { path, bytesWritten: result.bytesWritten, backupPath: result.backupPath });
|
|
429
|
-
const output = {
|
|
430
|
-
success: result.success,
|
|
431
|
-
bytesWritten: result.bytesWritten,
|
|
432
|
-
backupPath: result.backupPath
|
|
433
|
-
};
|
|
434
|
-
return {
|
|
435
|
-
content: [
|
|
436
|
-
{
|
|
437
|
-
type: "text",
|
|
438
|
-
text: JSON.stringify(output, null, 2)
|
|
439
|
-
}
|
|
440
|
-
]
|
|
441
|
-
};
|
|
442
|
-
} catch (error) {
|
|
443
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
444
|
-
logger.error("File write error", { path, error: errorMessage });
|
|
445
|
-
return {
|
|
446
|
-
content: [
|
|
447
|
-
{
|
|
448
|
-
type: "text",
|
|
449
|
-
text: JSON.stringify({
|
|
450
|
-
success: false,
|
|
451
|
-
bytesWritten: 0,
|
|
452
|
-
error: errorMessage
|
|
453
|
-
}, null, 2)
|
|
454
|
-
}
|
|
455
|
-
]
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
|
|
460
257
|
// src/utils/ssh-connection.ts
|
|
461
258
|
import { Client } from "ssh2";
|
|
462
|
-
|
|
463
|
-
// src/types/file-entry.ts
|
|
464
|
-
function modeToPermissionString(mode) {
|
|
465
|
-
const perms = [
|
|
466
|
-
mode & 256 ? "r" : "-",
|
|
467
|
-
mode & 128 ? "w" : "-",
|
|
468
|
-
mode & 64 ? "x" : "-",
|
|
469
|
-
mode & 32 ? "r" : "-",
|
|
470
|
-
mode & 16 ? "w" : "-",
|
|
471
|
-
mode & 8 ? "x" : "-",
|
|
472
|
-
mode & 4 ? "r" : "-",
|
|
473
|
-
mode & 2 ? "w" : "-",
|
|
474
|
-
mode & 1 ? "x" : "-"
|
|
475
|
-
];
|
|
476
|
-
return perms.join("");
|
|
477
|
-
}
|
|
478
|
-
function parsePermissions(mode) {
|
|
479
|
-
return {
|
|
480
|
-
mode,
|
|
481
|
-
string: modeToPermissionString(mode),
|
|
482
|
-
owner: {
|
|
483
|
-
read: (mode & 256) !== 0,
|
|
484
|
-
write: (mode & 128) !== 0,
|
|
485
|
-
execute: (mode & 64) !== 0
|
|
486
|
-
},
|
|
487
|
-
group: {
|
|
488
|
-
read: (mode & 32) !== 0,
|
|
489
|
-
write: (mode & 16) !== 0,
|
|
490
|
-
execute: (mode & 8) !== 0
|
|
491
|
-
},
|
|
492
|
-
others: {
|
|
493
|
-
read: (mode & 4) !== 0,
|
|
494
|
-
write: (mode & 2) !== 0,
|
|
495
|
-
execute: (mode & 1) !== 0
|
|
496
|
-
}
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
function getFileType(stats) {
|
|
500
|
-
if (stats.isDirectory())
|
|
501
|
-
return "directory";
|
|
502
|
-
if (stats.isFile())
|
|
503
|
-
return "file";
|
|
504
|
-
if (stats.isSymbolicLink())
|
|
505
|
-
return "symlink";
|
|
506
|
-
return "other";
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
// src/utils/ssh-connection.ts
|
|
510
259
|
var SSHConnectionManager = class {
|
|
511
260
|
client;
|
|
512
261
|
config;
|
|
@@ -685,243 +434,6 @@ var SSHConnectionManager = class {
|
|
|
685
434
|
});
|
|
686
435
|
});
|
|
687
436
|
}
|
|
688
|
-
/**
|
|
689
|
-
* Get SFTP wrapper for file operations
|
|
690
|
-
*/
|
|
691
|
-
async getSFTP() {
|
|
692
|
-
if (!this.connected) {
|
|
693
|
-
await this.connect();
|
|
694
|
-
}
|
|
695
|
-
return new Promise((resolve, reject) => {
|
|
696
|
-
this.client.sftp((err, sftp) => {
|
|
697
|
-
if (err) {
|
|
698
|
-
reject(err);
|
|
699
|
-
} else {
|
|
700
|
-
resolve(sftp);
|
|
701
|
-
}
|
|
702
|
-
});
|
|
703
|
-
});
|
|
704
|
-
}
|
|
705
|
-
/**
|
|
706
|
-
* List files in a directory with comprehensive metadata
|
|
707
|
-
* Uses hybrid approach: shell ls for filenames (includes hidden), SFTP stat for metadata
|
|
708
|
-
*
|
|
709
|
-
* @param path - Directory path to list
|
|
710
|
-
* @param includeHidden - Whether to include hidden files (default: true)
|
|
711
|
-
* @returns Array of FileEntry objects with complete metadata
|
|
712
|
-
*/
|
|
713
|
-
async listFiles(path, includeHidden = true) {
|
|
714
|
-
const startTime = Date.now();
|
|
715
|
-
logger.debug("Listing files", { path, includeHidden });
|
|
716
|
-
try {
|
|
717
|
-
const lsFlag = includeHidden ? "-A" : "";
|
|
718
|
-
const command = `ls ${lsFlag} -1 "${path}" 2>/dev/null`;
|
|
719
|
-
const result = await this.execWithTimeout(command, 10);
|
|
720
|
-
if (result.exitCode !== 0) {
|
|
721
|
-
throw new Error(`ls command failed: ${result.stderr}`);
|
|
722
|
-
}
|
|
723
|
-
const filenames = result.stdout.split("\n").map((f) => f.trim()).filter((f) => f !== "" && f !== "." && f !== "..");
|
|
724
|
-
logger.debug("Filenames retrieved via shell", {
|
|
725
|
-
path,
|
|
726
|
-
count: filenames.length,
|
|
727
|
-
method: "shell"
|
|
728
|
-
});
|
|
729
|
-
const sftp = await this.getSFTP();
|
|
730
|
-
const entries = [];
|
|
731
|
-
for (const filename of filenames) {
|
|
732
|
-
const fullPath = `${path}/${filename}`.replace(/\/+/g, "/");
|
|
733
|
-
try {
|
|
734
|
-
const stats = await new Promise((resolve, reject) => {
|
|
735
|
-
sftp.stat(fullPath, (err, stats2) => {
|
|
736
|
-
if (err)
|
|
737
|
-
reject(err);
|
|
738
|
-
else
|
|
739
|
-
resolve(stats2);
|
|
740
|
-
});
|
|
741
|
-
});
|
|
742
|
-
entries.push({
|
|
743
|
-
name: filename,
|
|
744
|
-
path: fullPath,
|
|
745
|
-
type: getFileType(stats),
|
|
746
|
-
size: stats.size,
|
|
747
|
-
permissions: parsePermissions(stats.mode),
|
|
748
|
-
owner: {
|
|
749
|
-
uid: stats.uid,
|
|
750
|
-
gid: stats.gid
|
|
751
|
-
},
|
|
752
|
-
timestamps: {
|
|
753
|
-
accessed: new Date(stats.atime * 1e3).toISOString(),
|
|
754
|
-
modified: new Date(stats.mtime * 1e3).toISOString()
|
|
755
|
-
}
|
|
756
|
-
});
|
|
757
|
-
} catch (error) {
|
|
758
|
-
logger.warn("Failed to stat file, skipping", {
|
|
759
|
-
path: fullPath,
|
|
760
|
-
error: error instanceof Error ? error.message : String(error)
|
|
761
|
-
});
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
const duration = Date.now() - startTime;
|
|
765
|
-
logger.debug("Files listed successfully", {
|
|
766
|
-
path,
|
|
767
|
-
count: entries.length,
|
|
768
|
-
duration: `${duration}ms`,
|
|
769
|
-
method: "hybrid"
|
|
770
|
-
});
|
|
771
|
-
return entries;
|
|
772
|
-
} catch (error) {
|
|
773
|
-
logger.warn("Shell ls command failed, falling back to SFTP readdir", {
|
|
774
|
-
path,
|
|
775
|
-
error: error instanceof Error ? error.message : String(error)
|
|
776
|
-
});
|
|
777
|
-
return this.listFilesViaSFTP(path, includeHidden);
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
/**
|
|
781
|
-
* Fallback method: List files using SFTP readdir (may miss hidden files)
|
|
782
|
-
* @private
|
|
783
|
-
*/
|
|
784
|
-
async listFilesViaSFTP(path, includeHidden) {
|
|
785
|
-
const sftp = await this.getSFTP();
|
|
786
|
-
return new Promise((resolve, reject) => {
|
|
787
|
-
sftp.readdir(path, (err, list) => {
|
|
788
|
-
if (err) {
|
|
789
|
-
logger.error("SFTP readdir failed", { path, error: err.message });
|
|
790
|
-
reject(err);
|
|
791
|
-
return;
|
|
792
|
-
}
|
|
793
|
-
let entries = list.map((item) => ({
|
|
794
|
-
name: item.filename,
|
|
795
|
-
path: `${path}/${item.filename}`.replace(/\/+/g, "/"),
|
|
796
|
-
type: getFileType(item.attrs),
|
|
797
|
-
size: item.attrs.size,
|
|
798
|
-
permissions: parsePermissions(item.attrs.mode),
|
|
799
|
-
owner: {
|
|
800
|
-
uid: item.attrs.uid,
|
|
801
|
-
gid: item.attrs.gid
|
|
802
|
-
},
|
|
803
|
-
timestamps: {
|
|
804
|
-
accessed: new Date(item.attrs.atime * 1e3).toISOString(),
|
|
805
|
-
modified: new Date(item.attrs.mtime * 1e3).toISOString()
|
|
806
|
-
}
|
|
807
|
-
}));
|
|
808
|
-
if (!includeHidden) {
|
|
809
|
-
entries = entries.filter((e) => !e.name.startsWith("."));
|
|
810
|
-
}
|
|
811
|
-
logger.debug("Files listed via SFTP fallback", {
|
|
812
|
-
path,
|
|
813
|
-
count: entries.length,
|
|
814
|
-
method: "sftp",
|
|
815
|
-
note: "Hidden files may be missing (SFTP limitation)"
|
|
816
|
-
});
|
|
817
|
-
resolve(entries);
|
|
818
|
-
});
|
|
819
|
-
});
|
|
820
|
-
}
|
|
821
|
-
/**
|
|
822
|
-
* Read file contents from remote machine
|
|
823
|
-
*/
|
|
824
|
-
async readFile(path, encoding = "utf-8", maxSize = 1048576) {
|
|
825
|
-
const startTime = Date.now();
|
|
826
|
-
logger.fileOperation("read", path, { encoding, maxSize });
|
|
827
|
-
const sftp = await this.getSFTP();
|
|
828
|
-
return new Promise((resolve, reject) => {
|
|
829
|
-
sftp.stat(path, (err, stats) => {
|
|
830
|
-
if (err) {
|
|
831
|
-
logger.error("File stat failed", { path, error: err.message });
|
|
832
|
-
reject(new Error(`File not found or inaccessible: ${path}`));
|
|
833
|
-
return;
|
|
834
|
-
}
|
|
835
|
-
logger.debug("File stat retrieved", { path, size: stats.size });
|
|
836
|
-
if (stats.size > maxSize) {
|
|
837
|
-
logger.warn("File too large", { path, size: stats.size, maxSize });
|
|
838
|
-
reject(new Error(`File too large: ${stats.size} bytes (max: ${maxSize} bytes)`));
|
|
839
|
-
return;
|
|
840
|
-
}
|
|
841
|
-
sftp.readFile(path, { encoding }, (err2, data) => {
|
|
842
|
-
if (err2) {
|
|
843
|
-
logger.error("File read failed", { path, error: err2.message });
|
|
844
|
-
reject(new Error(`Failed to read file: ${err2.message}`));
|
|
845
|
-
return;
|
|
846
|
-
}
|
|
847
|
-
const duration = Date.now() - startTime;
|
|
848
|
-
logger.debug("File read completed", { path, size: stats.size, duration: `${duration}ms` });
|
|
849
|
-
resolve({
|
|
850
|
-
content: data.toString(),
|
|
851
|
-
size: stats.size,
|
|
852
|
-
encoding
|
|
853
|
-
});
|
|
854
|
-
});
|
|
855
|
-
});
|
|
856
|
-
});
|
|
857
|
-
}
|
|
858
|
-
/**
|
|
859
|
-
* Write file contents to remote machine
|
|
860
|
-
*/
|
|
861
|
-
async writeFile(path, content, options = {}) {
|
|
862
|
-
const { encoding = "utf-8", createDirs = false, backup = false } = options;
|
|
863
|
-
const startTime = Date.now();
|
|
864
|
-
logger.fileOperation("write", path, {
|
|
865
|
-
contentSize: content.length,
|
|
866
|
-
encoding,
|
|
867
|
-
createDirs,
|
|
868
|
-
backup
|
|
869
|
-
});
|
|
870
|
-
const sftp = await this.getSFTP();
|
|
871
|
-
return new Promise((resolve, reject) => {
|
|
872
|
-
const writeOperation = () => {
|
|
873
|
-
if (backup) {
|
|
874
|
-
const backupPath = `${path}.backup`;
|
|
875
|
-
sftp.rename(path, backupPath, (err) => {
|
|
876
|
-
if (err && err.message !== "No such file") {
|
|
877
|
-
reject(new Error(`Failed to create backup: ${err.message}`));
|
|
878
|
-
return;
|
|
879
|
-
}
|
|
880
|
-
performWrite(backupPath);
|
|
881
|
-
});
|
|
882
|
-
} else {
|
|
883
|
-
performWrite();
|
|
884
|
-
}
|
|
885
|
-
};
|
|
886
|
-
const performWrite = (backupPath) => {
|
|
887
|
-
const buffer = Buffer.from(content, encoding);
|
|
888
|
-
const tempPath = `${path}.tmp`;
|
|
889
|
-
sftp.writeFile(tempPath, buffer, (err) => {
|
|
890
|
-
if (err) {
|
|
891
|
-
reject(new Error(`Failed to write file: ${err.message}`));
|
|
892
|
-
return;
|
|
893
|
-
}
|
|
894
|
-
sftp.rename(tempPath, path, (err2) => {
|
|
895
|
-
if (err2) {
|
|
896
|
-
logger.error("File rename failed", { tempPath, path, error: err2.message });
|
|
897
|
-
reject(new Error(`Failed to rename temp file: ${err2.message}`));
|
|
898
|
-
return;
|
|
899
|
-
}
|
|
900
|
-
const duration = Date.now() - startTime;
|
|
901
|
-
logger.debug("File write completed", {
|
|
902
|
-
path,
|
|
903
|
-
bytesWritten: buffer.length,
|
|
904
|
-
duration: `${duration}ms`,
|
|
905
|
-
backupPath
|
|
906
|
-
});
|
|
907
|
-
resolve({
|
|
908
|
-
success: true,
|
|
909
|
-
bytesWritten: buffer.length,
|
|
910
|
-
backupPath
|
|
911
|
-
});
|
|
912
|
-
});
|
|
913
|
-
});
|
|
914
|
-
};
|
|
915
|
-
if (createDirs) {
|
|
916
|
-
const dirPath = path.substring(0, path.lastIndexOf("/"));
|
|
917
|
-
this.exec(`mkdir -p ${dirPath}`).then(() => {
|
|
918
|
-
writeOperation();
|
|
919
|
-
}).catch(reject);
|
|
920
|
-
} else {
|
|
921
|
-
writeOperation();
|
|
922
|
-
}
|
|
923
|
-
});
|
|
924
|
-
}
|
|
925
437
|
/**
|
|
926
438
|
* Wrap command to source shell configuration files
|
|
927
439
|
* This ensures PATH and other environment variables are properly set
|
|
@@ -978,7 +490,7 @@ async function createServer(serverConfig) {
|
|
|
978
490
|
);
|
|
979
491
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
980
492
|
logger.debug("Tool discovery requested", { userId: serverConfig.userId });
|
|
981
|
-
const tools = [
|
|
493
|
+
const tools = [acpRemoteExecuteCommandTool];
|
|
982
494
|
logger.debug(`Returning ${tools.length} tools`, { tools: tools.map((t) => t.name), userId: serverConfig.userId });
|
|
983
495
|
return { tools };
|
|
984
496
|
});
|
|
@@ -987,14 +499,8 @@ async function createServer(serverConfig) {
|
|
|
987
499
|
logger.toolInvoked(request.params.name, request.params.arguments, serverConfig.userId);
|
|
988
500
|
try {
|
|
989
501
|
let result;
|
|
990
|
-
if (request.params.name === "
|
|
991
|
-
result = await handleAcpRemoteListFiles(request.params.arguments, sshConnection);
|
|
992
|
-
} else if (request.params.name === "acp_remote_execute_command") {
|
|
502
|
+
if (request.params.name === "acp_remote_execute_command") {
|
|
993
503
|
result = await handleAcpRemoteExecuteCommand(request.params.arguments, sshConnection, extra, server);
|
|
994
|
-
} else if (request.params.name === "acp_remote_read_file") {
|
|
995
|
-
result = await handleAcpRemoteReadFile(request.params.arguments, sshConnection);
|
|
996
|
-
} else if (request.params.name === "acp_remote_write_file") {
|
|
997
|
-
result = await handleAcpRemoteWriteFile(request.params.arguments, sshConnection);
|
|
998
504
|
} else {
|
|
999
505
|
throw new Error(`Unknown tool: ${request.params.name}`);
|
|
1000
506
|
}
|