Skip to main content
Glama
vilasone455

SSH MCP Server

by vilasone455

create_connection

Open and manage SSH sessions to remote systems for executing commands through the SSH MCP Server.

Instructions

Open an SSH session to the given machine and track it in global state so subsequent tool calls can reuse it.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
machine_idYesID from get_available_connections
titleYesPurpose of this session (displayed in UIs)

Implementation Reference

  • The handler function for the 'create_connection' tool. It validates inputs, finds the machine config, creates an SSH client, connects, retrieves the initial working directory, stores the connection in the global 'connections' map, and returns the connection details.
    if (name === "create_connection") {
      const { machine_id, title } = args as { machine_id: string; title: string };
    
      if (!machine_id || !title)
        throw new Error("Both machine_id and title are required.");
    
      const machine = findMachine(machine_id);
      if (!machine) throw new Error(`Unknown machine_id '${machine_id}'.`);
    
      const client = new SSHClient();
      const connection_id = crypto.randomUUID();
    
      return new Promise((resolve, reject) => {
        client
          .on("ready", async () => {
            try {
              const { stdout } = await wrapExec(client, "pwd");
              const connInfo = {
                connection_id,
                machine_id,
                title,
                currentPath: stdout.trim(),
                client,
              };
              connections.set(connection_id, connInfo);
    
              resolve({
                content: [
                  {
                    type: "text",
                    text: JSON.stringify(
                      {
                        connection_id,
                        machine_id,
                        title,
                        currentPath: connInfo.currentPath,
                      },
                      null,
                      2
                    ),
                  },
                ],
              });
            } catch (e) {
              client.end();
              reject(e);
            }
          })
          .on("error", (err) => reject(err))
          .connect(buildSshConfig(machine));
      });
    }
  • Input schema definition for the 'create_connection' tool, specifying required 'machine_id' and 'title' parameters.
    {
      name: "create_connection",
      description:
        "Open an SSH session to the given machine and track it in global state so subsequent tool calls can reuse it.",
      inputSchema: {
        type: "object",
        required: ["machine_id", "title"],
        properties: {
          machine_id: { type: "string", description: "ID from get_available_connections" },
          title: { type: "string", description: "Purpose of this session (displayed in UIs)" },
        },
        additionalProperties: false,
      },
    },
  • src/index.ts:140-207 (registration)
    Registers the 'create_connection' tool (among others) by including it in the ListTools response.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        {
          name: "get_available_connections",
          description:
            "List every SSH-capable machine this server knows about (but is NOT yet connected).",
          inputSchema: { type: "object", properties: {}, additionalProperties: false },
        },
        {
          name: "create_connection",
          description:
            "Open an SSH session to the given machine and track it in global state so subsequent tool calls can reuse it.",
          inputSchema: {
            type: "object",
            required: ["machine_id", "title"],
            properties: {
              machine_id: { type: "string", description: "ID from get_available_connections" },
              title: { type: "string", description: "Purpose of this session (displayed in UIs)" },
            },
            additionalProperties: false,
          },
        },
        {
          name: "get_connections",
          description: "Return every STILL-OPEN SSH session in global state.",
          inputSchema: { type: "object", properties: {}, additionalProperties: false },
        },
        {
          name: "execute_command",
          description:
            "Run a shell command in an existing SSH session and return stdout/stderr/exitCode.",
          inputSchema: {
            type: "object",
            required: ["connection_id", "command"],
            properties: {
              connection_id: { type: "string" },
              command: { type: "string", description: "Shell command to execute" },
            },
            additionalProperties: false,
          },
        },
        {
          name: "secure_execute_command",
          description:
            "Run a **read‑only** shell command (i.e., one that does not mutate state) in an existing SSH session and return stdout/stderr/exitCode.",
          inputSchema: {
            type: "object",
            required: ["connection_id", "command"],
            properties: {
              connection_id: { type: "string" },
              command: { type: "string", description: "Read‑only shell command to execute (e.g., ls, cat)." },
            },
            additionalProperties: false,
          },
        },
    
        {
          name: "close_connection",
          description: "Terminate an SSH session and remove it from global state.",
          inputSchema: {
            type: "object",
            required: ["connection_id"],
            properties: { connection_id: { type: "string" } },
            additionalProperties: false,
          },
        },
      ],
    }));
  • Helper function used by create_connection to locate the machine configuration by ID.
    function findMachine(machine_id) {
      return availableMachines.find((m) => m.machine_id === machine_id);
    }
  • Helper function used by create_connection to construct the SSH configuration object.
    function buildSshConfig(m) {
      const cfg: any = {
        host: m.ssh.host,
        port: m.ssh.port,
        username: m.ssh.username,
      };
      if (m.ssh.password) cfg.password = m.ssh.password;
      if (m.ssh.keyPath) {
        // Lazy‑load fs so we don’t pay the I/O cost unless needed
        cfg.privateKey = readFileSync(m.ssh.keyPath, "utf8");
      }
      return cfg;
Behavior3/5

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

With no annotations, the description carries full burden. It discloses key behavioral traits: it opens an SSH session (implies network/authentication needs) and tracks it globally (stateful, reusable). However, it lacks details on error handling, timeouts, permissions, or what 'global state' entails (e.g., persistence across calls).

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?

It's a single, well-structured sentence that front-loads the core action and adds necessary context efficiently. Every word earns its place with zero waste, making it easy to parse quickly.

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 no annotations and no output schema, the description is adequate for a setup tool but has gaps. It covers the purpose and state tracking well, but lacks details on return values (e.g., success/failure indicators), error cases, or prerequisites (e.g., valid credentials). It's minimal 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 description coverage is 100%, so the schema already documents both parameters fully. The description adds no additional meaning beyond implying 'machine_id' comes from 'get_available_connections' (which is in the schema) and 'title' is for display. Baseline 3 is appropriate as the schema does the heavy lifting.

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 specific action ('Open an SSH session') and resource ('to the given machine'), plus the additional effect of tracking it in global state for reuse. It distinguishes from siblings like 'get_available_connections' (list) and 'execute_command' (use).

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

Usage Guidelines4/5

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

It implies usage context by mentioning 'subsequent tool calls can reuse it,' suggesting this is a setup step before commands. However, it doesn't explicitly state when not to use it (e.g., for one-off commands) or name alternatives like 'secure_execute_command' for direct execution.

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

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