sshExecute
Execute commands on remote servers via SSH using configured profiles. Run scripts, manage infrastructure, and perform administrative tasks securely from the Infer MCP Server interface.
Instructions
Execute a command on a remote server via SSH using a configured profile
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| profile | Yes | SSH credential profile to use | |
| command | Yes | Command to execute | |
| cwd | No | Working directory on remote host | |
| env | No | Environment variables for the command | |
| timeoutMs | No | Execution timeout in milliseconds | |
| maxOutputBytes | No | Maximum bytes to capture from stdout/stderr |
Implementation Reference
- src/tools/sshExecute.ts:43-87 (handler)The asynchronous handler function for the 'sshExecute' tool. It processes input arguments, sets up progress reporting, executes the SSH command using executeSshCommand from sshService, and returns the structured output including stdout, stderr, exit code, etc.async (args, extra) => { const progress = createProgressReporter(extra, "sshExecute"); const total = 1; progress?.({ progress: 0, total, message: "Scheduling SSH command" }); const options: SshCommandOptions = { cwd: args.cwd, env: args.env, timeoutMs: args.timeoutMs, maxOutputBytes: args.maxOutputBytes, signal: extra.signal, onProgress: (update) => { progress?.({ progress: update.progress, total, message: update.message }); } }; const result: SshCommandResult = await executeSshCommand( args.profile, args.command, options, { requestId: String(extra.requestId), tool: "sshExecute" } ); const structuredContent: Record<string, unknown> = { stdout: result.stdout, stderr: result.stderr, truncated: result.truncated, exitCode: result.exitCode, signal: result.signal, durationMs: result.durationMs }; return { content: [], structuredContent }; }
- src/tools/sshExecute.ts:10-33 (schema)Zod schemas defining the input parameters (profile, command, cwd, env, timeoutMs, maxOutputBytes) and output shape (stdout, stderr, truncated, exitCode, signal, durationMs) for the sshExecute tool.const SshExecuteInputSchema = z.object({ profile: z.string().describe("SSH credential profile to use"), command: z.string().min(1).describe("Command to execute"), cwd: z.string().optional().describe("Working directory on remote host"), env: z.record(z.string(), z.string()).optional().describe("Environment variables for the command"), timeoutMs: z.number().int().positive().optional().describe("Execution timeout in milliseconds"), maxOutputBytes: z .number() .int() .positive() .optional() .describe("Maximum bytes to capture from stdout/stderr") }); const SshExecuteOutputShape = { stdout: z.string(), stderr: z.string(), truncated: z.object({ stdout: z.boolean(), stderr: z.boolean() }), exitCode: z.number().nullable(), signal: z.string().optional(), durationMs: z.number().int().nonnegative() }; export const SshExecuteOutputSchema = z.object(SshExecuteOutputShape);
- src/tools/sshExecute.ts:35-89 (registration)The registerSshTool function that registers the 'sshExecute' tool on the MCP server, specifying the tool name, description, input/output schemas, and the handler function.export function registerSshTool(server: McpServer): void { server.registerTool( "sshExecute", { description: "Execute a command on a remote server via SSH using a configured profile", inputSchema: SshExecuteInputSchema.shape, outputSchema: SshExecuteOutputShape }, async (args, extra) => { const progress = createProgressReporter(extra, "sshExecute"); const total = 1; progress?.({ progress: 0, total, message: "Scheduling SSH command" }); const options: SshCommandOptions = { cwd: args.cwd, env: args.env, timeoutMs: args.timeoutMs, maxOutputBytes: args.maxOutputBytes, signal: extra.signal, onProgress: (update) => { progress?.({ progress: update.progress, total, message: update.message }); } }; const result: SshCommandResult = await executeSshCommand( args.profile, args.command, options, { requestId: String(extra.requestId), tool: "sshExecute" } ); const structuredContent: Record<string, unknown> = { stdout: result.stdout, stderr: result.stderr, truncated: result.truncated, exitCode: result.exitCode, signal: result.signal, durationMs: result.durationMs }; return { content: [], structuredContent }; } ); }
- src/tools/index.ts:6-10 (registration)The top-level registerTools function that invokes registerSshTool to register the sshExecute tool along with other tools.export function registerTools(server: McpServer): void { registerSshTool(server); registerDbTool(server); registerTrainingTool(server); }