MCP 终端是一个强大的终端控制服务器,它借助 MCP 协议与大型语言模型集成,能够高效执行和管理终端命令,为用户带来便捷的操作体验。
运行以下命令启动 MCP 终端服务器:
python -m src.mcp_terminal.stdiostream_server
pip 进行包管理uv mcp-terminal@latest
make install
# 基本使用
mcp-terminal execute_command --command "ls"
# 带超时设置的命令执行
mcp-terminal execute_command --command "sleep 10" --timeout 5
在 Claude Desktop 中添加 MCP 终端工具:
{
"tools": {
"mcp-terminal": {
"type": "execute_command",
"config": {
"host": "localhost",
"port": "1234"
}
}
}
}
问题:无法连接到 MCP 终端服务器
问题:命令执行超时
execute_command(
command: str,
wait_for_output: bool = True,
timeout: int = 10
) -> dict
参数说明:
command:要执行的终端命令。wait_for_output:是否等待命令输出,默认为 True。timeout:等待超时时间,单位为秒,默认为 10。返回值:
{
"success": bool,
"output": str,
"error": str,
"return_code": int,
"warning": str
}
get_terminal_info() -> dict
返回值:
{
"terminal_type": str,
"platform": str
}
项目根目录/
├── mcp_terminal.py # 入口脚本
├── pyproject.toml # 项目配置与依赖管理
├── README.md # 用户文档
├── Makefile # 构建与运行脚本
└── src/
├── __init__.py
└── mcp_terminal/
├── stdio_server.py # 标准输入输出服务器实现
├── controllers/ # 终端控制器模块
│ ├── base.py # 基础接口定义
│ ├── subprocess.py # 子进程控制器实现
│ ├── applescript.py # AppleScript 控制器实现
│ └── iterm.py # iTerm2 API 控制器实现
└── tools/ # 工具模块
└── terminal_tools.py # 终端操作工具函数
文档中未提及许可证相关信息。