MCP Linux 实用工具插件功能强大,借助 MCP 协议,可访问并控制 Linux 系统的各类功能。以下为您详细介绍该插件的安装、配置及使用方法。
git clone https://github.com/your-username/mcplinux.git
cd mcplinux
pip install -r requirements.txt
python3 server.py [--port PORT] [--config CONFIG_FILE]
其中,--port 为可选参数,默认值是 5000;--config 是配置文件的路径。
4. 配置插件
创建或编辑 config.yml 文件,内容如下:
server:
port: 5000
host: 0.0.0.0
filesystem:
allowed_paths:
- "/safe/directory"
- "/another/safe/path"
network:
allowed_domains:
- "example.com"
- "another.example.org"
command:
enabled: true
allowed_commands:
- "ls"
- "cat /etc/os-release"
blocked_commands:
- "rm"
- "sudo"
allow_sudo: false
timeout: 30 # seconds
output_limit: 1024 # bytes
monitoring:
interval: 60 # seconds
python3 server.py --port 5000
此命令将在地址 http://localhost:5000 上启动服务器。
2. 通过 MCP 访问资源
使用 MCP 客户端访问资源,示例代码如下:
from mcpclient import MCPClient
client = MCPClient("localhost", 5000)
print(client.request("linux://system/info")) # 获取系统信息
result = client.execute("ls /safe/directory")
print(result)
配置选项如下:
command:
enabled: true
allowed_commands:
- "ls"
- "cat /etc/os-release"
blocked_commands:
- "rm"
- "sudo"
allow_sudo: false
timeout: 30 # seconds
output_limit: 1024 # bytes
file_info = client.request("linux://fs/info/usr/local/bin/myfile")
print(file_info)
dir_content = client.request(f"linux://fs/dir/{safe_path}")
print(dir_content)
network_stats = client.request("linux://network/interfaces")
print(network_stats)
curl -X POST "http://localhost:5000/api/network/gateway" -d '{"gateway":"192.168.1.1"}'
load_avg = client.request("linux://system/load")
print(load_avg)
disk_usage = client.request("linux://system/disk")
print(disk_usage)
具体安装步骤见上文“安装与配置”部分。
from mcpclient import MCPClient
client = MCPClient("localhost", 5000)
print(client.request("linux://system/info")) # 获取系统信息
from mcpclient import MCPClient
# 创建 MCP 客户端实例
client = MCPClient("localhost", 5000)
# 获取系统信息
system_info = client.request("linux://system/info")
print("System Information:")
print(system_info)
# 获取网络接口状态
network_interfaces = client.request("linux://network/interfaces")
print("\nNetwork Interfaces:")
print(network_interfaces)
# 获取磁盘使用情况
disk_usage = client.request("linux://system/disk")
print("\nDisk Usage:")
print(disk_usage)
# 设置默认网关
curl -X POST "http://localhost:5000/api/network/gateway" -d '{"gateway":"192.168.1.1"}'
该插件通过 MCP 协议实现对 Linux 系统的访问和控制。在配置方面,可通过 config.yml 文件对服务器端口、允许访问的文件路径、网络域、命令执行权限等进行灵活配置。在使用时,通过 MCP 客户端向服务器发送请求,服务器根据配置对请求进行处理并返回相应结果。
MCP Linux 实用工具插件项目在 MIT License 许可证下发布。详情请查看 LICENSE 文件。
在配置 config.yml 文件时,需谨慎设置允许和禁止的命令,避免因配置不当导致系统安全问题。例如,禁止使用 rm 和 sudo 等危险命令,以防止误操作删除重要文件或执行高权限命令。
在使用该插件前,建议先在测试环境中进行充分测试,确保各项功能正常且配置符合需求。同时,定期检查配置文件,根据实际情况调整允许访问的路径、网络域和命令等参数。