一个通过标准化接口实现安全终端命令执行、目录导航和文件系统操作的模型上下文协议(MCP)服务器。
要通过Smithery自动安装Claude Desktop的终端控制器:
npx -y @smithery/cli install @GongRzhe/terminal-controller-mcp --client claude
直接从PyPI安装包:
pip install terminal-controller
或者如果你更喜欢使用UV:
uv pip install terminal-controller
如果你更喜欢从源代码安装:
克隆此仓库:
git clone https://github.com/GongRzhe/terminal-controller-mcp.git
cd terminal-controller-mcp
运行设置脚本:
python setup_mcp.py
有两种方式配置Claude Desktop以使用终端控制器:
在你的Claude Desktop配置文件中添加以下内容:
"terminal-controller": {
"command": "uvx",
"args": ["terminal_controller"]
}
"terminal-controller": {
"command": "python",
"args": ["-m", "terminal_controller"]
}
配置路径因操作系统而异:
~/Library/Application Support/Claude/claude_desktop_config.json对于Cursor,使用与Claude Desktop类似的配置设置。
对于其他客户端,请参考它们的文档了解如何配置外部MCP服务器。
一旦配置完成,你可以通过MCP客户端使用自然语言与终端进行交互:
ls -la"终端控制器暴露了以下MCP工具:
execute_command执行终端命令并返回其结果。
参数:
command:要执行的命令行命令timeout:命令超时时间(秒,默认值:30)返回:
get_command_history获取最近的命令执行历史。
参数:
count:要返回的最近命令数量(默认值:10)返回:
get_current_directory获取当前工作目录。
返回:
change_directory更改当前工作目录。
参数:
path:切换到的目录路径返回:
list_directory列出指定目录中的文件和子目录。
参数:
path:列出内容的目录路径(默认值:当前目录)返回:
write_file以覆盖或追加选项向文件写入内容。
参数:
path:文件路径content:要写入的内容mode:写入模式('覆盖'或'追加',默认值:'覆盖')返回:
read_file可选行选择地从文件中读取内容。
参数:
path:文件路径start_row:开始读取的行号(0起始,可选)end_row:结束读取的行号(0起始,包含,可选)返回:
insert_file_content在文件的特定行处插入内容。
参数:
path:文件路径content:要插入的内容row:插入的行号(0起始,可选)rows:插入的行号列表(0起始,可选)返回:
delete_file_content从文件的特定行处删除内容。
参数:
path:文件路径row:要删除的行号(0起始,可选)rows:要删除的行号列表(0起始,可选)返回:
update_file_content更新文件的特定行处的内容。
参数:
path:文件路径content:放置在指定行的新内容row:要更新的行号(0起始,可选)rows:要更新的行号列表(0起始,可选)返回:
终端控制器实现了多项安全措施:
如果遇到问题:
python -m terminal_controller
uvx terminal_controller
欢迎贡献!请随时提交Pull Request。
MIT