Skip to main content
Glama
kunwarmahen

SSH Read-Only MCP Server

by kunwarmahen

ssh_connect

Establish a secure read-only SSH connection to a remote machine for safe command execution. Authenticate using host, username, port, and optional private key or password.

Instructions

Establish SSH connection to a remote machine (read-only access only).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostYesRemote host IP address or hostname
usernameYesSSH username
portNoSSH port (default: 22)
key_filenameNoPath to private key file (recommended)
passwordNoSSH password (fallback if no key)

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The ssh_connect tool handler function. Uses paramiko to establish an SSH connection to a remote host. Accepts host, username, port (default 22), key_filename, and password. Creates an SSHClient, connects via key or password, stores the client in a global dict keyed by 'username@host:port', and returns a success or failure message.
    @mcp.tool()
    def ssh_connect(
        host: str,
        username: str,
        port: int = 22,
        key_filename: str = None,
        password: str = None
    ) -> str:
        """
        Establish SSH connection to a remote machine (read-only access only).
        
        Args:
            host: Remote host IP address or hostname
            username: SSH username
            port: SSH port (default: 22)
            key_filename: Path to private key file (recommended)
            password: SSH password (fallback if no key)
        
        Returns:
            Connection status message
        """
        try:
            client = paramiko.SSHClient()
            client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            
            if key_filename:
                client.connect(host, port=port, username=username,
                              key_filename=key_filename, timeout=10)
            elif password:
                client.connect(host, port=port, username=username,
                              password=password, timeout=10)
            else:
                raise ValueError("Either key_filename or password must be provided")
            
            # Store client with connection identifier
            connection_id = f"{username}@{host}:{port}"
            ssh_clients[connection_id] = {
                'client': client,
                'host': host,
                'username': username,
                'port': port
            }
            
            return f"Successfully connected to {connection_id}\nRead-only access enabled."
        
        except Exception as e:
            return f"Connection failed: {str(e)}"
  • Registration of ssh_connect as an MCP tool via the @mcp.tool() decorator, along with its type-annotated parameter schema (host: str, username: str, port: int = 22, key_filename: str = None, password: str = None).
    @mcp.tool()
    def ssh_connect(
        host: str,
        username: str,
        port: int = 22,
        key_filename: str = None,
        password: str = None
    ) -> str:
  • Duplicate implementation of ssh_connect in the multicast-discovery variant of the server. Same logic using paramiko, same parameter schema, same global storage pattern.
    @mcp.tool()
    def ssh_connect(
        host: str,
        username: str,
        port: int = 22,
        key_filename: str = None,
        password: str = None
    ) -> str:
        """
        Establish SSH connection to a remote machine (read-only access only).
        
        Args:
            host: Remote host IP address or hostname
            username: SSH username
            port: SSH port (default: 22)
            key_filename: Path to private key file (recommended)
            password: SSH password (fallback if no key)
        
        Returns:
            Connection status message
        """
        try:
            client = paramiko.SSHClient()
            client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            
            if key_filename:
                client.connect(host, port=port, username=username,
                              key_filename=key_filename, timeout=10)
            elif password:
                client.connect(host, port=port, username=username,
                              password=password, timeout=10)
            else:
                raise ValueError("Either key_filename or password must be provided")
            
            # Store client with connection identifier
            connection_id = f"{username}@{host}:{port}"
            ssh_clients[connection_id] = {
                'client': client,
                'host': host,
                'username': username,
                'port': port
            }
            
            return f"Successfully connected to {connection_id}\nRead-only access enabled."
        
        except Exception as e:
            return f"Connection failed: {str(e)}"
  • Registration of ssh_connect via @mcp.tool() decorator in the multicast discovery server variant.
    @mcp.tool()
    def ssh_connect(
        host: str,
        username: str,
        port: int = 22,
        key_filename: str = None,
        password: str = None
    ) -> str:
Behavior3/5

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

With no annotations, the description carries the burden. It adds the behavioral trait 'read-only access only', but lacks detail on failure modes, authentication behavior, or state changes. This is a minimal addition beyond the parameter schema.

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?

A single, front-loaded sentence of 11 words. Every word is informative, no redundancy. Perfectly concise for a simple connection tool.

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 has 5 parameters, no annotations, and an output schema (not shown), the description is adequate but sparse. It covers the basic action and access level but omits details like connection lifecycle or output structure. Sufficient for simple scenarios.

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 baseline is 3. The description does not add any parameter-specific meaning beyond what the schema already provides, maintaining the baseline.

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's purpose: establishing an SSH connection to a remote machine. It also notes 'read-only access only', which distinguishes it from ssh_execute (for executing commands) and other siblings.

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

Usage Guidelines3/5

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

The description implies usage ('establish SSH connection') but does not explicitly compare to alternatives like ssh_execute or provide when-not-to-use guidance. No direct mention of prerequisites or context for selection among siblings.

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

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