Skip to main content
Glama

task_exec_sequence

Execute multiple SSH commands sequentially on a single remote server to automate server management tasks through the MCP SFTP Orchestrator.

Instructions

Exécute plusieurs commandes SSH en séquence sur le même serveur.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
aliasYesAlias du serveur cible.
commandsYesListe des commandes à exécuter en séquence (minimum 1).
continueOnErrorNoContinuer même si une commande échoue.
rappelNoDéfinit un rappel en secondes.

Implementation Reference

  • ssh.js:302-361 (handler)
    Core handler function that executes the sequence of SSH commands sequentially using a pooled connection, collects results for each step, handles per-command timeouts and continueOnError flags.
    async function executeCommandSequence(jobId) { const job = queue.getJob(jobId); if (!job) return queue.log('error', `Tâche introuvable: ${jobId}`); const results = []; let connection = null; try { const serverConfig = await serverManager.getServer(job.alias); queue.updateJobStatus(jobId, 'running'); // Obtenir une connexion du pool connection = await sshPool.getConnection(job.alias, serverConfig); // Exécuter chaque commande en séquence for (let i = 0; i < job.commands.length; i++) { const cmd = job.commands[i]; const stepJob = { ...job, cmd: typeof cmd === 'string' ? cmd : cmd.command, timeout: cmd.timeout || job.timeout, continueOnError: cmd.continueOnError || job.continueOnError }; try { queue.log('info', `Exécution étape ${i+1}/${job.commands.length}: ${stepJob.cmd}`); const result = await executeWithPooledConnection(connection, stepJob, `${jobId}_step_${i}`); results.push({ step: i + 1, command: stepJob.cmd, success: true, ...result }); } catch (err) { results.push({ step: i + 1, command: stepJob.cmd, success: false, error: err.message }); if (!stepJob.continueOnError) { throw new Error(`Échec à l'étape ${i+1}: ${err.message}`); } } } queue.updateJobStatus(jobId, 'completed', { results }); } catch (err) { queue.updateJobStatus(jobId, 'failed', { error: err.message, results }); } finally { if (connection) { sshPool.releaseConnection(connection.id); } } }
  • Zod input schema for the tool, defining server alias, array of commands (string or object with options), global continueOnError, and optional reminder.
    inputSchema: z.object({ alias: z.string().describe("Alias du serveur cible."), commands: z.array(z.union([ z.string(), z.object({ command: z.string(), timeout: z.number().optional(), continueOnError: z.boolean().optional() }) ])).min(1).describe("Liste des commandes à exécuter en séquence (minimum 1)."), continueOnError: z.boolean().optional().default(false).describe("Continuer même si une commande échoue."), rappel: z.number().optional().describe("Définit un rappel en secondes.") })
  • server.js:580-615 (registration)
    Tool registration in the MCP server, including title, description, schema, and the stub handler that queues the job, logs it, triggers execution, waits for completion with adjusted timeout, and returns results or background notice.
    server.registerTool( "task_exec_sequence", { title: "Exécuter une séquence de commandes (SSH)", description: "Exécute plusieurs commandes SSH en séquence sur le même serveur.", inputSchema: z.object({ alias: z.string().describe("Alias du serveur cible."), commands: z.array(z.union([ z.string(), z.object({ command: z.string(), timeout: z.number().optional(), continueOnError: z.boolean().optional() }) ])).min(1).describe("Liste des commandes à exécuter en séquence (minimum 1)."), continueOnError: z.boolean().optional().default(false).describe("Continuer même si une commande échoue."), rappel: z.number().optional().describe("Définit un rappel en secondes.") }) }, async (params) => { const job = queue.addJob({ type: 'ssh_sequence', ...params, status: 'pending' }); history.logTask(job); ssh.executeCommandSequence(job.id); const finalJob = await waitForJobCompletion(job.id, config.syncTimeout * params.commands.length); if (finalJob) { return { content: [{ type: "text", text: `Résultat séquence (tâche ${finalJob.id}):\n${JSON.stringify(finalJob, null, 2)}` }] }; } else { return { content: [{ type: "text", text: `Séquence de commandes ${job.id} initiée en arrière-plan.` }] }; } } );
  • Helper function used by the tool handler to poll for job completion with a timeout, resolving to the job or null if timed out.
    async function waitForJobCompletion(jobId, timeout) { return new Promise((resolve) => { const startTime = Date.now(); const interval = setInterval(() => { const job = queue.getJob(jobId); if (job.status === 'completed' || job.status === 'failed') { clearInterval(interval); resolve(job); } else if (Date.now() - startTime > timeout) { clearInterval(interval); resolve(null); } }, 200); }); }

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/fkom13/mcp-sftp-orchestrator'

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