终端控制器 MCP 服务器是一个基于 Model Context Protocol (MCP) 的服务器,它借助标准化接口,实现了安全的终端命令执行、目录导航以及文件系统操作,为用户提供了便捷且安全的操作体验。
终端控制器 MCP 服务器能帮助你安全、高效地进行终端命令执行、目录导航和文件系统操作。你可以按照以下步骤进行安装和配置。
pip install terminal_controller
python -m terminal_controller
在 config.json 文件中添加以下内容:
{
"server_address": "localhost:8000",
"timeout": 3600
}
mcp exec "ls -l"
mcp cd /path/to/directory
mcp read_file example.txt
mcp insert_file_content example.txt "new content" 5
mcp delete_file_content example.txt 3
def execute_command(command: str, timeout: int = 3600) -> dict:
"""
执行终端命令。
参数:
command (str): 要执行的命令
timeout (int): 超时时间(秒,默认为 3600)
返回值:
dict:包含结果或错误信息的字典
"""
def read_file(path: str, start_row: int = None, end_row: int = None) -> str:
"""
从文件中读取内容。
参数:
path (str): 文件路径
start_row (int, 可选): 开始行(0 基础)
end_row (int, 可选): 结束行(0 基础,包含)
返回值:
str:文件内容或指定范围的内容
"""
rm -rf / 等危险操作。python -m terminal_controller
uvx terminal_controller
欢迎贡献!请随意提交 Pull Request。
MIT