Skip to main content
Glama
d3v1an
by d3v1an

ssh_undo

Revert specific SSH operations like file writes, uploads, or downloads using their history ID. Requires confirmation to execute the reversal for safe remote server administration.

Instructions

Revierte una operación específica del historial usando su ID. Solo funciona con operaciones marcadas como reversibles (ssh_write_file, ssh_upload, ssh_download). Requiere confirm: true para ejecutar la reversión

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
recordIdYesID del registro de operación a revertir (obtenido de ssh_history)
confirmNoConfirmar la reversión de la operación

Implementation Reference

  • The `handleUndo` method manages the logic for reverting reversible operations from the command history.
    private async handleUndo(args: any): Promise<CallToolResult> {
      this.requireConnection();
      const recordId = args.recordId as number;
      const confirm = args.confirm as boolean | undefined;
    
      const record = this.commandHistory.find((r) => r.id === recordId);
      if (!record) {
        throw new Error(`Registro #${recordId} no encontrado en el historial.`);
      }
    
      if (!record.reversible) {
        throw new Error(`Registro #${recordId} (${record.tool}) no es reversible.`);
      }
    
      if (record.reversed) {
        throw new Error(`Registro #${recordId} ya fue revertido.`);
      }
    
      if (!record.reverseInfo) {
        throw new Error(`Registro #${recordId} no tiene información de reversión.`);
      }
    
      if (!confirm) {
        return {
          content: [
            {
              type: "text",
              text: [
                `Operación a revertir:`,
                `  #${record.id} ${record.tool} — ${record.reverseInfo.description}`,
                ``,
                `Para confirmar, reenvía con confirm: true.`,
              ].join("\n"),
            },
          ],
        };
      }
    
      const info = record.reverseInfo;
    
      switch (info.type) {
        case "file_restore": {
          const sftp = await this.getSftp();
          await new Promise<void>((resolve, reject) => {
            const stream = sftp.createWriteStream(info.remotePath!);
            stream.on("close", () => resolve());
            stream.on("error", (err: Error) => reject(err));
            stream.end(info.previousContent!, "utf-8");
          });
          record.reversed = true;
          this.audit("ssh_undo", `record=${recordId} file_restore ${info.remotePath}`, "ok");
          return {
            content: [
              {
                type: "text",
                text: `Revertido #${recordId}: contenido previo restaurado en ${info.remotePath}`,
              },
            ],
          };
        }
    
        case "file_delete": {
          await this.execCommand(`rm ${escapeShellArg(info.remotePath!)}`);
          record.reversed = true;
          this.audit("ssh_undo", `record=${recordId} file_delete ${info.remotePath}`, "ok");
          return {
            content: [
              {
                type: "text",
                text: `Revertido #${recordId}: archivo ${info.remotePath} eliminado (no existía antes)`,
              },
            ],
          };
        }
    
        case "local_file_delete": {
          if (fs.existsSync(info.localPath!)) {
            fs.unlinkSync(info.localPath!);
          }
          record.reversed = true;
          this.audit("ssh_undo", `record=${recordId} local_file_delete ${info.localPath}`, "ok");
          return {
            content: [
              {
                type: "text",
                text: `Revertido #${recordId}: archivo local ${info.localPath} eliminado`,
              },
            ],
          };
        }
    
        default:
          throw new Error(`Tipo de reversión desconocido: ${(info as ReverseInfo).type}`);
      }
    }
  • src/tools.ts:296-313 (registration)
    Tool definition and registration for "ssh_undo".
      name: "ssh_undo",
      description:
        "Revierte una operación específica del historial usando su ID. Solo funciona con operaciones marcadas como reversibles (ssh_write_file, ssh_upload, ssh_download). Requiere confirm: true para ejecutar la reversión",
      inputSchema: {
        type: "object",
        properties: {
          recordId: {
            type: "number",
            description: "ID del registro de operación a revertir (obtenido de ssh_history)",
          },
          confirm: {
            type: "boolean",
            description: "Confirmar la reversión de la operación",
          },
        },
        required: ["recordId"],
      },
    },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/d3v1an/ssh-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server