โโโโ โโโโ โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโ โโโ โโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโ โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโ โโโโโโโโโโโโโโ โโโโโโโ โโโโโโโโโโโโโโโ โโโโโ โโโ โโโ โโโโโโโโโโโโโโ โโโโโโโโโโโ โโโ โโโ โโโ โโโโโโโโโโ โโโโโโโโโโโ โโโMCPSpy - Real-time monitoring for Model Context Protocol communication using eBPF
MCPSpy is a powerful command-line tool that leverages eBPF (Extended Berkeley Packet Filter) technology to monitor Model Context Protocol (MCP) communication at the kernel level. It provides real-time visibility into JSON-RPC 2.0 messages exchanged between MCP clients and servers by hooking into low-level system calls.
The Model Context Protocol supports three transport protocols for communication:
MCPSpy supports monitoring of both Stdio and HTTP/HTTPS transports (including Server-Sent Events), providing comprehensive coverage of MCP communication channels.

The Model Context Protocol is becoming the standard for AI tool integration, but understanding what's happening under the hood can be challenging. MCPSpy addresses this by providing:
Download the latest release from the release page:
# Set platform-aware binary name
BIN="mcpspy-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')"
# Download the correct binary
wget "https://github.com/alex-ilgayev/mcpspy/releases/latest/download/${BIN}"
# Make it executable and move to a directory in your PATH
chmod +x "${BIN}"
sudo mv "${BIN}" /usr/local/bin/mcpspy
โ Note: Currently supported platforms: linux-amd64, linux-arm64
First, install the required system dependencies:
sudo apt-get update
# Install build essentials, eBPF dependencies
sudo apt-get install -y clang clang-format llvm make libbpf-dev build-essential
# Install Python 3 and pip (for e2e tests)
sudo apt-get install -y python3 python3-pip python3-venv
# Install docker and buildx (if not already installed)
sudo apt-get install -y docker.io docker-buildx
MCPSpy requires Go 1.24 or later. Install Go using one of these methods:
Option 1: Install from the official Go website (Recommended)
# Download and install Go 1.24.1 (adjust version as needed)
wget https://go.dev/dl/go1.24.1.linux-amd64.tar.gz
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.24.1.linux-amd64.tar.gz
# Add Go to PATH (add this to your ~/.bashrc or ~/.profile for persistence)
export PATH=$PATH:/usr/local/go/bin
Option 2: Install via snap
sudo snap install go --classic
Clone the repository and build MCPSpy:
# Clone the repository
git clone https://github.com/alex-ilgayev/mcpspy.git
cd mcpspy
# Build the project
make all
# Build Docker image
make image
# Or pull the latest image
docker pull ghcr.io/alex-ilgayev/mcpspy:latest
# Or pull a specific image release
docker pull ghcr.io/alex-ilgayev/mcpspy:v0.1.0
# Run the container
docker run --rm -it --privileged ghcr.io/alex-ilgayev/mcpspy:latest
MCPSpy can be deployed in Kubernetes clusters to monitor MCP traffic from AI/LLM services like LangFlow, LangGraph, and other applications that use the Model Context Protocol.
# Deploy MCPSpy as a DaemonSet
kubectl apply -f https://raw.githubusercontent.com/alex-ilgayev/mcpspy/main/deploy/kubernetes/mcpspy.yaml
Monitoring LangFlow/LangGraph Deployments
AI Service Monitoring
Development and Testing
For detailed instructions and real-world examples of monitoring AI services in Kubernetes, see the Kubernetes Usage Guide.
# Start monitoring MCP communication (TUI mode is default)
sudo mcpspy
# Start monitoring with static console output (disable TUI)
sudo mcpspy --tui=false
# Start monitoring and save output to JSONL file
sudo mcpspy -o output.jsonl
# Stop monitoring with Ctrl+C (or 'q' in TUI mode)
MCPSpy includes optional real-time prompt injection detection using HuggingFace's Inference API. When enabled, it analyzes MCP tool calls for potential injection attacks and jailbreak attempts.
Detection coverage:
# Enable security scanning with HuggingFace token
sudo mcpspy --security --hf-token=hf_xxxxx
# Use a custom detection model
sudo mcpspy --security --hf-token=hf_xxxxx --security-model=protectai/deberta-v3-base-prompt-injection-v2
# Adjust detection threshold (default: 0.5)
sudo mcpspy --security --hf-token=hf_xxxxx --security-threshold=0.7
# Run analysis synchronously (blocks until analysis completes)
sudo mcpspy --security --hf-token=hf_xxxxx --security-async=false
Security CLI Flags:
| Flag | Description | Default |
|---|---|---|
--security | Enable prompt injection detection | false |
--hf-token | HuggingFace API token (required when security is enabled) | - |
--security-model | HuggingFace model for detection | protectai/deberta-v3-base-prompt-injection-v2 |
--security-threshold | Detection threshold (0.0-1.0) | 0.5 |
--security-async | Run analysis asynchronously | true |
Supported Models:
protectai/deberta-v3-base-prompt-injection-v2 (default, publicly accessible)meta-llama/Llama-Prompt-Guard-2-86M (deprecated on HF Inference API)When a potential injection is detected, MCPSpy displays a security alert with risk level (low/medium/high/critical), category, and the analyzed content.
MCPSpy runs in interactive Terminal UI mode by default. The TUI provides:
When running with --tui=false:
12:34:56.789 python[12345] โ python[12346] REQ tools/call (get_weather) Execute a tool
12:34:56.890 python[12346] โ python[12345] RESP OK
Stdio Transport - Request:
{
"timestamp": "2024-01-15T12:34:56.789Z",
"transport_type": "stdio",
"stdio_transport": {
"from_pid": 12345,
"from_comm": "python",
"to_pid": 12346,
"to_comm": "python"
},
"type": "request",
"id": 7,
"method": "tools/call",
"params": {
"name": "get_weather",
"arguments": { "city": "New York" }
},
"error": {},
"raw": "{...}"
}
Stdio Transport - Response:
{
"timestamp": "2024-01-15T12:34:56.890Z",
"transport_type": "stdio",
"stdio_transport": {
"from_pid": 12346,
"from_comm": "python",
"to_pid": 12345,
"to_comm": "python"
},
"type": "response",
"id": 7,
"result": {
"content": [
{
"type": "text",
"text": "Weather in New York: 20ยฐC"
}
],
"isError": false
},
"error": {},
"request": {
"type": "request",
"id": 7,
"method": "tools/call",
"params": {
"name": "get_weather",
"arguments": { "city": "New York" }
},
"error": {}
},
"raw": "{...}"
}
HTTP/HTTPS Transport - Request:
{
"timestamp": "2024-01-15T12:34:56.789Z",
"transport_type": "http",
"http_transport": {
"pid": 47837,
"comm": "python",
"host": "127.0.0.1:12345",
"is_request": true
},
"type": "request",
"id": 7,
"method": "tools/call",
"params": {
"name": "get_weather",
"arguments": { "city": "New York" }
},
"error": {},
"raw": "{...}"
}
HTTP/HTTPS Transport - Response:
{
"timestamp": "2024-01-15T12:34:56.890Z",
"transport_type": "http",
"http_transport": {
"pid": 47837,
"comm": "python",
"host": "127.0.0.1:12345"
},
"type": "response",
"id": 7,
"result": {
"content": [
{
"type": "text",
"text": "Weather in New York: 20ยฐC"
}
],
"isError": false
},
"error": {},
"request": {
"type": "request",
"id": 7,
"method": "tools/call",
"params": {
"name": "get_weather",
"arguments": { "city": "New York" }
},
"error": {}
},
"raw": "{...}"
}
MCPSpy uses an event-driven architecture with a publish-subscribe pattern to decouple components and enable extensibility. The system consists of several components that communicate through a central event bus:
pkg/bus/)github.com/asaskevich/EventBus librarybpf/)vfs_read and vfs_write kernel functions for stdio transportSSL_read, SSL_write) for HTTP/HTTPS transportpkg/ebpf/)pkg/http/)pkg/mcp/)pkg/output/)pkg/eventlogger/)pkg/security/)tools/call, resources/read, prompts/get)# Generate eBPF bindings and build
make all
# Build Docker image
make image
MCPSpy includes comprehensive end-to-end tests that simulate real MCP communication across different transports:
# (Optional) Set up test environment
make test-e2e-setup
# Run all tests (requires root privileges)
make test-e2e
# Run individual transport tests
make test-e2e-stdio # Test stdio transport
make test-e2e-https # Test HTTP/HTTPS transport
The test suite includes:
read or write syscalls. This means that if an MCP message is larger than the buffer size used in a single syscall, it may be missed or ignored.MCPSpy supports development with AI coding assistants like Claude Code. Since mcpspy requires root privileges for eBPF operations, you need to configure passwordless sudo to enable autonomous test execution.
Create a sudoers rule that allows your user to run mcpspy without a password. The E2E tests use the binary at build/mcpspy-linux-amd64 (or build/mcpspy-linux-arm64 on ARM):
# Option 1: Using visudo (opens editor)
sudo visudo -f /etc/sudoers.d/mcpspy
# Add this line (replace YOUR_USERNAME and adjust path as needed):
# YOUR_USERNAME ALL=(ALL) NOPASSWD: /home/YOUR_USERNAME/mcpspy/build/mcpspy-linux-amd64, /home/YOUR_USERNAME/mcpspy/.worktrees/*/build/mcpspy-linux-amd64
# Option 2: One-liner (replace YOUR_USERNAME and path)
echo 'YOUR_USERNAME ALL=(ALL) NOPASSWD: /home/YOUR_USERNAME/mcpspy/build/mcpspy-linux-amd64, /home/YOUR_USERNAME/mcpspy/.worktrees/*/build/mcpspy-linux-amd64' | sudo tee /etc/sudoers.d/mcpspy && sudo chmod 440 /etc/sudoers.d/mcpspy
The .worktrees/* pattern enables passwordless execution from git worktrees. Note that sudoers * doesn't match /, so both patterns are needed.
After configuration, verify it works:
sudo /path/to/build/mcpspy-linux-amd64 --help # Should not prompt for password
This enables AI assistants to run E2E tests (make test-e2e) which require sudo for eBPF operations.
We welcome contributions! Feel free to open an issue or a pull request.
bpf/*): GPL-2.0-only (see LICENSE-BPF)107 followers ยท starred Aug 2025
1,331 followers ยท starred Sep 2025
191 followers ยท starred Jul 2025
1,476 followers ยท starred Jul 2025
โโโโ โโโโ โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโ โโโ โโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโ โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโ โโโโโโโโโโโโโโ โโโโโโโ โโโโโโโโโโโโโโโ โโโโโ โโโ โโโ โโโโโโโโโโโโโโ โโโโโโโโโโโ โโโ โโโ โโโ โโโโโโโโโโ โโโโโโโโโโโ โโโMCPSpy - Real-time monitoring for Model Context Protocol communication using eBPF
MCPSpy is a powerful command-line tool that leverages eBPF (Extended Berkeley Packet Filter) technology to monitor Model Context Protocol (MCP) communication at the kernel level. It provides real-time visibility into JSON-RPC 2.0 messages exchanged between MCP clients and servers by hooking into low-level system calls.
The Model Context Protocol supports three transport protocols for communication:
MCPSpy supports monitoring of both Stdio and HTTP/HTTPS transports (including Server-Sent Events), providing comprehensive coverage of MCP communication channels.

The Model Context Protocol is becoming the standard for AI tool integration, but understanding what's happening under the hood can be challenging. MCPSpy addresses this by providing:
Download the latest release from the release page:
# Set platform-aware binary name
BIN="mcpspy-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')"
# Download the correct binary
wget "https://github.com/alex-ilgayev/mcpspy/releases/latest/download/${BIN}"
# Make it executable and move to a directory in your PATH
chmod +x "${BIN}"
sudo mv "${BIN}" /usr/local/bin/mcpspy
โ Note: Currently supported platforms: linux-amd64, linux-arm64
First, install the required system dependencies:
sudo apt-get update
# Install build essentials, eBPF dependencies
sudo apt-get install -y clang clang-format llvm make libbpf-dev build-essential
# Install Python 3 and pip (for e2e tests)
sudo apt-get install -y python3 python3-pip python3-venv
# Install docker and buildx (if not already installed)
sudo apt-get install -y docker.io docker-buildx
MCPSpy requires Go 1.24 or later. Install Go using one of these methods:
Option 1: Install from the official Go website (Recommended)
# Download and install Go 1.24.1 (adjust version as needed)
wget https://go.dev/dl/go1.24.1.linux-amd64.tar.gz
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.24.1.linux-amd64.tar.gz
# Add Go to PATH (add this to your ~/.bashrc or ~/.profile for persistence)
export PATH=$PATH:/usr/local/go/bin
Option 2: Install via snap
sudo snap install go --classic
Clone the repository and build MCPSpy:
# Clone the repository
git clone https://github.com/alex-ilgayev/mcpspy.git
cd mcpspy
# Build the project
make all
# Build Docker image
make image
# Or pull the latest image
docker pull ghcr.io/alex-ilgayev/mcpspy:latest
# Or pull a specific image release
docker pull ghcr.io/alex-ilgayev/mcpspy:v0.1.0
# Run the container
docker run --rm -it --privileged ghcr.io/alex-ilgayev/mcpspy:latest
MCPSpy can be deployed in Kubernetes clusters to monitor MCP traffic from AI/LLM services like LangFlow, LangGraph, and other applications that use the Model Context Protocol.
# Deploy MCPSpy as a DaemonSet
kubectl apply -f https://raw.githubusercontent.com/alex-ilgayev/mcpspy/main/deploy/kubernetes/mcpspy.yaml
Monitoring LangFlow/LangGraph Deployments
AI Service Monitoring
Development and Testing
For detailed instructions and real-world examples of monitoring AI services in Kubernetes, see the Kubernetes Usage Guide.
# Start monitoring MCP communication (TUI mode is default)
sudo mcpspy
# Start monitoring with static console output (disable TUI)
sudo mcpspy --tui=false
# Start monitoring and save output to JSONL file
sudo mcpspy -o output.jsonl
# Stop monitoring with Ctrl+C (or 'q' in TUI mode)
MCPSpy includes optional real-time prompt injection detection using HuggingFace's Inference API. When enabled, it analyzes MCP tool calls for potential injection attacks and jailbreak attempts.
Detection coverage:
# Enable security scanning with HuggingFace token
sudo mcpspy --security --hf-token=hf_xxxxx
# Use a custom detection model
sudo mcpspy --security --hf-token=hf_xxxxx --security-model=protectai/deberta-v3-base-prompt-injection-v2
# Adjust detection threshold (default: 0.5)
sudo mcpspy --security --hf-token=hf_xxxxx --security-threshold=0.7
# Run analysis synchronously (blocks until analysis completes)
sudo mcpspy --security --hf-token=hf_xxxxx --security-async=false
Security CLI Flags:
| Flag | Description | Default |
|---|---|---|
--security | Enable prompt injection detection | false |
--hf-token | HuggingFace API token (required when security is enabled) | - |
--security-model | HuggingFace model for detection | protectai/deberta-v3-base-prompt-injection-v2 |
--security-threshold | Detection threshold (0.0-1.0) | 0.5 |
--security-async | Run analysis asynchronously | true |
Supported Models:
protectai/deberta-v3-base-prompt-injection-v2 (default, publicly accessible)meta-llama/Llama-Prompt-Guard-2-86M (deprecated on HF Inference API)When a potential injection is detected, MCPSpy displays a security alert with risk level (low/medium/high/critical), category, and the analyzed content.
MCPSpy runs in interactive Terminal UI mode by default. The TUI provides:
When running with --tui=false:
12:34:56.789 python[12345] โ python[12346] REQ tools/call (get_weather) Execute a tool
12:34:56.890 python[12346] โ python[12345] RESP OK
Stdio Transport - Request:
{
"timestamp": "2024-01-15T12:34:56.789Z",
"transport_type": "stdio",
"stdio_transport": {
"from_pid": 12345,
"from_comm": "python",
"to_pid": 12346,
"to_comm": "python"
},
"type": "request",
"id": 7,
"method": "tools/call",
"params": {
"name": "get_weather",
"arguments": { "city": "New York" }
},
"error": {},
"raw": "{...}"
}
Stdio Transport - Response:
{
"timestamp": "2024-01-15T12:34:56.890Z",
"transport_type": "stdio",
"stdio_transport": {
"from_pid": 12346,
"from_comm": "python",
"to_pid": 12345,
"to_comm": "python"
},
"type": "response",
"id": 7,
"result": {
"content": [
{
"type": "text",
"text": "Weather in New York: 20ยฐC"
}
],
"isError": false
},
"error": {},
"request": {
"type": "request",
"id": 7,
"method": "tools/call",
"params": {
"name": "get_weather",
"arguments": { "city": "New York" }
},
"error": {}
},
"raw": "{...}"
}
HTTP/HTTPS Transport - Request:
{
"timestamp": "2024-01-15T12:34:56.789Z",
"transport_type": "http",
"http_transport": {
"pid": 47837,
"comm": "python",
"host": "127.0.0.1:12345",
"is_request": true
},
"type": "request",
"id": 7,
"method": "tools/call",
"params": {
"name": "get_weather",
"arguments": { "city": "New York" }
},
"error": {},
"raw": "{...}"
}
HTTP/HTTPS Transport - Response:
{
"timestamp": "2024-01-15T12:34:56.890Z",
"transport_type": "http",
"http_transport": {
"pid": 47837,
"comm": "python",
"host": "127.0.0.1:12345"
},
"type": "response",
"id": 7,
"result": {
"content": [
{
"type": "text",
"text": "Weather in New York: 20ยฐC"
}
],
"isError": false
},
"error": {},
"request": {
"type": "request",
"id": 7,
"method": "tools/call",
"params": {
"name": "get_weather",
"arguments": { "city": "New York" }
},
"error": {}
},
"raw": "{...}"
}
MCPSpy uses an event-driven architecture with a publish-subscribe pattern to decouple components and enable extensibility. The system consists of several components that communicate through a central event bus:
pkg/bus/)github.com/asaskevich/EventBus librarybpf/)vfs_read and vfs_write kernel functions for stdio transportSSL_read, SSL_write) for HTTP/HTTPS transportpkg/ebpf/)pkg/http/)pkg/mcp/)pkg/output/)pkg/eventlogger/)pkg/security/)tools/call, resources/read, prompts/get)# Generate eBPF bindings and build
make all
# Build Docker image
make image
MCPSpy includes comprehensive end-to-end tests that simulate real MCP communication across different transports:
# (Optional) Set up test environment
make test-e2e-setup
# Run all tests (requires root privileges)
make test-e2e
# Run individual transport tests
make test-e2e-stdio # Test stdio transport
make test-e2e-https # Test HTTP/HTTPS transport
The test suite includes:
read or write syscalls. This means that if an MCP message is larger than the buffer size used in a single syscall, it may be missed or ignored.MCPSpy supports development with AI coding assistants like Claude Code. Since mcpspy requires root privileges for eBPF operations, you need to configure passwordless sudo to enable autonomous test execution.
Create a sudoers rule that allows your user to run mcpspy without a password. The E2E tests use the binary at build/mcpspy-linux-amd64 (or build/mcpspy-linux-arm64 on ARM):
# Option 1: Using visudo (opens editor)
sudo visudo -f /etc/sudoers.d/mcpspy
# Add this line (replace YOUR_USERNAME and adjust path as needed):
# YOUR_USERNAME ALL=(ALL) NOPASSWD: /home/YOUR_USERNAME/mcpspy/build/mcpspy-linux-amd64, /home/YOUR_USERNAME/mcpspy/.worktrees/*/build/mcpspy-linux-amd64
# Option 2: One-liner (replace YOUR_USERNAME and path)
echo 'YOUR_USERNAME ALL=(ALL) NOPASSWD: /home/YOUR_USERNAME/mcpspy/build/mcpspy-linux-amd64, /home/YOUR_USERNAME/mcpspy/.worktrees/*/build/mcpspy-linux-amd64' | sudo tee /etc/sudoers.d/mcpspy && sudo chmod 440 /etc/sudoers.d/mcpspy
The .worktrees/* pattern enables passwordless execution from git worktrees. Note that sudoers * doesn't match /, so both patterns are needed.
After configuration, verify it works:
sudo /path/to/build/mcpspy-linux-amd64 --help # Should not prompt for password
This enables AI assistants to run E2E tests (make test-e2e) which require sudo for eBPF operations.
We welcome contributions! Feel free to open an issue or a pull request.
bpf/*): GPL-2.0-only (see LICENSE-BPF)107 followers ยท starred Aug 2025
1,331 followers ยท starred Sep 2025
191 followers ยท starred Jul 2025
1,476 followers ยท starred Jul 2025