Skip to main content
Glama

sshExecute

Execute commands on remote servers via SSH to manage infrastructure, run administrative tasks, and perform system operations from a centralized interface.

Instructions

Execute a command on a remote server via SSH

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYesCommand to execute
hostYesSSH host
passwordYesSSH password
portNoSSH port
usernameYesSSH username

Implementation Reference

  • The core handler logic for the sshExecute tool. It sets up progress reporting, constructs SSH command options, executes the command via executeSshCommand from sshService, and returns structured content with 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 }; }
  • Zod input schema defining parameters for the sshExecute tool: profile, command, cwd, env, timeoutMs, maxOutputBytes.
    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") });
  • Zod output schema defining the shape of the response from sshExecute: stdout, stderr, truncated flags, exitCode, signal, durationMs.
    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);
  • Registration of the sshExecute tool via registerSshTool function, specifying name, description, input/output schemas, and handler.
    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 }; } ); }
  • Top-level registration entry point that invokes registerSshTool to add the sshExecute tool to the MCP server.
    export function registerTools(server: McpServer): void { registerSshTool(server); registerDbTool(server); registerTrainingTool(server); }

Other Tools

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/jackyxhb/InferMCPServer'

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