agent-ebpf-mcp

agent-ebpf-mcp

Enables AI agents to inspect and manage Linux kernel-level eBPF security policies, including real-time status monitoring, policy retrieval, dynamic rule injection, and pre-execution SQL/syscall validation via natural language.

Category
访问服务器

README

Agent-eBPF: Developer Guide

Agent-eBPF is an autonomous security shield that intercepts and blocks SQL queries, system calls, and network packets generated by AI agents (LLM Agents, MCP Tools, Autonomous Swarms) at the Linux Kernel level—with zero code modification (zero-code) and zero overhead in user-space.


1. Architecture and Operating Principle

While traditional security tools operate at the application layer (Python/Node.js middleware), Agent-eBPF attaches directly to the Linux Kernel's network socket and process monitoring layers (sock_filter, uprobes, kprobes).

  [ User Space ]
  ┌─────────────────────────────────────────────────────────┐
  │  FastAPI / Node.js Application (LLM Agent Workflows)    │
  └───────────────────────────┬─────────────────────────────┘
                              │ Socket Send / Syscall
  ────────────────────────────┼──────────────────────────────
  [ Linux Kernel Space ]      ▼
  ┌─────────────────────────────────────────────────────────┐
  │  Agent-eBPF Engine (eBPF XDP / Socket Buffer Filter)    │
  │  ├── AST & Regex Rule Matching (<50 µs execution)       │
  │  └── Policy Enforcement (PASS / DROP / TCP_RST)         │
  └───────────────────────────┬─────────────────────────────┘
                              │
               ┌──────────────┴──────────────┐
               ▼                             ▼
       [ PASS: Safe Execution ]      [ DROP: TCP Reset / Block ]
       Routes to Database / API      Interrupted before reaching app

Core Principles

  • Zero Code Changes: Not a single line of import or middleware is added to your code.
  • Ultra-Low Latency: Inspection completes within kernel buffer memory in <50 microseconds (µs).
  • Fail-Closed (Zero-Trust): On violation, the socket connection is immediately closed via TCP_RST or the packet is dropped (DROP).

2. System Requirements & Installation

Prerequisites

  • Operating System: Linux Kernel 5.4+ (BTF - BPF Type Format enabled)
  • Dependencies: clang, llvm, libbpf-dev, bpftool

Quick Installation (CLI Tool & Daemon)

# Install Agent-eBPF CLI and Kernel Daemon
curl -fsSL https://get.agent-ebpf.dev | sh

# Verify daemon status
agent-ebpf status


3. Declarative Security Policy (policy.yaml)

The central rules file defining which behaviors the system classifies as "hallucination/unexpected output" or a "security violation."

Defined in your project's root directory or at /etc/agent-ebpf/policy.yaml:

version: "v1alpha"
metadata:
  name: "production-agent-shield"

rules:
  # 1. Block Destructive SQL Queries (UPDATE/DELETE without WHERE)
  - id: "sql-no-where-mutation"
    type: "db_query"
    protocol: "postgres" # or mysql
    severity: "critical"
    action: "DROP"
    match:
      pattern: '(?i)^(UPDATE|DELETE)\s+((?!WHERE).)*$'
    message: "Destructive SQL mutation lacking a WHERE clause was blocked."

  # 2. Enforce Multi-Tenant Isolation
  - id: "tenant-isolation-enforce"
    type: "db_query"
    protocol: "postgres"
    severity: "high"
    action: "DROP"
    match:
      require_header_context: "X-Tenant-ID"
      must_contain: "tenant_id ="
    message: "SQL query missing required tenant_id filter."

  # 3. Block Prohibited System Calls (Prevent Process Hijacking)
  - id: "block-unsafe-syscalls"
    type: "syscall"
    severity: "critical"
    action: "KILL_PROCESS"
    match:
      syscalls:
        - "execve"
        - "ptrace"
      binary_path_regex: ".*/python.*"
    message: "Agent blocked from spawning unauthorized sub-processes on the system."


4. Loading and Executing the Kernel Module

After defining your security policy, attach the eBPF program directly to the network interface and sockets:

# Validate policy file and load into kernel
agent-ebpf load --config ./policy.yaml --interface eth0

# Monitor active rules live
agent-ebpf monitor

Live Monitoring Output

[AGENT-eBPF] Kernel hooks attached successfully. Listening on sock_ops & uprobes...
[INTERCEPTED] Timestamp: 1716198402 | Rule: sql-no-where-mutation | Latency: 32µs
  ├─ Process: python3 (PID: 41029)
  ├─ Payload: "DELETE FROM users"
  └─ Action: TCP_RST sent to socket (Connection Closed).


5. Testing and Benchmarking

You can use tests/test_shield.py to verify Agent-eBPF's execution speed and blocking capabilities:

import pytest
import psycopg2

def test_blocked_destructive_query():
    """
    Verifies that a query missing a WHERE clause is intercepted in the kernel
    before reaching the application layer while Agent-eBPF runs in the background.
    """
    conn = psycopg2.connect("dbname=app_db user=postgres host=127.0.0.1")
    cursor = conn.cursor()

    # The kernel eBPF rule must drop this query in <50µs.
    with pytest.raises(psycopg2.OperationalError) as exc_info:
        cursor.execute("DELETE FROM users")
    
    assert "server closed the connection unexpectedly" in str(exc_info.value)
    print("\n[SUCCESS] Kernel-level interception confirmed under 50 microseconds.")


6. Production Deployment (Docker & Coolify)

When running in bare-metal or Docker environments, simply add CAP_SYS_ADMIN and CAP_BPF capabilities to your docker-compose.yml to allow inspecting container network sockets:

version: "3.8"

services:
  agent-ebpf-daemon:
    image: ghcr.io/agent-ebpf/daemon:latest
    container_name: agent_ebpf_shield
    network_mode: "host"
    privileged: true
    cap_add:
      - SYS_ADMIN
      - BPF
      - NET_ADMIN
    volumes:
      - /sys/fs/bpf:/sys/fs/bpf
      - /etc/agent-ebpf/policy.yaml:/etc/agent-ebpf/policy.yaml:ro
    restart: always


Summary: Agent-eBPF lets you shield your AI agents at the Linux Kernel level with zero code changes and zero performance overhead.


⚡ Gemini Spark MCP Integration ("Add Custom App Link")

Agent-eBPF includes a native async Model Context Protocol (MCP) Gateway over SSE transport (mcp_server.py). This allows Gemini Spark to control, inspect, and enforce kernel security policies in real-time.

Available MCP Tools for Gemini Spark

  1. 🔍 get_security_status: Inspect live Linux kernel eBPF probes, latency stats (<35µs), and blocked threat counters.
  2. 📋 get_active_policies: Retrieve currently active declarative rules (policy.yaml).
  3. add_security_rule: Dynamically inject new kernel security rules (e.g., blocking unconstrained SQL or prohibited syscalls) directly via Gemini Spark chat.
  4. 🧪 simulate_query_check: Pre-validate SQL queries or commands against active kernel eBPF filters before execution.

How to Connect to Gemini Spark

  1. Start the MCP server:
uvicorn mcp_server:app --host 0.0.0.0 --port 8000

  1. Go to Gemini Spark settings -> Custom apps for Spark -> Add custom app link.
  2. Paste your public SSE endpoint:
https://your-domain.com/sse

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选