Sponsored by Deepsite.site

Remote Session Mcp

Created By
kayoch1n21 days ago
A Model Context Protocol (MCP) server that enables AI assistants to manage persistent SSH sessions and execute commands on remote servers.
Content

Remote Session MCP Server

A Model Context Protocol (MCP) server that enables AI assistants to manage persistent SSH sessions and execute commands on remote servers.

Key Advantages

Persistent Sessions with State

Unlike SSH tools that execute single commands in isolation, this server uses invoke_shell() to maintain interactive shell sessions where state persists across multiple commands:

CapabilityPersistent SessionsSingle-Command
Working directory (cd)PersistsLost after each command
Environment variables (export)PersistsLost after each command
Multi-step workflowsNatural flowRequires manual context passing
AI context awarenessTracks pwd automaticallyNo state tracking

Typical workflow:

create → execute("cd /app") → execute("export ENV=prod") → execute("./deploy.sh") → close

This is ideal for AI-driven deployment, debugging, and server management tasks where commands build on each other.

Automatic SSH Config Integration

  • Parses ~/.ssh/config automatically for connection parameters
  • Supports key-based authentication, custom ports, jump hosts, and all standard SSH options
  • No need to hardcode credentials or connection details

Installation

# Using uv (recommended)
uv pip install -e .

# Or using pip
pip install -e .

Usage

1. Configure SSH

Ensure your servers are configured in ~/.ssh/config:

Host production
    HostName 192.168.1.100
    User deploy
    IdentityFile ~/.ssh/id_rsa

2. Run the MCP Server

remote-session-mcp
# Or: python -m remote_session_mcp

3. Claude Code Integration

Create .claude/settings.json or mcp.json in your project:

{
  "mcpServers": {
    "remote-session": {
      "command": "uv",
      "args": ["run", "remote-session-mcp"],
      "cwd": "/path/to/sshmcp"
    }
  }
}

4. Available Tools

ToolDescription
hostsList all hosts from ~/.ssh/config
createCreate a persistent SSH session
executeExecute a command (state persists)
closeClose a session
sessionsList active sessions
uploadUpload a file to remote server
downloadDownload a file from remote server

Example: Deploy an Application

// 1. Create session
{"tool": "create", "arguments": {"host": "production"}}

// 2. Navigate and deploy (state persists)
{"tool": "execute", "arguments": {"session_id": "session_abc", "command": "cd /var/www/myapp"}}
{"tool": "execute", "arguments": {"session_id": "session_abc", "command": "git pull"}}
{"tool": "execute", "arguments": {"session_id": "session_abc", "command": "npm install"}}
{"tool": "execute", "arguments": {"session_id": "session_abc", "command": "sudo systemctl restart myapp"}}

// 3. Close session
{"tool": "close", "arguments": {"session_id": "session_abc"}}

Configuration (Optional)

Create ~/.remote-session/config.json for custom settings:

{
  "enable_raw_output": false,
  "ssh_config_path": "~/.ssh/config"
}
OptionDefaultDescription
enable_raw_outputfalseReturn raw output with only ANSI codes removed
ssh_config_path~/.ssh/configCustom path to SSH config file

Limitations

  • Linux/POSIX Only - Assumes POSIX-compatible shells and commands (pwd, echo $?)
  • Interactive Shell Required - Remote server must support interactive shell sessions
  • Session Timeout - Sessions auto-close after 1 hour of inactivity (configurable)

Server Config

{
  "mcpServers": {
    "remote-session": {
      "command": "remote-session-mcp"
    }
  }
}
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Amap Maps高德地图官方 MCP Server
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
DeepChatYour AI Partner on Desktop
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
RedisA Model Context Protocol server that provides access to Redis databases. This server enables LLMs to interact with Redis key-value stores through a set of standardized tools.
Y GuiA web-based graphical interface for AI chat interactions with support for multiple AI models and MCP (Model Context Protocol) servers.
Tavily Mcp
WindsurfThe new purpose-built IDE to harness magic
Playwright McpPlaywright MCP server
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
CursorThe AI Code Editor
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Serper MCP ServerA Serper MCP Server
ChatWiseThe second fastest AI chatbot™
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。