it-tools-mcp 3.0.10 → 3.0.12
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/build/tools/network.js +46 -2
- package/package.json +1 -1
package/build/tools/network.js
CHANGED
|
@@ -6,8 +6,44 @@ import Telnet from "telnet-client";
|
|
|
6
6
|
import psList from "ps-list";
|
|
7
7
|
import fs from "fs";
|
|
8
8
|
import readLastLines from "read-last-lines";
|
|
9
|
+
import path from "path";
|
|
10
|
+
import os from "os";
|
|
9
11
|
// For Telnet import (telnet-client exports as an object, not a class)
|
|
10
12
|
const TelnetClient = Telnet.Telnet || Telnet;
|
|
13
|
+
function resolvePrivateKey(privateKeyArg) {
|
|
14
|
+
// If not provided, try default keys
|
|
15
|
+
if (!privateKeyArg) {
|
|
16
|
+
const home = os.homedir();
|
|
17
|
+
const defaultKeys = [
|
|
18
|
+
path.join(home, '.ssh', 'id_rsa'),
|
|
19
|
+
path.join(home, '.ssh', 'id_ed25519'),
|
|
20
|
+
];
|
|
21
|
+
for (const keyPath of defaultKeys) {
|
|
22
|
+
if (fs.existsSync(keyPath)) {
|
|
23
|
+
return fs.readFileSync(keyPath, 'utf8');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
// If it looks like a path, try to read it
|
|
29
|
+
if (privateKeyArg.startsWith('/') ||
|
|
30
|
+
privateKeyArg.startsWith('~') ||
|
|
31
|
+
privateKeyArg.endsWith('.pem') ||
|
|
32
|
+
privateKeyArg.endsWith('.key')) {
|
|
33
|
+
let keyPath = privateKeyArg;
|
|
34
|
+
if (keyPath.startsWith('~')) {
|
|
35
|
+
keyPath = path.join(os.homedir(), keyPath.slice(1));
|
|
36
|
+
}
|
|
37
|
+
if (fs.existsSync(keyPath)) {
|
|
38
|
+
return fs.readFileSync(keyPath, 'utf8');
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
throw new Error('Private key file not found: ' + keyPath);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Otherwise, assume it's the key content
|
|
45
|
+
return privateKeyArg;
|
|
46
|
+
}
|
|
11
47
|
export function registerNetworkTools(server) {
|
|
12
48
|
// IP address tools
|
|
13
49
|
server.tool("ip-subnet-calculator", "Calculate subnet information for IPv4", {
|
|
@@ -536,9 +572,17 @@ Common issues:
|
|
|
536
572
|
target: z.string().describe("Target host"),
|
|
537
573
|
user: z.string().describe("Username"),
|
|
538
574
|
command: z.string().describe("Command to run on remote host"),
|
|
539
|
-
privateKey: z.string().optional().describe("Private key for authentication (PEM format, optional)")
|
|
575
|
+
privateKey: z.string().optional().describe("Private key for authentication (PEM format, optional, or path to key file)")
|
|
540
576
|
}, async ({ target, user, command, privateKey }) => {
|
|
541
577
|
return new Promise((resolve) => {
|
|
578
|
+
let resolvedKey;
|
|
579
|
+
try {
|
|
580
|
+
resolvedKey = resolvePrivateKey(privateKey);
|
|
581
|
+
}
|
|
582
|
+
catch (err) {
|
|
583
|
+
resolve({ content: [{ type: "text", text: `SSH key error: ${err.message}` }] });
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
542
586
|
const conn = new SSHClient();
|
|
543
587
|
let output = "";
|
|
544
588
|
conn.on("ready", () => {
|
|
@@ -562,7 +606,7 @@ Common issues:
|
|
|
562
606
|
}).connect({
|
|
563
607
|
host: target,
|
|
564
608
|
username: user,
|
|
565
|
-
...(
|
|
609
|
+
...(resolvedKey ? { privateKey: resolvedKey } : {})
|
|
566
610
|
});
|
|
567
611
|
});
|
|
568
612
|
});
|