bpftrace MCP Server是一个轻量级的MCP(模型上下文协议)服务器,它为AI助手提供了访问bpftrace内核跟踪功能的途径,可助力开发者高效地对Linux内核进行跟踪和分析。
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
sudo apt-get install bpftrace # Ubuntu/Debian
# 或者
sudo dnf install bpftrace # Fedora
cargo build --release
可以使用我们提供的自动化设置脚本:
./setup/setup_claude.sh./setup/setup_claude_code.sh如需详细的设置说明和手动配置方法,请参阅 setup/SETUP.md。
./target/release/bpftrace-mcp-server
cargo run --release
如需Claude桌面版或Claude代码版的手动设置说明,请参阅 setup/SETUP.md。
await list_probes(filter="syscalls:*read*")
info = await bpf_info()
# 返回系统信息、内核辅助函数、特性、映射类型和探测点类型
result = await exec_program(
'tracepoint:syscalls:sys_enter_open { printf("%s\\n", comm); }',
timeout=10
)
exec_id = result["execution_id"]
output = await get_result(exec_id)
print(output["output"])
Rust服务器采用了以下技术和组件:
.env 文件并存储你的sudo密码:echo "BPFTRACE_PASSWD=your_sudo_password" > .env
sudo visudo
# 添加:your_username ALL=(ALL) NOPASSWD: /usr/bin/bpftrace
get_result 进行轮询)。