当前项目已经不在维护。我建议大家用更先进的终端MCP工具 Desktop Commander
终端MCP服务器是一个模型上下文协议(MCP)服务器,允许在本地或远程主机上执行命令。它提供了一个简单而强大的接口,使AI模型和其他应用程序能够执行系统命令,这些命令可以在本地机器上运行,也可以通过SSH在远程主机上运行。
要通过Smithery自动安装terminal-mcp-server:
npx -y @smithery/cli install @weidwonder/terminal-mcp-server --client claude
# 克隆仓库
git clone https://github.com/weidwonder/terminal-mcp-server.git
cd terminal-mcp-server
# 安装依赖
npm install
# 构建项目
npm run build
# 使用stdio模式启动服务器(默认模式)
npm start
# 或者直接运行构建文件
node build/index.js
SSE(服务器发送事件)模式允许您通过HTTP远程连接到服务器。
# 在SSE模式下启动服务器
npm run start:sse
# 或者直接运行带有SSE标志的构建文件
node build/index.js --sse
您可以使用以下命令行选项来自定义SSE服务器:
| 选项 | 描述 | 默认值 |
|---|---|---|
--port 或 -p | 监听的端口 | 8080 |
--endpoint 或 -e | 端点路径 | /sse |
--host 或 -h | 绑定的主机 | localhost |
带有自定义选项的例子:
# 在端口3000上启动SSE服务器,端点为/mcp,并绑定到所有接口
node build/index.js --sse --port 3000 --endpoint /mcp --host 0.0.0.0
这将启动服务器并监听http://0.0.0.0:3000/mcp上的SSE连接。
# 启动MCP Inspector工具
npm run inspector
execute_command工具是Terminal MCP Server提供的核心功能,用于在本地或远程主机上执行命令。
| 参数 | 类型 | 必需 | 描述 |
|---|---|---|---|
| command | string | 是 | 要执行的命令 |
| host | string | 否 | 要连接的远程主机。如果没有提供,则命令将在本地执行 |
| username | string | 当指定了host时必需 | SSH连接的用户名 |
| session | string | 否 | 会话名称,默认为"default"。相同的会话名称将在20分钟内重复使用相同的终端环境 |
| env | object | 否 | 环境变量,默认为空对象 |
{
"command": "ls -la",
"session": "my-local-session",
"env": {
"NODE_ENV": "development"
}
}
{
"host": "example.com",
"username": "user",
"command": "ls -la",
"session": "my-remote-session",
"env": {
"NODE_ENV": "production"
}
}
~/Library/Application Support/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json{
"mcpServers": {
"terminal-mcp": {
"command": "node",
"args": ["/path/to/terminal-mcp-server/build/index.js"],
"env": {}
}
}
}
{
"mcpServers": {
"terminal-mcp-sse": {
"url": "http://localhost:8080/sse",
"headers": {}
}
}
}
请根据实际情况替换localhost:8080/sse中的服务器地址、端口和端点。
~/.cline/config.json{
"mcpServers": {
"terminal-mcp": {
"command": "node",
"args": ["/path/to/terminal-mcp-server/build/index.js"],
"env": {}
}
}
}
{
"mcpServers": {
"terminal-mcp-sse": {
"url": "http://localhost:8080/sse",
"headers": {}
}
}
}
~/Library/Application Support/Claude/claude_desktop_config.json{
"mcpServers": {
"terminal-mcp": {
"command": "node",
"args": ["/path/to/terminal-mcp-server/build/index.js"],
"env": {}
}
}
}
{
"mcpServers": {
"terminal-mcp-sse": {
"url": "http://localhost:8080/sse",
"headers": {}
}
}
}
&&连接多个命令nohup或screen/tmux~/.ssh/id_rsa)