终端 MCP 服务器是一个 Model Context Protocol (MCP) 服务器,允许在本地或远程主机上执行命令。它为 AI 模型和其他应用程序提供了一个简单但强大的接口,用于在本地机器或通过 SSH 在远程主机上执行系统命令。
要通过 Smithery 自动为 Claude Desktop 安装 terminal-mcp-server:
npx -y @smithery/cli install @weidwonder/terminal-mcp-server --client claude
# Clone the repository
git clone https://github.com/weidwonder/terminal-mcp-server.git
cd terminal-mcp-server
# Install dependencies
npm install
# Build the project
npm run build

# Start the server using stdio (default mode)
npm start
# Or run the built file directly
node build/index.js

SSE(Server-Sent Events)模式允许您通过 HTTP 远程连接到服务器。
# Start the server in SSE mode
npm run start:sse
# Or run the built file directly with SSE flag
node build/index.js --sse

您可以使用以下命令行选项来自定义 SSE 服务器:
选项 | 描述 | 默认值 |
---|---|---|
--port 或 -p |
监听的端口 | 8080 |
--endpoint 或 -e |
端点路径 | /sse |
--host 或 -h |
绑定的主机 | localhost |
带自定义选项的示例:
# Start SSE server on port 3000, endpoint /mcp, and bind to all interfaces
node build/index.js --sse --port 3000 --endpoint /mcp --host 0.0.0.0

这将启动服务器并监听 http://0.0.0.0:3000/mcp
上的 SSE 连接。
# Start the MCP Inspector tool
npm run inspector

execute_command 工具是终端 MCP 服务器提供的核心功能,用于在本地或远程主机上执行命令。
参数 | 类型 | 必需 | 描述 |
---|---|---|---|
command | 字符串 | 是 | 要执行的命令 |
host | 字符串 | 否 | 要连接的远程主机。如果未提供,则命令将在本地执行 |
username | 字符串 | 当指定了 host 时必需 | SSH 连接的用户名 |
session | 字符串 | 否 | 会话名称,默认为 "default"。相同的会话名称将在20分钟内重用相同的终端环境 |
env | 对象 | 否 | 环境变量,默认为空对象 |
{
"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
)