Back to MCP directory
publicPublicdnsLocal runtime

terminal-mcp-server

Terminal MCP Server是一个支持本地和远程主机命令执行的MCP协议服务器,为AI模型提供系统命令操作接口。

article

README

🚀 终端 MCP 服务器

终端 MCP 服务器基于 Model Context Protocol (MCP),可在远程或本地执行命令。它支持通过 SSH 连接实现远程命令执行,也能在本地环境运行指令,为用户提供了灵活的命令执行方式。

smithery badge

English Documentation

🚀 快速开始

终端 MCP 服务器允许用户在远程或本地执行命令。你可以通过 SSH 连接到远程设备,也可以在本地环境中运行指令。

✨ 主要特性

  • 远程命令执行:借助 SSH 协议连接到远程设备并执行命令。
  • 本地命令执行:可直接在启动服务器的本地环境中运行指令。
  • 会话管理:提供 20 分钟的活动会话,保障环境上下文的一致性。
  • 多平台兼容:支持 Mac、Linux 等多种操作系统。

📦 安装指南

通过 Smithery 安装

使用提供的链接在 Smithery 平台上直接安装终端 MCP 服务器。

手动安装

  1. 克隆项目仓库:
git clone https://github.com/weidwonder/terminal-mcp-server.git
  1. 进入项目目录并安装依赖:
cd terminal-mcp-server
npm install

💻 使用示例

启动服务器

  • 本地模式(不带 SSH):
node index.js --local
  • 远程模式(启用 SSH):
node index.js --ssh

通过 SSH 连接

确保目标设备已配置 SSH 密钥认证。默认情况下,服务器将尝试使用 ~/.ssh/id_rsa 密钥进行连接。

执行命令

本地执行

直接在启动的服务器环境中运行指令:

execute_command --local "your command"

远程执行

通过 SSH 连接的目标设备上运行命令:

execute_command --ssh <target-host> "your command"

execute_command 工具

参数说明

| 参数 | 详情 | |------|------| | --local | 在本地环境中执行命令 | | --ssh | 通过 SSH 连接远程设备并执行命令 | | <target-host> | 远程目标主机地址(仅在 SSH 模式下使用) | | "your command" | 要执行的具体指令 |

示例

  1. 本地运行简单命令
execute_command --local "echo 'Hello, World!'"
  1. 远程设备上执行复杂任务
execute_command --ssh 192.168.1.100 "sudo apt update && sudo apt upgrade"

📚 详细文档

最佳实践

命令执行

  • 根据目标系统类型(Mac、Linux 等)调整命令。
  • 使用完整路径避免依赖关系问题。
  • 对于需要保持环境的多步操作,使用 && 连接。

SSH 连接

  • 提前配置 SSH 密钥认证。
  • 检查密钥文件是否存在(默认:~/.ssh/id_rsa)。
  • 确保远程设备上的 SSH 服务正常运行。

会话管理

  • 使用 --local--ssh 参数维护环境上下文。
  • 复杂操作建议保持相同会话以维持环境一致性。
  • 20 分钟后若无活动,连接将自动断开。

注意事项

⚠️ 重要提示

远程执行命令时,确保目标设备的安全性。

⚠️ 重要提示

本地或远程命令的权限取决于启动服务器和 SSH 连接的用户身份。

⚠️ 重要提示

长时间运行的任务可能需要额外的资源管理和监控。

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client