SSH-MCP (SSH Machine Chat Protocol) is a lightweight tool that provides a structured, JSON-based interface for securely executing commands on remote servers over SSH. This tutorial will guide you through installing, configuring, and using ssh-mcp.
-
Clone the repository:
git clone https://github.com/yourusername/ssh-mcp.git cd ssh-mcp
-
Install locally:
./install.sh
To install ssh-mcp on a remote server:
./install.sh --remote user@hostname --key ~/.ssh/your_key.pem
This will:
- Create the necessary directories on the remote server
- Copy the mcp.sh script
- Install all tool scripts
- Check for dependencies (jq)
# Basic syntax
./ssh-mcp.sh [HOST] TOOL [KEY=VALUE...]
# Examples
./ssh-mcp.sh webserver system.info verbose=true
./ssh-mcp.sh webserver file.read path=/etc/hostname
# With explicit SSH key
./ssh-mcp.sh --key ~/.ssh/aws.pem webserver system.info verbose=true
echo '{"tool":"system.info","args":{"verbose":true}}' | ./ssh-mcp.sh webserver
SSH-MCP includes several meta tools to help you discover and understand available functionality.
Lists all available tools on the remote server:
./ssh-mcp.sh webserver meta.discover
Sample output:
{
"tools": [
{
"name": "meta.describe",
"description": "Returns detailed description for a specific tool",
"version": "0.1.0",
"author": "ssh-mcp Team",
"tags": ["meta", "discovery", "documentation"]
},
{
"name": "system.info",
"description": "Returns basic system information",
"version": "0.1.0",
"author": "ssh-mcp Team",
"tags": ["system", "monitoring", "diagnostics"]
},
...
],
"count": 4,
"explanation": "These are all the available tools on this system. You can get more details about a specific tool using meta.describe."
}
You can also filter tools by category:
./ssh-mcp.sh webserver meta.discover category=system
Get detailed information about a specific tool:
./ssh-mcp.sh webserver meta.describe tool=system.info
Sample output:
{
"tool": "system.info",
"description": "Returns basic system information",
"metadata": {
"author": "ssh-mcp Team",
"version": "0.1.0",
"tags": ["system", "monitoring", "diagnostics"]
},
"args_description": [
"verbose: Set to true for more detailed information (boolean, default: false)"
],
"examples": [
{"tool": "system.info", "args": {"verbose": true}}
],
"explanation": "This tool (system.info) is used for retrieving system information like hostname, OS details, CPU, memory and more.",
"suggestions": [
{"tool": "meta.schema", "description": "Get the JSON schema for this tool"},
{"tool": "meta.discover", "description": "Discover other available tools"}
]
}
Get the JSON schema for a specific tool:
./ssh-mcp.sh webserver meta.schema tool=system.info
Sample output:
{
"type": "object",
"properties": {
"verbose": {
"type": "boolean",
"description": "Whether to include detailed system information",
"default": false
}
}
}
Returns basic system information:
./ssh-mcp.sh webserver system.info verbose=true
Sample output:
{
"hostname": "webserver-01",
"os": "Linux",
"kernel": "5.15.0-35-generic",
"uptime": "14 days, 6:43",
"cpu": {
"model": "Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz",
"count": 8
},
"memory": {
"total": "16G",
"used": "8.5G"
},
"load_average": "0.14 0.15 0.19",
"ip_address": "10.0.1.5",
"disk": [
{
"device": "/dev/sda1",
"total": "100G",
"used": "45G",
"usage": "45%"
}
],
"explanation": "This system (webserver-01) is running Linux kernel 5.15.0-35-generic with 8 CPU cores and 16G of memory."
}
./ssh-mcp.sh --hosts
./ssh-mcp.sh --add-host webserver 192.168.1.10 ubuntu ~/.ssh/web-key.pem
Tools are simple bash scripts stored in ~/.ssh-mcp/tools/
on the remote server. Here's a simple template:
#!/bin/bash
# Tool: category.name - Short description
# Author: Your Name
# Version: 1.0.0
# Tags: tag1, tag2, tag3
#
# Args:
# arg1: Description of first argument (type, constraints)
#
# Example:
# {"tool": "category.name", "args": {"arg1": "value"}}
# Parse arguments
ARGS_FILE="$1"
ARG1=$(jq -r '.arg1 // "default"' "$ARGS_FILE")
# Tool implementation
RESULT=$(cat <<EOF
{
"key1": "value1",
"key2": "value2",
"explanation": "Human-friendly explanation of the result"
}
EOF
)
echo "$RESULT"
exit 0
import json
import subprocess
def run_ssh_mcp(host, tool, args=None):
if args is None:
args = {}
# Build the command
cmd_args = [tool]
for key, value in args.items():
cmd_args.append(f"{key}={value}")
# Execute the command
result = subprocess.run(
["./ssh-mcp.sh", host] + cmd_args,
capture_output=True, text=True
)
return json.loads(result.stdout)
# Example usage
system_info = run_ssh_mcp("webserver", "system.info", {"verbose": True})
print(f"Running {system_info['os']} with {system_info['cpu']['count']} CPUs")
- Tool not found: Ensure the tool script exists in
~/.ssh-mcp/tools/
on the remote server - Permission denied: Ensure tool scripts are executable (
chmod +x
) - jq errors: Ensure jq is installed on the remote server
- Syntax errors: Check the tool script for bash syntax errors
- Use key-based authentication: Avoid password prompts by setting up SSH key authentication
- Keep tools modular: Each tool should do one thing well
- Include good documentation: Every tool should have clear descriptions, examples, and argument documentation
- Return structured data: Always return valid JSON
- Add useful suggestions: Help users discover related functionality
SSH-MCP supports conversation tracking via the conversation_id
parameter:
echo '{"tool":"system.info","conversation_id":"session-123"}' | ./ssh-mcp.sh webserver
This allows you to associate multiple commands as part of the same logical session.
SSH-MCP is designed to be AI-friendly, enabling AI agents to interact with remote systems through a structured interface. The protocol supports context information that can be used by AI systems:
echo '{
"tool": "system.info",
"args": {"verbose": true},
"conversation_id": "session-123",
"context": {
"user_intent": "The user wants to diagnose high memory usage",
"reasoning": "System information will help identify resource constraints"
}
}' | ./ssh-mcp.sh webserver
SSH-MCP inherits its security model from SSH:
- Authentication: Uses SSH's key-based authentication
- Encryption: All traffic is encrypted via SSH
- Authorization: Tools run with the permissions of the SSH user
- Audit: All commands are logged for accountability
It's recommended to:
- Use dedicated SSH keys with appropriate restrictions
- Create separate users with limited permissions for SSH-MCP access
- Regularly review logs for suspicious activity
- Keep tools simple and focused to minimize security risks