ebpf-mcp-tracer

ebpf-mcp-tracer

Enables LLMs to safely write and run bpftrace scripts against the Linux kernel for observability, with explicit probe allowlists and execution timeout.

Category
访问服务器

README

ebpf-mcp-tracer

An MCP server that lets an LLM write and run bpftrace scripts against your kernel, gated by an explicit probe allowlist and a hard execution timeout.

It does not compile raw eBPF C. bpftrace is the engine -- it already handles BTF/CO-RE portability, hook attachment, and ring-buffer-to-text formatting, so this project is the orchestration and safety layer on top of it rather than a from-scratch eBPF compiler.

The ebpf-mcp-tracer is a secure MCP server that bridges LLMs and the Linux kernel by orchestrating bpftrace for natural-language, kernel-level observability. Instead of compiling raw eBPF C, it leverages bpftrace's built-in safety and portability while enforcing strict guardrails through explicit probe allowlists, blocked dangerous builtins, and hard execution timeouts. By exposing simple tools for probe discovery, dry-run validation, and timed trace execution over local stdio, it empowers AI agents to safely debug complex system bottlenecks and analyze process behavior without requiring deep eBPF expertise or risking host stability.

What it exposes

Three tools, callable by any MCP client (Claude Desktop, etc.):

  • list_probes(pattern) -- read-only listing of kernel probes (bpftrace -l)
  • validate_script(script) -- safety allowlist check + compile-only dry run (bpftrace -d, no attachment)
  • run_trace(script, duration_seconds) -- attaches and streams events for up to 60s, then detaches and returns parsed JSON events

And one resource: ebpf://system/kernel-info (kernel version, bpftrace availability).

Setup on your machine

  1. Install bpftrace:

    sudo apt update && sudo apt install -y bpftrace
    

    Confirm it works standalone first:

    sudo bpftrace -e 'BEGIN { printf("it works\n"); exit(); }'
    
  2. Install the Python deps:

    cd ebpf-mcp-tracer
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
    
  3. Permissions. bpftrace needs to load BPF programs into the kernel, which normally requires root. You have two options:

    • Simplest: run the MCP server process itself as root. Fine for a personal box, not something to do on a shared machine.

    • Better, if your kernel is 5.8+: grant the venv's python binary the specific capabilities bpftrace needs instead of full root:

      sudo setcap cap_bpf,cap_perfmon,cap_sys_resource+ep $(readlink -f venv/bin/python3)
      

      Note this grants those capabilities to any script run by that exact python binary -- keep the venv dedicated to this project.

  4. Test the server directly before wiring it into a client:

    python3 -m mcp dev src/ebpf_mcp_tracer/server.py
    

    or run it raw and talk to it over stdio:

    python3 src/ebpf_mcp_tracer/server.py
    
  5. Point your MCP client at it. Example Claude Desktop config entry:

    {
      "mcpServers": {
        "ebpf-tracer": {
          "command": "/absolute/path/to/ebpf-mcp-tracer/venv/bin/python3",
          "args": ["/absolute/path/to/ebpf-mcp-tracer/src/ebpf_mcp_tracer/server.py"]
        }
      }
    }
    

    (Verify the exact config file location and key names against current Claude Desktop docs -- this has changed before.)

Running the tests

The safety-allowlist tests need no privileges and no bpftrace install:

pip install pytest
python3 -m pytest tests/test_safety.py -v

There's also a fake bpftrace shim at tests/fakebin/bpftrace used during development to exercise the subprocess/timeout/JSON-parsing logic in engine.py without needing a real kernel. You shouldn't need it once you have the real binary installed, but it's there if you want to test changes to engine.py without root.

Extending the probe allowlist

src/ebpf_mcp_tracer/safety.py has ALLOWED_PROBE_PATTERNS. Every probe the LLM can attach to must match one of these regexes -- there are no wildcards on purpose. To add a new function:

  1. Look up what it does and confirm it's safe to hook (read-only tracing, not something that can be abused to leak secrets across processes or degrade performance under load).
  2. Add an explicit pattern, e.g. r"^kprobe:tcp_v4_connect$".
  3. Re-run the safety tests.

Don't add kprobe:* or kprobe:do_*-style wildcards -- that defeats the point of the allowlist.

For furthur documentation

Look into https://github.com/blackdragoon26/ebpf-mcp-tracer/blob/main/INSTALL.md

What's deliberately NOT here yet

  • No --unsafe flag anywhere, which means system(), override(), and a few other dangerous bpftrace builtins are unreachable even if the allowlist regex check somehow had a hole. This is enforced at two independent layers on purpose.
  • No automatic verifier-error-to-LLM retry loop. validate_script returns the raw bpftrace compile error; wiring up an automatic "LLM reads the error and retries" loop is a natural next step once you've used this manually a few times and have a feel for what errors actually show up.
  • No network exposure. This talks stdio only. If you want this reachable remotely later, that's a real auth/access-control project on its own -- don't bolt on a port without thinking that through separately.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选