Skip to main content
Glama
lgariv
by lgariv

Test SSH Connection

ssh_test_connection

Test SSH connectivity to configured servers by establishing a connection and returning the remote hostname for verification.

Instructions

Attempts to connect to the configured SSH host and returns the remote hostname

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler function that executes the ssh_test_connection tool: connects via SSH using env vars, runs 'hostname', returns result or error.
    async () => {
      try {
        const ssh = await createSshConnection();
        try {
          const { stdout, stderr, exitCode } = await runRemoteCommand(ssh, "hostname");
          ssh.end();
          const details = JSON.stringify(
            { exitCode, stderr: stderr.trim(), stdout: stdout.trim() },
            null,
            2
          );
          return { content: [{ type: "text", text: details }] };
        } finally {
          // Ensure connection is closed if not already
          ssh.end();
        }
      } catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        return { content: [{ type: "text", text: `SSH connection failed: ${message}` }], isError: true };
      }
    }
  • Handler function that executes the ssh_test_connection tool: connects via SSH using provided config, runs 'hostname', returns result or error.
    async () => {
      try {
        const ssh = await createSshConnection(config);
        try {
          const { stdout, stderr, exitCode } = await runRemoteCommand(ssh, "hostname");
          ssh.end();
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify({ exitCode, stdout: stdout.trim(), stderr: stderr.trim() }, null, 2),
              },
            ],
          };
        } finally {
          ssh.end();
        }
      } catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        return { content: [{ type: "text", text: `SSH connection failed: ${message}` }], isError: true };
      }
    }
  • src/index.ts:81-109 (registration)
    Registration of the ssh_test_connection tool in the main MCP server in index.ts
    server.registerTool(
      "ssh_test_connection",
      {
        title: "Test SSH Connection",
        description: "Attempts to connect to the configured SSH host and returns the remote hostname",
        inputSchema: {},
      },
      async () => {
        try {
          const ssh = await createSshConnection();
          try {
            const { stdout, stderr, exitCode } = await runRemoteCommand(ssh, "hostname");
            ssh.end();
            const details = JSON.stringify(
              { exitCode, stderr: stderr.trim(), stdout: stdout.trim() },
              null,
              2
            );
            return { content: [{ type: "text", text: details }] };
          } finally {
            // Ensure connection is closed if not already
            ssh.end();
          }
        } catch (error) {
          const message = error instanceof Error ? error.message : String(error);
          return { content: [{ type: "text", text: `SSH connection failed: ${message}` }], isError: true };
        }
      }
    );
  • src/smithery.ts:57-86 (registration)
    Registration of the ssh_test_connection tool in the smithery module
    server.registerTool(
      "ssh_test_connection",
      {
        title: "Test SSH Connection",
        description: "Attempts to connect and returns the remote hostname",
        inputSchema: {},
      },
      async () => {
        try {
          const ssh = await createSshConnection(config);
          try {
            const { stdout, stderr, exitCode } = await runRemoteCommand(ssh, "hostname");
            ssh.end();
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify({ exitCode, stdout: stdout.trim(), stderr: stderr.trim() }, null, 2),
                },
              ],
            };
          } finally {
            ssh.end();
          }
        } catch (error) {
          const message = error instanceof Error ? error.message : String(error);
          return { content: [{ type: "text", text: `SSH connection failed: ${message}` }], isError: true };
        }
      }
    );
  • Helper function to create SSH connection using environment variables.
    async function createSshConnection(): Promise<SSHClient> {
      const env = getEnv();
      const ssh = new SSHClient();
      const config: ConnectConfig = {
        host: env.SSH_HOST,
        port: Number(env.SSH_PORT),
        username: env.SSH_USERNAME,
        password: env.SSH_PASSWORD,
        readyTimeout: 15000,
        tryKeyboard: false,
        algorithms: {
          // Keep defaults; allow host key algo negotiation modern-first
        },
      };
      await new Promise<void>((resolve, reject) => {
        ssh
          .on("ready", () => resolve())
          .on("error", (err: Error) => reject(err))
          .connect(config);
      });
      return ssh;
    }
Behavior2/5

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

With no annotations provided, the description carries full burden. It mentions the connection attempt and return value, but doesn't disclose important behavioral traits like: what happens on connection failure (error message format), timeout behavior, authentication requirements, whether it modifies any state, or if it has rate limits. For a connectivity tool with zero annotation coverage, this is insufficient.

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?

The description is a single, efficient sentence that communicates the core functionality and return value. It's front-loaded with the main action and has zero wasted words. Every part of the sentence earns its place by conveying essential information.

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?

Given the tool's simplicity (0 parameters, no output schema), the description is reasonably complete for basic understanding. However, without annotations and with no output schema, it should ideally describe what happens on failure and the format of the return value. The description mentions the return but doesn't specify if it's a string, object, or what happens if connection fails.

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

Parameters4/5

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

The tool has 0 parameters with 100% schema description coverage, so the baseline is 4. The description appropriately doesn't waste space discussing non-existent parameters. It correctly focuses on what the tool does rather than parameter documentation.

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

Purpose4/5

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

The description clearly states the action ('attempts to connect') and resource ('configured SSH host'), and specifies the return value ('returns the remote hostname'). It distinguishes from the sibling 'ssh_run' by focusing on connection testing rather than command execution. However, it doesn't explicitly mention that this is for validation/diagnostic purposes, which would make it a perfect 5.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus the sibling 'ssh_run'. It doesn't mention prerequisites like needing SSH configuration or suggest this should be used before running commands. There's no explicit when/when-not guidance or alternative tool recommendations.

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

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