Skip to main content
Glama
YawLabs

SSH MCP Server

by YawLabs

ssh_test

Test SSH connectivity before running operations. Reports success or failure with timing and actionable error details for quick troubleshooting.

Instructions

Quick connectivity test to an SSH host. Reports success/failure with timing and actionable error details. Lighter and faster than ssh_diagnose — use this for a quick check before running operations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostYesSSH hostname or IP address
portNoSSH port (default: 22)

Implementation Reference

  • src/tools.ts:279-290 (registration)
    Registration of the 'ssh_test' tool on the MCP server with its schema (HostSchema, PortSchema) and description, delegating to testConnection().
    server.tool(
      "ssh_test",
      "Quick connectivity test to an SSH host. Reports success/failure with timing and actionable error details. Lighter and faster than ssh_diagnose — use this for a quick check before running operations.",
      {
        host: HostSchema,
        port: PortSchema,
      },
      async ({ host, port }) => {
        const result = testConnection(host, port || 22);
        return { content: [{ type: "text", text: result.message }], isError: result.status === "error" };
      },
    );
  • The actual handler function 'testConnection' that executes the SSH connectivity test logic: validates hostname, runs ssh with ConnectTimeout/BatchMode/StrictHostKeyChecking=no, checks stdout for success/failure patterns, and returns status with actionable error messages.
    export function testConnection(host: string, port = 22): { status: "ok" | "warning" | "error"; message: string } {
      if (!isValidHostname(host)) {
        return { status: "error", message: `Invalid hostname: "${host}"` };
      }
    
      const start = Date.now();
      // StrictHostKeyChecking=no on a read-only "echo SSH_OK" probe. No passwords or
      // private-key material transit -- BatchMode=yes suppresses password prompts and ssh
      // never sends private keys over the wire. But the SSH client WILL attempt pubkey auth
      // against the (possibly-MitM'd) endpoint, so the public-key fingerprints of any
      // identities loaded in the agent are observable to whatever answers on this port.
      // For real connections, hostVerifier in resolveConfig (src/ssh.ts) enforces
      // known_hosts matching and prevents this exposure.
      const { ok, stdout } = runArgs("ssh", [
        "-o",
        "ConnectTimeout=5",
        "-o",
        "BatchMode=yes",
        "-o",
        "StrictHostKeyChecking=no",
        "-p",
        String(port),
        host,
        "echo",
        "SSH_OK",
      ]);
      const elapsed = Date.now() - start;
    
      if (ok && stdout.includes("SSH_OK")) {
        return { status: "ok", message: `Connected to ${host}:${port} in ${elapsed}ms` };
      }
    
      if (stdout.includes("Permission denied")) {
        return {
          status: "error",
          message: `Authentication failed to ${host}:${port} (${elapsed}ms). Key not authorized. Check: ssh-add -l, verify correct username, verify key is in remote authorized_keys.`,
        };
      }
      if (stdout.includes("Connection refused")) {
        return {
          status: "error",
          message: `Connection refused at ${host}:${port}. SSH server not running or port blocked.`,
        };
      }
      if (stdout.includes("timed out")) {
        return { status: "error", message: `Connection timed out to ${host}:${port}. Host down or firewall blocking.` };
      }
      if (stdout.includes("Host key verification failed")) {
        return {
          status: "error",
          message: `Host key mismatch for ${host}. Instance was likely recreated. Fix with ssh_known_hosts_fix.`,
        };
      }
      if (stdout.includes("Could not resolve")) {
        return { status: "error", message: `Could not resolve "${host}". Check DNS, /etc/hosts, or SSH config.` };
      }
    
      return { status: "error", message: `Connection failed to ${host}:${port}: ${stdout}` };
    }
  • The HostSchema and PortSchema used as input schema for ssh_test (and other tools).
    const HostSchema = z.string().describe("SSH hostname or IP address");
    const PortSchema = z.number().int().min(1).max(65535).optional().describe("SSH port (default: 22)");
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It indicates a quick test with success/failure, timing, and error details, but does not specify the exact nature of the connectivity test (e.g., TCP only or SSH handshake), leaving some ambiguity.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two concise sentences with no wasted words. Key information is front-loaded, making it efficient for an agent to process.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

No output schema exists, so the description should explain return values. It mentions reports of success/failure, timing, and error details, but lacks specifics on output format, which is acceptable for a simple tool but not fully comprehensive.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% for both parameters. The description does not add new semantic details about the parameters beyond what the schema already provides, so it meets the baseline but does not exceed it.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool performs a connectivity test on an SSH host, and explicitly distinguishes it from its sibling ssh_diagnose by highlighting its lighter and faster nature.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly says to use this tool for a quick check before running operations, and contrasts it with ssh_diagnose, providing clear when-to-use and when-not-to-use guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install 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/YawLabs/ssh-mcp'

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