Persistent Shell MCP

Persistent Shell MCP

Enables AI assistants to execute shell commands and manage long-running processes within persistent tmux sessions across isolated workspaces. It features a dual-window architecture to separate raw command execution from interactive terminal output.

Category
访问服务器

README

This is experimental software intended for testing and development purposes only. Do not use in production environments or with sensitive data.

A Model Context Protocol (MCP) server that provides persistent shell execution through tmux sessions. This server enables AI assistants to execute commands in a persistent shell. This unlocks a lot of possiblities, such as Agent Orchestration... final_optimized

Features

  • Dual-Window Architecture: Each workspace has two windows - exec for command execution and ui for clean output display
  • Persistent Workspaces: Execute commands in tmux sessions that persist across MCP client restarts
  • Interactive Process Support: Handle long-running processes, REPLs, and interactive commands
  • Workspace Isolation: Multiple isolated workspaces for different projects or tasks
  • Clean UI Management: Separate windows for execution and user-facing output
  • Automatic Session Management: Create, destroy, and monitor workspaces seamlessly

Installation

🚨 SECURITY WARNING: This software allows AI assistants to execute arbitrary shell commands on your system. Only install and use in isolated testing environments. Never use on systems with sensitive data or in production environments.

Prerequisites

  • Node.js 18.0.0 or higher
  • tmux installed on your system
    • Ubuntu/Debian: sudo apt install tmux
    • macOS: brew install tmux
    • CentOS/RHEL: sudo yum install tmux

Install from npm

npm install -g tmux-mcp-server

Install from source

git clone https://github.com/TNTisdial/persistent-shell-mcp.git
cd persistent-shell-mcp
npm install
npm link

Usage

MCP Client Configuration

Add to your MCP client configuration:

{
  "mcpServers": {
    "tmux-shell": {
      "command": "tmux-mcp-server"
    }
  }
}

Available Tools

Core Execution Tools

execute_command

Execute commands that complete quickly and return full output. Uses the exec window.

execute_command({
  command: "ls -la", 
  workspace_id: "my-project"
})

start_process

Start long-running or interactive processes. Can target either window:

  • exec window (default): For background processes
  • ui window: For interactive applications that need user visibility
start_process({
  command: "python3", 
  workspace_id: "dev",
  target_window: "ui"  // For interactive apps like vim, python REPL
})

get_output

Capture current terminal output from either window:

  • ui window (default): Clean user-facing output
  • exec window: Raw shell with all commands
get_output({
  workspace_id: "dev",
  window_name: "ui"  // or "exec" for raw output
})

send_input

Send input to running processes in either window.

send_input({
  text: "print('Hello World')", 
  workspace_id: "dev",
  target_window: "ui"
})

stop_process

Stop the currently running process in the exec window (sends Ctrl+C).

stop_process({workspace_id: "dev"})

Workspace Management Tools

create_workspace

Create a new isolated workspace with dual windows.

destroy_workspace

Destroy a workspace and all its processes.

list_workspaces

List all active workspaces.

Architecture

Dual-Window Design

Each workspace consists of two tmux windows:

  1. exec window: Raw shell for command execution

    • Handles all command execution
    • Shows full shell history and prompts
    • Used for background processes
  2. ui window: Clean output display

    • Shows clean output for user interaction
    • Used for interactive applications
    • Provides better user experience

Workspace Isolation

  • Each workspace is a separate tmux session
  • Independent working directories and environments
  • Processes don't interfere between workspaces
  • Clean separation of different projects/tasks

Common Workflows

Quick Command Execution

// Execute and get results immediately
execute_command({command: "npm install", workspace_id: "frontend"})
execute_command({command: "git status", workspace_id: "frontend"})

Interactive Development

// Start Python REPL in UI window
start_process({
  command: "python3", 
  workspace_id: "python-dev",
  target_window: "ui"
})

// Send Python commands
send_input({text: "import os", workspace_id: "python-dev", target_window: "ui"})
send_input({text: "print(os.getcwd())", workspace_id: "python-dev", target_window: "ui"})

// Check output
get_output({workspace_id: "python-dev", window_name: "ui"})

Background Process Management

// Start server in background
start_process({command: "npm run dev", workspace_id: "server"})

// Check server status
get_output({workspace_id: "server", window_name: "exec"})

// Stop server when done
stop_process({workspace_id: "server"})

Multi-Project Development

// Frontend workspace
create_workspace({workspace_id: "frontend"})
execute_command({command: "cd /path/to/frontend", workspace_id: "frontend"})

// Backend workspace  
create_workspace({workspace_id: "backend"})
execute_command({command: "cd /path/to/backend", workspace_id: "backend"})

// Database workspace
create_workspace({workspace_id: "database"})
start_process({command: "mysql -u root -p", workspace_id: "database", target_window: "ui"})

Project Structure

tmux-mcp/
├── src/
│   ├── server.js          # Main MCP server and tool definitions
│   ├── tmux-manager.js    # Tmux session and window management
│   └── index.js           # Entry point
├── bin/
│   └── tmux-mcp-server    # Executable script
├── package.json
└── README.md

Troubleshooting

Tmux Not Found

Error: tmux command not found

Install tmux: sudo apt install tmux (Ubuntu/Debian) or brew install tmux (macOS)

Workspace Creation Failed

Error: Failed to create workspace

Check if tmux server is running and you have permissions to create sessions

Commands Not Responding

Check workspace status with get_output

Use get_output with window_name: "exec" to see raw shell state

Process Stuck

Use stop_process to send Ctrl+C

Send interrupt signal with stop_process to terminate hanging processes

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选