it-tools-mcp 3.0.9 → 3.0.11

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