MCP server for managing persistent SSH sessions
Project description
MCP SSH Session
An MCP (Model Context Protocol) server that enables AI agents to establish and manage persistent SSH sessions.
Features
- Persistent Sessions: SSH connections are reused across multiple command executions
- SSH Config Support: Automatically reads and uses settings from
~/.ssh/config - Multi-host Support: Manage connections to multiple hosts simultaneously
- Automatic Reconnection: Dead connections are detected and automatically re-established
- Thread-safe: Safe for concurrent operations
- Network Device Support: Automatic enable mode handling for routers and switches
- Sudo Support: Automatic password handling for sudo commands on Unix/Linux hosts
- File Operations: Safe helpers to read and write remote files over SFTP
Installation
Using uvx
uvx mcp-ssh-session
Using Claude Code
Add to your ~/.claude.json:
{
"mcpServers": {
"ssh-session": {
"type": "stdio",
"command": "uvx",
"args": ["mcp-ssh-session"],
"env": {}
}
}
}
Using MCP Inspector
npx @modelcontextprotocol/inspector uvx mcp-ssh-session
Development Installation
uv venv
source .venv/bin/activate
uv pip install -e .
Usage
Available Tools
execute_command
Execute a command on an SSH host using a persistent session.
Using SSH config alias:
{
"host": "myserver",
"command": "uptime"
}
Using explicit parameters:
{
"host": "example.com",
"username": "user",
"command": "ls -la",
"key_filename": "~/.ssh/id_rsa",
"port": 22
}
Network device with enable mode:
{
"host": "router.example.com",
"username": "admin",
"password": "ssh_password",
"enable_password": "enable_password",
"command": "show running-config"
}
Unix/Linux with sudo:
{
"host": "server.example.com",
"username": "user",
"sudo_password": "user_password",
"command": "systemctl restart nginx"
}
list_sessions
List all active SSH sessions.
close_session
Close a specific SSH session.
{
"host": "myserver"
}
close_all_sessions
Close all active SSH sessions.
read_file
Read the contents of a remote file via SFTP, with optional sudo support.
Basic usage:
{
"host": "myserver",
"remote_path": "/etc/nginx/nginx.conf",
"max_bytes": 131072
}
With passwordless sudo (NOPASSWD in sudoers):
{
"host": "myserver",
"remote_path": "/etc/shadow",
"use_sudo": true
}
With sudo password:
{
"host": "myserver",
"remote_path": "/etc/shadow",
"sudo_password": "user_password"
}
- Attempts SFTP first for best performance
- Falls back to
sudo catvia shell if permission denied anduse_sudo=trueorsudo_passwordprovided - Supports both passwordless sudo (NOPASSWD) and password-based sudo
- Enforces a 2 MB maximum per request (configurable per call up to that limit)
- Returns truncated notice when the content size exceeds the requested limit
write_file
Write text content to a remote file via SFTP, with optional sudo support.
Basic usage:
{
"host": "myserver",
"remote_path": "/tmp/app.env",
"content": "DEBUG=true\n",
"append": true,
"make_dirs": true
}
With passwordless sudo (NOPASSWD in sudoers):
{
"host": "myserver",
"remote_path": "/etc/nginx/nginx.conf",
"content": "server { ... }",
"use_sudo": true,
"permissions": 420
}
With sudo password:
{
"host": "myserver",
"remote_path": "/etc/nginx/nginx.conf",
"content": "server { ... }",
"sudo_password": "user_password",
"permissions": 420
}
- Uses SFTP when
use_sudo=falseand nosudo_passwordprovided - Uses
sudo teevia shell whenuse_sudo=trueorsudo_passwordis provided - Supports both passwordless sudo (NOPASSWD) and password-based sudo
- Content larger than 2 MB is rejected for safety
- Optional
appendmode to add to existing files - Optional
make_dirsflag will create missing parent directories - Supports
permissionsto set octal file modes after write (e.g.,420for0644) - Note: Shell fallback is slower than SFTP but enables writing to protected files
SSH Config Support
The server automatically reads ~/.ssh/config and supports:
- Host aliases
- Hostname mappings
- Port configurations
- User specifications
- IdentityFile settings
Example ~/.ssh/config:
Host myserver
HostName example.com
User myuser
Port 2222
IdentityFile ~/.ssh/id_rsa
Then simply use:
{
"host": "myserver",
"command": "uptime"
}
Documentation
See CLAUDE.md for detailed documentation.
License
Distributed under the MIT License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_ssh_session-0.1.1.tar.gz.
File metadata
- Download URL: mcp_ssh_session-0.1.1.tar.gz
- Upload date:
- Size: 101.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da736d932b5805de740b11cbc9ad89c2b50129c2e60d1aa828b4833984c52b8c
|
|
| MD5 |
3d7f7cbe009d2649092c9861007fdbe2
|
|
| BLAKE2b-256 |
bc4d02536b370c515ac3ec5bf2c6f4d5b14afa85b019649272c5e6be8c692e60
|
Provenance
The following attestation bundles were made for mcp_ssh_session-0.1.1.tar.gz:
Publisher:
publish.yaml on devnullvoid/mcp-ssh-session
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_ssh_session-0.1.1.tar.gz -
Subject digest:
da736d932b5805de740b11cbc9ad89c2b50129c2e60d1aa828b4833984c52b8c - Sigstore transparency entry: 669272834
- Sigstore integration time:
-
Permalink:
devnullvoid/mcp-ssh-session@1bcc865cc4b50cc6e6b4b27d9e749668ab30373a -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/devnullvoid
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@1bcc865cc4b50cc6e6b4b27d9e749668ab30373a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file mcp_ssh_session-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mcp_ssh_session-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18e635b64c86dee17ef8485859153c66b86969759f5ef0982ba9e1176e62883a
|
|
| MD5 |
eff488b701d400ca9ae24190c3c76196
|
|
| BLAKE2b-256 |
e7bc3defcbae29e3e2270dc8b02d7e4c01ac09f4f10ed749f27bce3c99873c21
|
Provenance
The following attestation bundles were made for mcp_ssh_session-0.1.1-py3-none-any.whl:
Publisher:
publish.yaml on devnullvoid/mcp-ssh-session
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_ssh_session-0.1.1-py3-none-any.whl -
Subject digest:
18e635b64c86dee17ef8485859153c66b86969759f5ef0982ba9e1176e62883a - Sigstore transparency entry: 669272840
- Sigstore integration time:
-
Permalink:
devnullvoid/mcp-ssh-session@1bcc865cc4b50cc6e6b4b27d9e749668ab30373a -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/devnullvoid
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@1bcc865cc4b50cc6e6b4b27d9e749668ab30373a -
Trigger Event:
workflow_dispatch
-
Statement type: